Add device capability and get authenticated device list
[platform/core/system/edge-orchestration.git] / CMain / src / orchestration_service.c
index 065dd17..48052fc 100644 (file)
@@ -21,7 +21,7 @@
 #include <stdbool.h>
 #include <pthread.h>
 #include <gio/gio.h>
-
+#include <app_control.h>
 #include "orchestration_key.h"
 
 static int request_service(
@@ -30,14 +30,51 @@ static int request_service(
                requestServiceInfo service_info[],
                int count,
                char* client_pname);
+static int request_service_on_device(
+                char* app_name,
+               bool self_select,
+               requestServiceInfo service_info[],
+               char *ip,
+               int count,
+               char* client_pname);
 static int update_key_pair(
                char* id,
                char* key,
                char* client_pname);
+static DeviceList* get_device_list(
+               char* service_name,
+               char* exec_type);
+static DeviceCapability* read_device_capability(char* ip);
+static char* write_device_capability(char *ip);
+
+int app_execute(char *pkg_name, char* args)
+{
+        app_control_h ac;
+        int ret = 0;;
+        ret = app_control_create(&ac);
+
+        if (ret != APP_CONTROL_ERROR_NONE) {
+                DEBUG("app_control_create failed : %d\n", ret);
+        }
+
+        ret = app_control_set_app_id(ac, pkg_name);
+        if (ret != APP_CONTROL_ERROR_NONE ) {
+                DEBUG("app_control_set_app_id error");
+        }
+
+        ret = app_control_send_launch_request(ac, NULL, NULL);
+        if (ret != APP_CONTROL_ERROR_NONE) {
+                DEBUG("app_control_send_launch_request error :%s", get_error_message(ret));
+        }
+
+        app_control_destroy(ac);
+
+        return ret;
+}
 
 void *orchestration_service_thread() {
        DEBUG("Start OrchestrationInit Thread !!\n");
-       OrchestrationInit();
+       OrchestrationInit(app_execute);
        SetPSKHandler(identityGetter, keyGetter);
 
        return NULL;
@@ -57,7 +94,11 @@ _orchestration_state_e orchestration_service_start() {
 dbus_funcs getDbusFuncs() {
        dbus_funcs funcs;
        funcs.request_service_f = request_service;
+       funcs.request_service_on_device_f = request_service_on_device;
        funcs.update_key_pair_f = update_key_pair;
+       funcs.get_device_list_f = get_device_list;
+       funcs.read_device_capability_f = read_device_capability;
+       funcs.write_device_capability_f = write_device_capability;
        return funcs;
 }
 
@@ -82,6 +123,28 @@ static int request_service(char* app_name, bool self_select, requestServiceInfo
        return ret;
 }
 
+static int request_service_on_device(char* app_name, bool self_select, requestServiceInfo service_info[], char *ip, int count, char* client_pname){
+        int ret = ORCH_ERROR_NONE;
+        ResponseService result;
+
+        DEBUG("[orchestration_server]\n")
+        DEBUG("\t app_name : %s\n", app_name);
+        DEBUG("\t self_select : %s\n", self_select ? "true" : "false");
+        DEBUG("\t Device IP addr : %s \n", ip);
+        DEBUG("\t count : %d\n", count);
+        DEBUG("\t process_name : %s\n", client_pname);
+        for (int ix = 0; ix < count; ix++) {
+                DEBUG("\t service_info[%d].ExecutionType : %s\n", ix, service_info[ix].ExecutionType);
+                DEBUG("\t service_info[%d].ExeCmd : %s\n", ix, service_info[ix].ExeCmd);
+        }
+
+        result = OrchestrationRequestServiceOnDevice(app_name, self_select, client_pname, service_info, ip, count);
+        DEBUG("result = %s\n", result.Message);
+
+        /* TO DO : parsing API response */
+        return ret;
+}
+
 #define ALLOWED_KEY_UPDATER "homeedge"
 
 static int update_key_pair(char* id, char* key, char* client_pname) {
@@ -92,3 +155,15 @@ static int update_key_pair(char* id, char* key, char* client_pname) {
 
        return updateKeyPair(id, key);
 }
+
+static DeviceList* get_device_list(char* service_name, char* exec_type) {
+       return OrchestrationGetDeviceList(service_name, exec_type);
+}
+
+static DeviceCapability* read_device_capability(char* ip) {
+       return OrchestrationReadCapability(ip);
+}
+
+static char* write_device_capability(char* capability) {
+       return OrchestrationWriteCapability(capability);
+}