*/
#include <stdio.h>
-#define NUM_ECORE_EVENT_HANDLERS 4
+#include <unistd.h>
+
+#define NUM_ECORE_EVENT_HANDLERS 7
+
+/* pre-requisite to use ecore_wl2 APIs */
#define EFL_BETA_API_SUPPORT
#include <Ecore_Wl2.h>
#include <Ecore_Input.h>
#include <PUI.h>
+int gpid;
+
#define debug_error(msg, ...) \
do { \
- fprintf(stderr, "[ERROR][%s] " msg, __FUNCTION__, ##__VA_ARGS__); \
+ fprintf(stderr, "[PUI sample][ERROR][PID:%d][%s] " msg, gpid, __FUNCTION__, ##__VA_ARGS__); \
} while(0)
#define debug_info(msg, ...) \
do { \
- fprintf(stdout, "[INFO][%s] " msg, __FUNCTION__, ##__VA_ARGS__); \
+ fprintf(stdout, "[PUI sample][INFO][PID:%d][%s] " msg, gpid, __FUNCTION__, ##__VA_ARGS__); \
} while(0)
typedef struct _animation animation_t;
struct app_data
{
pui_h ph;
- pui_ani_h ani_h;
+ int ani_idx;
+ int n_animation;
Ecore_Wl2_Display *ewd;
Ecore_Wl2_Window *win;
static Eina_Array *_ecore_event_hdls = NULL;
static animation_t ani_collection[] = {
- { "processing", PUI_ANI_CMD_START, -1 },
- { "listening", PUI_ANI_CMD_START, -1 },
- { "speaking", PUI_ANI_CMD_START, -1 },
- { "streaming", PUI_ANI_CMD_START, -1 },
-#if 0
{ "alarm calm", PUI_ANI_CMD_START, 1 },
{ "bixby listening", PUI_ANI_CMD_START, -1 },
{ "bixby speaking", PUI_ANI_CMD_START, -1 },
{ "bixby_error", PUI_ANI_CMD_START, 1 },
{ "blinking", PUI_ANI_CMD_START, -1 },
{ "notification", PUI_ANI_CMD_START, -1 },
-#endif
};
-static void
-ani_stop(app_data_t *app)
-{
- pui_error e = PUI_ERROR_NONE;
-
- debug_info("Animation(%s) will be stopped !\n", pui_ani_get_id(app->ani_h));
-
- /* stop animation running already */
- e = pui_ani_control(app->ani_h, PUI_ANI_CMD_STOP, 0);
-
- if (PUI_ERROR_NONE != e)
- {
- debug_error("Failed on stopping an animation !(cmd:%d, repeat:%d)\n", PUI_ANI_CMD_STOP, 0);
- return;
- }
-}
+pui_ani_h ani_handles[sizeof(ani_collection) / sizeof(animation_t)];
static void
ani_collection_play(app_data_t *app)
{
- static int ani_idx = 0;
- int n_animation = 0;
- pui_ani_h ani_h = NULL;
pui_error e = PUI_ERROR_NONE;
-
- n_animation = sizeof(ani_collection) / sizeof(animation_t);
-
- if (n_animation < 0)
- {
- debug_error("No animation is available ! (n_animation=%d)\n", n_animation);
- return;
- }
+ pui_ani_h ani_h = NULL;
if (!app->ph)
{
return;
}
- if (app->ani_h)
+ while (!ani_handles[app->ani_idx])
{
- /* stop animation running already */
- ani_stop(app);
- pui_ani_destroy(app->ani_h);
- app->ani_h = NULL;
- }
-
- ani_h = pui_ani_create(app->ph, ani_collection[ani_idx].id);
-
- if (!ani_h)
- {
- debug_error("Failed to create new PUI animation handle !\n");
-
- if (++ani_idx >= n_animation)
- ani_idx = 0;
+ app->ani_idx++;
- return;
+ if (++app->ani_idx >= app->n_animation)
+ app->ani_idx = 0;
}
- app->ani_h = ani_h;
-
- debug_info("Animation(%s) will be started !\n", pui_ani_get_id(app->ani_h));
+ debug_info("Animation(%s) will be started !\n", pui_ani_get_id(ani_handles[app->ani_idx]));
/* play animation */
- e = pui_ani_control(app->ani_h, PUI_ANI_CMD_START, ani_collection[ani_idx].repeat);
+ ani_h = ani_handles[app->ani_idx];
+ e = pui_ani_control(ani_h, PUI_ANI_CMD_START, ani_collection[app->ani_idx].repeat);
if (PUI_ERROR_NONE != e)
{
- debug_error("Failed on playing an animation ! (cmd:%d, repeat:%d)\n", PUI_ANI_CMD_START, ani_collection[ani_idx].repeat);
+ debug_error("Failed on playing an animation ! (cmd:%d, repeat:%d)\n", PUI_ANI_CMD_START, ani_collection[app->ani_idx].repeat);
return;
}
- if (++ani_idx >= n_animation)
- ani_idx = 0;
+ if (++app->ani_idx >= app->n_animation)
+ app->ani_idx = 0;
return;
}
app_data_t *app = (app_data_t *)data;
Ecore_Wl2_Event_Window_Visibility_Change *ev;
+ (void) app;
ev = event;
-
debug_info("Visibility change (window=0x%x, fully_obscured=%d)\n", ev->win, ev->fully_obscured);
- if (ev->fully_obscured)
- {
- debug_info("Loose LED control !\n");
- ani_stop(app);
- }
- else
- {
- debug_info("Gain LED control !\n");
- ani_collection_play(app);
- }
+ return ECORE_CALLBACK_PASS_ON;
+}
+
+static Eina_Bool
+_cb_ani_started(void *data, int type EINA_UNUSED, void *event)
+{
+ app_data_t *app = (app_data_t *)data;
+ PUI_Event_Animation_Status *ev;
+
+ (void) app;
+ ev = event;
+ debug_info("[%s] ani id=%s, status=%d, window=0x%x\n", __FUNCTION__, pui_ani_get_id(ev->ani_h), ev->status, ev->win);
+
+ return ECORE_CALLBACK_PASS_ON;
+}
+
+static Eina_Bool
+_cb_ani_stopped(void *data, int type EINA_UNUSED, void *event)
+{
+ app_data_t *app = (app_data_t *)data;
+ PUI_Event_Animation_Status *ev;
+
+ (void) app;
+ ev = event;
+ debug_info("[%s] ani id=%s, status=%d, window=0x%x\n", __FUNCTION__, pui_ani_get_id(ev->ani_h), ev->status, ev->win);
+
+ /* decrease animation idx for starting from stopped animation */
+ app->ani_idx--;
+
+ return ECORE_CALLBACK_PASS_ON;
+}
+
+static Eina_Bool
+_cb_ani_ready_to_start(void *data, int type EINA_UNUSED, void *event)
+{
+ app_data_t *app = (app_data_t *)data;
+ PUI_Event_Animation_Status *ev;
+
+ (void) app;
+ ev = event;
+ debug_info("[%s] ani id=%s, status=%d, window=0x%x\n", __FUNCTION__, pui_ani_get_id(ev->ani_h), ev->status, ev->win);
+
+ /* start animation */
+ ani_collection_play(app);
return ECORE_CALLBACK_PASS_ON;
}
h = ecore_event_handler_add(ECORE_WL2_EVENT_WINDOW_VISIBILITY_CHANGE, _cb_visibility_change, app);
eina_array_push(_ecore_event_hdls, h);
+
+ h = ecore_event_handler_add(PUI_EVENT_ANI_STARTED, _cb_ani_started, app);
+ eina_array_push(_ecore_event_hdls, h);
+
+ h = ecore_event_handler_add(PUI_EVENT_ANI_STOPPED, _cb_ani_stopped, app);
+ eina_array_push(_ecore_event_hdls, h);
+
+ h = ecore_event_handler_add(PUI_EVENT_ANI_READY_TO_START, _cb_ani_ready_to_start, app);
+ eina_array_push(_ecore_event_hdls, h);
}
int main()
app_data_t *app = NULL;
const char *socket_name = NULL;
+ gpid = getpid();
+
if (!ecore_wl2_init())
{
- fprintf(stderr, "Failed to init ecore wl2 !\n");
+ debug_error("Failed to init ecore wl2 !\n");
return EXIT_SUCCESS;
}
goto err;
}
+ app->ani_idx = 0;
app->ewd = ecore_wl2_display_connect(socket_name);
if (!app->ewd)
goto err;
}
+ app->n_animation = sizeof(ani_collection) / sizeof(animation_t);
+
+ for(int i=0;i<app->n_animation;i++)
+ {
+ ani_handles[i] = pui_ani_create(app->ph, ani_collection[i].id);
+
+ if (!ani_handles[i])
+ debug_error("Failed to create pui ani handle !(id:%s)\n", ani_collection[i].id);
+ }
+
event_handlers_init(app);
ecore_main_loop_begin();
err:
- if (app->ani_h)
- pui_ani_destroy(app->ani_h);
+ if (app->n_animation > 0)
+ {
+ for(int i=0;i<app->n_animation;i++)
+ {
+ pui_ani_destroy(ani_handles[i]);
+ }
+ }
+
if (app->ph)
pui_destroy(app->ph);