change sys-noti to resourced dbus interface. 96/34396/4
authorJiwoong Im <jiwoong.im@samsung.com>
Mon, 26 Jan 2015 07:48:13 +0000 (16:48 +0900)
committerJiwoong Im <jiwoong.im@samsung.com>
Tue, 27 Jan 2015 06:43:04 +0000 (22:43 -0800)
sys-noti was managed in system-server which is replaced to resourced and
deviced.
Resource daemon listens foreground/background notification, and manages
process's oom_adj score.
The sysnoti api is changed to resourced dbus interface.

JIRA ticket : TC-2400

Change-Id: Ifca65f48a7863655559ff96c687e2357045fd3f6
Signed-off-by: Jiwoong Im <jiwoong.im@samsung.com>
CMakeLists.txt
packaging/app-core.spec
src/appcore-efl.c

index fd053b714420cadc6b98dd2b44140f06d4252ae3..fa4255ee3d548ab10dfb472eab9443a62ece5945 100644 (file)
@@ -36,7 +36,7 @@ ENDIF (with_wayland)
 SET(HEADERS_common appcore-common.h)
 
 INCLUDE(FindPkgConfig)
-SET(APPCORE_PKG_CHECK_MODULES "vconf sensor aul dlog libtzplatform-config ecore")
+SET(APPCORE_PKG_CHECK_MODULES "dbus-1 vconf sensor aul dlog libtzplatform-config ecore")
 IF (with_x11)
        SET(APPCORE_PKG_CHECK_MODULES "${APPCORE_PKG_CHECK_MODULES} x11 ecore-x")
 ENDIF (with_x11)
index e291ce50d736a5e7c4e903f450a2e82b64bcf782..194330da9ec5d1b1adf70bfab47b118cd6a0c65a 100644 (file)
@@ -18,6 +18,7 @@ BuildRequires:  pkgconfig(x11)
 BuildRequires:  pkgconfig(ecore-x)
 %endif
 Source1001:     app-core.manifest
+BuildRequires:  pkgconfig(dbus-1)
 BuildRequires:  pkgconfig(sensor)
 BuildRequires:  pkgconfig(vconf)
 BuildRequires:  pkgconfig(aul)
index 969fe3c7ccde012ddb85c05b55ae9655ffb5a2f0..c5bcac965ceab27c376709c93e90a53d757929e8 100644 (file)
 #include <glib-object.h>
 #include <malloc.h>
 #include <glib.h>
+#include <dbus/dbus.h>
 #include <stdbool.h>
 #include <aul.h>
 #include "appcore-internal.h"
 #include "appcore-efl.h"
 
-#define SYSMAN_MAXSTR 100
-#define SYSMAN_MAXARG 16
-#define SYSNOTI_SOCKET_PATH "/tmp/sn"
-#define RETRY_READ_COUNT       10
-
-#define PREDEF_BACKGRD                         "backgrd"
-#define PREDEF_FOREGRD                         "foregrd"
-
-enum sysnoti_cmd {
-       ADD_SYSMAN_ACTION,
-       CALL_SYSMAN_ACTION
-};
-
-struct sysnoti {
-       int pid;
-       int cmd;
-       char *type;
-       char *path;
-       int argc;
-       char *argv[SYSMAN_MAXARG];
-};
-
 static pid_t _pid;
 
 static bool resource_reclaiming = TRUE;
 static int tmp_val = 0;
 
+enum proc_status_type { /** cgroup command type **/
+       PROC_STATUS_LAUNCH,
+       PROC_STATUS_RESUME,
+       PROC_STATUS_TERMINATE,
+       PROC_STATUS_FOREGRD,
+       PROC_STATUS_BACKGRD,
+};
 
 struct ui_priv {
        const char *name;
@@ -131,147 +117,47 @@ struct win_node {
 static struct ui_wm_rotate wm_rotate;
 static Eina_Bool __visibility_cb(void *data, int type, void *event);
 
-static inline int send_int(int fd, int val)
-{
-       return write(fd, &val, sizeof(int));
-}
 
-static inline int send_str(int fd, char *str)
+static void _send_to_resourced(enum proc_status_type type)
 {
-       int len;
-       int ret;
-       if (str == NULL) {
-               len = 0;
-               ret = write(fd, &len, sizeof(int));
-       } else {
-               len = strlen(str);
-               if (len > SYSMAN_MAXSTR)
-                       len = SYSMAN_MAXSTR;
-               write(fd, &len, sizeof(int));
-               ret = write(fd, str, len);
-       }
-       return ret;
-}
+       DBusConnection *conn;
+       DBusMessage* msg;
+       DBusError dbus_error;
 
-static int sysnoti_send(struct sysnoti *msg)
-{
-       _ERR("--- %s: start", __FUNCTION__);
-       int client_len;
-       int client_sockfd;
-       int result;
-       int r;
-       int retry_count = 0;
-       struct sockaddr_un clientaddr;
-       int i;
-
-       client_sockfd = socket(AF_UNIX, SOCK_STREAM, 0);
-       if (client_sockfd == -1) {
-               _ERR("%s: socket create failed\n", __FUNCTION__);
-               return -1;
-       }
-       bzero(&clientaddr, sizeof(clientaddr));
-       clientaddr.sun_family = AF_UNIX;
-       strncpy(clientaddr.sun_path, SYSNOTI_SOCKET_PATH, sizeof(clientaddr.sun_path) - 1);
-       client_len = sizeof(clientaddr);
-
-       if (connect(client_sockfd, (struct sockaddr *)&clientaddr, client_len) <
-           0) {
-               _ERR("%s: connect failed\n", __FUNCTION__);
-               close(client_sockfd);
-               return -1;
-       }
-
-       send_int(client_sockfd, msg->pid);
-       send_int(client_sockfd, msg->cmd);
-       send_str(client_sockfd, msg->type);
-       send_str(client_sockfd, msg->path);
-       send_int(client_sockfd, msg->argc);
-       for (i = 0; i < msg->argc; i++)
-               send_str(client_sockfd, msg->argv[i]);
-
-       _ERR("--- %s: read", __FUNCTION__);
-       while (retry_count < RETRY_READ_COUNT) {
-               r = read(client_sockfd, &result, sizeof(int));
-               if (r < 0) {
-                       if (errno == EINTR) {
-                               _ERR("Re-read for error(EINTR)");
-                               retry_count++;
-                               continue;
-                       }
-                       _ERR("Read fail for str length");
-                       result = -1;
-                       break;
+       dbus_error_init(&dbus_error);
 
-               }
-               break;
-       }
-       if (retry_count == RETRY_READ_COUNT) {
-               _ERR("Read retry failed");
+       conn = dbus_bus_get(DBUS_BUS_SYSTEM, &dbus_error);
+       if (!conn) {
+               _ERR("dbus_bus_get failed : [%s]", dbus_error.message);
+               dbus_error_free(&dbus_error);
+               return;
        }
 
-       close(client_sockfd);
-       _ERR("--- %s: end", __FUNCTION__);
-       return result;
-}
-
-static int _call_predef_action(const char *type, int num, ...)
-{
-       _ERR("--- %s: start", __FUNCTION__);
-       struct sysnoti *msg;
-       int ret;
-       va_list argptr;
-
-       int i;
-       char *args = NULL;
-
-       if (type == NULL || num > SYSMAN_MAXARG) {
-               errno = EINVAL;
-               return -1;
+       msg = dbus_message_new_signal("/Org/Tizen/ResourceD/Process",
+                       "org.tizen.resourced.process",
+                       "ProcStatus");
+       if (!msg) {
+               _ERR("dbus_message_new_signal is failed");
+               return;
        }
 
-       msg = malloc(sizeof(struct sysnoti));
-
-       if (msg == NULL) {
-               /* Do something for not enought memory error */
-               return -1;
+       if (!dbus_message_append_args(msg,
+                               DBUS_TYPE_INT32, &type,
+                               DBUS_TYPE_INT32, &_pid,
+                               DBUS_TYPE_INVALID)) {
+               _ERR("dbus_message_append_args is failed. type = %d, pid = %d",
+                               type, _pid);
+               dbus_message_unref(msg);
+               return;
        }
 
-       msg->pid = getpid();
-       msg->cmd = CALL_SYSMAN_ACTION;
-       msg->type = (char *)type;
-       msg->path = NULL;
-
-       msg->argc = num;
-       va_start(argptr, num);
-       for (i = 0; i < num; i++) {
-               args = va_arg(argptr, char *);
-               msg->argv[i] = args;
+       if (!dbus_connection_send (conn, msg, NULL)) {
+               _ERR("dbus_connection_send is failed");
        }
-       va_end(argptr);
-
-       _ERR("--- %s: send msg", __FUNCTION__);
-       ret = sysnoti_send(msg);
-       free(msg);
-
-       _ERR("--- %s: end", __FUNCTION__);
-       return ret;
-}
-
-static int _inform_foregrd(void)
-{
-       char buf[255];
-       snprintf(buf, sizeof(buf), "%d", getpid());
-       return _call_predef_action(PREDEF_FOREGRD, 1, buf);
-}
 
-static int _inform_backgrd(void)
-{
-       char buf[255];
-       snprintf(buf, sizeof(buf), "%d", getpid());
-       return _call_predef_action(PREDEF_BACKGRD, 1, buf);
+       dbus_message_unref(msg);
 }
 
-
 static int WIN_COMP(gconstpointer data1, gconstpointer data2)
 {
        struct win_node *a = (struct win_node *)data1;
@@ -388,8 +274,7 @@ static void __do_app(enum app_event event, void *data, bundle * b)
                }
                /* TODO : rotation stop */
                //r = appcore_pause_rotation_cb();
-
-               _inform_backgrd();
+               _send_to_resourced(PROC_STATUS_BACKGRD);
                break;
        case AE_RESUME:
                LOG(LOG_DEBUG, "LAUNCH", "[%s:Application:resume:start]",
@@ -407,8 +292,7 @@ static void __do_app(enum app_event event, void *data, bundle * b)
                    ui->name);
                LOG(LOG_DEBUG, "LAUNCH", "[%s:Application:Launching:done]",
                    ui->name);
-               _inform_foregrd();
-
+               _send_to_resourced(PROC_STATUS_FOREGRD);
                break;
        default:
                /* do nothing */