* See the License for the specific language governing permissions and
* limitations under the License.
*
-*/
+ */
/**
*
*/
+#include <error.h>
#include <Ecore.h>
#include "util.h"
#include "device-node.h"
#include "core/common.h"
+
#define DISP_INDEX_BIT 4
#define COMBINE_DISP_CMD(cmd, prop, index) (cmd = (prop | (index << DISP_INDEX_BIT)))
-static DBusMessage* e_dbus_start_cb(E_DBus_Object *obj, DBusMessage* msg)
+static DBusMessage *e_dbus_start_cb(E_DBus_Object *obj, DBusMessage *msg)
{
start_pm_main();
return dbus_message_new_method_return(msg);
}
-static DBusMessage* e_dbus_stop_cb(E_DBus_Object *obj, DBusMessage* msg)
+static DBusMessage *e_dbus_stop_cb(E_DBus_Object *obj, DBusMessage *msg)
{
end_pm_main();
return dbus_message_new_method_return(msg);
}
-static DBusMessage* e_dbus_getbrightness_cb(E_DBus_Object *obj, DBusMessage* msg)
+static DBusMessage *e_dbus_lockstate_cb(E_DBus_Object *obj, DBusMessage *msg)
+{
+ DBusError err;
+ DBusMessageIter iter;
+ DBusMessage *reply;
+ char *state_str;
+ char *option1_str;
+ char *option2_str;
+ int timeout;
+ pid_t pid;
+ int state;
+ int flag;
+ int ret;
+
+ dbus_error_init(&err);
+
+ if (!dbus_message_get_args(msg, &err,
+ DBUS_TYPE_STRING, &state_str,
+ DBUS_TYPE_STRING, &option1_str,
+ DBUS_TYPE_STRING, &option2_str,
+ DBUS_TYPE_INT32, &timeout, DBUS_TYPE_INVALID)) {
+ LOGERR("there is no message");
+ ret = -EINVAL;
+ goto out;
+ }
+
+ if (!state_str || timeout < 0) {
+ LOGERR("message is invalid!");
+ ret = -EINVAL;
+ goto out;
+ }
+
+ pid = get_edbus_sender_pid(msg);
+ if (kill(pid, 0) == -1) {
+ LOGERR("%d process does not exist, dbus ignored!", pid);
+ ret = -ESRCH;
+ goto out;
+ }
+
+ if (!strcmp(state_str, PM_LCDON_STR))
+ state = LCD_NORMAL;
+ else if (!strcmp(state_str, PM_LCDDIM_STR))
+ state = LCD_DIM;
+ else if (!strcmp(state_str, PM_LCDOFF_STR))
+ state = LCD_OFF;
+ else {
+ LOGERR("%s state is invalid, dbus ignored!", state_str);
+ ret = -EINVAL;
+ goto out;
+ }
+
+ if (!strcmp(option1_str, STAYCURSTATE_STR))
+ flag = STAY_CUR_STATE;
+ else if (!strcmp(option1_str, GOTOSTATENOW_STR))
+ flag = GOTO_STATE_NOW;
+ else {
+ LOGERR("%s option is invalid. set default option!", option1_str);
+ flag = STAY_CUR_STATE;
+ }
+
+ ret = pm_lock_internal(pid, state, flag, timeout);
+out:
+ reply = dbus_message_new_method_return(msg);
+ dbus_message_iter_init_append(reply, &iter);
+ dbus_message_iter_append_basic(&iter, DBUS_TYPE_INT32, &ret);
+
+ return reply;
+}
+
+static DBusMessage *e_dbus_unlockstate_cb(E_DBus_Object *obj, DBusMessage *msg)
+{
+ DBusError err;
+ DBusMessageIter iter;
+ DBusMessage *reply;
+ char *state_str;
+ char *option_str;
+ pid_t pid;
+ int state;
+ int flag;
+ int ret;
+
+ dbus_error_init(&err);
+
+ if (!dbus_message_get_args(msg, &err,
+ DBUS_TYPE_STRING, &state_str,
+ DBUS_TYPE_STRING, &option_str, DBUS_TYPE_INVALID)) {
+ LOGERR("there is no message");
+ ret = -EINVAL;
+ goto out;
+ }
+
+ if (!state_str) {
+ LOGERR("message is invalid!");
+ ret = -EINVAL;
+ goto out;
+ }
+
+ pid = get_edbus_sender_pid(msg);
+ if (kill(pid, 0) == -1) {
+ LOGERR("%d process does not exist, dbus ignored!", pid);
+ ret = -ESRCH;
+ goto out;
+ }
+
+ if (!strcmp(state_str, PM_LCDON_STR))
+ state = LCD_NORMAL;
+ else if (!strcmp(state_str, PM_LCDDIM_STR))
+ state = LCD_DIM;
+ else if (!strcmp(state_str, PM_LCDOFF_STR))
+ state = LCD_OFF;
+ else {
+ LOGERR("%s state is invalid, dbus ignored!", state_str);
+ ret = -EINVAL;
+ goto out;
+ }
+
+ if (!strcmp(option_str, SLEEP_MARGIN_STR))
+ flag = PM_SLEEP_MARGIN;
+ else if (!strcmp(option_str, RESET_TIMER_STR))
+ flag = PM_RESET_TIMER;
+ else if (!strcmp(option_str, KEEP_TIMER_STR))
+ flag = PM_KEEP_TIMER;
+ else {
+ LOGERR("%s option is invalid. set default option!", option_str);
+ flag = PM_RESET_TIMER;
+ }
+
+ ret = pm_unlock_internal(pid, state, flag);
+out:
+ reply = dbus_message_new_method_return(msg);
+ dbus_message_iter_init_append(reply, &iter);
+ dbus_message_iter_append_basic(&iter, DBUS_TYPE_INT32, &ret);
+
+ return reply;
+}
+
+static DBusMessage *e_dbus_changestate_cb(E_DBus_Object *obj, DBusMessage *msg)
+{
+ DBusError err;
+ DBusMessageIter iter;
+ DBusMessage *reply;
+ char *state_str;
+ pid_t pid;
+ int state;
+ int ret;
+
+ dbus_error_init(&err);
+
+ if (!dbus_message_get_args(msg, &err,
+ DBUS_TYPE_STRING, &state_str, DBUS_TYPE_INVALID)) {
+ LOGERR("there is no message");
+ ret = -EINVAL;
+ goto out;
+ }
+
+ if (!state_str) {
+ LOGERR("message is invalid!");
+ ret = -EINVAL;
+ goto out;
+ }
+
+ pid = get_edbus_sender_pid(msg);
+ if (kill(pid, 0) == -1) {
+ LOGERR("%d process does not exist, dbus ignored!", pid);
+ ret = -ESRCH;
+ goto out;
+ }
+
+ if (!strcmp(state_str, PM_LCDON_STR))
+ state = LCD_NORMAL;
+ else if (!strcmp(state_str, PM_LCDDIM_STR))
+ state = LCD_DIM;
+ else if (!strcmp(state_str, PM_LCDOFF_STR))
+ state = LCD_OFF;
+ else {
+ LOGERR("%s state is invalid, dbus ignored!", state_str);
+ ret = -EINVAL;
+ goto out;
+ }
+
+ ret = pm_change_internal(pid, state);
+out:
+ reply = dbus_message_new_method_return(msg);
+ dbus_message_iter_init_append(reply, &iter);
+ dbus_message_iter_append_basic(&iter, DBUS_TYPE_INT32, &ret);
+
+ return reply;
+}
+
+static DBusMessage *e_dbus_getbrightness_cb(E_DBus_Object *obj, DBusMessage *msg)
{
DBusMessageIter iter;
DBusMessage *reply;
return reply;
}
-static DBusMessage* e_dbus_setbrightness_cb(E_DBus_Object *obj, DBusMessage* msg)
+static DBusMessage *e_dbus_setbrightness_cb(E_DBus_Object *obj, DBusMessage *msg)
{
DBusMessageIter iter;
DBusMessage *reply;
const char *reply_signature;
E_DBus_Method_Cb func;
} edbus_methods[] = {
- { "start", NULL, NULL, e_dbus_start_cb },
- { "stop", NULL, NULL, e_dbus_stop_cb },
- { "getbrightness", NULL, "i", e_dbus_getbrightness_cb },
- { "setbrightness", "i", "i", e_dbus_setbrightness_cb },
- /* Add methods here */
+ { "start", NULL, NULL, e_dbus_start_cb },
+ { "stop", NULL, NULL, e_dbus_stop_cb },
+ { "lockstate", "sssi", "i", e_dbus_lockstate_cb },
+ { "unlockstate", "ss", "i", e_dbus_unlockstate_cb },
+ { "changestate", "s", "i", e_dbus_changestate_cb },
+ { "getbrightness", NULL, "i", e_dbus_getbrightness_cb },
+ { "setbrightness", "i", "i", e_dbus_setbrightness_cb }
+ /* Add methods here */
};
int init_pm_dbus(void)
return NULL;
}
+pid_t get_edbus_sender_pid(DBusMessage *msg)
+{
+ const char *sender;
+ DBusMessage *send_msg;
+ DBusPendingCall *pending;
+ DBusMessageIter iter;
+ int ret;
+ pid_t pid;
+
+ if (!msg) {
+ PRT_TRACE_ERR("invalid argument!");
+ return -1;
+ }
+
+ sender = dbus_message_get_sender(msg);
+ if (!sender) {
+ PRT_TRACE_ERR("invalid sender!");
+ return -1;
+ }
+
+ send_msg = dbus_message_new_method_call(DBUS_SERVICE_DBUS,
+ DBUS_PATH_DBUS,
+ DBUS_INTERFACE_DBUS,
+ "GetConnectionUnixProcessID");
+ if (!send_msg) {
+ PRT_TRACE_ERR("invalid send msg!");
+ return -1;
+ }
+
+ ret = dbus_message_append_args(send_msg, DBUS_TYPE_STRING,
+ &sender, DBUS_TYPE_INVALID);
+ if (!ret) {
+ PRT_TRACE_ERR("fail to append args!");
+ dbus_message_unref(send_msg);
+ return -1;
+ }
+
+ pending = e_dbus_message_send(edbus_conn, send_msg, NULL, -1, NULL);
+ if (!pending) {
+ PRT_TRACE_ERR("pending is null!");
+ dbus_message_unref(send_msg);
+ return -1;
+ }
+
+ dbus_message_unref(send_msg);
+
+ /* block until reply is received */
+ dbus_pending_call_block(pending);
+
+ msg = dbus_pending_call_steal_reply(pending);
+ dbus_pending_call_unref(pending);
+ if (!msg) {
+ PRT_TRACE_ERR("reply msg is null!");
+ return -1;
+ }
+
+ dbus_message_iter_init(msg, &iter);
+ dbus_message_iter_get_basic(&iter, &pid);
+ dbus_message_unref(msg);
+
+ return pid;
+}
+
static void unregister_edbus_signal_handle(void)
{
Eina_List *tmp;