+++ /dev/null
-/*
- * Copyright © 2019 Samsung Electronics co., Ltd. All Rights Reserved.
- *
- * Permission is hereby granted, free of charge, to any person obtaining
- * a copy of this software and associated documentation files (the
- * "Software"), to deal in the Software without restriction, including
- * without limitation the rights to use, copy, modify, merge, publish,
- * distribute, sublicense, and/or sell copies of the Software, and to
- * permit persons to whom the Software is furnished to do so, subject to
- * the following conditions:
- *
- * The above copyright notice and this permission notice (including the
- * next paragraph) shall be included in all copies or substantial
- * portions of the Software.
- *
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
- * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
- * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
- * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
- * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
- * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
- * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
- * SOFTWARE.
- */
-
-#include <stdio.h>
-#include <unistd.h>
-
-#define NUM_ECORE_EVENT_HANDLERS 7
-
-/* pre-requisite to use ecore_wl2 APIs */
-#define EFL_BETA_API_SUPPORT
-
-#define MAX_STR 1024
-
-#include <Ecore_Wl2.h>
-#include <Ecore_Input.h>
-#include <PUI.h>
-
-int gpid;
-
-#define debug_error(msg, ...) \
- do { \
- fprintf(stderr, "[PUI sample][ERROR][PID:%d][%s] " msg, gpid, __FUNCTION__, ##__VA_ARGS__); \
- } while(0)
-
-#define debug_info(msg, ...) \
- do { \
- fprintf(stdout, "[PUI sample][INFO][PID:%d][%s] " msg, gpid, __FUNCTION__, ##__VA_ARGS__); \
- } while(0)
-
-typedef struct _animation animation_t;
-struct _animation
-{
- pui_id id;
- pui_ani_cmd cmd;
- int repeat;
-};
-
-typedef struct app_data app_data_t;
-struct app_data
-{
- pui_h ph;
- int ani_idx;
- int n_animation;
- int manual_idx;
-
- Ecore_Wl2_Display *ewd;
- Ecore_Wl2_Window *win;
-};
-
-static Eina_Array *_ecore_event_hdls = NULL;
-static animation_t ani_collection[] = {
- { "system/easy_setup", PUI_ANI_CMD_START, -1 },
- { "system/processing", PUI_ANI_CMD_START, -1 },
- { "system/sw_update_done", PUI_ANI_CMD_START, 1 },
- { "system/mic_off", PUI_ANI_CMD_START, 1 },
- { "voice/listening", PUI_ANI_CMD_START, 1 },
- { "voice/streaming", PUI_ANI_CMD_START, -1 },
- { "voice/processing", PUI_ANI_CMD_START, -1 },
- { "voice/speaking", PUI_ANI_CMD_START, -1 },
- { "voice/timeout", PUI_ANI_CMD_START, 1 },
- { "notification/normal", PUI_ANI_CMD_START, 1 },
- { "notification/emergency", PUI_ANI_CMD_START, -1 },
- { "notification/network_error", PUI_ANI_CMD_START, -1 },
- { "notification/error", PUI_ANI_CMD_START, -1 },
- { "notification/alarm", PUI_ANI_CMD_START, 1 },
- { "bt/pairing", PUI_ANI_CMD_START, -1 },
- { "bt/connected", PUI_ANI_CMD_START, 3 }
-};
-
-pui_ani_h ani_handles[sizeof(ani_collection) / sizeof(animation_t)];
-
-static void
-ani_collection_play(app_data_t *app)
-{
- pui_error e = PUI_ERROR_NONE;
- pui_ani_h ani_h = NULL;
-
- if (!app->ph)
- {
- debug_error("Invalid pui_h handle !\n");
- return;
- }
-
- while (!ani_handles[app->ani_idx])
- {
- app->ani_idx++;
-
- if (++app->ani_idx >= app->n_animation)
- app->ani_idx = 0;
- }
-
- debug_info("Animation(%s) will be started !\n", pui_ani_get_id(ani_handles[app->ani_idx]));
-
- /* play animation */
- 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[app->ani_idx].repeat);
- return;
- }
-
- if (++app->ani_idx >= app->n_animation)
- app->ani_idx = 0;
-
- return;
-}
-
-static Eina_Bool
-_cb_key_up(void *data EINA_UNUSED, int type EINA_UNUSED, void *event)
-{
- app_data_t *app = (app_data_t *)data;
- Ecore_Event_Key *ev = event;
-
- debug_info("KEY: name:%s, sym:%s, code:%d\n", ev->keyname, ev->key, ev->keycode);
-
- ani_collection_play(app);
-
- return ECORE_CALLBACK_PASS_ON;
-}
-
-static Eina_Bool
-_cb_focus_in(void *data, int type EINA_UNUSED, void *event)
-{
- app_data_t *app = (app_data_t *)data;
- Ecore_Wl2_Event_Focus_In *ev = (Ecore_Wl2_Event_Focus_In *)event;
-
- debug_info("\n");
-
- /* TODO */
- (void) app;
- (void) ev;
-
- return ECORE_CALLBACK_PASS_ON;
-}
-
-static Eina_Bool
-_cb_focus_out(void *data, int type EINA_UNUSED, void *event)
-{
- app_data_t *app = (app_data_t *)data;
- Ecore_Wl2_Event_Focus_Out *ev = (Ecore_Wl2_Event_Focus_Out *)event;
-
- debug_info("\n");
-
- /* TODO */
- (void) app;
- (void) ev;
-
- return ECORE_CALLBACK_PASS_ON;
-}
-
-static Eina_Bool
-_cb_visibility_change(void *data, int type EINA_UNUSED, void *event)
-{
- 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);
-
- 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_resume(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);
-
- /* resume animation */
- app->ani_idx--;
- ani_collection_play(app);
-
- return ECORE_CALLBACK_PASS_ON;
-}
-
-static void
-_ani_play(app_data_t *app, const char *ani_type, int repeat)
-{
- pui_error e = PUI_ERROR_NONE;
- pui_ani_h ani_h = NULL;
- int idx = -1;
-
- if (!app->ph)
- {
- debug_error("Invalid pui_h handle !\n");
- return;
- }
-
- for (int i = 0; i < app->n_animation; i++)
- {
- if (!strncmp(ani_collection[i].id, ani_type, strlen(ani_type)))
- {
- idx = i;
- break;
- }
- }
- if (idx < 0)
- {
- debug_error("%s is not supported animation id.\n", ani_type);
- return;
- }
-
- debug_info("Animation(%s) will be started !\n", pui_ani_get_id(ani_handles[idx]));
-
- /* play animation */
- ani_h = ani_handles[idx];
- e = pui_ani_control(ani_h, PUI_ANI_CMD_START, repeat);
-
- if (PUI_ERROR_NONE != e)
- {
- debug_error("Failed on playing an animation ! (cmd:%d, repeat:%d)\n", PUI_ANI_CMD_START, repeat);
- return;
- }
-
- app->manual_idx = idx;
-}
-
-static void
-_ani_stop(app_data_t *app)
-{
- pui_error e = PUI_ERROR_NONE;
- pui_ani_h ani_h = NULL;
-
- if (!app->ph)
- {
- debug_error("Invalid pui_h handle !\n");
- return;
- }
-
- if (app->manual_idx < 0)
- {
- debug_info("manual animation is not started\n");
- return;
- }
-
- debug_info("Animation(%s) will be stop !\n", pui_ani_get_id(ani_handles[app->manual_idx]));
-
- /* play animation */
- ani_h = ani_handles[app->manual_idx];
- e = pui_ani_control(ani_h, PUI_ANI_CMD_STOP, -1);
-
- if (PUI_ERROR_NONE != e)
- {
- debug_error("Failed on stop an animation ! (cmd:%d)\n", PUI_ANI_CMD_STOP);
- }
-
- app->manual_idx = -1;
-}
-
-
-static void
-_usage(void)
-{
- printf(" Supported commands: help (Print this help text)\n");
- printf(" : q/quit (Quit program)\n");
- printf(" : play {ani_id} {repeat} (play manual animation)\n");
- printf(" ex> play system/processing 2\n");
- printf(" : stop (stop manual animation)\n");
- printf("\n");
-}
-
-static void
-_process_options(app_data_t *app, char *options)
-{
- char *tmp, *buf_ptr;
- int count = 0;
- char ani_type[MAX_STR] = {0, };
- int repeat = 0;
-
- tmp = strtok_r(options, " ", &buf_ptr);
- if (!tmp) return;
-
- if (!strncmp(options, "q", MAX_STR) || !strncmp(options, "quit", MAX_STR)) {
- ecore_main_loop_quit();
- }
- else if (!strncmp(options, "help", MAX_STR)) {
- _usage();
- }
- else if (!strncmp(tmp, "play", sizeof("play"))) {
- while (tmp) {
- tmp = strtok_r(NULL, " ", &buf_ptr);
- if (tmp) {
- switch (count) {
- case 0:
- strncpy(ani_type, tmp, MAX_STR - 1);
- break;
- case 1:
- repeat = atoi(tmp);
- break;
- default:
- break;
- }
- }
- count++;
- }
- if (strlen(ani_type) <= 0) {
- printf("Please input valid arguments for ani type\n");
- _usage();
- }
- else
- _ani_play(app, ani_type, repeat);
- }
- else if (!strncmp(tmp, "stop", sizeof("stop"))) {
- _ani_stop(app);
- }
- else {
- printf("Invalid arguments\n");
- _usage();
- }
-}
-
-static Eina_Bool
-_stdin_cb(void *data, Ecore_Fd_Handler *handler EINA_UNUSED)
-{
- app_data_t *app = (app_data_t *)data;
- char c, buf[MAX_STR] = {0, };
- int count = 0;
-
- while ((c = getchar()) != EOF) {
- if (c == '\n') break;
- if (count >= MAX_STR) break;
-
- buf[count] = c;
- count++;
- }
-
- _process_options(app, buf);
-
- return ECORE_CALLBACK_RENEW;
-}
-
-
-static void
-event_handlers_init(app_data_t *app)
-{
- Ecore_Event_Handler *h = NULL;
- _ecore_event_hdls = eina_array_new(NUM_ECORE_EVENT_HANDLERS);
-
- h = ecore_event_handler_add(ECORE_EVENT_KEY_UP, _cb_key_up, app);
- eina_array_push(_ecore_event_hdls, h);
-
- h = ecore_event_handler_add(ECORE_WL2_EVENT_FOCUS_IN, _cb_focus_in, app);
- eina_array_push(_ecore_event_hdls, h);
-
- h = ecore_event_handler_add(ECORE_WL2_EVENT_FOCUS_OUT, _cb_focus_out, app);
- eina_array_push(_ecore_event_hdls, h);
-
- 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_RESUME, _cb_ani_ready_to_resume, app);
- eina_array_push(_ecore_event_hdls, h);
-}
-
-int main(int argc, char **argv)
-{
- app_data_t *app = NULL;
- const char *socket_name = NULL;
-
- gpid = getpid();
-
- if (!ecore_wl2_init())
- {
- debug_error("Failed to init ecore wl2 !\n");
- return EXIT_SUCCESS;
- }
-
- socket_name = getenv("WAYLAND_DISPLAY");
-
- if (!socket_name)
- socket_name = "wayland-0";
-
- app = (app_data_t *)calloc(1, sizeof(app_data_t));
-
- if (!app)
- {
- debug_error("Failed to allocate app data !\n");
- goto err;
- }
-
- app->ani_idx = 0;
- app->manual_idx = -1;
- app->ewd = ecore_wl2_display_connect(socket_name);
-
- if (!app->ewd)
- {
- debug_error("Failed to connect to display !\n");
- goto err;
- }
-
- app->win = ecore_wl2_window_new(app->ewd, NULL, 0, 0, 1, 1);
-
- if (!app->win)
- {
- debug_error("Failed to create a window !\n");
- goto err;
- }
-
- ecore_wl2_window_alpha_set(app->win, EINA_FALSE);
- ecore_wl2_window_show(app->win);
- ecore_wl2_window_commit(app->win, EINA_TRUE);
- ecore_wl2_window_activate(app->win);
-
- if (!pui_init())
- {
- debug_error("Failed to init pui !\n");
- goto err;
- }
-
- app->ph = pui_create(app->win);
-
- if (!app->ph)
- {
- debug_error("Failed to create PUI handle !\n");
- 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);
- if (argc >= 2 && !strncmp(argv[1], "stdin", sizeof("stdin")))
- {
- ecore_main_fd_handler_add(STDIN_FILENO, ECORE_FD_READ, _stdin_cb, app, NULL, NULL);
- }
-
- ecore_main_loop_begin();
-err:
- 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);
-
- pui_shutdown();
- ecore_wl2_shutdown();
-
- return EXIT_SUCCESS;
-}