Add Process Name parameter on DBUS server 21/215221/5
authorwansu.yoo <wansu.yoo@samsung.com>
Thu, 3 Oct 2019 06:02:07 +0000 (15:02 +0900)
committerwansu.yoo <wansu.yoo@samsung.com>
Fri, 4 Oct 2019 05:48:27 +0000 (14:48 +0900)
-. get PID form DBUS client
-. get Process Name form PID
-. add Process Name as parameter on C-API

Change-Id: I0b326d02ba0c0245ab92a3f0905eb04fb759afdc
Signed-off-by: wansu.yoo <wansu.yoo@samsung.com>
CMain/inc/orchestration.h
CMain/inc/orchestration_server.h
CMain/src/main.c
CMain/src/orchestration_server.c
libedge-orchestration/inc/dbus_consumer.h
libedge-orchestration/src/dbus_consumer.c
libedge-orchestration/src/orchestration_client.c

index e25d012..3417743 100644 (file)
@@ -106,7 +106,7 @@ extern "C" {
 
 extern int OrchestrationInit();
 
-extern ResponseService OrchestrationRequestService(char* p0, int p1, RequestServiceInfo* p2, int p3);
+extern ResponseService OrchestrationRequestService(char* p0, int p1, char* p2, RequestServiceInfo* p3, int p4);
 
 extern int PrintLog(char* p0);
 
index 4661ec3..f3f32bd 100644 (file)
@@ -42,7 +42,7 @@ typedef enum  {
        ORCH_ERROR_NONE = 0,
 } _orchestration_state_e;
 
-typedef int (*request_service_cb)(char* app_name, bool self_select, RequestServiceInfo service_info[], int count);
+typedef int (*request_service_cb)(char* app_name, bool self_select, RequestServiceInfo service_info[], int count, int client_pid);
 
 void set_default_dbus_interface(void);
 int orchestration_server_initialize(request_service_cb cb);
index a317850..09d8c95 100644 (file)
 #include <stdarg.h>
 #include <stdlib.h>
 #include <pthread.h>
+#include <string.h>
 
 #include <orchestration_server.h>
 
-int request_cb(char* app_name, bool self_select, RequestServiceInfo service_info[], int count){
+int get_process_name_by_pid(char* process_name, int pid) {
+       char fname[1024] = {0, };
+       char line[1024] = {0, };
+       ssize_t fname_len = snprintf(NULL, 0, "/proc/%d/status", pid);
+
+       snprintf(fname, fname_len + 1, "/proc/%d/status", pid);
+       FILE *fp = fopen(fname, "r");
+       if (fp == NULL) {
+               DEBUG("%d Process not found!!!\n", pid);
+               return -1;
+       }
+       while (!feof(fp)) {
+               fgets(line, 1024, fp);
+               if (strstr(line, "Name:") != NULL) {
+                       int index = 0;
+                       char *ptr = strchr(line, ':');
+                       while (1) {
+                               ptr++;
+                               if (*ptr == '\n' || *ptr == '\0')
+                                       break;
+                               if (*ptr != ' ' && *ptr != '\t')
+                                       process_name[index++] = *ptr;
+                       }
+                       process_name[index] = '\0';
+                       printf("process_name = %s\n", process_name);
+                       fclose(fp);
+                       return 0;
+               }
+       }
+       printf("%d Process status have no Process name!!\n", pid);
+       fclose(fp);
+       return -1;
+}
+
+int request_cb(char* app_name, bool self_select, RequestServiceInfo service_info[], int count, int client_pid){
        int ret = ORCH_ERROR_NONE;
+       char process_name[128] = {0, };
        ResponseService result;
 
+       if (get_process_name_by_pid(process_name, client_pid) != 0) {
+               DEBUG("could not get Process name");
+               strncpy(process_name, "Unknown", strlen("Unknown"));
+       }
+
        DEBUG("[orchestration_server]\n")
        DEBUG("\t app_name : %s\n", app_name);
        DEBUG("\t self_select : %s\n", self_select ? "true" : "false");
        DEBUG("\t count : %d\n", count);
+       DEBUG("\t client_pid : %d\n", client_pid);
+       DEBUG("\t process_name : %s\n", process_name);
        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 = OrchestrationRequestService(app_name, self_select, service_info, count);
+       result = OrchestrationRequestService(app_name, self_select, process_name, service_info, count);
        DEBUG("result = %s\n", result.Message);
 
        /* TO DO : parsing API response */
index 504a774..42d4972 100644 (file)
@@ -41,6 +41,7 @@ static gchar introspection_xml[] =
     "          <arg type='i' name='self_select' direction='in'/>"
     "          <arg type='a(ss)' name='service_info' direction='in'/>"
     "          <arg type='i' name='count' direction='in'/>"
+    "          <arg type='i' name='client_pid' direction='in'/>"
     "          <arg type='i' name='return_value' direction='out'/>"
     "        </method>"
     "  </interface>"
@@ -66,6 +67,7 @@ static int _request_service(GVariant *parameters)
     char *app_name;
     int count;
     bool self_select;
+    int client_pid;
     GVariantIter *iter;
     RequestServiceInfo service_info[MAX_SVC_INFO_NUM] = {NULL, };
 
@@ -74,12 +76,13 @@ static int _request_service(GVariant *parameters)
         return ORCH_ERROR_INVALID_PARAMETER;
     }
 
-    g_variant_get(parameters, "(sia(ss)i)", &app_name, &self_select, &iter, &count);
+    g_variant_get(parameters, "(sia(ss)ii)", &app_name, &self_select, &iter, &count, &client_pid);
 
     DEBUG("[orchestration dbus_interface] _request_service\n");
     DEBUG("\t app_name = %s\n", app_name);
     DEBUG("\t self_select = %s\n", self_select ? "true" : "false");
     DEBUG("\t count = %d\n", count);
+    DEBUG("\t client_pid = %d\n", client_pid);
 
     for (int i = 0; i < count; i++) {
         g_variant_iter_loop (iter, "(ss)", &service_info[i].ExecutionType, &service_info[i].ExeCmd);
@@ -92,7 +95,7 @@ static int _request_service(GVariant *parameters)
     if (g_strcmp0(app_name, "") == 0)
         return ORCH_ERROR_INVALID_PARAMETER;
 
-    result = _request_service_cb(app_name, self_select, service_info, count);
+    result = _request_service_cb(app_name, self_select, service_info, count, client_pid);
 
     return result;
 }
@@ -126,10 +129,11 @@ static void _handle_method_call(
 }
 
 static const GDBusInterfaceVTable _interface_vtable =
-    {
-        _handle_method_call,
-        NULL,
-        NULL};
+{
+    _handle_method_call,
+    NULL,
+    NULL
+};
 
 static int _get_sync(void)
 {
index dea127d..ac736fa 100644 (file)
@@ -32,7 +32,7 @@ typedef enum  {
 } _orchestration_dbus_state_e;
 
 int dbus_consumer_initailze();
-int request_service_execute(char* app_name, bool self_select, service_info_s service_info[], int count);
+int request_service_execute(char* app_name, bool self_select, service_info_s service_info[], int count, int client_pid);
 
 #ifdef __cplusplus
 }
index f7dc435..b98b54c 100755 (executable)
@@ -47,7 +47,7 @@ int dbus_consumer_initailze()
     return ORCH_DBUS_ERROR_NONE;
 }
 
-int request_service_execute(char* app_name, bool self_select, service_info_s service_info[], int count)
+int request_service_execute(char* app_name, bool self_select, service_info_s service_info[], int count, int client_pid)
 {
     int idx;
     GError *error = NULL;
@@ -58,6 +58,7 @@ int request_service_execute(char* app_name, bool self_select, service_info_s ser
     printf("\t app_name = %s\n", app_name);
     printf("\t self_select = %s\n", self_select ? "true" : "false");
     printf("\t count = %d\n", count);
+    printf("\t client_pid = %d\n", client_pid);
     for (idx = 0; idx < count; idx++) {
         printf("\t service_info[%d].exec_type = %s\n", idx, service_info[idx].exec_type);
         printf("\t service_info[%d].exec_parameter = %s\n", idx, service_info[idx].exec_parameter);
@@ -73,7 +74,7 @@ int request_service_execute(char* app_name, bool self_select, service_info_s ser
         );
     }
 
-    services = g_variant_new ("(sia(ss)i)", app_name, self_select, builder, count);
+    services = g_variant_new ("(sia(ss)ii)", app_name, self_select, builder, count, client_pid);
     g_variant_builder_unref (builder);
 
     GVariant *result =
index e2a9305..8db5e5b 100755 (executable)
@@ -35,6 +35,7 @@ orchestration_client_state_e orchestration_request_service(char *app_name,
                                                         void *user_data)
 {
     int result = 0;
+    int client_pid = getpid();
 
     if (strcmp(app_name, "") == 0)
     {
@@ -56,6 +57,7 @@ orchestration_client_state_e orchestration_request_service(char *app_name,
     }
 
     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);
@@ -64,7 +66,7 @@ orchestration_client_state_e orchestration_request_service(char *app_name,
         printf("\t service_info[%d]->exec_parameter : %s\n", i, service_info.services[i].exec_parameter);
     }
 
-    result = request_service_execute(app_name, self_select, service_info.services, service_info.count);
+    result = request_service_execute(app_name, self_select, service_info.services, service_info.count, client_pid);
     if (result != ORCH_DBUS_ERROR_NONE)
     {
         printf("request_service_execute failed\n");