demo: Added test code for device monitoring
authorSaurav Babu <saurav.babu@samsung.com>
Fri, 20 Apr 2018 04:52:02 +0000 (10:22 +0530)
committersaerome.kim <saerome.kim@samsung.com>
Mon, 2 Jul 2018 10:38:50 +0000 (19:38 +0900)
Signed-off-by: Saurav Babu <saurav.babu@samsung.com>
capi/demo/comp-manager.c

index 9e103e5..64798a2 100755 (executable)
@@ -41,6 +41,7 @@ static char group_idx_b[MENU_DATA_SIZE + 1] = "2";
 static char device_idx[MENU_DATA_SIZE + 1] = "1";
 static char pin[MENU_DATA_SIZE + 1] = "12341234";
 static char message[MENU_DATA_SIZE + 1] = "Hello World!!";
+static char monitor[MENU_DATA_SIZE + 1] = "1";
 
 static int run_group_find(MManager *mm, struct menu_data *menu);
 static int run_devices_find(MManager *mm, struct menu_data *menu);
@@ -1189,6 +1190,38 @@ static int run_request_delete_group(MManager *mm, struct menu_data *menu)
        return RET_SUCCESS;
 }
 
+static void device_monitor_result(char *uuid, char *group_name,
+                                                 companion_device_status_e status, void *user_data)
+{
+       msgp("device monitor result uuid %s group_name %s status %s", uuid,
+                group_name, status == COMPANION_DEVICE_ADDED ? "ADDED" : "REMOVED");
+}
+
+static int run_start_device_monitor(MManager *mm, struct menu_data *menu)
+{
+       int ret;
+
+       if (g_strcmp0(monitor, "1") == 0) {
+               msg(" - Start device monitor");
+               ret = companion_device_monitor_start(handle, device_monitor_result,
+                                                                                        NULL);
+               if (COMP_ERROR_NONE != ret) {
+                       msgr("Failed to Start Monitor: [%s(0x%X)]",
+                                comp_error_to_string(ret), ret);
+                       return RET_FAILURE;
+               }
+       } else {
+               msg(" - Stop device monitor");
+               ret = companion_device_monitor_stop(handle);
+               if (COMP_ERROR_NONE != ret) {
+                       msgr("Failed to Stop Monitor: [%s(0x%X)]",
+                                comp_error_to_string(ret), ret);
+                       return RET_FAILURE;
+               }
+       }
+       return RET_SUCCESS;
+}
+
 
 static struct menu_data menu_group_create[] = {
        { "0", "Group Name", NULL, NULL, groupid },
@@ -1305,6 +1338,12 @@ static struct menu_data menu_request_delete_group[] = {
        { NULL, NULL, },
 };
 
+static struct menu_data menu_monitor[] = {
+       { "1", "Input 1 to Start and 2 to Stop Monitor", NULL, NULL,  monitor },
+       { "2", "Start/Stop Device Monitor", NULL, run_start_device_monitor, NULL },
+       { NULL, NULL, },
+};
+
 struct menu_data menu_comp_manager[] = {
        { "0", "Show My Device ID", NULL, run_get_my_id, NULL },
        { "1", "Show My Device", NULL, run_device_show_my_device, NULL },
@@ -1326,5 +1365,6 @@ struct menu_data menu_comp_manager[] = {
        { "17", "Request Eject", menu_request_eject, NULL, NULL },
        { "18", "Request Delete Group (Not yet developed)", menu_request_delete_group,
                NULL, NULL },
+       { "19", "Start/Stop Device Monitor", menu_monitor, NULL, NULL },
        { NULL, NULL, },
 };