#include <stdbool.h>
#include <libsyscommon/libgdbus.h>
#include <device/display.h>
+#include <device/power.h>
#include "ambient-mode.h"
#include "core/log.h"
return g_variant_new("(i)", ret);
}
+static GVariant *dbus_pmlockgetlockstate(GDBusConnection *conn,
+ const gchar *sender, const gchar *path, const gchar *iface, const gchar *name,
+ GVariant *param, GDBusMethodInvocation *invocation, gpointer user_data)
+{
+ power_lock_e power_lock_type;
+ bool pmlock_state = false;
+ enum state_t pmlock_type;
+ pid_t pid;
+
+ g_variant_get(param, "(i)", &power_lock_type);
+
+ if (power_lock_type < POWER_LOCK_CPU || power_lock_type > POWER_LOCK_DISPLAY_DIM)
+ _W("Invalid parameter power lock type=(%d)", power_lock_type);
+
+ pmlock_type = power_lock_type_to_pmlock(power_lock_type);
+
+ pmlock_state = pmlock_get_lock_state(pmlock_type);
+
+ pid = gdbus_connection_get_sender_pid(conn, sender);
+ _D("Pmlock get lock state pid=%d power lock state=%d", pid, pmlock_state);
+
+ return g_variant_new("(i)", (int)pmlock_state);
+}
+
static const dbus_method_s dbus_methods[] = {
{ "start", NULL, NULL, dbus_start },
{ "stop", NULL, NULL, dbus_stop },
{ "SetWhiteBalance", "ii", "i", dbus_setwhitebalance},
{ "GetWhiteBalance", "i", "i", dbus_getwhitebalance},
{ "GetRotationAngle", "i", "iii", dbus_getrotationangle},
- { "SetRotationAngle", "iii", "i", dbus_setrotationangle}
+ { "SetRotationAngle", "iii", "i", dbus_setrotationangle},
+ { "PmlockGetLockState", "i", "i", dbus_pmlockgetlockstate},
/* Add methods here */
};
return false;
}
+bool pmlock_get_lock_state(enum state_t state)
+{
+ return (bool)SYS_G_LIST_LENGTH(cond_head[state]);
+}
+
+enum state_t power_lock_type_to_pmlock(power_lock_e power_lock_type)
+{
+ switch(power_lock_type) {
+ case POWER_LOCK_CPU:
+ return S_LCDOFF;
+ case POWER_LOCK_DISPLAY:
+ return S_LCDON;
+ case POWER_LOCK_DISPLAY_DIM:
+ return S_LCDDIM;
+ default:
+ return S_END;
+ }
+}
+
static void refresh_app_cond(void)
{
trans_condition = 0;
trans_condition |= MASK_OFF;
}
+static void broadcast_pmlock_state_changed(enum state_t state)
+{
+ int num_of_pmlock;
+
+ switch(state) {
+ case S_LCDON:
+ case S_LCDDIM:
+ case S_LCDOFF:
+ break;
+ default:
+ return;
+ }
+
+ num_of_pmlock = g_list_length(cond_head[state]);
+ if (num_of_pmlock > 1)
+ return;
+
+ gdbus_signal_emit(NULL,
+ DEVICED_PATH_DISPLAY,
+ DEVICED_INTERFACE_DISPLAY,
+ DEVICED_SIGNAL_POWER_LOCK_STATE_CHANGED,
+ g_variant_new("(ii)", state, num_of_pmlock));
+}
+
static void broadcast_pmlock_expired(pid_t pid, enum state_t state, const char* appid, time_t locktime)
{
time_t now;
SYS_G_LIST_APPEND(cond_head[s_index], n);
refresh_app_cond();
+
+ broadcast_pmlock_state_changed(s_index);
+
return n;
}
n->warning_param = NULL;
}
+ broadcast_pmlock_state_changed(s_index);
+
free(n);
refresh_app_cond();
return 0;
SYS_G_LIST_FREE_LIST(cond_head[state]);
cond_head[state] = NULL;
+ broadcast_pmlock_state_changed(state);
+
return 0;
}
#ifndef __DISPLAY_LOCK_H__
#define __DISPLAY_LOCK_H__
+#include <device/power.h>
+
#include "core.h"
typedef struct _pm_lock_node {
} PmLockNode;
bool check_lock_state(int state);
+bool pmlock_get_lock_state(enum state_t state);
+enum state_t power_lock_type_to_pmlock(power_lock_e power_lock_type);
PmLockNode *find_node(enum state_t s_index, pid_t pid);
PmLockNode *add_node(enum state_t s_index, pid_t pid, guint timeout_id, bool holdkey_block);
int del_node(enum state_t s_index, PmLockNode *n);