Add device capability and get authenticated device list
[platform/core/system/edge-orchestration.git] / libedge-orchestration / src / orchestration_client.c
index ec0e5e7..1f186bb 100755 (executable)
@@ -29,6 +29,79 @@ orchestration_changed_service_status_cb _changed_service_status_cb;
 #define _ORCHESTRATION_INTERFACE "org.tizen.orchestration.agent"
 #define _ORCHESTRATION_REQUEST_SERVICE_METHOD "request_service"
 
+
+orchestration_client_state_e orchestration_get_devicelist(char *service_name, char *exec_type, orchestration_devicelist_s **deviceList)
+{
+    *deviceList = NULL;
+
+    int client_pid = getpid();
+    int result = 0;
+
+    result = dbus_consumer_initailze();
+    if (result != ORCH_DBUS_ERROR_NONE)
+    {
+        printf("dbus_consumer_initailze failed\n");
+        return ORCH_CLIENT_ERROR_FAULT;
+    }
+
+    result = get_device_list(service_name, exec_type, client_pid, deviceList);
+    if (result != ORCH_DBUS_ERROR_NONE)
+    {
+        printf("get device list failed\n");
+        return ORCH_CLIENT_ERROR_FAULT;
+    }
+    return ORCH_CLIENT_ERROR_NONE;
+}
+
+orchestration_client_state_e orchestration_read_capability(char *ip, orchestration_device_capability_s **device_capability)
+{
+    *device_capability = NULL;
+    if (!ip)
+    {
+        printf("[read cappability] ip cannot be empty!!\n");
+        return ORCH_CLIENT_ERROR_INVALID_PARAMETER;
+    }
+
+    int client_pid = getpid();
+    int result = 0;
+
+    result = dbus_consumer_initailze();
+    if (result != ORCH_DBUS_ERROR_NONE)
+    {
+        printf("dbus_consumer_initialize failed\n");
+        return ORCH_CLIENT_ERROR_FAULT;
+    }
+
+    result = read_capability(ip, client_pid, device_capability);
+    if (result != ORCH_DBUS_ERROR_NONE)
+    {
+        printf("read capability failed\n");
+        return ORCH_CLIENT_ERROR_FAULT;
+    }
+    return ORCH_CLIENT_ERROR_NONE;
+}
+
+orchestration_client_state_e orchestration_write_capability(char *capability)
+{
+    int client_pid = getpid();
+    int result = 0;
+
+    result = dbus_consumer_initailze();
+    if (result != ORCH_DBUS_ERROR_NONE)
+    {
+        printf("dbus_consumer_initialize failed\n");
+        return ORCH_CLIENT_ERROR_FAULT;
+    }
+
+    result = write_capability(capability, client_pid);
+    if (result != ORCH_DBUS_ERROR_NONE)
+    {
+        printf("write capability failed\n");
+        return ORCH_CLIENT_ERROR_FAULT;
+    }
+    return ORCH_CLIENT_ERROR_NONE;
+}
+
 orchestration_client_state_e orchestration_request_service(char *app_name,
                                                         bool self_select,
                                                         orchestration_service_info_s service_info,
@@ -76,3 +149,52 @@ orchestration_client_state_e orchestration_request_service(char *app_name,
 
     return ORCH_CLIENT_ERROR_NONE;
 }
+
+orchestration_client_state_e orchestration_request_service_on_device(char *app_name,
+                                                        bool self_select,
+                                                        orchestration_service_info_s service_info,
+                                                        char *ip,
+                                                        orchestration_changed_service_status_cb cb,
+                                                        void *user_data)
+{
+    int result = 0;
+    int client_pid = getpid();
+
+    if (strcmp(app_name, "") == 0)
+    {
+        printf("app_name is null\n");
+        return ORCH_CLIENT_ERROR_INVALID_PARAMETER;
+    }
+    if (cb == NULL)
+    {
+        printf("orchestration_changed_service_status_cb is null\n");
+        return ORCH_CLIENT_ERROR_INVALID_PARAMETER;
+    }
+    _changed_service_status_cb = cb;
+
+    result = dbus_consumer_initailze();
+    if (result != ORCH_DBUS_ERROR_NONE)
+    {
+        printf("dbus_consumer_initailze failed\n");
+        return ORCH_CLIENT_ERROR_FAULT;
+    }
+
+    printf("[orchestration_client]\n");
+    printf("\t client_pid : %d\n", client_pid);
+    printf("\t app_name : %s\n", app_name);
+    printf("\t self_select : %s\n", self_select ? "true" : "false");
+    printf("\t count : %d\n", service_info.count);
+    for (int i = 0; i < service_info.count; i++) {
+        printf("\t service_info[%d]->exec_type : %s\n", i, service_info.services[i].exec_type);
+        printf("\t service_info[%d]->exec_parameter : %s\n", i, service_info.services[i].exec_parameter);
+    }
+
+    result = request_service_execute_on_device(app_name, self_select, service_info.services, ip, service_info.count, client_pid);
+    if (result != ORCH_DBUS_ERROR_NONE)
+    {
+        printf("request_service_execute failed\n");
+        return ORCH_CLIENT_ERROR_FAULT;
+    }
+
+    return ORCH_CLIENT_ERROR_NONE;
+}