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})
--- /dev/null
+/*
+ * 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 <companion.h>
+
+__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__ */
--- /dev/null
+
+/*
+ * 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 <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <sys/time.h>
+#include <unistd.h>
+#include <glib.h>
+#include <gio/gio.h>
+
+#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, },
+};
--- /dev/null
+/*
+ * 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 <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <sys/time.h>
+#include <sys/socket.h>
+#include <unistd.h>
+#include <errno.h>
+
+#include <glib.h>
+#include <gio/gio.h>
+
+#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;
+}
--- /dev/null
+/*
+ * 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 <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <sys/types.h>
+#include <glib.h>
+#include <asm/unistd.h>
+#include <unistd.h>
+#include <sys/syscall.h>
+
+#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("");
+}
--- /dev/null
+/*
+ * 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
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,
#include <stdio.h>
+#define NOTUSED(var) (var = var)
+
#define COLOR_BLACK "\033[0;30m"
#define COLOR_RED "\033[0;31m"
#define COLOR_GREEN "\033[0;32m"
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)
{
group_call_device_find_sync(group_proxy, timeout, &ret, NULL, &error);
return ret;
-
}
int companion_send_data(companion_device_h device, char *data)
#include <tizen.h>
+#define NOTUSED(var) (var = var)
+
#define TIZEN_ERROR_COMP 0
/* error enum */
+#include <comp_enum.h>
#include <comp_group.h>
+#include <comp_gdbus_group.h>
GList *found_group_list;
GList *mot_enb_dev_list = NULL;
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;
+}
return OC_STACK_OK;
}
+#ifdef IOTIVITY_DB_TEST
static OCStackResult getUUIDforId(int id, OicUuid_t *uid, bool *result)
{
sqlite3_stmt *stmt = 0;
return OC_STACK_INVALID_PARAM;
}
-
+#endif
static OCStackResult getIdForUUID(const OicUuid_t *UUID , int *id)
{
sqlite3_stmt *stmt = 0;
{
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;