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 *******************************************************************************/
25 #include <orchestration_server.h>
27 int get_process_name_by_pid(char* process_name, int pid) {
28 char fname[1024] = {0, };
29 char line[1024] = {0, };
30 ssize_t fname_len = snprintf(NULL, 0, "/proc/%d/status", pid);
32 snprintf(fname, fname_len + 1, "/proc/%d/status", pid);
33 FILE *fp = fopen(fname, "r");
35 DEBUG("%d Process not found!!!\n", pid);
39 fgets(line, 1024, fp);
40 if (strstr(line, "Name:") != NULL) {
42 char *ptr = strchr(line, ':');
45 if (*ptr == '\n' || *ptr == '\0')
47 if (*ptr != ' ' && *ptr != '\t')
48 process_name[index++] = *ptr;
50 process_name[index] = '\0';
51 printf("process_name = %s\n", process_name);
56 printf("%d Process status have no Process name!!\n", pid);
61 int request_cb(char* app_name, bool self_select, RequestServiceInfo service_info[], int count, int client_pid){
62 int ret = ORCH_ERROR_NONE;
63 char process_name[128] = {0, };
64 const char unknown[] = "Unknown";
65 ResponseService result;
67 if (get_process_name_by_pid(process_name, client_pid) != 0) {
68 DEBUG("could not get Process name");
69 strncpy(process_name, unknown, strlen(unknown));
72 DEBUG("[orchestration_server]\n")
73 DEBUG("\t app_name : %s\n", app_name);
74 DEBUG("\t self_select : %s\n", self_select ? "true" : "false");
75 DEBUG("\t count : %d\n", count);
76 DEBUG("\t client_pid : %d\n", client_pid);
77 DEBUG("\t process_name : %s\n", process_name);
78 for (int ix = 0; ix < count; ix++) {
79 DEBUG("\t service_info[%d].ExecutionType : %s\n", ix, service_info[ix].ExecutionType);
80 DEBUG("\t service_info[%d].ExeCmd : %s\n", ix, service_info[ix].ExeCmd);
83 result = OrchestrationRequestService(app_name, self_select, process_name, service_info, count);
84 DEBUG("result = %s\n", result.Message);
86 /* TO DO : parsing API response */
90 void* thread_orchestration() {
91 DEBUG("Start OrchestrationInit Thread !!\n");
102 /* DEBUG for log can be used after OrchestrationInit */
103 if (pthread_create(&p_thread, NULL, thread_orchestration, NULL) != 0) {
104 DEBUG("Fail to start OrchestrationInit Thread !!");
108 set_default_dbus_interface();
109 DEBUG("orchestration_server_initialize call\n");
110 result = orchestration_server_initialize(request_cb);
111 if(result != ORCH_ERROR_NONE){
112 DEBUG("orchestration_server_initialize failed\n");
113 orchestration_server_finish();
116 loop = g_main_loop_new(NULL, FALSE);
120 g_main_loop_run (loop);
121 orchestration_server_finish();
127 void printLog(const char *format, ...) {
132 va_start(args, format);
133 buf_size = vsnprintf(0, 0, format, args);
136 buffer = malloc(buf_size + 1);
139 va_start(args, format);
140 vsnprintf(buffer, buf_size + 1, format, args);
142 if (buffer != NULL) free(buffer);