#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;
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;
}
/* 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]",
ui->name);
LOG(LOG_DEBUG, "LAUNCH", "[%s:Application:Launching:done]",
ui->name);
- _inform_foregrd();
-
+ _send_to_resourced(PROC_STATUS_FOREGRD);
break;
default:
/* do nothing */