1 /*******************************************************************************
2 * Copyright 2019 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 *******************************************************************************/
21 #include <dbus_consumer.h>
24 /* ---------------------------------------------------------------------------------------------------- */
25 orchestration_changed_service_status_cb _changed_service_status_cb;
27 #define _ORCHESTRATION_BUS_NAME "org.tizen.orchestration"
28 #define _ORCHESTRATION_OBJECT_PATH "/org/tizen/orchestration"
29 #define _ORCHESTRATION_INTERFACE "org.tizen.orchestration.agent"
30 #define _ORCHESTRATION_REQUEST_SERVICE_METHOD "request_service"
33 orchestration_client_state_e orchestration_get_devicelist(char *service_name, char *exec_type, orchestration_devicelist_s **deviceList)
37 int client_pid = getpid();
40 result = dbus_consumer_initailze();
41 if (result != ORCH_DBUS_ERROR_NONE)
43 printf("dbus_consumer_initailze failed\n");
44 return ORCH_CLIENT_ERROR_FAULT;
47 result = get_device_list(service_name, exec_type, client_pid, deviceList);
48 if (result != ORCH_DBUS_ERROR_NONE)
50 printf("get device list failed\n");
51 return ORCH_CLIENT_ERROR_FAULT;
53 return ORCH_CLIENT_ERROR_NONE;
56 orchestration_client_state_e orchestration_read_capability(char *ip, orchestration_device_capability_s **device_capability)
58 *device_capability = NULL;
61 printf("[read cappability] ip cannot be empty!!\n");
62 return ORCH_CLIENT_ERROR_INVALID_PARAMETER;
65 int client_pid = getpid();
68 result = dbus_consumer_initailze();
69 if (result != ORCH_DBUS_ERROR_NONE)
71 printf("dbus_consumer_initialize failed\n");
72 return ORCH_CLIENT_ERROR_FAULT;
75 result = read_capability(ip, client_pid, device_capability);
76 if (result != ORCH_DBUS_ERROR_NONE)
78 printf("read capability failed\n");
79 return ORCH_CLIENT_ERROR_FAULT;
81 return ORCH_CLIENT_ERROR_NONE;
84 orchestration_client_state_e orchestration_write_capability(char *capability)
86 int client_pid = getpid();
89 result = dbus_consumer_initailze();
90 if (result != ORCH_DBUS_ERROR_NONE)
92 printf("dbus_consumer_initialize failed\n");
93 return ORCH_CLIENT_ERROR_FAULT;
96 result = write_capability(capability, client_pid);
97 if (result != ORCH_DBUS_ERROR_NONE)
99 printf("write capability failed\n");
100 return ORCH_CLIENT_ERROR_FAULT;
102 return ORCH_CLIENT_ERROR_NONE;
105 orchestration_client_state_e orchestration_request_service(char *app_name,
107 orchestration_service_info_s service_info,
108 orchestration_changed_service_status_cb cb,
112 int client_pid = getpid();
114 if (strcmp(app_name, "") == 0)
116 printf("app_name is null\n");
117 return ORCH_CLIENT_ERROR_INVALID_PARAMETER;
121 printf("orchestration_changed_service_status_cb is null\n");
122 return ORCH_CLIENT_ERROR_INVALID_PARAMETER;
124 _changed_service_status_cb = cb;
126 result = dbus_consumer_initailze();
127 if (result != ORCH_DBUS_ERROR_NONE)
129 printf("dbus_consumer_initailze failed\n");
130 return ORCH_CLIENT_ERROR_FAULT;
133 printf("[orchestration_client]\n");
134 printf("\t client_pid : %d\n", client_pid);
135 printf("\t app_name : %s\n", app_name);
136 printf("\t self_select : %s\n", self_select ? "true" : "false");
137 printf("\t count : %d\n", service_info.count);
138 for (int i = 0; i < service_info.count; i++) {
139 printf("\t service_info[%d]->exec_type : %s\n", i, service_info.services[i].exec_type);
140 printf("\t service_info[%d]->exec_parameter : %s\n", i, service_info.services[i].exec_parameter);
143 result = request_service_execute(app_name, self_select, service_info.services, service_info.count, client_pid);
144 if (result != ORCH_DBUS_ERROR_NONE)
146 printf("request_service_execute failed\n");
147 return ORCH_CLIENT_ERROR_FAULT;
150 return ORCH_CLIENT_ERROR_NONE;
153 orchestration_client_state_e orchestration_request_service_on_device(char *app_name,
155 orchestration_service_info_s service_info,
157 orchestration_changed_service_status_cb cb,
161 int client_pid = getpid();
163 if (strcmp(app_name, "") == 0)
165 printf("app_name is null\n");
166 return ORCH_CLIENT_ERROR_INVALID_PARAMETER;
170 printf("orchestration_changed_service_status_cb is null\n");
171 return ORCH_CLIENT_ERROR_INVALID_PARAMETER;
173 _changed_service_status_cb = cb;
175 result = dbus_consumer_initailze();
176 if (result != ORCH_DBUS_ERROR_NONE)
178 printf("dbus_consumer_initailze failed\n");
179 return ORCH_CLIENT_ERROR_FAULT;
182 printf("[orchestration_client]\n");
183 printf("\t client_pid : %d\n", client_pid);
184 printf("\t app_name : %s\n", app_name);
185 printf("\t self_select : %s\n", self_select ? "true" : "false");
186 printf("\t count : %d\n", service_info.count);
187 for (int i = 0; i < service_info.count; i++) {
188 printf("\t service_info[%d]->exec_type : %s\n", i, service_info.services[i].exec_type);
189 printf("\t service_info[%d]->exec_parameter : %s\n", i, service_info.services[i].exec_parameter);
192 result = request_service_execute_on_device(app_name, self_select, service_info.services, ip, service_info.count, client_pid);
193 if (result != ORCH_DBUS_ERROR_NONE)
195 printf("request_service_execute failed\n");
196 return ORCH_CLIENT_ERROR_FAULT;
199 return ORCH_CLIENT_ERROR_NONE;