Add device capability and get authenticated device list
[platform/core/system/edge-orchestration.git] / libedge-orchestration / sample / main_native.c
index 35864fe..5a2b21a 100644 (file)
  *******************************************************************************/
 
 #include <stdio.h>
+#include <glib.h>
 #include <orchestration_client.h>
 
+#define LINUX_IPADDR   "192.168.1.8"
+#define ANDROID_IPADDR "192.168.1.2"
+
 void status_cb(orchestration_service_status_e staus, void* user_data)
 {
 
 }
 
-int main() {
-    orchestration_service_info_s service_info;
-    service_info.count = 1;
-    service_info.services[0].exec_type = "native";
-    service_info.services[0].exec_parameter = "ls -al";
-    orchestration_request_service("native_sample", false, service_info, status_cb, NULL);
+int main(int argc, char *argv[]) {
+
+    if (g_strcmp0(argv[1], "get_device_list") == 0) {
+
+       printf("--------------------\n");
+        printf("Get Device List \n");
+        printf("--------------------\n");
+
+        // Get Device List
+        orchestration_devicelist_s *device_list = NULL;
+        orchestration_client_state_e ret = orchestration_get_devicelist((char*) "native_sample", (char*) "native", &device_list);
+        if (ret == ORCH_CLIENT_ERROR_NONE)
+        {
+            for (int i = 0; i < device_list->num_ip; i++)
+            {
+                printf("IP Addr :: [ %s ] \n", device_list->ipaddr[i]);
+                free(device_list->ipaddr[i]);
+            }
+            if (device_list->ipaddr) {
+                free(device_list->ipaddr);
+            }
+            if (device_list->message) {
+                free(device_list->message);
+            }
+            free(device_list);
+        }
+
+        device_list = NULL;
+       //ret = orchestration_get_devicelist(NULL, NULL, &device_list);
+        ret = orchestration_get_devicelist((char*) "", (char*) "", &device_list);
+        if (ret == ORCH_CLIENT_ERROR_NONE)
+        {
+            for (int i = 0; i < device_list->num_ip; i++)
+            {
+                printf("IP Addr :: [ %s ] \n", device_list->ipaddr[i]);
+                free(device_list->ipaddr[i]);
+            }
+            if (device_list->ipaddr) {
+                free(device_list->ipaddr);
+            }
+            if (device_list->message) {
+                free(device_list->message);
+            }
+            free(device_list);
+        }
+    }
+    else if (g_strcmp0(argv[1], "write") == 0) {
+
+        printf("--------------------\n");
+        printf("Write Capability \n");
+        printf("--------------------\n");
+
+        const char* json= "{'os':'linux', 'apps':['app3','app4']}";
+        orchestration_client_state_e ret = orchestration_write_capability((char*) json);
+        if (ret == ORCH_CLIENT_ERROR_NONE)
+        {
+            printf("\t SUCCESS !! \n");
+        }
+    }
+    else if (g_strcmp0(argv[1], "read") == 0) {
+
+        printf("--------------------\n");
+        printf("Read Capability \n");
+        printf("--------------------\n\n");
+
+        orchestration_device_capability_s *device_capability = NULL;
+        orchestration_client_state_e ret = orchestration_read_capability(LINUX_IPADDR, &device_capability);
+        if (ret == ORCH_CLIENT_ERROR_NONE)
+        {
+            printf("Read Capability succes\n");
+            if (device_capability)
+            {
+                printf("\t [%s : %s] \n", LINUX_IPADDR, device_capability->capability);
+                //printf("message : %s\n", device_capability->message);
+
+                free(device_capability->capability);
+                free(device_capability->message);
+                free(device_capability);
+            }
+        }
+
+        device_capability = NULL;
+        ret = orchestration_read_capability(ANDROID_IPADDR, &device_capability);
+        if (ret == ORCH_CLIENT_ERROR_NONE)
+        {
+            printf("Read Capability succes\n");
+            if (device_capability)
+            {
+                printf("\t [%s : %s] \n", ANDROID_IPADDR, device_capability->capability);
+                //printf("message : %s\n", device_capability->message);
+
+                free(device_capability->capability);
+                free(device_capability->message);
+                free(device_capability);
+            }
+        }
+
+        printf("\n\n");
+    }
+    else if (g_strcmp0(argv[1], "request_service_on_device") == 0) {
+
+        printf("-----------------------\n");
+        printf("Request Service (IP)  \n");
+        printf("-----------------------\n");
+
+        // Request Service on device
+        orchestration_service_info_s service_info;
+        service_info.count = 1;
+        service_info.services[0].exec_type = "native";
+        service_info.services[0].exec_parameter = "org.tizen.camera-app";
+        //orchestration_request_service("native_sample", true, service_info, status_cb, NULL);
+        orchestration_request_service_on_device("native_sample", true, service_info, LINUX_IPADDR, status_cb, NULL);
+
+        //service_info.count = 1;
+        //service_info.services[0].exec_type = "android";
+        //service_info.services[0].exec_parameter = "com.samsung.android.sample";
+        //orchestration_request_service_on_device("android_sample", false, service_info, ANDRIOD_IP_ADDR, status_cb, NULL);
+
+        printf("\n\n");
+    }
+
     return 0;
-}
\ No newline at end of file
+}