From: saerome.kim Date: Tue, 16 Jan 2018 06:08:42 +0000 (+0900) Subject: demo: add demo application & fixed build warnings X-Git-Tag: submit/tizen/20190131.065036~213 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=22187fd562008e4d67fcdf496321b8c16fbe28f3;p=platform%2Fcore%2Fapi%2Fmulti-device-group.git demo: add demo application & fixed build warnings Signed-off-by: saerome.kim --- diff --git a/capi/demo/CMakeLists.txt b/capi/demo/CMakeLists.txt old mode 100755 new mode 100644 index 840c827..c46601a --- a/capi/demo/CMakeLists.txt +++ b/capi/demo/CMakeLists.txt @@ -1,7 +1,9 @@ SET(COMP_DEMO "companion_demo") SET(COMP_DEMO_SOURCES - companion_demo.c + main.c + menu.c + comp-manager.c ) ADD_EXECUTABLE(${COMP_DEMO} ${COMP_DEMO_SOURCES}) diff --git a/capi/demo/common.h b/capi/demo/common.h new file mode 100644 index 0000000..a14df50 --- /dev/null +++ b/capi/demo/common.h @@ -0,0 +1,30 @@ +/* + * Copyright (c) 2016 Samsung Electronics Co., Ltd. All rights reserved. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + */ + +#ifndef __COMMON_H__ +#define __COMMON_H__ + +#include + +__BEGIN_DECLS + +const char* comp_error_to_string(comp_error_e err); +const char *comp_group_type_to_string(companion_group_type_e e); + +__END_DECLS + +#endif /** __COMMON_H__ */ diff --git a/capi/demo/comp-manager.c b/capi/demo/comp-manager.c new file mode 100644 index 0000000..b26f0ec --- /dev/null +++ b/capi/demo/comp-manager.c @@ -0,0 +1,267 @@ + +/* + * Copyright (c) 2016 Samsung Electronics Co., Ltd. All rights reserved. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + */ + +#include +#include +#include +#include +#include +#include +#include + +#include "menu.h" +#include "common.h" + +GList *found_group_list; +GList *found_device_list; + +static char groupid[MENU_DATA_SIZE + 1] = "mygroup"; +static char timeout[MENU_DATA_SIZE + 1] = "1"; +static char group_idx[MENU_DATA_SIZE + 1] = "1"; + +static void _group_leave_finish_cb(int result, void *user_data) +{ + msgb("leave operation finished"); +} + +static int run_group_leave(MManager *mm, struct menu_data *menu) +{ + int ret; + int idx; + companion_group_h *group; + + msg("Leave Group"); + + if (strlen(group_idx)) { + idx = (unsigned short)strtol(group_idx, NULL, 10); + if (0 >= idx) { + msgp("Invalid index. set to 1"); + idx = 1; + } + } + + if (found_group_list) { + group = g_list_nth_data(found_group_list, idx - 1); + if (NULL == group) { + msgr("Failed to g_hash_table_find"); + return RET_FAILURE; + } + } + + ret = companion_group_leave(group, _group_leave_finish_cb, NULL); + if (COMP_ERROR_NONE != ret) { + msgr("Failed to Leave Group: [%s(0x%X)]", comp_error_to_string(ret), ret); + return RET_FAILURE; + } + msg(" - companion_group_leave() ret: [0x%X] [%s]", ret, comp_error_to_string(ret)); + + return RET_SUCCESS; +} + +static int run_group_show(MManager *mm, struct menu_data *menu) +{ + char *rt; + char *uri; + companion_group_type_e type; + companion_group_h group; + + int i; + GList *iter = NULL; + + /* Get a first item */ + i = 0; + iter = g_list_first(found_group_list); + while (NULL != iter) { + group = iter->data; + if (group) { + msgr("groups is null"); + break; + } + companion_group_information_get_type(group, &type); + companion_group_information_get_uri_path(group, &uri); + companion_group_information_get_resource_type(group, &rt); + msgb("[%d] type:%s, URI: %s RT: %s", i+1, + comp_group_type_to_string(type), uri, rt); + free(uri); + free(rt); + /* Next item */ + iter = g_list_next(iter); + i++; + } + + return RET_SUCCESS; +} + +static void _group_join_finish_cb(int result, void *user_data) +{ + msgb("join operation finished"); +} + +static int run_group_join(MManager *mm, struct menu_data *menu) +{ + int ret; + int idx; + companion_group_h *group; + + msg("Join Group"); + + if (strlen(group_idx)) { + idx = (unsigned short)strtol(group_idx, NULL, 10); + if (0 >= idx) { + msgp("Invalid index. set to 1"); + idx = 1; + } + } + + if (found_group_list) { + group = g_list_nth_data(found_group_list, idx - 1); + if (NULL == group) { + msgr("Failed to g_hash_table_find"); + return RET_FAILURE; + } + } + + ret = companion_group_join(group, _group_join_finish_cb, NULL); + if (COMP_ERROR_NONE != ret) { + msgr("Failed to Join Group: [%s(0x%X)]", comp_error_to_string(ret), ret); + return RET_FAILURE; + } + msg(" - companion_group_join() ret: [0x%X] [%s]", ret, comp_error_to_string(ret)); + + return RET_SUCCESS; +} + +static int run_group_get_found(MManager *mm, struct menu_data *menu) +{ + int ret; + int count; + companion_group_h *groups; + + msg("Get Found Groups"); + + ret = companion_group_get_found_groups(&groups, &count); + if (COMP_ERROR_NONE != ret) { + msgr("Failed to Get Found Groups: [%s(0x%X)]", comp_error_to_string(ret), ret); + return RET_FAILURE; + } + msg(" - companion_group_get_found_groups() ret: [0x%X] [%s]", ret, comp_error_to_string(ret)); + + for (int i = 0; i < count; i++) { + companion_group_type_e type; + char *uri_path; + companion_group_information_get_type(groups[i], &type); + companion_group_information_get_uri_path(groups[i], &uri_path); + msgb("%d. type : %d, uri path : %s", i+1, type, uri_path); + found_group_list = g_list_prepend(found_group_list, groups[i]); + } + + return RET_SUCCESS; +} + +bool _group_found_cb(companion_group_type_e type, companion_group_h group, void *user_data) +{ + char *uri_path; + + companion_group_information_get_uri_path(group, &uri_path); + + msgb("found group type : %d, uri : %s", type, uri_path); + + found_group_list = g_list_prepend(found_group_list, group); + + return TRUE; +} + +void _group_finish_cb(int result, void *user_data) +{ + msgb("find operation finished"); +} + +static int run_group_find(MManager *mm, struct menu_data *menu) +{ + int ret; + int duration; + msg("Find Group"); + + if (strlen(timeout)) + duration = (unsigned short)strtol(timeout, NULL, 10); + + ret = companion_group_find(duration, _group_found_cb, _group_finish_cb, NULL); + if (COMP_ERROR_NONE != ret) { + msgr("Failed to Find Group: [%s(0x%X)]", comp_error_to_string(ret), ret); + return RET_FAILURE; + } + msg(" - companion_group_find() ret: [0x%X] [%s]", ret, comp_error_to_string(ret)); + + return RET_SUCCESS; +} + +static int run_group_create(MManager *mm, struct menu_data *menu) +{ + int ret; + msg("Create Group"); + + ret = companion_group_create(groupid); + if (COMP_ERROR_NONE != ret) { + msgr("Failed to Create Group: [%s(0x%X)]", comp_error_to_string(ret), ret); + return RET_FAILURE; + } + msg(" - companion_group_create() ret: [0x%X] [%s]", ret, comp_error_to_string(ret)); + + return RET_SUCCESS; +} + +static struct menu_data menu_group_create[] = { + { "0", "Group Name", NULL, NULL, groupid }, + { "2", "Run", NULL, run_group_create, NULL }, + { NULL, NULL, }, +}; + +static struct menu_data menu_group_find[] = { + { "0", "Timeout", NULL, NULL, timeout }, + { "2", "Run", NULL, run_group_find, NULL }, + { NULL, NULL, }, +}; + +static struct menu_data menu_group_join[] = { + { "0", "Show Found Group(s)", NULL, run_group_show, NULL }, + { "1", "Index", NULL, NULL, group_idx }, + { "2", "Run", NULL, run_group_join, NULL }, + { NULL, NULL, }, +}; + +static struct menu_data menu_group_leave[] = { + { "0", "Show Found Group(s)", NULL, run_group_show, NULL }, + { "1", "Index", NULL, NULL, group_idx }, + { "2", "Run", NULL, run_group_leave, NULL }, + { NULL, NULL, }, +}; + +struct menu_data menu_comp_manager[] = { + { "1", "Group Create", menu_group_create, NULL, NULL }, + { "2", "Find Groups", menu_group_find, NULL, NULL }, + { "3", "Get Found Groups", NULL, run_group_get_found , NULL }, + { "4", "Join Group", menu_group_join, NULL, NULL }, + { "5", "Leave Group", menu_group_leave, NULL, NULL }, + { "6", "Delete Group", NULL, NULL, NULL }, + { "7", "Merge Group", NULL, NULL, NULL }, + { "8", "Get Group Member Devices", NULL, NULL, NULL }, + { "9", "Find Devices", NULL, NULL, NULL }, + { "10", "Invite Device", NULL, NULL, NULL }, + { "11", "Eject Device", NULL, NULL, NULL }, + { NULL, NULL, }, +}; diff --git a/capi/demo/companion_demo.c b/capi/demo/companion_demo.c old mode 100755 new mode 100644 diff --git a/capi/demo/main.c b/capi/demo/main.c new file mode 100644 index 0000000..0dc7736 --- /dev/null +++ b/capi/demo/main.c @@ -0,0 +1,130 @@ +/* + * Copyright (c) 2016 Samsung Electronics Co., Ltd. All rights reserved. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + */ + +#include +#include +#include +#include +#include +#include +#include + +#include +#include + +#include "menu.h" +#include "common.h" + +extern struct menu_data menu_comp_manager[]; + +extern GList *found_group_list; +extern GList *found_device_list; + +#define CASE_TO_STR(x) case x: return #x; + +const char* comp_error_to_string(comp_error_e err) +{ + switch (err) { + /* CHECK: List all enum values here */ + CASE_TO_STR(COMP_ERROR_NONE) + default : + return "COMP_ERROR_GENERAL"; + } +} + +const char *comp_group_type_to_string(companion_group_type_e e) +{ + switch (e) { + CASE_TO_STR(COMPANION_GROUP_TYPE_MINE) + CASE_TO_STR(COMPANION_GROUP_TYPE_REMOTE) + default : + return "Unknown station type"; + } +} + + +static int __init_func(MManager *mm, struct menu_data *menu) +{ + int ret = -1; + + ret = companion_initialize(); + if (ret != 0) { + msg("Failed to initialize companion-manager: [%s(0x%X)]", + comp_error_to_string(ret), ret); + return RET_FAILURE; + } + return RET_SUCCESS; +} + +static struct menu_data menu_main[] = { + { "1", "comp-manager", menu_comp_manager, NULL, NULL }, + { NULL, NULL, }, +}; + +static gboolean __create_init_menu(struct menu_data init_menu[1]) +{ + init_menu[0].key = "1"; + init_menu[0].title = "Init"; + init_menu[0].sub_menu = menu_main; + init_menu[0].callback = __init_func; + init_menu[0].data = NULL; + + return TRUE; +} + +int main(int arg, char **argv) +{ + GMainLoop *mainloop = NULL; + GIOChannel *channel = g_io_channel_unix_new(STDIN_FILENO); + MManager *manager; + struct menu_data init_menu[1+1] = { {NULL, NULL, } }; + +#if !GLIB_CHECK_VERSION(2, 35, 0) + g_type_init(); +#endif + mainloop = g_main_loop_new(NULL, FALSE); + + msg(""); + msg("* Companion-Manager Test application "); + msg("* Build On: %s %s", __DATE__, __TIME__); + + if (__create_init_menu(init_menu) == FALSE) + goto OUT; + + manager = menu_manager_new(init_menu, mainloop); + if (!manager) + goto OUT; + + menu_manager_run(manager); + + g_io_add_watch(channel, (G_IO_IN | G_IO_ERR | G_IO_HUP | G_IO_NVAL), + on_menu_manager_keyboard, manager); + g_main_loop_run(mainloop); + +OUT: + if (found_group_list) + g_list_free(found_group_list); + if (found_device_list) + g_list_free(found_device_list); + + companion_deinitialize(); + + g_main_loop_unref(mainloop); + msg("******* Bye bye *******"); + + return 0; +} diff --git a/capi/demo/menu.c b/capi/demo/menu.c new file mode 100644 index 0000000..e3a38d3 --- /dev/null +++ b/capi/demo/menu.c @@ -0,0 +1,378 @@ +/* + * Copyright (c) 2016 Samsung Electronics Co., Ltd. All rights reserved. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + */ + +#define _GNU_SOURCE +#include +#include +#include +#include +#include +#include +#include +#include + +#include "menu.h" + +#define DEFAULT_MENU_MENU "m" +#define DEFAULT_MENU_PREV "p" +#define DEFAULT_MENU_QUIT "q" +#define DEFAULT_MENU_NONE "-" +#define TAB_SPACE " " + +struct menu_manager { + GQueue *stack; + GQueue *title_stack; + + struct menu_data *menu; + + char *buf; + + void *user_data; + GMainLoop *mainloop; +}; + + +char key_buffer[MENU_DATA_SIZE]; +int flag_pid_display = 1; + +extern unsigned short dest_addr16; +extern struct menu_data menu_sel_device[]; + +static void _show_prompt(void) +{ + msgn("(%5d) >> ", get_tid()); +} + +static void _show_reserved_menu(void) +{ + msg(ANSI_COLOR_DARKGRAY HR_SINGLE2 ANSI_COLOR_NORMAL); + msg(ANSI_COLOR_DARKGRAY HR_SINGLE2 ANSI_COLOR_NORMAL); + msg(ANSI_COLOR_DARKGRAY " [ " ANSI_COLOR_NORMAL "%s" ANSI_COLOR_DARKGRAY + " ] " ANSI_COLOR_NORMAL "Previous menu " , DEFAULT_MENU_PREV); + msg(ANSI_COLOR_DARKGRAY " [ " ANSI_COLOR_NORMAL "%s" ANSI_COLOR_DARKGRAY + " ] " ANSI_COLOR_NORMAL "Show Menu " , DEFAULT_MENU_MENU); + msg(ANSI_COLOR_DARKGRAY " [ " ANSI_COLOR_NORMAL "%s" ANSI_COLOR_DARKGRAY + " ] " ANSI_COLOR_NORMAL "Quit " , DEFAULT_MENU_QUIT); +} + +static void _show_input_ok(void) +{ + msg("OK."); +} + +static void _show_menu(MManager *m, struct menu_data menu[]) +{ + int i = 0; + int len = 0; + struct menu_data *item; + char title_buf[256] = { 0, }; + + if (!menu) + return; + + msg(""); + msg(HR_DOUBLE); + + len = g_queue_get_length(m->title_stack); + msgn(ANSI_COLOR_YELLOW " Main"); + if (len > 0) { + for (i = 0; i < len; i++) { + msgn(ANSI_COLOR_NORMAL " >> " ANSI_COLOR_YELLOW "%s", + (char *)g_queue_peek_nth(m->title_stack, i)); + } + } + msg(ANSI_COLOR_NORMAL); + msg(HR_SINGLE); + + hide_pid(); + i = 0; + + while (1) { + item = menu + i; + if (item->key == NULL) + break; + + if (!g_strcmp0(item->key, "-")) { + msgn(" "); + } else if (!g_strcmp0(item->key, "_")) { + msg(ANSI_COLOR_DARKGRAY HR_SINGLE2 ANSI_COLOR_NORMAL); + + if (item->callback) + item->callback(m, item); + + i++; + + continue; + } else if (!g_strcmp0(item->key, "*")) { + msg(" %s", item->title); + if (item->callback) + item->callback(m, item); + } else { + msgn(ANSI_COLOR_DARKGRAY " [" ANSI_COLOR_NORMAL "%3s" + ANSI_COLOR_DARKGRAY "] " ANSI_COLOR_NORMAL, item->key); + } + + memset(title_buf, 0, 256); + if (item->title) { + snprintf(title_buf, MAX_TITLE, "%s", item->title); + + if (strlen(item->title) >= MAX_TITLE) { + title_buf[MAX_TITLE - 2] = '.'; + title_buf[MAX_TITLE - 1] = '.'; + } + } + + if (item->data) { + msg("%s " ANSI_COLOR_LIGHTBLUE "(%s)" ANSI_COLOR_NORMAL, + title_buf, item->data); + } else if (!g_strcmp0(item->key, "*")) { + /* none */ + } else { + msg("%s", title_buf); + } + + if (item->sub_menu) + msg("\e[1A\e[%dC >", (int)POS_MORE); + + i++; + } + + show_pid(); + + _show_reserved_menu(); + + msg(HR_DOUBLE); + + _show_prompt(); +} + +static void _show_item_data_input_msg(struct menu_data *item) +{ + msg(""); + msg(HR_DOUBLE); + msg(" Input [%s] data ", item->title); + msg(HR_SINGLE); + msg(" current = [%s]", item->data); + msgn(" new >> "); +} + +static void _move_menu(MManager *mm, struct menu_data menu[], char *key) +{ + struct menu_data *item; + int i = 0; + + if (!mm->menu) + return; + + if (!g_strcmp0(DEFAULT_MENU_PREV, key)) { + if (g_queue_get_length(mm->stack) > 0) { + mm->menu = g_queue_pop_tail(mm->stack); + g_queue_pop_tail(mm->title_stack); + } + + _show_menu(mm, mm->menu); + mm->buf = key_buffer; + + return; + } else if (!g_strcmp0(DEFAULT_MENU_MENU, key)) { + _show_menu(mm, mm->menu); + return; + } else if (!g_strcmp0(DEFAULT_MENU_QUIT, key)) { + g_main_loop_quit(mm->mainloop); + return; + } else if (!g_strcmp0(DEFAULT_MENU_NONE, key)) { + _show_prompt(); + return; + } + + while (1) { + int ret = RET_SUCCESS; + item = menu + i; + if (item->key == NULL) + break; + + if (!g_strcmp0(item->key, key)) { + if (item->callback) { + ret = item->callback(mm, item); + _show_prompt(); + } + + if (RET_SUCCESS == ret) { + if (item->sub_menu) { + g_queue_push_tail(mm->stack, mm->menu); + g_queue_push_tail(mm->title_stack, (gpointer *)item->title); + + mm->menu = item->sub_menu; + _show_menu(mm, mm->menu); + mm->buf = key_buffer; + } + + if (item->data) { + _show_item_data_input_msg(item); + mm->buf = item->data; + } + } + + return; + } + + i++; + } + + _show_prompt(); +} + +MManager *menu_manager_new(struct menu_data items[], GMainLoop *mainloop) +{ + MManager *mm; + + mm = calloc(sizeof(struct menu_manager), 1); + if (!mm) + return NULL; + + mm->stack = g_queue_new(); + mm->title_stack = g_queue_new(); + mm->menu = items; + mm->mainloop = mainloop; + + return mm; +} + +int menu_manager_run(MManager *mm) +{ + _show_menu(mm, mm->menu); + + mm->buf = key_buffer; + + return 0; +} + +int menu_manager_set_user_data(MManager *mm, void *user_data) +{ + if (!mm) + return -1; + + mm->user_data = user_data; + + return 0; +} + +void *menu_manager_ref_user_data(MManager *mm) +{ + if (!mm) + return NULL; + + return mm->user_data; +} + +gboolean on_menu_manager_keyboard(GIOChannel *src, GIOCondition con, + gpointer data) +{ + MManager *mm = data; + char local_buf[MENU_DATA_SIZE + 1] = { 0, }; + + if (fgets(local_buf, MENU_DATA_SIZE, stdin) == NULL) + return TRUE; + + if (strlen(local_buf) > 0) { + if (local_buf[strlen(local_buf) - 1] == '\n') + local_buf[strlen(local_buf) - 1] = '\0'; + } + + if (mm->buf == key_buffer) { + if (strlen(local_buf) < 1) { + _show_prompt(); + return TRUE; + } + + _move_menu(mm, mm->menu, local_buf); + } else { + if (mm->buf) { + memset(mm->buf, 0, MENU_DATA_SIZE); + memcpy(mm->buf, local_buf, MENU_DATA_SIZE); + _show_input_ok(); + } + mm->buf = key_buffer; + _move_menu(mm, mm->menu, (char *)DEFAULT_MENU_MENU); + } + + return TRUE; +} + +pid_t get_tid() +{ + return syscall(__NR_gettid); +} + +void hide_pid() +{ + flag_pid_display = 0; +} + +void show_pid() +{ + flag_pid_display = 1; +} + +int is_pid_show() +{ + return flag_pid_display; +} + +static void _hex_dump(const char *pad, int size, const void *data) +{ + char buf[255] = {0, }; + char hex[4] = {0, }; + int i; + unsigned char *p; + + if (size <= 0) { + msg("%sno data", pad); + return; + } + p = (unsigned char *)data; + + snprintf(buf, 255, "%s%04X: ", pad, 0); + for (i = 0; i < size; i++) { + snprintf(hex, 4, "%02X ", p[i]); + strncat(buf, hex, 255 - strlen(buf) - 1); + + if ((i + 1) % 8 == 0) { + if ((i + 1) % 16 == 0) { + msg("%s", buf); + memset(buf, 0, 255); + snprintf(buf, 255, "%s%04X: ", pad, i + 1); + } else { + strncat(buf, TAB_SPACE, 255 - strlen(buf) - 1); + } + } + } + + msg("%s", buf); +} + +void menu_print_dump(int data_len, void *data) +{ + if (!data) + return; + + msg(""); + msg(" \tlen=%d", data_len); + _hex_dump(" ", data_len, data); + + msg(""); +} diff --git a/capi/demo/menu.h b/capi/demo/menu.h new file mode 100644 index 0000000..5959d55 --- /dev/null +++ b/capi/demo/menu.h @@ -0,0 +1,125 @@ +/* + * Copyright (c) 2016 Samsung Electronics Co., Ltd. All rights reserved. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + */ + +#ifndef __MENU_H__ +#define __MENU_H__ + +__BEGIN_DECLS + +#define ANSI_COLOR_NORMAL "\e[0m" + +#define ANSI_COLOR_BLACK "\e[0;30m" +#define ANSI_COLOR_RED "\e[0;31m" +#define ANSI_COLOR_GREEN "\e[0;32m" +#define ANSI_COLOR_BROWN "\e[0;33m" +#define ANSI_COLOR_BLUE "\e[0;34m" +#define ANSI_COLOR_MAGENTA "\e[0;35m" +#define ANSI_COLOR_CYAN "\e[0;36m" +#define ANSI_COLOR_LIGHTGRAY "\e[0;37m" + +#define ANSI_COLOR_DARKGRAY "\e[1;30m" +#define ANSI_COLOR_LIGHTRED "\e[1;31m" +#define ANSI_COLOR_LIGHTGREEN "\e[1;32m" +#define ANSI_COLOR_YELLOW "\e[1;33m" +#define ANSI_COLOR_LIGHTBLUE "\e[1;34m" +#define ANSI_COLOR_LIGHTMAGENTA "\e[1;35m" +#define ANSI_COLOR_LIGHTCYAN "\e[1;36m" +#define ANSI_COLOR_WHITE "\e[1;37m" + + +#define msg(fmt, args...) do { fprintf(stdout, fmt "\n", ##args); \ + fflush(stdout); } while (0) +#define msgn(fmt, args...) do { fprintf(stdout, fmt, ##args); \ + fflush(stdout); } while (0) + +/* Bold (red) */ +#define msgr(fmt, args...) do { fprintf(stdout, ANSI_COLOR_RED fmt \ + ANSI_COLOR_NORMAL "\n", ##args); fflush(stdout); } while (0) + +/* Bold (green) */ +#define msgb(fmt, args...) do { fprintf(stdout, ANSI_COLOR_LIGHTGREEN fmt \ + ANSI_COLOR_NORMAL "\n", ##args); fflush(stdout); } while (0) + +/* Property message */ +#define msgp(fmt, args...) do { fprintf(stdout, ANSI_COLOR_LIGHTMAGENTA fmt \ + ANSI_COLOR_NORMAL "\n", ##args); fflush(stdout); } while (0) + +#define msgt(n, fmt, args...) do { fprintf(stdout, "\e[%dC" fmt "\n", \ + 3 + ((n) * 2), ##args); fflush(stdout); } while (0) + +#define pmsg(fmt, args...) do { \ + if (is_pid_show()) { fprintf(stdout, "(%5d) ", get_tid()); } \ + fprintf(stdout, fmt "\n", ##args); fflush(stdout); } while (0) + +#define pmsgb(fmt, args...) do { \ + if (is_pid_show()) { fprintf(stdout, "(%5d) ", get_tid()); } \ + fprintf(stdout, ANSI_COLOR_LIGHTGREEN fmt \ + ANSI_COLOR_NORMAL "\n", ##args); fflush(stdout); } while (0) + +#define pmsgt(n, fmt, args...) do { \ + if (is_pid_show()) { fprintf(stdout, "(%5d) ", get_tid()); } \ + fprintf(stdout, "\e[%dC" fmt "\n", \ + 3 + ((n) * 2), ##args); fflush(stdout); } while (0) + +#define MENU_DATA_SIZE 255 + + + +/* + * Horizontal Line - width: 65 + * .12345678901234567890123456789012345678901234567890. + */ +#define HR_SINGLE "----------------------------------------" \ + "-------------------------" +#define HR_DOUBLE "========================================" \ + "=========================" +#define HR_SINGLE2 " ---------------------------------------" \ + "------------------------ " + +#define MAX_WIDTH strlen(HR_SINGLE) +#define MAX_TITLE ((MAX_WIDTH) - 10) +#define POS_MORE ((MAX_WIDTH) - 3) +#define RET_SUCCESS 0 +#define RET_FAILURE -1 + +typedef struct menu_manager MManager; + +struct menu_data { + const char *key; + const char *title; + struct menu_data *sub_menu; + int (*callback)(MManager *mm, struct menu_data *menu); + char *data; +}; + +MManager* menu_manager_new(struct menu_data items[], GMainLoop *mainloop); +int menu_manager_run(MManager *mm); +int menu_manager_set_user_data(MManager *mm, void *user_data); +void* menu_manager_ref_user_data(MManager *mm); + +gboolean on_menu_manager_keyboard(GIOChannel *src, GIOCondition con, + gpointer data); + +pid_t get_tid(); +void hide_pid(); +void show_pid(); +int is_pid_show(); +void menu_print_dump(int data_len, void *data); + +__END_DECLS + +#endif diff --git a/capi/include/companion.h b/capi/include/companion.h index d980471..0964136 100755 --- a/capi/include/companion.h +++ b/capi/include/companion.h @@ -7,6 +7,25 @@ extern "C" { #endif +#define TIZEN_ERROR_COMP 0 + +/* error enum */ +typedef enum { + COMP_ERROR_NONE = TIZEN_ERROR_NONE, /**< Successful */ + COMP_ERROR_IO_ERROR = TIZEN_ERROR_IO_ERROR, /**< I/O error */ + COMP_ERROR_INVALID_PARAMETER = TIZEN_ERROR_INVALID_PARAMETER, /**< Invalid parameter */ + COMP_ERROR_OUT_OF_MEMORY = TIZEN_ERROR_OUT_OF_MEMORY, /**< Out of memory */ + COMP_ERROR_PERMISSION_DENIED = TIZEN_ERROR_PERMISSION_DENIED, /**< Permission denied */ + COMP_ERROR_NOT_SUPPORTED = TIZEN_ERROR_NOT_SUPPORTED, /**< Not supported */ + COMP_ERROR_COMM_ERROR = TIZEN_ERROR_COMP | 0x01, /**< communication error */ + COMP_ERROR_RX = TIZEN_ERROR_COMP | 0x02, /**< RX error */ + COMP_ERROR_TX = TIZEN_ERROR_COMP | 0x03, /**< TX error */ + COMP_ERROR_PLUGIN_FAIL = TIZEN_ERROR_COMP | 0x04, /**< Plugin failed */ + COMP_ERROR_OPERATION_FAILED = TIZEN_ERROR_COMP | 0x05, /**< Operation Failed */ + COMP_ERROR_ALREADY_IN_PROGRESS = TIZEN_ERROR_COMP | 0x06, /**< Already initilized */ + COMP_ERROR_UNKNOWN = -999, +} comp_error_e; + typedef enum { COMPANION_GROUP_TYPE_MINE = 0, COMPANION_GROUP_TYPE_REMOTE, diff --git a/capi/include/companion_debug.h b/capi/include/companion_debug.h index 967b3d3..9b4f68d 100755 --- a/capi/include/companion_debug.h +++ b/capi/include/companion_debug.h @@ -3,6 +3,8 @@ #include +#define NOTUSED(var) (var = var) + #define COLOR_BLACK "\033[0;30m" #define COLOR_RED "\033[0;31m" #define COLOR_GREEN "\033[0;32m" diff --git a/capi/src/companion.c b/capi/src/companion.c index 994692d..912ea6b 100755 --- a/capi/src/companion.c +++ b/capi/src/companion.c @@ -381,6 +381,24 @@ int companion_group_get_found_groups(companion_group_h **groups, int *count) return ret; } +int companion_group_join(companion_group_h group, companion_group_find_finish_cb callback, void *user_data) +{ + int ret = COMP_ERROR_NONE; + NOTUSED(group); + NOTUSED(callback); + NOTUSED(user_data); + return ret; +} + +int companion_group_leave(companion_group_h group, companion_group_find_finish_cb callback, void *user_data) +{ + int ret = COMP_ERROR_NONE; + NOTUSED(group); + NOTUSED(callback); + NOTUSED(user_data); + return ret; +} + int companion_device_find(int timeout, companion_device_found_cb found_cb, companion_device_find_finish_cb finish_cb, void *user_data) { @@ -396,7 +414,6 @@ int companion_device_find(int timeout, companion_device_found_cb found_cb, group_call_device_find_sync(group_proxy, timeout, &ret, NULL, &error); return ret; - } int companion_send_data(companion_device_h device, char *data) diff --git a/src/companion-manager/include/comp_enum.h b/src/companion-manager/include/comp_enum.h index 1442e2b..7ae88a9 100755 --- a/src/companion-manager/include/comp_enum.h +++ b/src/companion-manager/include/comp_enum.h @@ -3,6 +3,8 @@ #include +#define NOTUSED(var) (var = var) + #define TIZEN_ERROR_COMP 0 /* error enum */ diff --git a/src/companion-manager/src/comp_group.c b/src/companion-manager/src/comp_group.c index 57126d7..3722935 100755 --- a/src/companion-manager/src/comp_group.c +++ b/src/companion-manager/src/comp_group.c @@ -1,4 +1,6 @@ +#include #include +#include GList *found_group_list; GList *mot_enb_dev_list = NULL; @@ -412,10 +414,39 @@ int comp_group_join_to(/* callback */){} //Join this device to in certain remote int comp_group_leave_from(/* callback */){} //leave from certain remote group (Async) /* Called when daemon is end. */ -int comp_group_deinitialize(){} +int comp_group_deinitialize() +{ + int ret = COMP_ERROR_NONE; + return ret; +} + +int comp_group_get_group_name(comp_group_t *handle, char **name) +{ + int ret = COMP_ERROR_NONE; + NOTUSED(handle); + NOTUSED(name); + return ret; +} + +int comp_group_get_group_type(comp_group_t *handle, int *type) +{ + int ret = COMP_ERROR_NONE; + NOTUSED(handle); + NOTUSED(type); + return ret; +} -int comp_group_get_group_name(comp_group_t *handle, char **name){} -int comp_group_get_group_type(comp_group_t *handle, int *type){} -int comp_group_get_group_device_type(comp_group_t *handle){} -int comp_group_get_group_device_id(comp_group_t *handle){} +int comp_group_get_group_device_type(comp_group_t *handle) +{ + int ret = COMP_ERROR_NONE; + NOTUSED(handle); + return ret; +} + +int comp_group_get_group_device_id(comp_group_t *handle) +{ + int ret = COMP_ERROR_NONE; + NOTUSED(handle); + return ret; +} diff --git a/src/mot-agent/ma-db.c b/src/mot-agent/ma-db.c index 3c12909..314326d 100644 --- a/src/mot-agent/ma-db.c +++ b/src/mot-agent/ma-db.c @@ -151,6 +151,7 @@ int ma_close_db() return OC_STACK_OK; } +#ifdef IOTIVITY_DB_TEST static OCStackResult getUUIDforId(int id, OicUuid_t *uid, bool *result) { sqlite3_stmt *stmt = 0; @@ -189,7 +190,7 @@ static OCStackResult getUUIDforId(int id, OicUuid_t *uid, bool *result) return OC_STACK_INVALID_PARAM; } - +#endif static OCStackResult getIdForUUID(const OicUuid_t *UUID , int *id) { sqlite3_stmt *stmt = 0; diff --git a/src/mot-agent/ma-subowner.c b/src/mot-agent/ma-subowner.c index 7934bbc..95d0a38 100644 --- a/src/mot-agent/ma-subowner.c +++ b/src/mot-agent/ma-subowner.c @@ -1883,7 +1883,6 @@ static gpointer _unlink_provisioning_func(gpointer data) { OCStackResult ret = OC_STACK_OK; ma_req_cb_s *con = (ma_req_cb_s *)data; - ma_service *service = (ma_service *)con->userdata; OicUuid_t *uuid1 = NULL; OicUuid_t *uuid2 = NULL;