#include "e.h"
#include "e_mod_processmgr.h"
+#define PATH "/org/enlightenment/wm"
+#define IFACE "org.enlightenment.wm.proc"
+
static Eina_List *hooks_ec = NULL;
+Eldbus_Connection *_e_processmgr_conn;
+Eldbus_Service_Interface *_e_processmgr_iface;
static void _e_processmgr_process_action_send(int pid, E_Process_Action act);
static void _e_processmgr_cb_hook_action_change(void *d EINA_UNUSED, E_Process *epro, void *user);
+static Eldbus_Message* _e_processmgr_process_info_get(const Eldbus_Service_Interface *iface EINA_UNUSED, const Eldbus_Message *msg);
+
+static const Eldbus_Method _e_processmgr_methods[] = {
+ { "GetProcStatus", ELDBUS_ARGS({"i", "pid"}), ELDBUS_ARGS({"i","process status"}, {"i", "focused"}), _e_processmgr_process_info_get, 0 },
+ { NULL, NULL, NULL, NULL, 0 }
+};
+static const Eldbus_Service_Interface_Desc iface_desc = {
+ IFACE, _e_processmgr_methods, NULL, NULL, NULL, NULL
+};
static void
_e_processmgr_process_action_send(int pid, E_Process_Action act)
{
- Eldbus_Connection *conn;
Eldbus_Message *msg;
-
int param_pid;
int param_act;
- conn = eldbus_connection_get(ELDBUS_CONNECTION_TYPE_SYSTEM);
- if (!conn) return;
+ if (!_e_processmgr_conn) return;
// set up msg for resourced
msg = eldbus_message_signal_new("/Org/Tizen/ResourceD/Process",
ELOGF("PROCESSMGR", "SEND ACTION:%d to PID:%d", NULL, NULL, act, pid);
// send the message
- if (!eldbus_connection_send(conn, msg, NULL, NULL, -1))
+ if (!eldbus_connection_send(_e_processmgr_conn, msg, NULL, NULL, -1))
return;
eldbus_message_unref(msg);
_e_processmgr_process_action_send(pid, action);
}
+static int
+_e_processmgr_process_is_focused(int pid)
+{
+ E_Client* focused_ec = NULL;
+
+ if (pid <= 0) return 0;
+
+ focused_ec = e_client_focused_get();
+ if (!focused_ec) return 0;
+
+ if (focused_ec->netwm.pid == pid)
+ return 1;
+ else
+ return 0;
+}
+
+static Eldbus_Message *
+_e_processmgr_process_info_get(const Eldbus_Service_Interface *iface EINA_UNUSED, const Eldbus_Message *msg)
+{
+ Eldbus_Message *reply = eldbus_message_method_return_new(msg);
+ int pid = -1;
+ int status = 0;
+ int is_focused = 0;
+
+ if (!eldbus_message_arguments_get(msg, "i", &pid))
+ {
+ ERR("Error getting arguments.");
+ return reply;
+ }
+
+ status = e_process_state_get(pid);
+ is_focused = _e_processmgr_process_is_focused(pid);
+
+ eldbus_message_arguments_append(reply, "ii", status, is_focused);
+
+ return reply;
+}
+
+static Eina_Bool
+_e_processmgr_dbus_init(void *data EINA_UNUSED)
+{
+ if (_e_processmgr_conn) return ECORE_CALLBACK_CANCEL;
+
+ if (!_e_processmgr_conn)
+ _e_processmgr_conn = eldbus_connection_get(ELDBUS_CONNECTION_TYPE_SYSTEM);
+
+ if(!_e_processmgr_conn)
+ {
+ ecore_timer_add(1, _e_processmgr_dbus_init, NULL);
+ return ECORE_CALLBACK_CANCEL;
+ }
+
+ _e_processmgr_iface = eldbus_service_interface_register(_e_processmgr_conn,
+ PATH,
+ &iface_desc);
+ EINA_SAFETY_ON_NULL_GOTO(_e_processmgr_iface, err);
+
+ return ECORE_CALLBACK_CANCEL;
+
+err:
+ if (_e_processmgr_conn)
+ {
+ eldbus_connection_unref(_e_processmgr_conn);
+ _e_processmgr_conn = NULL;
+ }
+
+ return ECORE_CALLBACK_CANCEL;
+}
+
+static void
+_e_processmgr_dbus_shutdown(void)
+{
+ if (_e_processmgr_iface)
+ {
+ eldbus_service_interface_unregister(_e_processmgr_iface);
+ _e_processmgr_iface = NULL;
+ }
+
+ if (_e_processmgr_conn)
+ {
+ eldbus_connection_unref(_e_processmgr_conn);
+ _e_processmgr_conn = NULL;
+ }
+}
EAPI Eina_Bool
e_mod_processmgr_init(void)
if (!eldbus_init())
return EINA_FALSE;
+ _e_processmgr_dbus_init(NULL);
+
hook = e_process_hook_add(E_PROCESS_HOOK_ACTION_CHANGE, _e_processmgr_cb_hook_action_change, NULL);
if (hook) hooks_ec = eina_list_append(hooks_ec, hook);
{
E_Client_Hook *hook;
+ _e_processmgr_dbus_shutdown();
+
eldbus_shutdown();
EINA_LIST_FREE(hooks_ec, hook)