1 /*******************************************************************************
2 * Copyright 2020 Samsung Electronics All Rights Reserved.
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
16 *******************************************************************************/
18 #include <orchestration_service.h>
24 #include <app_control.h>
25 #include "orchestration_key.h"
27 static int request_service(
30 requestServiceInfo service_info[],
33 static int request_service_on_device(
36 requestServiceInfo service_info[],
40 static int update_key_pair(
44 static DeviceList* get_device_list(
47 static DeviceCapability* read_device_capability(char* ip);
48 static char* write_device_capability(char *ip);
50 int app_execute(char *pkg_name, char* args)
54 ret = app_control_create(&ac);
56 if (ret != APP_CONTROL_ERROR_NONE) {
57 DEBUG("app_control_create failed : %d\n", ret);
60 ret = app_control_set_app_id(ac, pkg_name);
61 if (ret != APP_CONTROL_ERROR_NONE ) {
62 DEBUG("app_control_set_app_id error");
65 ret = app_control_send_launch_request(ac, NULL, NULL);
66 if (ret != APP_CONTROL_ERROR_NONE) {
67 DEBUG("app_control_send_launch_request error :%s", get_error_message(ret));
70 app_control_destroy(ac);
75 void *orchestration_service_thread() {
76 DEBUG("Start OrchestrationInit Thread !!\n");
77 OrchestrationInit(app_execute);
78 SetPSKHandler(identityGetter, keyGetter);
83 _orchestration_state_e orchestration_service_start() {
86 if (pthread_create(&p_thread, NULL, orchestration_service_thread, NULL) != 0) {
87 DEBUG("Fail to start OrchestrationInit Thread !!");
88 return ORCH_ERROR_NOT_READY;
91 return ORCH_ERROR_NONE;
94 dbus_funcs getDbusFuncs() {
96 funcs.request_service_f = request_service;
97 funcs.request_service_on_device_f = request_service_on_device;
98 funcs.update_key_pair_f = update_key_pair;
99 funcs.get_device_list_f = get_device_list;
100 funcs.read_device_capability_f = read_device_capability;
101 funcs.write_device_capability_f = write_device_capability;
105 static int request_service(char* app_name, bool self_select, requestServiceInfo service_info[], int count, char* client_pname){
106 int ret = ORCH_ERROR_NONE;
107 ResponseService result;
109 DEBUG("[orchestration_server]\n")
110 DEBUG("\t app_name : %s\n", app_name);
111 DEBUG("\t self_select : %s\n", self_select ? "true" : "false");
112 DEBUG("\t count : %d\n", count);
113 DEBUG("\t process_name : %s\n", client_pname);
114 for (int ix = 0; ix < count; ix++) {
115 DEBUG("\t service_info[%d].ExecutionType : %s\n", ix, service_info[ix].ExecutionType);
116 DEBUG("\t service_info[%d].ExeCmd : %s\n", ix, service_info[ix].ExeCmd);
119 result = OrchestrationRequestService(app_name, self_select, client_pname, service_info, count);
120 DEBUG("result = %s\n", result.Message);
122 /* TO DO : parsing API response */
126 static int request_service_on_device(char* app_name, bool self_select, requestServiceInfo service_info[], char *ip, int count, char* client_pname){
127 int ret = ORCH_ERROR_NONE;
128 ResponseService result;
130 DEBUG("[orchestration_server]\n")
131 DEBUG("\t app_name : %s\n", app_name);
132 DEBUG("\t self_select : %s\n", self_select ? "true" : "false");
133 DEBUG("\t Device IP addr : %s \n", ip);
134 DEBUG("\t count : %d\n", count);
135 DEBUG("\t process_name : %s\n", client_pname);
136 for (int ix = 0; ix < count; ix++) {
137 DEBUG("\t service_info[%d].ExecutionType : %s\n", ix, service_info[ix].ExecutionType);
138 DEBUG("\t service_info[%d].ExeCmd : %s\n", ix, service_info[ix].ExeCmd);
141 result = OrchestrationRequestServiceOnDevice(app_name, self_select, client_pname, service_info, ip, count);
142 DEBUG("result = %s\n", result.Message);
144 /* TO DO : parsing API response */
148 #define ALLOWED_KEY_UPDATER "homeedge"
150 static int update_key_pair(char* id, char* key, char* client_pname) {
151 if (g_strcmp0(client_pname, ALLOWED_KEY_UPDATER) != 0) {
152 DEBUG("process_name : %s -> is not allowed.\n", client_pname);
156 return updateKeyPair(id, key);
159 static DeviceList* get_device_list(char* service_name, char* exec_type) {
160 return OrchestrationGetDeviceList(service_name, exec_type);
163 static DeviceCapability* read_device_capability(char* ip) {
164 return OrchestrationReadCapability(ip);
167 static char* write_device_capability(char* capability) {
168 return OrchestrationWriteCapability(capability);