src/pmqos/pmqos.c
src/pmqos/pmqos-parser.c
src/hal/hal.c
- src/shared/pass-systemd.c
src/core/common.c
src/core/config-parser.c
src/core/device-notifier.c
src/core/devices.c
- src/core/edbus-handler.c
src/core/main.c
- src/core/sig-handler.c
- src/core/boot.c
+ src/core/gdbus-util.c
+ #Generated by a custom command 'gdbus-codegen' below
+ src/pass/pass-dbus-stub.c
+ #Generated by a custom command 'gdbus-codegen' below
+ src/pmqos/pmqos-dbus-stub.c
)
INCLUDE_DIRECTORIES(${CMAKE_CURRENT_SOURCE_DIR})
INCLUDE_DIRECTORIES(${CMAKE_CURRENT_SOURCE_DIR}/src/hal)
SET(PKG_MODULES
- ecore
- edbus
vconf
dlog
device-node
glib-2.0
dbus-1
gio-2.0
+ gio-unix-2.0
eventsystem
libtzplatform-config
- mount
)
INCLUDE(FindPkgConfig)
ADD_DEFINITIONS("-DARCH_64BIT")
ENDIF()
+ADD_CUSTOM_COMMAND(
+ OUTPUT src/pass/pass-dbus-stub.c
+ COMMAND gdbus-codegen --interface-prefix org.tizen.
+ --generate-c-code pass-dbus-stub
+ --output-directory src/pass/
+ scripts/pass-dbus.xml
+ COMMENT "Generating GDBus stub for core interface")
+ADD_CUSTOM_COMMAND(
+ OUTPUT src/pmqos/pmqos-dbus-stub.c
+ COMMAND gdbus-codegen --interface-prefix org.tizen.
+ --generate-c-code pmqos-dbus-stub
+ --output-directory src/pmqos/
+ scripts/pmqos-dbus.xml
+ COMMENT "Generating GDBus stub for pmqos interface")
+
ADD_EXECUTABLE(${PROJECT_NAME} ${SRCS})
-TARGET_LINK_LIBRARIES(${PROJECT_NAME} ${pkgs_LDFLAGS} "-ldl" "-lm" shared)
+TARGET_LINK_LIBRARIES(${PROJECT_NAME} ${pkgs_LDFLAGS} "-ldl" "-lm")
INSTALL(TARGETS ${PROJECT_NAME} DESTINATION bin)
INSTALL(DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/src/pass/ DESTINATION include/${PROJECT_NAME}
PATTERN "*.service"
)
-ADD_SUBDIRECTORY(src/shared)
ADD_SUBDIRECTORY(src/hal)
BuildRequires: cmake
BuildRequires: libattr-devel
BuildRequires: gettext-devel
-BuildRequires: pkgconfig(ecore)
BuildRequires: pkgconfig(vconf)
BuildRequires: pkgconfig(dlog)
BuildRequires: pkgconfig(device-node)
-BuildRequires: pkgconfig(edbus)
BuildRequires: pkgconfig(capi-base-common)
BuildRequires: pkgconfig(dbus-1)
-BuildRequires: pkgconfig(dbus-glib-1)
BuildRequires: pkgconfig(gio-2.0)
+BuildRequires: pkgconfig(gio-unix-2.0)
BuildRequires: pkgconfig(glib-2.0)
BuildRequires: pkgconfig(eventsystem)
BuildRequires: pkgconfig(libtzplatform-config)
--- /dev/null
+<?xml version="1.0" encoding="UTF-8" ?>
+<node name="/Org/Tizen/System/Pass/Core">
+ <interface name="org.tizen.system.pass.core">
+ <method name="start">
+ <arg type="i" name="return_code" direction="out" />
+ </method>
+ <method name="stop">
+ <arg type="i" name="return_code" direction="out" />
+ </method>
+ </interface>
+</node>
--- /dev/null
+<?xml version="1.0" encoding="UTF-8" ?>
+<node name="/Org/Tizen/System/Pass/Pmqos">
+ <interface name="org.tizen.system.pass.pmqos">
+ <method name="start">
+ <arg type="i" name="return_code" direction="out" />
+ </method>
+ <method name="stop">
+ <arg type="i" name="return_code" direction="out" />
+ </method>
+ <method name="AppLaunch">
+ <arg type="i" name="duration" direction="in" />
+ <arg type="i" name="return_code" direction="out" />
+ </method>
+ <method name="UltraPowerSaving">
+ <arg type="i" name="duration" direction="in" />
+ <arg type="i" name="return_code" direction="out" />
+ </method>
+ </interface>
+</node>
+++ /dev/null
-/*
- * PASS
- *
- * Copyright (c) 2017 Samsung Electronics Co., Ltd.
- *
- * Licensed under the Apache License, Version 2.0 (the License);
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-#include <stdio.h>
-#include <unistd.h>
-#include <bundle.h>
-#include <eventsystem.h>
-
-#include "core/device-notifier.h"
-#include "core/common.h"
-#include "core/edbus-handler.h"
-#include "shared/pass-systemd.h"
-#include "shared/log.h"
-
-#define SIGNAL_BOOTING_DONE "BootingDone"
-
-#define SYSTEMD_DBUS_SIGNAL_STARTUP_FINISHED "StartupFinished"
-#define SYSTEMD_DBUS_METHOD_SYSTEM_STATE "SystemState"
-#define SYSTEMD_STATE_RUNNING "running"
-#define SYSTEMD_STATE_DEGRADED "degraded"
-
-int booting_finished(void)
-{
- char *state;
- int ret;
- size_t len;
-
- ret = pass_systemd_get_manager_property_as_string(
- SYSTEMD_DBUS_IFACE_MANAGER,
- SYSTEMD_DBUS_METHOD_SYSTEM_STATE,
- &state);
- if (ret < 0) {
- _E("Failed to get System State (%d)", ret);
- return ret;
- }
-
- len = strlen(state) + 1;
- if (!strncmp(state, SYSTEMD_STATE_RUNNING, len) ||
- !strncmp(state, SYSTEMD_STATE_DEGRADED, len))
- ret = 1;
- else
- ret = 0;
-
- free(state);
-
- return ret;
-}
-
-
-static void boot_complete_send_system_event(void)
-{
- bundle *b;
- const char *str = EVT_VAL_BOOT_COMPLETED_TRUE;
-
- b = bundle_create();
- bundle_add_str(b, EVT_KEY_BOOT_COMPLETED, str);
- eventsystem_send_system_event(SYS_EVENT_BOOT_COMPLETED, b);
- bundle_free(b);
-}
-
-
-void remove_booting_done_handler(void *data)
-{
- unregister_edbus_signal_handler(SYSTEMD_DBUS_PATH,
- SYSTEMD_DBUS_IFACE_MANAGER,
- SYSTEMD_DBUS_SIGNAL_STARTUP_FINISHED);
-}
-
-static void booting_done_received(void *data, DBusMessage *msg)
-{
- static int done = 0;
-
- if (!dbus_message_is_signal(msg, SYSTEMD_DBUS_IFACE_MANAGER,
- SYSTEMD_DBUS_SIGNAL_STARTUP_FINISHED)) {
- _E("there is no StartupFinished signal");
- return;
- }
-
- if (done)
- return;
-
- done = booting_finished();
- if (done != TRUE) {
- _E("Booting is not finished");
- return;
- }
-
- remove_booting_done_handler(NULL);
-
- /*
- _I("real booting done, unlock LCD_OFF");
- pm_unlock_internal(INTERNAL_LOCK_BOOTING, LCD_OFF, PM_SLEEP_MARGIN);
- */
-
- broadcast_edbus_signal(PASS_PATH_CORE,
- PASS_INTERFACE_CORE,
- SIGNAL_BOOTING_DONE,
- NULL, NULL);
-
- boot_complete_send_system_event();
-
- device_notify(DEVICE_NOTIFIER_BOOTING_DONE, &done);
-}
-
-void add_booting_done_handler(void *data)
-{
- /* Normal booting done: System Session is loaded completely */
- register_edbus_signal_handler(SYSTEMD_DBUS_PATH,
- SYSTEMD_DBUS_IFACE_MANAGER,
- SYSTEMD_DBUS_SIGNAL_STARTUP_FINISHED,
- booting_done_received);
-}
+++ /dev/null
-/*
- * PASS
- *
- * Copyright (c) 2017 Samsung Electronics Co., Ltd.
- *
- * Licensed under the Apache License, Version 2.0 (the License);
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-#ifndef __PASS_BOOT_H__
-#define __PASS_BOOT_H__
-
-int booting_finished(void);
-void add_booting_done_handler(void *data);
-void remove_booting_done_handler(void *data);
-
-#endif /* __PASS_BOOT_H__ */
#ifndef __CORE_COMMON_H__
#define __CORE_COMMON_H__
-#include <Ecore.h>
#include <stdio.h>
+#include <stdlib.h>
#include <error.h>
#include <stdbool.h>
#include <unistd.h>
#define DEVICE_NOTIFIER_MAX_COUNT 255
static GList *device_notifier_list;
-static Ecore_Idler *idl;
+static guint idle_func_id = 0;
static struct device_notifier device_notifiers[DEVICE_NOTIFIER_MAX_COUNT];
static struct device_notifier *get_device_notifier(void) {
return 0;
}
-static Eina_Bool delete_unused_notifier_cb(void *data)
+static gboolean delete_unused_notifier_cb(gpointer user_data)
{
- GList *n;
+ GList *list;
GList *next;
struct device_notifier *notifier;
- n = device_notifier_list;
- while (n != NULL) {
- notifier = n->data;
- next = n->next;
+ list = device_notifier_list;
+ while (list != NULL) {
+ notifier = (struct device_notifier *)list->data;
+ next = list->next;
if (!notifier->is_used) {
memset(notifier, 0, sizeof(*notifier));
- device_notifier_list = g_list_delete_link(
- device_notifier_list, n);
+ device_notifier_list = g_list_remove_link(
+ device_notifier_list,
+ list);
}
- n = next;
+ list = next;
}
+ idle_func_id = 0;
- idl = NULL;
-
- return ECORE_CALLBACK_CANCEL;
+ return false;
}
void device_notify(enum device_notifier_type status, void *data)
}
}
- if (!idl)
- idl = ecore_idler_add(delete_unused_notifier_cb, NULL);
+ if (!idle_func_id)
+ idle_func_id = g_idle_add(delete_unused_notifier_cb, NULL);
}
#include "common.h"
#include "devices.h"
-#include "edbus-handler.h"
static const struct device_ops default_ops = {
.name = "default-ops",
+++ /dev/null
-/*
- * PASS
- *
- * Copyright (c) 2012 - 2013 Samsung Electronics Co., Ltd.
- *
- * Licensed under the Apache License, Version 2.0 (the License);
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-#include <assert.h>
-#include <glib.h>
-
-#include "core/edbus-handler.h"
-#include "core/common.h"
-#include "core/device-notifier.h"
-#include "shared/log.h"
-
-#define EDBUS_INIT_RETRY_COUNT 5
-#define EDBUS_LIST_POOL_MAX_COUNT 255
-
-struct edbus_list {
- char *signal_name;
- E_DBus_Signal_Handler *handler;
-};
-
-static struct edbus_object {
- char *path;
- char *interface;
- E_DBus_Object *obj;
- E_DBus_Interface *iface;
-} edbus_objects[] = {
- { PASS_PATH_CORE , PASS_INTERFACE_CORE , NULL, NULL },
- { PASS_PATH_PMQOS , PASS_INTERFACE_PMQOS , NULL, NULL },
- /* Add new object & interface here*/
-};
-
-static GList *edbus_owner_list;
-static GList *edbus_handler_list;
-static int edbus_init_val;
-static DBusConnection *conn;
-static E_DBus_Connection *edbus_conn;
-static DBusPendingCall *edbus_request_name;
-static struct edbus_list edbus_list_pool[EDBUS_LIST_POOL_MAX_COUNT];
-
-static bool is_empty_edbus_list(struct edbus_list *list) {
- if ((list->signal_name == NULL) && (list->handler == NULL)) {
- return true;
- }
- return false;
-}
-
-static void put_edbus_list(struct edbus_list *list) {
- memset(list, 0, sizeof(*list));
-}
-
-static struct edbus_list *get_edbus_list(void) {
- static int pos = 0;
-
- if ((pos < EDBUS_LIST_POOL_MAX_COUNT) &&
- is_empty_edbus_list(&edbus_list_pool[pos])) {
- return &edbus_list_pool[pos++];;
- } else {
- for (pos = 0; pos < EDBUS_LIST_POOL_MAX_COUNT; pos++) {
- if (is_empty_edbus_list(&edbus_list_pool[pos]))
- return &edbus_list_pool[pos];
- }
- }
-
- return NULL;
-}
-static int register_edbus_interface(struct edbus_object *object)
-{
- if (!object) {
- _E("object is invalid value!");
- return -1;
- }
-
- object->obj = e_dbus_object_add(edbus_conn, object->path, NULL);
- if (!object->obj) {
- _E("fail to add edbus obj");
- return -1;
- }
-
- object->iface = e_dbus_interface_new(object->interface);
- if (!object->iface) {
- _E("fail to add edbus interface");
- return -1;
- }
-
- e_dbus_object_interface_attach(object->obj, object->iface);
-
- return 0;
-}
-
-E_DBus_Interface *get_edbus_interface(const char *path)
-{
- int i;
-
- for (i = 0; i < ARRAY_SIZE(edbus_objects); i++)
- if (!strcmp(path, edbus_objects[i].path))
- return edbus_objects[i].iface;
-
- 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) {
- _E("invalid argument!");
- return -1;
- }
-
- sender = dbus_message_get_sender(msg);
- if (!sender) {
- _E("invalid sender!");
- return -1;
- }
-
- send_msg = dbus_message_new_method_call(DBUS_SERVICE_DBUS,
- DBUS_PATH_DBUS,
- DBUS_INTERFACE_DBUS,
- "GetConnectionUnixProcessID");
- if (!send_msg) {
- _E("invalid send msg!");
- return -1;
- }
-
- ret = dbus_message_append_args(send_msg, DBUS_TYPE_STRING,
- &sender, DBUS_TYPE_INVALID);
- if (!ret) {
- _E("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) {
- _E("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) {
- _E("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)
-{
- GList *tmp, *next;
- struct edbus_list *entry;
-
- tmp = edbus_handler_list;
- while (tmp != NULL) {
- entry = tmp->data;
- next = tmp->next;
- if (entry->handler) {
- e_dbus_signal_handler_del(edbus_conn, entry->handler);
- edbus_handler_list = g_list_remove(edbus_handler_list,
- (gconstpointer)entry);
- free(entry->signal_name);
- put_edbus_list(entry);
- }
- tmp = next;
- }
-}
-
-int register_edbus_signal_handler(const char *path, const char *interface,
- const char *name, E_DBus_Signal_Cb cb)
-{
- GList *tmp;
- struct edbus_list *entry;
- E_DBus_Signal_Handler *handler;
-
- for (tmp = edbus_handler_list; tmp != NULL; tmp = tmp->next) {
- entry = tmp->data;
- if (strncmp(entry->signal_name, name, strlen(name)) == 0)
- return -EEXIST;
- }
-
- handler = e_dbus_signal_handler_add(edbus_conn, NULL, path,
- interface, name, cb, NULL);
-
- if (!handler) {
- _E("fail to add edbus handler");
- return -ENOMEM;
- }
-
- entry = get_edbus_list();
-
- if (!entry) {
- e_dbus_signal_handler_del(edbus_conn, handler);
- _E("Malloc failed");
- return -ENOMEM;
- }
-
- entry->signal_name = strndup(name, strlen(name));
-
- if (!entry->signal_name) {
- _E("Malloc failed");
- e_dbus_signal_handler_del(edbus_conn, handler);
- put_edbus_list(entry);
- return -ENOMEM;
- }
-
- entry->handler = handler;
- edbus_handler_list = g_list_prepend(edbus_handler_list,
- (gpointer)entry);
- if (!edbus_handler_list) {
- _E("g_list_prepend failed");
- e_dbus_signal_handler_del(edbus_conn, handler);
- free(entry->signal_name);
- put_edbus_list(entry);
- return -ENOMEM;
- }
- return 0;
-}
-
-int unregister_edbus_signal_handler(const char *path, const char *interface,
- const char *name)
-{
- GList *tmp, *next;
- struct edbus_list *entry;
-
- tmp = edbus_handler_list;
- while (tmp != NULL) {
- entry = tmp->data;
- next = tmp->next;
- if (strncmp(entry->signal_name, name, strlen(name) + 1) == 0) {
- e_dbus_signal_handler_del(edbus_conn, entry->handler);
- edbus_handler_list = g_list_remove(edbus_handler_list,
- (gpointer)entry);
- free(entry->signal_name);
- put_edbus_list(entry);
-
- return 0;
- }
- tmp = next;
- }
-
- return -1;
-}
-
-int broadcast_edbus_signal(const char *path, const char *interface,
- const char *name, const char *sig, char *param[])
-{
- DBusMessage *msg;
- DBusMessageIter iter;
- int r;
-
- msg = dbus_message_new_signal(path, interface, name);
- if (!msg) {
- _E("fail to allocate new %s.%s signal", interface, name);
- return -EPERM;
- }
-
- dbus_message_iter_init_append(msg, &iter);
- r = append_variant(&iter, sig, param);
- if (r < 0) {
- _E("append_variant error(%d)", r);
- return -EPERM;
- }
-
- r = dbus_connection_send(conn, msg, NULL);
- dbus_message_unref(msg);
-
- if (r != TRUE) {
- _E("dbus_connection_send error(%s:%s-%s)",
- path, interface, name);
- return -ECOMM;
- }
-
- return 0;
-}
-
-static int register_method(E_DBus_Interface *iface,
- const struct edbus_method *edbus_methods, int size)
-{
- int ret;
- int i;
-
- assert(iface);
- assert(edbus_methods);
-
- for (i = 0; i < size; i++) {
- ret = e_dbus_interface_method_add(iface,
- edbus_methods[i].member,
- edbus_methods[i].signature,
- edbus_methods[i].reply_signature,
- edbus_methods[i].func);
- if (!ret) {
- _E("fail to add method %s!", edbus_methods[i].member);
- return -EINVAL;
- }
- }
-
- return 0;
-}
-
-int register_edbus_method(const char *path, const struct edbus_method *edbus_methods, int size)
-{
- E_DBus_Interface *iface;
- int ret;
-
- if (!path || !edbus_methods || size < 1) {
- _E("invalid parameter");
- return -EINVAL;
- }
-
- iface = get_edbus_interface(path);
- if (!iface) {
- _E("fail to get edbus interface!");
- return -ENODEV;
- }
-
- ret = register_method(iface, edbus_methods, size);
- if (ret < 0) {
- _E("fail to register %s method(%d)", path, ret);
- return ret;
- }
-
- return 0;
-}
-
-static void request_name_cb(void *data, DBusMessage *msg, DBusError *error)
-{
- DBusError err;
- unsigned int val;
- int r;
-
- if (!msg) {
- _E("invalid DBusMessage!");
- return;
- }
-
- dbus_error_init(&err);
- r = dbus_message_get_args(msg, &err, DBUS_TYPE_UINT32, &val, DBUS_TYPE_INVALID);
- if (!r) {
- _E("no message : [%s:%s]", err.name, err.message);
- dbus_error_free(&err);
- return;
- }
-}
-static void check_owner_name(void)
-{
- DBusError err;
- DBusMessage *msg;
- DBusMessageIter iter;
- char *pa[1];
- char exe_name[PATH_MAX];
- char *entry;
- GList *n;
- int pid;
-
- for (n = edbus_owner_list; n != NULL; n = n->next) {
- entry = n->data;
- pa[0] = entry;
- msg = dbus_method_sync_with_reply(E_DBUS_FDO_BUS,
- E_DBUS_FDO_PATH,
- E_DBUS_FDO_INTERFACE,
- "GetConnectionUnixProcessID", "s", pa);
-
- if (!msg) {
- _E("invalid DBusMessage!");
- return;
- }
-
- dbus_error_init(&err);
- dbus_message_iter_init(msg, &iter);
-
- dbus_message_iter_get_basic(&iter, &pid);
- if (get_cmdline_name(pid, exe_name, PATH_MAX) != 0)
- goto out;
-
-out:
- dbus_message_unref(msg);
- dbus_error_free(&err);
- }
-}
-
-static void check_owner_list(void)
-{
- DBusError err;
- DBusMessage *msg;
- DBusMessageIter array, item;
- char *pa[1];
- char *name;
- char *entry;
-
- pa[0] = PASS_BUS_NAME;
- msg = dbus_method_sync_with_reply(E_DBUS_FDO_BUS,
- E_DBUS_FDO_PATH,
- E_DBUS_FDO_INTERFACE,
- "ListQueuedOwners", "s", pa);
-
- if (!msg) {
- _E("invalid DBusMessage!");
- return;
- }
-
- dbus_error_init(&err);
- dbus_message_iter_init(msg, &array);
-
- if (dbus_message_iter_get_arg_type(&array) != DBUS_TYPE_ARRAY)
- goto out;
- dbus_message_iter_recurse(&array, &item);
- while (dbus_message_iter_get_arg_type(&item) == DBUS_TYPE_STRING) {
- dbus_message_iter_get_basic(&item, &name);
- entry = strndup(name, strlen(name));
- edbus_owner_list = g_list_append(edbus_owner_list,
- (gpointer)entry);
- if (!edbus_owner_list) {
- _E("append failed");
- free(entry);
- goto out;
- }
- dbus_message_iter_next(&item);
- }
-
-out:
- dbus_message_unref(msg);
- dbus_error_free(&err);
-}
-
-void edbus_init(void *data)
-{
- DBusError error;
- int retry = 0;
- int i, ret;
-
- dbus_threads_init_default();
- dbus_error_init(&error);
-
- do {
- edbus_init_val = e_dbus_init();
- if (edbus_init_val)
- break;
- if (retry == EDBUS_INIT_RETRY_COUNT) {
- _E("fail to init edbus");
- return;
- }
- retry++;
- } while (retry <= EDBUS_INIT_RETRY_COUNT);
-
- retry = 0;
- do {
- conn = dbus_bus_get(DBUS_BUS_SYSTEM, &error);
- if (conn)
- break;
- if (retry == EDBUS_INIT_RETRY_COUNT) {
- _E("fail to get dbus");
- goto out1;
- }
- retry++;
- } while (retry <= EDBUS_INIT_RETRY_COUNT);
-
- retry = 0;
- do {
- edbus_conn = e_dbus_connection_setup(conn);
- if (edbus_conn)
- break;
- if (retry == EDBUS_INIT_RETRY_COUNT) {
- _E("fail to get edbus");
- goto out2;
- }
- retry++;
- } while (retry <= EDBUS_INIT_RETRY_COUNT);
-
- retry = 0;
- do {
- edbus_request_name = e_dbus_request_name(edbus_conn, PASS_BUS_NAME,
- DBUS_NAME_FLAG_REPLACE_EXISTING, request_name_cb, NULL);
- if (edbus_request_name)
- break;
- if (retry == EDBUS_INIT_RETRY_COUNT) {
- _E("fail to request edbus name");
- goto out3;
- }
- retry++;
- } while (retry <= EDBUS_INIT_RETRY_COUNT);
-
- for (i = 0; i < ARRAY_SIZE(edbus_objects); i++) {
- ret = register_edbus_interface(&edbus_objects[i]);
- if (ret < 0) {
- _E("fail to add obj & interface for %s",
- edbus_objects[i].interface);
- goto out3;
- }
- _D("add new obj for %s", edbus_objects[i].interface);
- }
- check_owner_list();
- check_owner_name();
- return;
-
-out3:
- e_dbus_connection_close(edbus_conn);
-out2:
- dbus_connection_set_exit_on_disconnect(conn, FALSE);
-out1:
- e_dbus_shutdown();
-}
-
-void edbus_exit(void *data)
-{
- unregister_edbus_signal_handle();
- e_dbus_connection_close(edbus_conn);
- e_dbus_shutdown();
-}
+++ /dev/null
-/*
- * PASS
- *
- * Copyright (c) 2017 Samsung Electronics Co., Ltd.
- *
- * Licensed under the Apache License, Version 2.0 (the License);
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-
-#ifndef __EDBUS_HANDLE_H__
-#define __EDBUS_HANDLE_H__
-
-#include <stdbool.h>
-#include <E_DBus.h>
-#include "shared/dbus.h"
-
-struct edbus_method {
- const char *member;
- const char *signature;
- const char *reply_signature;
- E_DBus_Method_Cb func;
-};
-
-int register_edbus_method(const char *path, const struct edbus_method *edbus_methods, int size);
-int register_edbus_signal_handler(const char *path, const char *interface,
- const char *name, E_DBus_Signal_Cb cb);
-int unregister_edbus_signal_handler(const char *path, const char *interface,
- const char *name);
-pid_t get_edbus_sender_pid(DBusMessage *msg);
-int broadcast_edbus_signal(const char *path, const char *interface,
- const char *name, const char *sig, char *param[]);
-void edbus_init(void *data);
-void edbus_exit(void *data);
-
-#endif /* __EDBUS_HANDLE_H__ */
-
--- /dev/null
+/*
+ * PASS (Power Aware System Service)
+ *
+ * Copyright (c) 2017 Samsung Electronics Co., Ltd.
+ *
+ * Licensed under the Apache License, Version 2.0 (the License);
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#include <errno.h>
+#include <stdbool.h>
+
+#include "gdbus-util.h"
+#include "shared/log.h"
+
+static GDBusConnection *g_dbus_sys_conn = NULL;
+
+int pass_gdbus_register_systemd_startup_callback(GDBusSignalCallback cb,
+ gpointer user_data, guint *id)
+{
+ guint tmp_id;
+
+ if (g_dbus_sys_conn == NULL) {
+ _E("cannot get the dbus connection "
+ "to the system message bus\n");
+ return -ENOSYS;
+ }
+
+ tmp_id = g_dbus_connection_signal_subscribe(g_dbus_sys_conn,
+ SYSTEMD_DBUS_NAME,
+ SYSTEMD_DBUS_IFACE_MANAGER,
+ "StartupFinished",
+ SYSTEMD_DBUS_OBJECT_PATH,
+ NULL,
+ G_DBUS_SIGNAL_FLAGS_NONE,
+ cb,
+ user_data,
+ NULL);
+ if (!tmp_id)
+ return -ENOTSUP;
+
+ *id = tmp_id;
+
+ return 0;
+}
+
+int pass_gdbus_unregister_systemd_startup_callback(guint id)
+{
+ if (g_dbus_sys_conn == NULL) {
+ _E("cannot get the dbus connection "
+ "to the system message bus\n");
+ return -ENOSYS;
+ }
+
+ if (!id)
+ return -EINVAL;
+
+ g_dbus_connection_signal_unsubscribe(g_dbus_sys_conn, id);
+
+ return 0;
+}
+
+int pass_gdbus_get_systemd_dbus_property_string(const char *iface,
+ const char *prop, const char **value)
+{
+ GError *error = NULL;
+ GVariant *reply;
+ GVariant *result;
+
+ if (g_dbus_sys_conn == NULL) {
+ _E("cannot get the dbus connection "
+ "to the system message bus\n");
+ return -ENOSYS;
+ }
+
+ reply = g_dbus_connection_call_sync(g_dbus_sys_conn,
+ SYSTEMD_DBUS_NAME,
+ SYSTEMD_DBUS_OBJECT_PATH,
+ SYSTEMD_DBUS_IFACE_FOR_PROPS,
+ SYSTEMD_DBUS_METHOD_GET_PROP,
+ g_variant_new(SYSTEMD_DBUS_METHOD_GET_PROP_ARG_TYPE,
+ iface,
+ prop),
+ G_VARIANT_TYPE(SYSTEMD_DBUS_METHOD_GET_PROP_RET_TYPE),
+ G_DBUS_SIGNAL_FLAGS_NONE,
+ -1,
+ NULL,
+ &error);
+ if (error != NULL) {
+ _E("cannot get property: %s\n", error->message);
+ return -EINVAL;
+ }
+
+ g_variant_get(reply, SYSTEMD_DBUS_METHOD_GET_PROP_RET_TYPE, &result);
+ *value = g_variant_get_string(result, NULL);
+ if (*value == NULL) {
+ _E("cannot get property: not string value property\n");
+ return -EINVAL;
+ }
+
+ return 0;
+}
+
+int pass_gdbus_export_interface(gpointer instance, const char *obj_path)
+{
+ gboolean ret;
+
+ if (g_dbus_sys_conn == NULL) {
+ _E("cannot get the dbus connection "
+ "to the system message bus\n");
+ return -ENOSYS;
+ }
+
+ ret = g_dbus_interface_skeleton_export(
+ G_DBUS_INTERFACE_SKELETON(instance),
+ g_dbus_sys_conn,
+ obj_path,
+ NULL);
+ if (ret == TRUE)
+ return 0;
+
+ return -1;
+}
+
+int pass_gdbus_get_name(const char *name)
+{
+ guint id;
+
+ id = g_bus_own_name_on_connection(g_dbus_sys_conn, name,
+ G_BUS_NAME_OWNER_FLAGS_NONE,
+ NULL, NULL, NULL, NULL);
+ if (id == 0)
+ return -ENOSYS;
+
+ return 0;
+}
+
+int pass_gdbus_connect_signal(gpointer instance, int num_signals,
+ struct pass_gdbus_signal_info *signal_infos)
+{
+ int i;
+ unsigned long handler_id;
+
+ for (i = 0; i < num_signals; i++) {
+ handler_id = g_signal_connect(instance,
+ signal_infos[i].handler,
+ signal_infos[i].cb,
+ signal_infos[i].cb_data);
+ if (handler_id <= 0)
+ goto out_err;
+ signal_infos[i].ret_id = handler_id;
+ }
+
+ return 0;
+
+out_err:
+ for (i = 0; i < num_signals; i++) {
+ if (signal_infos[i].ret_id > 0) {
+ g_signal_handler_disconnect(instance,
+ signal_infos[i].ret_id);
+ signal_infos[i].ret_id = 0;
+ }
+ }
+
+ return -EINVAL;
+}
+
+void pass_gdbus_disconnect_signal(gpointer instance, int num_signals,
+ struct pass_gdbus_signal_info *signal_infos)
+{
+ int i;
+
+ for (i = 0; i < num_signals; i++) {
+ if (signal_infos[i].ret_id > 0) {
+ g_signal_handler_disconnect(instance,
+ signal_infos[i].ret_id);
+ signal_infos[i].ret_id = 0;
+ }
+ }
+}
+
+static void put_instance(gpointer *instance)
+{
+ g_object_unref(*instance);
+ *instance = NULL;
+}
+
+SystemPassCore *pass_gdbus_get_instance_core(void)
+{
+ return system_pass_core_skeleton_new();
+}
+
+void pass_gdbus_put_instance_core(SystemPassCore **instance)
+{
+ put_instance((gpointer *)instance);
+}
+
+SystemPassPmqos *pass_gdbus_get_instance_pmqos(void)
+{
+ return system_pass_pmqos_skeleton_new();
+}
+
+void pass_gdbus_put_instance_pmqos(SystemPassPmqos **instance)
+{
+ put_instance((gpointer *)instance);
+}
+
+int pass_gdbus_get_system_connection(void)
+{
+ GError *error = NULL;
+
+ g_dbus_sys_conn = g_bus_get_sync(G_BUS_TYPE_SYSTEM, NULL,
+ &error);
+ if (g_dbus_sys_conn == NULL) {
+ _E("cannot connect to the system message bus: %s\n",
+ error->message);
+ return -ENOSYS;
+ }
+
+ return 0;
+}
+
+void pass_gdbus_put_system_connection(void)
+{
+ if (g_dbus_sys_conn) {
+ g_object_unref(g_dbus_sys_conn);
+ g_dbus_sys_conn = NULL;
+ }
+}
--- /dev/null
+/*
+ * PASS (Power Aware System Service)
+ *
+ * Copyright (c) 2017 Samsung Electronics Co., Ltd.
+ *
+ * Licensed under the Apache License, Version 2.0 (the License);
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#ifndef __GDBUS_UTIL_H__
+#define __GDBUS_UTIL_H__
+
+#include <gio/gio.h>
+#include <stdbool.h>
+
+#include "pass/pass-dbus-stub.h"
+#include "pmqos/pmqos-dbus-stub.h"
+
+#define SYSTEMD_DBUS_NAME "org.freedesktop.systemd1"
+#define SYSTEMD_DBUS_OBJECT_PATH "/org/freedesktop/systemd1"
+#define SYSTEMD_DBUS_IFACE_FOR_PROPS "org.freedesktop.DBus.Properties"
+#define SYSTEMD_DBUS_METHOD_GET_PROP "Get"
+#define SYSTEMD_DBUS_METHOD_GET_PROP_ARG_TYPE "(ss)"
+#define SYSTEMD_DBUS_METHOD_GET_PROP_RET_TYPE "(v)"
+#define SYSTEMD_DBUS_IFACE_MANAGER SYSTEMD_DBUS_NAME ".Manager"
+
+struct pass_gdbus_signal_info {
+ const gchar *handler;
+ GCallback cb;
+ gpointer cb_data;
+ gulong ret_id;
+};
+
+int pass_gdbus_register_systemd_startup_callback(GDBusSignalCallback cb,
+ gpointer user_data, guint *id);
+int pass_gdbus_unregister_systemd_startup_callback(guint id);
+int pass_gdbus_get_systemd_dbus_property_string(const char *iface,
+ const char *prop, const char **value);
+int pass_gdbus_export_interface(gpointer instance, const char *obj_path);
+int pass_gdbus_get_name(const char *name);
+int pass_gdbus_connect_signal(gpointer instance, int num_signals,
+ struct pass_gdbus_signal_info *signal_infos);
+void pass_gdbus_disconnect_signal(gpointer instance, int num_signals,
+ struct pass_gdbus_signal_info *signal_infos);
+SystemPassCore *pass_gdbus_get_instance_core(void);
+void pass_gdbus_put_instance_core(SystemPassCore **instance);
+SystemPassPmqos *pass_gdbus_get_instance_pmqos(void);
+void pass_gdbus_put_instance_pmqos(SystemPassPmqos **instance);
+int pass_gdbus_get_system_connection(void);
+void pass_gdbus_put_system_connection(void);
+#endif /* __GDBUS_UTIL_H__ */
* limitations under the License.
*/
-
#include <stdio.h>
#include <fcntl.h>
+#include <glib.h>
+#include <string.h>
+#include <gio/gio.h>
#include <sys/reboot.h>
-#include "shared/dbus.h"
#include "shared/log.h"
-#include "boot.h"
#include "common.h"
#include "device-notifier.h"
#include "devices.h"
-#include "edbus-handler.h"
+#include "gdbus-util.h"
+
+#define PASS_DBUS_BUS_NAME "org.tizen.system.pass"
+
+unsigned int g_startup_cb_id;
+GMainLoop *g_mainloop;
static void sig_quit(int signo)
{
{
_D("received SIGUSR1 signal %d", signo);
- ecore_main_loop_quit();
+ g_main_loop_quit(g_mainloop);
+}
+
+static bool check_systemd_state(void)
+{
+ const char *prop = "SystemState";
+ const char *prop_valid_values[] = {"running", "degraded", NULL};
+ const char *value;
+ int i, ret;
+
+ ret = pass_gdbus_get_systemd_dbus_property_string(
+ SYSTEMD_DBUS_IFACE_MANAGER,
+ prop, &value);
+ if (ret < 0)
+ return false;
+
+ i = 0;
+ while (prop_valid_values[i] != NULL) {
+ if (!strncmp(prop_valid_values[i], value,
+ strlen(prop_valid_values[i])))
+ return true;
+
+ i++;
+ }
+
+ return false;
}
-static int pass_main(int argc, char **argv)
+static void cb_systemd_startup_finished(GDBusConnection *connection,
+ const gchar *sender_name,
+ const gchar *object_path,
+ const gchar *interface_name,
+ const gchar *signal_name,
+ GVariant *parameters,
+ gpointer user_data)
{
int ret;
- edbus_init(NULL);
- devices_init(NULL);
- add_booting_done_handler(NULL);
- ret = booting_finished();
- if (ret == 1)
+ if (check_systemd_state()) {
+ ret = 1;
device_notify(DEVICE_NOTIFIER_BOOTING_DONE, &ret);
+ }
+
+ pass_gdbus_unregister_systemd_startup_callback(g_startup_cb_id);
+ g_startup_cb_id = 0;
+}
+
+static int late_init(void)
+{
+ int ret;
+
signal(SIGTERM, sig_quit);
signal(SIGUSR1, sig_usr1);
- ecore_main_loop_begin();
+ ret = pass_gdbus_get_name(PASS_DBUS_BUS_NAME);
+ if (ret < 0)
+ return ret;
+
+ if (check_systemd_state()) {
+ ret = 1;
+ device_notify(DEVICE_NOTIFIER_BOOTING_DONE, &ret);
+ } else {
+ ret = pass_gdbus_register_systemd_startup_callback(
+ cb_systemd_startup_finished,
+ NULL,
+ &g_startup_cb_id);
+ if (ret < 0)
+ return ret;
+ }
- devices_exit(NULL);
- edbus_exit(NULL);
- ecore_shutdown();
return 0;
}
int main(int argc, char **argv)
{
- ecore_init();
- return pass_main(argc, argv);
+ g_mainloop = g_main_loop_new(NULL, FALSE);
+ pass_gdbus_get_system_connection();
+
+ devices_init(NULL);
+ if (late_init() < 0)
+ _E("cannot init pass core system\n");
+
+ g_main_loop_run(g_mainloop);
+
+ devices_exit(NULL);
+ pass_gdbus_put_system_connection();
+ g_main_loop_unref(g_mainloop);
+
+ return 0;
}
+++ /dev/null
-/*
- * PASS
- *
- * Copyright (c) 2012 - 2013 Samsung Electronics Co., Ltd.
- *
- * Licensed under the Apache License, Version 2.0 (the License);
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-
-#include <stdio.h>
-#include <sys/types.h>
-#include <sys/wait.h>
-
-#include "shared/log.h"
-
-#include "common.h"
-#include "devices.h"
-
-static struct sigaction sig_child_old_act;
-static struct sigaction sig_pipe_old_act;
-
-static void sig_child_handler(int signo, siginfo_t *info, void *data)
-{
- pid_t pid;
- int status;
-
- if (!info || signo != SIGCHLD)
- return;
-
- pid = waitpid(info->si_pid, &status, 0);
- if (pid == -1) {
- _E("SIGCHLD received\n");
- return;
- }
-
- _D("sig child actend call - %d\n", info->si_pid);
-}
-
-static void sig_pipe_handler(int signo, siginfo_t *info, void *data)
-{
-
-}
-
-static void signal_init(void *data)
-{
- struct sigaction sig_act;
-
- sig_act.sa_handler = NULL;
- sig_act.sa_sigaction = sig_child_handler;
- sig_act.sa_flags = SA_SIGINFO;
- sigemptyset(&sig_act.sa_mask);
- sigaction(SIGCHLD, &sig_act, &sig_child_old_act);
-
- sig_act.sa_handler = NULL;
- sig_act.sa_sigaction = sig_pipe_handler;
- sig_act.sa_flags = SA_SIGINFO;
- sigemptyset(&sig_act.sa_mask);
- sigaction(SIGPIPE, &sig_act, &sig_pipe_old_act);
-}
-
-static const struct device_ops signal_device_ops = {
- .name = "signal",
- .init = signal_init,
-};
-
-DEVICE_OPS_REGISTER(&signal_device_ops)
}
/*
- * pass_governor_core_timer - Callback function of core timer for PASS governor
+ * pass_governor_timeout_cb - Callback for each timeout interval of the governor
*
* @data: the instance of struct pass_policy
- */
-static Eina_Bool pass_governor_core_timer(void *data)
+*/
+static gboolean pass_governor_timeout_cb(gpointer data)
{
- struct pass_policy *policy = (struct pass_policy *)data;
+ struct pass_policy *policy = (struct pass_policy *) data;
static int count = 0;
double curr_gov_timeout, next_gov_timeout;
- int level;
- int ret;
+ int level, ret;
if (!policy) {
- _E("cannot execute PASS core timer");
- return ECORE_CALLBACK_CANCEL;
+ _E("cannot call the governor timeout callback\n");
+ return FALSE;
}
/*
ret = pass_get_cpu_stats(policy);
if (ret < 0) {
if (count++ < PASS_CPU_STATS_MAX_COUNT)
- return ECORE_CALLBACK_RENEW;
+ return TRUE;
count = 0;
- _E("cannot read 'pass_cpu_stats' sysfs entry");
+ _E("cannot read the 'pass_cpu_stats' sysfs entry");
pass_governor_update(policy, PASS_GOV_STOP);
- return ECORE_CALLBACK_CANCEL;
+ return FALSE;
}
/* Calculate the number of busy cpu */
pass_rescon_set_level(policy, level);
} else {
- _E("cannot execute governor function");
+ _E("cannot call the governor function");
pass_governor_update(policy, PASS_GOV_STOP);
- return ECORE_CALLBACK_CANCEL;
+ return FALSE;
}
- /* Store next governor timeout */
+ /* Get the governor timeout interval for the next */
next_gov_timeout = policy->pass_table[policy->curr_level].gov_timeout;
- /* Change the period of govenor timer according to PASS level */
+ /*
+ * Change the governor timeout interval when the next interval is not
+ * same as the current one
+ */
if (curr_gov_timeout != next_gov_timeout) {
_I("Change the period of governor timer from %fs to %fs\n",
curr_gov_timeout,
next_gov_timeout);
- ecore_timer_interval_set(policy->gov_timer_id,
- next_gov_timeout);
- ecore_timer_reset(policy->gov_timer_id);
+ g_source_remove(policy->gov_timeout_id);
+ policy->gov_timeout_id = g_timeout_add(
+ (guint)(next_gov_timeout * 1000),
+ pass_governor_timeout_cb,
+ (gpointer)policy);
}
- return ECORE_CALLBACK_RENEW;
+ return TRUE;
}
/*
return;
}
- /* Create the core timer of PASS governor */
+ /* Add callback function for each governor timeout */
if (policy->gov_timeout > 0) {
- policy->gov_timer_id = ecore_timer_add(
- policy->gov_timeout,
- (Ecore_Task_Cb)pass_governor_core_timer,
- (void *)policy);
- if (!policy->gov_timer_id) {
+ policy->gov_timeout_id = g_timeout_add(
+ (guint)(policy->gov_timeout * 1000),
+ (GSourceFunc)pass_governor_timeout_cb,
+ (gpointer)policy);
+ if (!policy->gov_timeout_id) {
_E("cannot add core timer for governor");
pass_governor_update(policy, PASS_GOV_STOP);
return;
}
} else {
- policy->gov_timer_id = NULL;
+ policy->gov_timeout_id = 0;
}
/*
pass_hotplug_stop(policy);
- if (policy->gov_timer_id) {
- ecore_timer_del(policy->gov_timer_id);
- policy->gov_timer_id = NULL;
+ if (policy->gov_timeout_id) {
+ g_source_remove(policy->gov_timeout_id);
+ policy->gov_timeout_id = 0;
}
/* Set PASS state as PASS_GOV_STOP */
* pass_notifier_pmqos - Callback function of DEVICE_NOTIFIER_PMQOS notifier
* @data: the scenario name
*/
-#define MAX(a,b) (a > b ? a : b)
int pass_notifier_pmqos_func(struct pass_policy *policy, void *data)
{
struct pass_resource *res;
#include "core/device-notifier.h"
#include "core/devices.h"
#include "core/common.h"
-#include "core/edbus-handler.h"
+#include "core/gdbus-util.h"
+#define DBUS_CORE_I_START_HANDLER "handle_start"
+#define DBUS_CORE_I_STOP_HANDLER "handle_stop"
+#define DBUS_CORE_I_NUM_SIGNALS 2
+#define DBUS_CORE_INTERFACE "org.tizen.system.pass.core"
+#define DBUS_CORE_PATH "/Org/Tizen/System/Pass/Core"
#define PASS_CONF_PATH "/etc/pass/pass.conf"
#define PASS_DEFAULT_MIN_LEVEL 0
#define PASS_DEFAULT_CPU_THRESHOLD 20
#define PASS_DEFAULT_LEVEL_DOWN_THRESHOLD 80
static struct pass g_pass;
+static SystemPassCore *g_gdbus_instance = NULL;
/******************************************************
* PASS interfaces: Probe/Init/Exit *
/******************************************************
* PASS D-Bus interface *
******************************************************/
-static DBusMessage* e_dbus_start_cb(E_DBus_Object *obj, DBusMessage* msg)
+static gboolean dbus_cb_core_start(SystemPassCore *obj,
+ GDBusMethodInvocation *invoc, gpointer user_data)
{
- DBusMessage *ret_dbus = NULL;
- int ret;
+ int ret = 0;
- ret = pass_init_done(NULL, NULL);
- if (ret < 0) {
- _E("failed to initialize the daemon in dbus callback \
- for a start message\n");
- return ret_dbus;
- }
+ if (g_pass.state == PASS_ON)
+ _I("PASS Core is already started\n");
+ else
+ ret = pass_init_done(NULL, NULL);
- ret_dbus = dbus_message_new_method_return(msg);
- return ret_dbus;
+ g_dbus_method_invocation_return_value(invoc, g_variant_new("(i)", ret));
+
+ if (!ret)
+ return TRUE;
+
+ _E("failed to initialize PASS Core of the daemon "
+ "in dbus callback for a start message\n");
+ return FALSE;
}
-static DBusMessage* e_dbus_stop_cb(E_DBus_Object *obj, DBusMessage* msg)
+static gboolean dbus_cb_core_stop(SystemPassCore *obj,
+ GDBusMethodInvocation *invoc, gpointer user_data)
{
- DBusMessage *ret_dbus = NULL;
- int ret;
+ int ret = 0;
- ret = pass_exit_done();
- if (ret < 0) {
- _E("failed to exit the daemon in dbus callback \
- for a stop message\n");
- return ret_dbus;
- }
+ if (g_pass.state == PASS_OFF)
+ _I("PASS Core is already stopped\n");
+ else
+ ret = pass_exit_done();
+
+ g_dbus_method_invocation_return_value(invoc, g_variant_new("(i)", ret));
- ret_dbus = dbus_message_new_method_return(msg);
- return ret_dbus;
+ if (!ret)
+ return TRUE;
+
+ _E("failed to exit PASS Core of the daemon in dbus callback "
+ "for a stop message\n");
+ return FALSE;
}
-static const struct edbus_method edbus_methods[] = {
- { "start", NULL, NULL, e_dbus_start_cb },
- { "stop", NULL, NULL, e_dbus_stop_cb },
+static struct pass_gdbus_signal_info g_gdbus_signal_infos[] = {
+ {
+ .handler = DBUS_CORE_I_START_HANDLER,
+ .cb = G_CALLBACK(dbus_cb_core_start),
+ .cb_data = NULL,
+ .ret_id = 0,
+ }, {
+ .handler = DBUS_CORE_I_STOP_HANDLER,
+ .cb = G_CALLBACK(dbus_cb_core_stop),
+ .cb_data = NULL,
+ .ret_id = 0,
+ },
};
/******************************************************
* PASS interface (Init/Exit) *
******************************************************/
-
static int pass_init_resource(struct pass_resource *res)
{
struct pass_policy *policy = &res->policy;
res->state = PASS_ON;
}
+ g_pass.state = PASS_ON;
+
return 0;
}
}
pass_put_resource_config(&g_pass);
+ g_pass.state = PASS_OFF;
return 0;
}
unregister_notifier(DEVICE_NOTIFIER_BOOTING_DONE,
pass_init_done, NULL);
+ pass_gdbus_disconnect_signal(g_gdbus_instance,
+ DBUS_CORE_I_NUM_SIGNALS, g_gdbus_signal_infos);
+ pass_gdbus_put_instance_core(&g_gdbus_instance);
+
ret = pass_exit_done();
if (ret < 0) {
_E("cannot exit PASS daemon\n");
{
int ret = 0;
- /*
- * Register methods to D-Bus interface of PASS. By using it,
- * user can turn on/off PASS
- */
- ret = register_edbus_method(PASS_PATH_CORE, edbus_methods,
- ARRAY_SIZE(edbus_methods));
+ g_pass.state = PASS_OFF;
+
+ g_gdbus_instance = pass_gdbus_get_instance_core();
+ if (g_gdbus_instance == NULL) {
+ _E("cannot get a dbus instance for the %s interface\n",
+ DBUS_CORE_INTERFACE);
+ return -ENOSYS;
+ }
+
+ ret = pass_gdbus_connect_signal(g_gdbus_instance,
+ DBUS_CORE_I_NUM_SIGNALS, g_gdbus_signal_infos);
if (ret < 0) {
- _E("cannot register dbus methods required \
- to control the daemon (%d)\n", ret);
- return ret;
+ _E("cannot register callbacks as the dbus method invocation "
+ "handlers\n");
+ ret = -ENOSYS;
+ goto out;
+ }
+
+ ret = pass_gdbus_export_interface(g_gdbus_instance, DBUS_CORE_PATH);
+ if (ret < 0) {
+ _E("cannot export the dbus interface '%s' "
+ "at the object path '%s'\n",
+ DBUS_CORE_INTERFACE,
+ DBUS_CORE_PATH);
+ ret = -ENOSYS;
+ goto out_disconnect;
}
/*
if (ret < 0) {
_E("cannot register booting-done notifier for the pass (%d)\n",
ret);
- return ret;
+ goto out_disconnect;
}
+ return 0;
+
+out_disconnect:
+ pass_gdbus_disconnect_signal(g_gdbus_instance,
+ DBUS_CORE_I_NUM_SIGNALS, g_gdbus_signal_infos);
+out:
+ pass_gdbus_put_instance_core(&g_gdbus_instance);
+
return ret;
}
#ifndef __PASS__
#define __PASS__
+#include <stddef.h>
+#include <stdint.h>
#include <stdio.h>
-#include <Ecore.h>
+#include <glib.h>
#include "shared/log.h"
struct pass_governor *governor;
double gov_timeout;
- Ecore_Timer *gov_timer_id;
+ guint gov_timeout_id;
struct pass_hotplug *hotplug;
};
};
struct pass {
+ enum pass_state state;
unsigned int num_resources;
struct pass_resource *res;
};
#include <stdio.h>
#include <stdbool.h>
+#include <stdlib.h>
#include <assert.h>
#include <errno.h>
#include <string.h>
#include "core/config-parser.h"
-#include "core/edbus-handler.h"
#include "shared/log.h"
#include "pmqos.h"
#include <glib.h>
#include <stdio.h>
#include <limits.h>
-#include <Ecore.h>
-#include <device-node.h>
-#include "core/edbus-handler.h"
+#include "core/gdbus-util.h"
#include "core/devices.h"
#include "core/common.h"
#include "core/device-notifier.h"
#define MILLISECONDS(tv) ((tv.tv_sec)*1000 + (tv.tv_nsec)/1000000)
#define DELTA(a, b) (MILLISECONDS(a) - MILLISECONDS(b))
-static Eina_Bool pmqos_timer(void *data);
+#define DBUS_PMQOS_I_APPLAUNCH_HANDLER "handle_app_launch"
+#define DBUS_PMQOS_I_ULTRAPOWERSAVING_HANDLER "handle_ultra_power_saving"
+#define DBUS_PMQOS_I_START_HANDLER "handle_start"
+#define DBUS_PMQOS_I_STOP_HANDLER "handle_stop"
+#define DBUS_PMQOS_I_NUM_SIGNALS 4
+#define DBUS_PMQOS_INTERFACE "org.tizen.system.pass.pmqos"
+#define DBUS_PMQOS_PATH "/Org/Tizen/System/Pass/Pmqos"
+
+static SystemPassPmqos *g_gdbus_instance = NULL;
+static struct pmqos_scenario *g_pmqos_scenarios = NULL;
+static bool g_initialized = false;
struct pmqos_cpu {
char name[NAME_MAX];
};
static GList *pmqos_head;
-static Ecore_Timer *unlock_timer;
+guint g_unlock_timeout_id;
static int unlock_max_timeout_ms;
static struct timespec unlock_timer_start_st;
static struct timespec unlock_timer_end_st;
static void pmqos_free(void);
/******************************************************
+ * Timeout-based unlock control functions *
+ * (Declarations) *
+ ******************************************************/
+static int pmqos_unlock_timer_start(void);
+static void pmqos_unlock_timeout_update(void);
+
+/******************************************************
+ * PMQoS feature control functions *
+ * (Declarations) *
+ ******************************************************/
+static int set_pmqos(const char *name, int val);
+static int pmqos_cancel(const char *name);
+static int pmqos_request(const char *name, int val);
+
+/******************************************************
* PASS D-Bus interface *
******************************************************/
-static DBusMessage* e_dbus_start_cb(E_DBus_Object *obj, DBusMessage* msg)
+static gboolean dbus_cb_pmqos_start(SystemPassPmqos *obj,
+ GDBusMethodInvocation *invoc, gpointer user_data)
{
- DBusMessage *ret_dbus = NULL;
+ int ret = 0;
int booting_done = 1;
- int ret;
- ret = pmqos_init_done(&booting_done, NULL);
- if (ret < 0) {
- _E("failed to initialize the daemon in dbus callback \
- for a start message\n");
- return ret_dbus;
+ if (g_initialized) {
+ _I("PASS PMQoS is already started\n");
+ } else {
+ ret = pmqos_init_done(&booting_done, NULL);
}
- ret_dbus = dbus_message_new_method_return(msg);
- return ret_dbus;
+ g_dbus_method_invocation_return_value(invoc, g_variant_new("(i)", ret));
+
+ if (!ret)
+ return TRUE;
+
+ _E("failed to initialize PASS PMQoS of the daemon "
+ "in dbus callback for a start message\n");
+ return FALSE;
}
-static DBusMessage* e_dbus_stop_cb(E_DBus_Object *obj, DBusMessage* msg)
+static gboolean dbus_cb_pmqos_stop(SystemPassPmqos *obj,
+ GDBusMethodInvocation *invoc, gpointer user_data)
{
- DBusMessage *ret_dbus;
+ if (!g_initialized)
+ _I("PASS PMQoS is already stopped\n");
+ else
+ pmqos_free();
- pmqos_free();
+ g_dbus_method_invocation_return_value(invoc, g_variant_new("(i)", 0));
+
+ return TRUE;
+}
+
+static gboolean dbus_cb_pmqos_legacy_scenario(SystemPassPmqos *obj,
+ GDBusMethodInvocation *invoc,
+ int duration,
+ gpointer user_data)
+{
+ const char *name_from;
+ char *name;
+ bool support;
+ int i, ret = 0;
+ gboolean ret_out = TRUE;
+
+ if (!g_initialized) {
+ _E("PASS PMQoS is stopped\n");
+ ret_out = FALSE;
+ goto out;
+ } else {
+ name_from = g_dbus_method_invocation_get_method_name(invoc);
+ ret = -ENOTSUP;
+ if (g_pmqos_scenarios != NULL) {
+ for (i = 0; i < g_pmqos_scenarios->num; i++) {
+ name = g_pmqos_scenarios->list[i].name;
+ support = g_pmqos_scenarios->list[i].support;
+ if (!strncmp(name, name_from, strlen(name)) &&
+ support) {
+ ret = 0;
+ break;
+ }
+ }
+ }
+
+ if (ret < 0) {
+ _E("cannot set the PMQoS sceanrio: "
+ "%s is not supported\n", name_from);
+ ret_out = FALSE;
+ goto out;
+ }
+ }
+
+ if (duration)
+ ret = pmqos_request(name_from, duration);
+ else
+ ret = pmqos_cancel(name_from);
+
+out:
+ g_dbus_method_invocation_return_value(invoc, g_variant_new("(i)", ret));
+
+ return ret_out;
+}
+
+static struct pass_gdbus_signal_info g_gdbus_signal_infos[] = {
+ {
+ .handler = DBUS_PMQOS_I_APPLAUNCH_HANDLER,
+ .cb = G_CALLBACK(dbus_cb_pmqos_legacy_scenario),
+ .cb_data = NULL,
+ .ret_id = 0,
+ }, {
+ .handler = DBUS_PMQOS_I_ULTRAPOWERSAVING_HANDLER,
+ .cb = G_CALLBACK(dbus_cb_pmqos_legacy_scenario),
+ .cb_data = NULL,
+ .ret_id = 0,
+ }, {
+ .handler = DBUS_PMQOS_I_START_HANDLER,
+ .cb = G_CALLBACK(dbus_cb_pmqos_start),
+ .cb_data = NULL,
+ .ret_id = 0,
+ }, {
+ .handler = DBUS_PMQOS_I_STOP_HANDLER,
+ .cb = G_CALLBACK(dbus_cb_pmqos_stop),
+ .cb_data = NULL,
+ .ret_id = 0,
+ },
+};
+
+static gboolean pmqos_timer(gpointer data)
+{
+ int ret;
+
+ ret = pmqos_cancel(unlock_timer_owner.name);
+ if (ret < 0)
+ _E("cannot find %s request", unlock_timer_owner.name);
+
+ return TRUE;
+}
+
+static int compare_timeout(const void *a, const void *b)
+{
+ const struct pmqos_cpu *pmqos_a = (const struct pmqos_cpu *)a;
+ const struct pmqos_cpu *pmqos_b = (const struct pmqos_cpu *)b;
+
+ if (!pmqos_a)
+ return 1;
+ if (!pmqos_b)
+ return -1;
- ret_dbus = dbus_message_new_method_return(msg);
- return ret_dbus;
+ if (pmqos_a->timeout < pmqos_b->timeout)
+ return -1;
+ else if (pmqos_a->timeout > pmqos_b->timeout)
+ return 1;
+ return 0;
}
static int set_pmqos(const char *name, int val)
}
}
-static int pmqos_unlock_timer_start(void)
-{
- int ret;
- GList *elem;
- struct pmqos_cpu *cpu;
-
- if (unlock_timer) {
- ecore_timer_del(unlock_timer);
- unlock_timer = NULL;
- }
-
- ret = g_list_length(pmqos_head);
- if (ret == 0)
- return 0;
-
- for (elem = pmqos_head; elem != NULL; elem = elem->next) {
- cpu = elem->data;
- if (cpu->timeout <= 0)
- continue;
- memcpy(&unlock_timer_owner, cpu, sizeof(struct pmqos_cpu));
- clock_gettime(CLOCK_REALTIME, &unlock_timer_start_st);
- unlock_timer = ecore_timer_add(((unlock_timer_owner.timeout)/1000.f),
- pmqos_timer, NULL);
- if (unlock_timer)
- break;
- _E("fail init pmqos unlock %s %d", cpu->name, cpu->timeout);
- return -EPERM;
- }
-
- return 0;
-}
-
static int pmqos_cancel(const char *name)
{
GList *elem;
return 0;
}
-static Eina_Bool pmqos_timer(void *data)
+static int pmqos_unlock_timer_start(void)
{
int ret;
+ GList *elem;
+ struct pmqos_cpu *cpu;
- ret = pmqos_cancel(unlock_timer_owner.name);
- if (ret < 0)
- _E("Can not find %s request", unlock_timer_owner.name);
-
- return ECORE_CALLBACK_CANCEL;
-}
+ if (g_unlock_timeout_id) {
+ g_source_remove(g_unlock_timeout_id);
+ g_unlock_timeout_id = 0;
+ }
-static int compare_timeout(const void *a, const void *b)
-{
- const struct pmqos_cpu *pmqos_a = (const struct pmqos_cpu *)a;
- const struct pmqos_cpu *pmqos_b = (const struct pmqos_cpu *)b;
+ ret = g_list_length(pmqos_head);
+ if (ret == 0)
+ return 0;
- if (!pmqos_a)
- return 1;
- if (!pmqos_b)
- return -1;
+ for (elem = pmqos_head; elem != NULL; elem = elem->next) {
+ cpu = elem->data;
+ if (cpu->timeout <= 0)
+ continue;
+ memcpy(&unlock_timer_owner, cpu, sizeof(struct pmqos_cpu));
+ clock_gettime(CLOCK_REALTIME, &unlock_timer_start_st);
+ g_unlock_timeout_id = g_timeout_add(
+ /* FIXME: this is int to uint conversion. */
+ (guint)unlock_timer_owner.timeout,
+ (GSourceFunc)pmqos_timer,
+ NULL);
+ if (g_unlock_timeout_id)
+ break;
- if (pmqos_a->timeout < pmqos_b->timeout)
- return -1;
- else if (pmqos_a->timeout > pmqos_b->timeout)
- return 1;
+ _E("fail init pmqos unlock %s %d", cpu->name, cpu->timeout);
+ return -EPERM;
+ }
return 0;
}
return ret;
}
-static DBusMessage *dbus_pmqos_handler(E_DBus_Object *obj, DBusMessage *msg)
+static int get_methods_from_conf(const char *path,
+ struct pmqos_scenario **pmqos_scenarios)
{
- DBusMessageIter iter;
- DBusMessage *reply;
- const char *member;
- int val, ret;
-
- if (!dbus_message_get_args(msg, NULL,
- DBUS_TYPE_INT32, &val, DBUS_TYPE_INVALID)) {
- _E("there is no message");
- ret = -EINVAL;
- goto error;
- }
-
- if (val < 0) {
- ret = -EINVAL;
- goto error;
- }
-
- member = dbus_message_get_member(msg);
-
- if (val)
- ret = pmqos_request(member, val);
- else
- ret = pmqos_cancel(member);
-
-error:
- 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 int get_methods_from_conf(const char *path, struct edbus_method **edbus_methods)
-{
- struct edbus_method *methods;
- struct pmqos_scenario scenarios = {0,};
+ struct pmqos_scenario *scenarios;
int i, ret, count = 0;
+ scenarios = malloc(sizeof(*scenarios));
+ if (scenarios == NULL)
+ return -ENOMEM;
+
/* get pmqos table from conf */
- ret = pmqos_get_scenario(path, &scenarios);
+ ret = pmqos_get_scenario(path, scenarios);
if (ret < 0) {
- pmqos_put_scenario(&scenarios);
+ pmqos_put_scenario(scenarios);
return ret;
}
/* if do not support scenario */
- if (!scenarios.support)
+ if (!scenarios->support)
return 0;
/* if do not have scenarios */
- if (scenarios.num <= 0)
+ if (scenarios->num <= 0)
return 0;
- /* allocate edbus methods structure */
- methods = calloc(scenarios.num, sizeof(struct edbus_method));
- if (!methods) {
- _E("failed to allocate memory for methods");
- pmqos_put_scenario(&scenarios);
- return -errno;
- }
-
/* set edbus_methods structure */
- for (i = 0; i < scenarios.num; ++i) {
+ for (i = 0; i < scenarios->num; ++i) {
/* if this scenario does not support */
- if (!scenarios.list[i].support)
+ if (!scenarios->list[i].support)
continue;
- methods[count].member = scenarios.list[i].name;
- methods[count].signature = "i";
- methods[count].reply_signature = "i";
- methods[count].func = dbus_pmqos_handler;
count++;
-
- _D("support [%s] scenario", scenarios.list[i].name);
+ _I("support [%s] scenario", scenarios->list[i].name);
}
-
/*
* Set maximum timeout for the sceanrio by using the parsed data from
* pass-pmqos.conf. But, if there is no setting from pass-pmqos.conf
* pmqos uses the default timeout value (3000 millisecond).
*/
- if (scenarios.max_timeout_ms)
- unlock_max_timeout_ms = scenarios.max_timeout_ms;
+ if (scenarios->max_timeout_ms)
+ unlock_max_timeout_ms = scenarios->max_timeout_ms;
else
unlock_max_timeout_ms = DEFAULT_PMQOS_TIMER;
- *edbus_methods = methods;
ret = count;
- pmqos_put_scenario(&scenarios);
+ *pmqos_scenarios = scenarios;
return ret;
}
-/* Add pmqos name as alphabetically */
-static const struct edbus_method edbus_methods[] = {
- { "start", NULL, NULL, e_dbus_start_cb },
- { "stop", NULL, NULL, e_dbus_stop_cb },
-};
-
static int pmqos_init_done(void *data, void *user_data)
{
- struct edbus_method *methods = NULL;
int *booting_done;
- int ret, size;
+ int size;
/*
* As a callback function for the booting-done event, it is notified
* first argument, void *data. When it is successfully booted up, an int
* value, 1 is passed with the first argument.
*/
- booting_done = (int *) data;
+ booting_done = (int *)data;
if (!(*booting_done))
return -EINVAL;
- /* register edbus methods */
- ret = register_edbus_method(PASS_PATH_PMQOS, edbus_methods,
- ARRAY_SIZE(edbus_methods));
- if (ret < 0)
- _E("fail to init edbus method(%d)", ret);
-
- /* get methods from config file */
- size = get_methods_from_conf(PMQOS_CONF_PATH, &methods);
- if (size < 0)
+ size = get_methods_from_conf(PMQOS_CONF_PATH, &g_pmqos_scenarios);
+ if (size < 0) {
_E("failed to load configuration file(%s)", PMQOS_CONF_PATH);
-
- /* register edbus methods for pmqos */
- if (methods) {
- ret = register_edbus_method(PASS_PATH_PMQOS, methods, size);
- if (ret < 0)
- _E("fail to init edbus method from conf(%d)", ret);
- free(methods);
+ return -EINVAL;
}
- return ret;
+ g_initialized = true;
+
+ return 0;
}
static void pmqos_init(void *data)
pmqos_head = NULL;
}
- /* Clean up unlock_timer */
- if (unlock_timer) {
- ecore_timer_del(unlock_timer);
- unlock_timer = NULL;
+ free(g_pmqos_scenarios);
+ g_pmqos_scenarios = NULL;
+
+ if (g_unlock_timeout_id) {
+ g_source_remove(g_unlock_timeout_id);
+ g_unlock_timeout_id = 0;
}
+
+ g_initialized = false;
}
static void pmqos_exit(void *data)
{
unregister_notifier(DEVICE_NOTIFIER_BOOTING_DONE,
pmqos_init_done, NULL);
+
+ pass_gdbus_disconnect_signal(g_gdbus_instance,
+ DBUS_PMQOS_I_NUM_SIGNALS, g_gdbus_signal_infos);
+ pass_gdbus_put_instance_pmqos(&g_gdbus_instance);
+
pmqos_free();
}
{
int ret = 0;
+ g_gdbus_instance = pass_gdbus_get_instance_pmqos();
+ if (g_gdbus_instance == NULL) {
+ _E("cannot get a dbus instance for the %s interface\n",
+ DBUS_PMQOS_INTERFACE);
+ return -ENOSYS;
+ }
+
+ ret = pass_gdbus_connect_signal(g_gdbus_instance,
+ DBUS_PMQOS_I_NUM_SIGNALS, g_gdbus_signal_infos);
+ if (ret < 0) {
+ _E("cannot register callbacks as the dbus method invocation "
+ "handlers\n");
+ ret = -ENOSYS;
+ goto out;
+ }
+
+ ret = pass_gdbus_export_interface(g_gdbus_instance, DBUS_PMQOS_PATH);
+ if (ret < 0) {
+ _E("cannot export the dbus interface '%s' "
+ "at the object path '%s'\n",
+ DBUS_PMQOS_INTERFACE,
+ DBUS_PMQOS_PATH);
+ ret = -ENOSYS;
+ goto out_disconnect;
+ }
+
/*
* Register a notifier for the booting-done event. The actual
* initialization of the daemon is performed by this notifier after
if (ret < 0) {
_E("cannot register a callback function \
for the booting-done event (%d)\n", ret);
- return ret;
+ goto out_disconnect;
}
+ return 0;
+
+out_disconnect:
+ pass_gdbus_disconnect_signal(g_gdbus_instance,
+ DBUS_PMQOS_I_NUM_SIGNALS, g_gdbus_signal_infos);
+out:
+ pass_gdbus_put_instance_pmqos(&g_gdbus_instance);
+
return ret;
+
}
static const struct device_ops pmqos_device_ops = {
+++ /dev/null
-CMAKE_MINIMUM_REQUIRED(VERSION 2.6)
-
-SET(SHARED_SRCS
- dbus.c
-)
-
-INCLUDE(FindPkgConfig)
-pkg_check_modules(libshared REQUIRED
- gio-2.0
- dlog
- dbus-1)
-
-FOREACH(flag ${libshared_CFLAGS})
- SET(SHARED_LIB_CFLAGS "${SHARED_LIB_CFLAGS} ${flag}")
-ENDFOREACH(flag)
-
-ADD_LIBRARY(shared STATIC ${SHARED_SRCS})
-TARGET_LINK_LIBRARIES(shared ${libshared_LDFLAGS})
-SET_TARGET_PROPERTIES(shared PROPERTIES COMPILE_FLAGS "-fPIC")
+++ /dev/null
-/*
- * PASS (Power Aware System Service)
- *
- * Copyright (c) 2017 Samsung Electronics Co., Ltd. All rights reserved.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-#ifndef __SHARED_COMMON_H__
-#define __SHARED_COMMON_H__
-
-#ifndef __CONSTRUCTOR__
-#define __CONSTRUCTOR__ __attribute__ ((constructor))
-#endif
-
-#ifndef __DESTRUCTOR__
-#define __DESTRUCTOR__ __attribute__ ((destructor))
-#endif
-
-#endif /* __SHARED_COMMON_H__ */
+++ /dev/null
-/*
- * PASS (Power Aware System Service)
- *
- * Copyright (c) 2017 Samsung Electronics Co., Ltd.
- *
- * Licensed under the Apache License, Version 2.0 (the License);
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-
-#include <stdio.h>
-#include <stdlib.h>
-#include <stdbool.h>
-#include <stdint.h>
-#include <errno.h>
-
-#include "common.h"
-#include "log.h"
-#include "dbus.h"
-
-/* -1 is a default timeout value, it's converted to 25*1000 internally. */
-#define DBUS_REPLY_TIMEOUT (-1)
-
-struct pending_call_data {
- dbus_pending_cb func;
- void *data;
-};
-
-int append_variant(DBusMessageIter *iter, const char *sig, char *param[])
-{
- char *ch;
- int i;
- int int_type;
- dbus_bool_t bool_type;
- uint64_t int64_type;
- DBusMessageIter arr;
- struct dbus_byte *byte;
-
- if (!sig || !param)
- return 0;
-
- for (ch = (char *)sig, i = 0; *ch != '\0'; ++i, ++ch) {
- switch (*ch) {
- case 'b':
- bool_type = (atoi(param[i])) ? TRUE : FALSE;
- dbus_message_iter_append_basic(iter, DBUS_TYPE_BOOLEAN, &bool_type);
- break;
- case 'i':
- int_type = atoi(param[i]);
- dbus_message_iter_append_basic(iter, DBUS_TYPE_INT32, &int_type);
- break;
- case 'u':
- int_type = strtoul(param[i], NULL, 10);
- dbus_message_iter_append_basic(iter, DBUS_TYPE_UINT32, &int_type);
- break;
- case 't':
- int64_type = atoll(param[i]);
- dbus_message_iter_append_basic(iter, DBUS_TYPE_UINT64, &int64_type);
- break;
- case 's':
- dbus_message_iter_append_basic(iter, DBUS_TYPE_STRING, ¶m[i]);
- break;
- case 'a':
- ++ch;
- switch (*ch) {
- case 'y':
- dbus_message_iter_open_container(iter, DBUS_TYPE_ARRAY, DBUS_TYPE_BYTE_AS_STRING, &arr);
- byte = (struct dbus_byte *)param[i];
- dbus_message_iter_append_fixed_array(&arr, DBUS_TYPE_BYTE, &(byte->data), byte->size);
- dbus_message_iter_close_container(iter, &arr);
- break;
- default:
- break;
- }
- break;
- default:
- return -EINVAL;
- }
- }
-
- return 0;
-}
-
-DBusMessage *dbus_method_sync_with_reply(const char *dest, const char *path,
- const char *interface, const char *method,
- const char *sig, char *param[])
-{
- DBusConnection *conn;
- DBusMessage *msg;
- DBusMessageIter iter;
- DBusMessage *reply;
- DBusError err;
- int r;
-
- conn = dbus_bus_get(DBUS_BUS_SYSTEM, NULL);
- if (!conn) {
- _E("dbus_bus_get error");
- return NULL;
- }
-
- msg = dbus_message_new_method_call(dest, path, interface, method);
- if (!msg) {
- _E("dbus_message_new_method_call(%s:%s-%s)",
- path, interface, method);
- return NULL;
- }
-
- dbus_message_iter_init_append(msg, &iter);
- r = append_variant(&iter, sig, param);
- if (r < 0) {
- _E("append_variant error(%d) %s %s:%s-%s",
- r, dest, path, interface, method);
- dbus_message_unref(msg);
- return NULL;
- }
-
- dbus_error_init(&err);
-
- reply = dbus_connection_send_with_reply_and_block(conn, msg, DBUS_REPLY_TIMEOUT, &err);
- if (!reply) {
- _E("dbus_connection_send error(No reply) %s %s:%s-%s",
- dest, path, interface, method);
- }
-
- if (dbus_error_is_set(&err)) {
- _E("dbus_connection_send error(%s:%s) %s %s:%s-%s",
- err.name, err.message, dest, path, interface, method);
- dbus_error_free(&err);
- reply = NULL;
- }
-
- dbus_message_unref(msg);
- return reply;
-}
-
-int dbus_method_sync(const char *dest, const char *path,
- const char *interface, const char *method,
- const char *sig, char *param[])
-{
- DBusConnection *conn;
- DBusMessage *msg;
- DBusMessageIter iter;
- DBusMessage *reply;
- DBusError err;
- int ret, result;
-
- conn = dbus_bus_get(DBUS_BUS_SYSTEM, NULL);
- if (!conn) {
- _E("dbus_bus_get error");
- return -EPERM;
- }
-
- msg = dbus_message_new_method_call(dest, path, interface, method);
- if (!msg) {
- _E("dbus_message_new_method_call(%s:%s-%s)",
- path, interface, method);
- return -EBADMSG;
- }
-
- dbus_message_iter_init_append(msg, &iter);
- ret = append_variant(&iter, sig, param);
- if (ret < 0) {
- _E("append_variant error(%d) %s %s:%s-%s",
- ret, dest, path, interface, method);
- dbus_message_unref(msg);
- return ret;
- }
-
- dbus_error_init(&err);
-
- reply = dbus_connection_send_with_reply_and_block(conn, msg, DBUS_REPLY_TIMEOUT, &err);
- dbus_message_unref(msg);
- if (!reply) {
- _E("dbus_connection_send error(%s:%s) %s %s:%s-%s",
- err.name, err.message, dest, path, interface, method);
- dbus_error_free(&err);
- return -ECOMM;
- }
-
- ret = dbus_message_get_args(reply, &err, DBUS_TYPE_INT32, &result, DBUS_TYPE_INVALID);
- dbus_message_unref(reply);
- if (!ret) {
- _E("no message : [%s:%s] %s %s:%s-%s",
- err.name, err.message, dest, path, interface, method);
- dbus_error_free(&err);
- return -ENOMSG;
- }
-
- return result;
-}
-
-int dbus_method_sync_timeout(const char *dest, const char *path,
- const char *interface, const char *method,
- const char *sig, char *param[], int timeout)
-{
- DBusConnection *conn;
- DBusMessage *msg;
- DBusMessageIter iter;
- DBusMessage *reply;
- DBusError err;
- int ret, result;
-
- conn = dbus_bus_get(DBUS_BUS_SYSTEM, NULL);
- if (!conn) {
- _E("dbus_bus_get error");
- return -EPERM;
- }
-
- msg = dbus_message_new_method_call(dest, path, interface, method);
- if (!msg) {
- _E("dbus_message_new_method_call(%s:%s-%s)",
- path, interface, method);
- return -EBADMSG;
- }
-
- dbus_message_iter_init_append(msg, &iter);
- ret = append_variant(&iter, sig, param);
- if (ret < 0) {
- _E("append_variant error(%d) %s %s:%s-%s",
- ret, dest, path, interface, method);
- dbus_message_unref(msg);
- return ret;
- }
-
- dbus_error_init(&err);
-
- reply = dbus_connection_send_with_reply_and_block(conn, msg, DBUS_REPLY_TIMEOUT, &err);
- dbus_message_unref(msg);
- if (!reply) {
- _E("dbus_connection_send error(%s:%s) %s %s:%s-%s",
- err.name, err.message, dest, path, interface, method);
- dbus_error_free(&err);
- return -ECOMM;
- }
-
- ret = dbus_message_get_args(reply, &err, DBUS_TYPE_INT32, &result, DBUS_TYPE_INVALID);
- dbus_message_unref(reply);
- if (!ret) {
- _E("no message : [%s:%s] %s %s:%s-%s",
- err.name, err.message, dest, path, interface, method);
- dbus_error_free(&err);
- return -ENOMSG;
- }
-
- return result;
-}
-
-int dbus_method_sync_pairs(const char *dest, const char *path,
- const char *interface, const char *method,
- int num, va_list args)
-{
- DBusConnection *conn;
- DBusMessage *msg;
- DBusMessage *reply;
- DBusMessageIter iter;
- DBusMessageIter aiter, piter;
- DBusError err;
- int ret, result, i;
- char *key, *value;
-
- conn = dbus_bus_get(DBUS_BUS_SYSTEM, NULL);
- if (!conn) {
- _E("dbus_bus_get error");
- return -EPERM;
- }
-
- msg = dbus_message_new_method_call(dest, path, interface, method);
- if (!msg) {
- _E("dbus_message_new_method_call(%s:%s-%s)",
- path, interface, method);
- return -EBADMSG;
- }
-
- dbus_message_iter_init_append(msg, &iter);
- dbus_message_iter_open_container(&iter, DBUS_TYPE_ARRAY, "{ss}", &aiter);
-
- for (i = 0 ; i < num ; i = i + 2) {
- key = va_arg(args, char *);
- value = va_arg(args, char *);
- _I("key(%s), value(%s)", key, value);
- dbus_message_iter_open_container(&aiter, DBUS_TYPE_DICT_ENTRY, NULL, &piter);
- dbus_message_iter_append_basic(&piter, DBUS_TYPE_STRING, &key);
- dbus_message_iter_append_basic(&piter, DBUS_TYPE_STRING, &value);
- dbus_message_iter_close_container(&aiter, &piter);
- }
-
- dbus_message_iter_close_container(&iter, &aiter);
-
- dbus_error_init(&err);
-
- reply = dbus_connection_send_with_reply_and_block(conn, msg, DBUS_REPLY_TIMEOUT, &err);
- dbus_message_unref(msg);
- if (!reply) {
- _E("dbus_connection_send error(%s:%s) %s %s:%s-%s",
- err.name, err.message, dest, path, interface, method);
- dbus_error_free(&err);
- return -ECOMM;
- }
-
- ret = dbus_message_get_args(reply, &err, DBUS_TYPE_INT32, &result, DBUS_TYPE_INVALID);
- dbus_message_unref(reply);
- if (!ret) {
- _E("no message : [%s:%s] %s %s:%s-%s",
- err.name, err.message, dest, path, interface, method);
- dbus_error_free(&err);
- return -ENOMSG;
- }
-
- return result;
-}
-
-int dbus_method_async(const char *dest, const char *path,
- const char *interface, const char *method,
- const char *sig, char *param[])
-{
- DBusConnection *conn;
- DBusMessage *msg;
- DBusMessageIter iter;
- int ret;
-
- conn = dbus_bus_get(DBUS_BUS_SYSTEM, NULL);
- if (!conn) {
- _E("dbus_bus_get error");
- return -EPERM;
- }
-
- msg = dbus_message_new_method_call(dest, path, interface, method);
- if (!msg) {
- _E("dbus_message_new_method_call(%s:%s-%s)",
- path, interface, method);
- return -EBADMSG;
- }
-
- dbus_message_iter_init_append(msg, &iter);
- ret = append_variant(&iter, sig, param);
- if (ret < 0) {
- _E("append_variant error(%d) %s %s:%s-%s",
- ret, dest, path, interface, method);
- dbus_message_unref(msg);
- return ret;
- }
-
- ret = dbus_connection_send(conn, msg, NULL);
- dbus_message_unref(msg);
- if (ret != TRUE) {
- _E("dbus_connection_send error(%s %s:%s-%s)",
- dest, path, interface, method);
- return -ECOMM;
- }
-
- return 0;
-}
-
-static void cb_pending(DBusPendingCall *pending, void *user_data)
-{
- DBusMessage *msg;
- DBusError err;
- struct pending_call_data *data = user_data;
- int ret;
-
- ret = dbus_pending_call_get_completed(pending);
- if (!ret) {
- _E("dbus_pending_call_get_completed() fail");
- dbus_pending_call_unref(pending);
- return;
- }
-
- dbus_error_init(&err);
- msg = dbus_pending_call_steal_reply(pending);
- if (!msg) {
- _E("no message : [%s:%s]", err.name, err.message);
-
- if (data->func) {
- dbus_set_error(&err, "org.tizen.system.pass.NoReply",
- "There was no reply to this method call");
- data->func(data->data, NULL, &err);
- dbus_error_free(&err);
- }
- return;
- }
-
- ret = dbus_set_error_from_message(&err, msg);
- if (ret) {
- _E("error msg : [%s:%s]", err.name, err.message);
-
- if (data->func)
- data->func(data->data, NULL, &err);
- dbus_error_free(&err);
- } else {
- if (data->func)
- data->func(data->data, msg, &err);
- }
-
- dbus_message_unref(msg);
- dbus_pending_call_unref(pending);
-}
-
-int dbus_method_async_with_reply(const char *dest, const char *path,
- const char *interface, const char *method,
- const char *sig, char *param[], dbus_pending_cb cb, int timeout, void *data)
-{
- DBusConnection *conn;
- DBusMessage *msg;
- DBusMessageIter iter;
- DBusPendingCall *pending = NULL;
- struct pending_call_data *pdata;
- int ret;
-
- conn = dbus_bus_get(DBUS_BUS_SYSTEM, NULL);
- if (!conn) {
- _E("dbus_bus_get error");
- return -EPERM;
- }
-
- msg = dbus_message_new_method_call(dest, path, interface, method);
- if (!msg) {
- _E("dbus_message_new_method_call(%s:%s-%s)",
- path, interface, method);
- return -EBADMSG;
- }
-
- dbus_message_iter_init_append(msg, &iter);
- ret = append_variant(&iter, sig, param);
- if (ret < 0) {
- _E("append_variant error(%d)%s %s:%s-%s",
- ret, dest, path, interface, method);
- dbus_message_unref(msg);
- return ret;
- }
-
- ret = dbus_connection_send_with_reply(conn, msg, &pending, timeout);
- if (!ret) {
- dbus_message_unref(msg);
- _E("dbus_connection_send error(%s %s:%s-%s)",
- dest, path, interface, method);
- return -ECOMM;
- }
-
- dbus_message_unref(msg);
-
- if (cb && pending) {
- pdata = malloc(sizeof(struct pending_call_data));
- if (!pdata)
- return -ENOMEM;
-
- pdata->func = cb;
- pdata->data = data;
-
- ret = dbus_pending_call_set_notify(pending, cb_pending, pdata, free);
- if (!ret) {
- free(pdata);
- dbus_pending_call_cancel(pending);
- return -ECOMM;
- }
- }
-
- return 0;
-}
-
-int check_systemd_active(void)
-{
- int ret = FALSE;
- DBusError err;
- DBusMessage *msg;
- DBusMessageIter iter, sub;
- const char *state;
- char *pa[2];
-
- pa[0] = "org.freedesktop.systemd1.Unit";
- pa[1] = "ActiveState";
-
- _I("%s %s", pa[0], pa[1]);
-
- msg = dbus_method_sync_with_reply("org.freedesktop.systemd1",
- "/org/freedesktop/systemd1/unit/default_2etarget",
- "org.freedesktop.DBus.Properties",
- "Get", "ss", pa);
- if (!msg)
- return -EBADMSG;
-
- dbus_error_init(&err);
-
- if (!dbus_message_iter_init(msg, &iter) ||
- dbus_message_iter_get_arg_type(&iter) != DBUS_TYPE_VARIANT)
- goto out;
-
- dbus_message_iter_recurse(&iter, &sub);
-
- if (dbus_message_iter_get_arg_type(&sub) != DBUS_TYPE_STRING) {
- ret = -EBADMSG;
- goto out;
- }
-
- dbus_message_iter_get_basic(&sub, &state);
-
- if (strncmp(state, "active", 6) == 0)
- ret = TRUE;
-out:
- dbus_message_unref(msg);
- dbus_error_free(&err);
- return ret;
-}
-
-static void __CONSTRUCTOR__ dbus_init(void)
-{
- dbus_threads_init_default();
-}
+++ /dev/null
-/*
- * PASS
- *
- * Copyright (c) 2012 - 2013 Samsung Electronics Co., Ltd.
- *
- * Licensed under the Apache License, Version 2.0 (the License);
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-
-#ifndef __DBUS_H__
-#define __DBUS_H__
-
-#include <dbus/dbus.h>
-#include <stdarg.h>
-
-/*
- * Template
- *
-#define XXX_BUS_NAME "org.tizen.system.XXX"
-#define XXX_OBJECT_PATH "/Org/Tizen/System/XXX"
-#define XXX_INTERFACE_NAME XXX_BUS_NAME
-#define XXX_PATH_YYY XXX_OBJECT_PATH"/YYY"
-#define XXX_INTERFACE_YYY XXX_INTERFACE_NAME".YYY"
-#define XXX_SIGNAL_ZZZ "ZZZ"
-#define XXX_METHOD_ZZZ "ZZZ"
- */
-
-/*
- * DBus daemon
- */
-#define DBUS_BUS_NAME "org.freedesktop.DBus"
-#define DBUS_OBJECT_PATH "/org/freedesktop/DBus"
-#define DBUS_INTERFACE_NAME DBUS_BUS_NAME
-
-/*
- * Device daemon
- */
-#define PASS_BUS_NAME "org.tizen.system.pass"
-#define PASS_OBJECT_PATH "/Org/Tizen/System/Pass"
-#define PASS_INTERFACE_NAME PASS_BUS_NAME
-
-/* Core service: get/set device status operations about device */
-#define PASS_PATH_CORE PASS_OBJECT_PATH"/Core"
-#define PASS_INTERFACE_CORE PASS_INTERFACE_NAME".core"
-
-/* PmQos service: operations about pmqos */
-#define PASS_PATH_PMQOS PASS_OBJECT_PATH"/Pmqos"
-#define PASS_INTERFACE_PMQOS PASS_INTERFACE_NAME".pmqos"
-
-struct dbus_byte {
- const unsigned char *data;
- int size;
-};
-
-int append_variant(DBusMessageIter *iter, const char *sig, char *param[]);
-
-DBusMessage *dbus_method_sync_with_reply(const char *dest, const char *path,
- const char *interface, const char *method,
- const char *sig, char *param[]);
-
-int dbus_method_sync(const char *dest, const char *path,
- const char *interface, const char *method,
- const char *sig, char *param[]);
-
-int dbus_method_sync_timeout(const char *dest, const char *path,
- const char *interface, const char *method,
- const char *sig, char *param[], int timeout);
-
-int dbus_method_sync_pairs(const char *dest, const char *path,
- const char *interface, const char *method,
- int num, va_list args);
-
-int dbus_method_async(const char *dest, const char *path,
- const char *interface, const char *method,
- const char *sig, char *param[]);
-
-typedef void (*dbus_pending_cb)(void *data, DBusMessage *msg, DBusError *err);
-
-int dbus_method_async_with_reply(const char *dest, const char *path,
- const char *interface, const char *method,
- const char *sig, char *param[], dbus_pending_cb cb, int timeout, void *data);
-
-int check_systemd_active(void);
-#endif
+++ /dev/null
-/*
- * PASS
- *
- * Copyright (c) 2014 Samsung Electronics Co., Ltd.
- *
- * Licensed under the Apache License, Version 2.0 (the License);
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-#define _GNU_SOURCE
-
-#include <stdio.h>
-#include <stdlib.h>
-#include <string.h>
-#include <errno.h>
-#include <assert.h>
-#include <dbus/dbus.h>
-#include <gio/gio.h>
-
-#include "shared/log.h"
-
-#include "common.h"
-#include "dbus.h"
-#include "pass-systemd.h"
-
-
-#define SYSTEMD_UNIT_ESCAPE_CHAR ".-"
-
-typedef unsigned int uint;
-typedef long long int64;
-typedef unsigned long long uint64;
-
-#define g_variant_type_int32 G_VARIANT_TYPE_INT32
-#define g_variant_type_int64 G_VARIANT_TYPE_INT64
-#define g_variant_type_uint32 G_VARIANT_TYPE_UINT32
-#define g_variant_type_uint64 G_VARIANT_TYPE_UINT64
-#define g_variant_type_string G_VARIANT_TYPE_STRING
-
-#define g_variant_get_function_int32(v) g_variant_get_int32(v)
-#define g_variant_get_function_int64(v) g_variant_get_int64(v)
-#define g_variant_get_function_uint32(v) g_variant_get_uint32(v)
-#define g_variant_get_function_uint64(v) g_variant_get_uint64(v)
-#define g_variant_get_function_string(v) g_variant_dup_string(v, NULL)
-
-
-static int pass_systemd_proxy_call_sync(const char *name,
- const char *path,
- const char *iface,
- const char *method,
- GVariant *variant,
- GVariant **reply)
-{
- GVariant *gvar;
- GError *error;
- GDBusProxy *proxy;
- int ret = 0;
-
-#if (GLIB_MAJOR_VERSION <= 2 && GLIB_MINOR_VERSION < 36)
- g_type_init();
-#endif
-
- error = NULL;
- proxy = g_dbus_proxy_new_for_bus_sync(G_BUS_TYPE_SYSTEM,
- G_DBUS_PROXY_FLAGS_NONE,
- NULL, /* GDBusInterfaceInfo */
- name,
- path,
- iface,
- NULL, /* GCancellable */
- &error);
-
- if (proxy == NULL) {
- _E("Error creating proxy: %s", error->message);
- ret = error->code;
- g_error_free(error);
- return ret;
- }
-
- error = NULL;
- gvar = g_dbus_proxy_call_sync(proxy,
- method,
- variant,
- G_DBUS_CALL_FLAGS_NONE,
- -1,
- NULL, /* GCancellable */
- &error);
-
- if (error) {
- _E("Error proxy call sync: %s", error->message);
- ret = error->code;
- g_error_free(error);
- return -ret;
- }
-
- g_assert(gvar != NULL);
- *reply = gvar;
- g_clear_error(&error);
- g_object_unref(proxy);
-
- return 0;
-}
-
-static int pass_systemd_start_or_stop_unit(char *method, char *name)
-{
- int ret;
- GVariant *reply = NULL;
-
- _I("Starting: %s %s", method, name);
- ret = pass_systemd_proxy_call_sync(SYSTEMD_DBUS_DEST,
- SYSTEMD_DBUS_PATH,
- SYSTEMD_DBUS_IFACE_MANAGER,
- method,
- g_variant_new("(ss)",
- name,
- "replace"),
- &reply);
- if (ret < 0)
- goto finish;
-
- if (!g_variant_is_of_type(reply, G_VARIANT_TYPE("(o)"))) {
- ret = -EBADMSG;
- goto finish;
- }
-
- ret = 0;
-finish:
- _I("Finished(%d): %s %s", ret, method, name);
-
- if (reply)
- g_variant_unref(reply);
-
- return ret;
-}
-
-int pass_systemd_start_unit(char *name)
-{
- assert(name);
-
- return pass_systemd_start_or_stop_unit("StartUnit", name);
-}
-
-int pass_systemd_stop_unit(char *name)
-{
- assert(name);
-
- return pass_systemd_start_or_stop_unit("StopUnit", name);
-}
-
-static void pass_systemd_get_unit_dbus_path(const char *unit,
- char *path, int max_path_len)
-{
- int i;
- size_t p, k, prefix_len, unit_len = strlen(unit);
- size_t path_len, len, escape;
-
- assert(unit);
-
- memset(path, '\0', sizeof(char) * max_path_len);
- for (escape = 0, p = 0; p < unit_len; escape++) {
- k = strcspn(unit+p, SYSTEMD_UNIT_ESCAPE_CHAR);
- if (p+k >= unit_len)
- break;
- p += k+1;
- }
-
- prefix_len = strlen(SYSTEMD_DBUS_UNIT_PATH);
- /* assume we try to get object path of foo-bar.service then
- * the object path will be
- * "/org/freedesktop/systemd1/unit/foo_2dbar_2eservice\n". In
- * this case we can find two escape characters, one of escape
- * char('-') is changed to three of char("_2d"). So the total
- * length will be: */
- /* (PREFIX) + (unit - escape + 3*escape) + NULL */
- path_len = prefix_len + (unit_len - escape) + (escape * 3) + 1;
- if (max_path_len < path_len) {
- path[0] = '\0';
- return;
- }
-
- strncpy(path, SYSTEMD_DBUS_UNIT_PATH, prefix_len + 1);
- for (i = 0, p = 0; i <= escape; i++) {
- k = strcspn(unit + p, SYSTEMD_UNIT_ESCAPE_CHAR);
- strncpy(path + prefix_len, unit + p, k);
- if (k < strlen(unit + p)) {
- len = path_len - (prefix_len + k);
- snprintf(path + prefix_len + k, len,
- "_%x", *(unit + p + k) & 0xff);
- prefix_len += k+3;
- p += k+1;
- }
- }
-}
-
-static int pass_systemd_get_property(const char *name,
- const char *path,
- const char *iface,
- const char *method,
- const char *interface,
- const char *property,
- GVariant **reply)
-{
- int ret;
- GVariant *variant;
-
- variant = g_variant_new("(ss)",
- interface,
- property);
-
- ret = pass_systemd_proxy_call_sync(name,
- path,
- iface,
- method,
- variant,
- reply);
-
- return ret;
-}
-
-int pass_systemd_get_manager_property(const char *iface,
- const char *property,
- GVariant **variant)
-{
- assert(iface);
- assert(property);
-
- return pass_systemd_get_property(SYSTEMD_DBUS_DEST,
- SYSTEMD_DBUS_PATH,
- DBUS_IFACE_DBUS_PROPERTIES,
- "Get",
- iface,
- property,
- variant);
-}
-
-int pass_systemd_get_unit_property(const char *unit,
- const char *property,
- GVariant **variant)
-{
- char path[PATH_MAX];
- int ret;
-
- assert(unit);
- assert(property);
-
- pass_systemd_get_unit_dbus_path(unit, path, PATH_MAX);
- if (!strlen(path))
- return -1;
-
- ret = pass_systemd_get_property(SYSTEMD_DBUS_DEST,
- path,
- DBUS_IFACE_DBUS_PROPERTIES,
- "Get",
- SYSTEMD_DBUS_IFACE_UNIT,
- property,
- variant);
-
- return ret;
-}
-
-int pass_systemd_get_service_property(const char *unit,
- const char *property,
- GVariant **variant)
-{
- char path[PATH_MAX];
- int ret;
-
- assert(unit);
- assert(property);
-
- pass_systemd_get_unit_dbus_path(unit, path, PATH_MAX);
- if (!strlen(path))
- return -1;
-
- ret = pass_systemd_get_property(SYSTEMD_DBUS_DEST,
- path,
- DBUS_IFACE_DBUS_PROPERTIES,
- "Get",
- SYSTEMD_DBUS_IFACE_SERVICE,
- property,
- variant);
- return ret;
-}
-
-#define DEFINE_SYSTEMD_GET_PROPERTY(iface, type, value) \
- int pass_systemd_get_##iface##_property_as_##type( \
- const char *target, \
- const char *property, \
- value*result) \
- { \
- \
- GVariant *var; \
- GVariant *inner; \
- int r; \
- \
- r = pass_systemd_get_##iface##_property(target, \
- property, \
- &var); \
- if (r < 0) { \
- _E("Failed to get property:\n" \
- " target: %s\n" \
- " property: %s", \
- target, property); \
- return r; \
- } \
- \
- if (!g_variant_is_of_type(var, \
- G_VARIANT_TYPE("(v)"))) \
- return -EBADMSG; \
- \
- g_variant_get(var, "(v)", &inner); \
- if (!g_variant_is_of_type(inner, \
- g_variant_type_##type)) \
- return -EBADMSG; \
- \
- *result = g_variant_get_function_##type(inner); \
- g_variant_unref(var); \
- \
- return 0; \
- }
-
-/* int pass_systemd_get_manager_property_as_int32(const char *iface, const char *property, int *result); */
-DEFINE_SYSTEMD_GET_PROPERTY(manager, int32, int)
-/* int pass_systemd_get_manager_property_as_uint32(const char *iface, const char *property, unsigned int *result); */
-DEFINE_SYSTEMD_GET_PROPERTY(manager, uint32, uint)
-/* int pass_systemd_get_manager_property_as_int64(const char *iface, const char *property, long long *result); */
-DEFINE_SYSTEMD_GET_PROPERTY(manager, int64, long long)
-/* int pass_systemd_get_manager_property_as_uint64(const char *iface, const char *property, unsigned long long *result); */
-DEFINE_SYSTEMD_GET_PROPERTY(manager, uint64, unsigned long long)
-/* int pass_systemd_get_manager_property_as_string(const char *iface, const char *property, char **result); */
-DEFINE_SYSTEMD_GET_PROPERTY(manager, string, char*)
-/* int pass_systemd_get_unit_property_as_int32(const char *unit, const char *property, int *result); */
-DEFINE_SYSTEMD_GET_PROPERTY(unit, int32, int)
-/* int pass_systemd_get_unit_property_as_uint32(const char *unit, const char *property, unsigned int *result); */
-DEFINE_SYSTEMD_GET_PROPERTY(unit, uint32, uint)
-/* int pass_systemd_get_unit_property_as_int64(const char *unit, const char *property, long long *result); */
-DEFINE_SYSTEMD_GET_PROPERTY(unit, int64, long long)
-/* int pass_systemd_get_unit_property_as_uint64(const char *unit, const char *property, unsigned long long *result); */
-DEFINE_SYSTEMD_GET_PROPERTY(unit, uint64, unsigned long long)
-/* int pass_systemd_get_unit_property_as_string(const char *unit, const char *property, char **result); */
-DEFINE_SYSTEMD_GET_PROPERTY(unit, string, char*)
-/* int pass_systemd_get_service_property_as_int32(const char *unit, const char *property, int *result); */
-DEFINE_SYSTEMD_GET_PROPERTY(service, int32, int)
-/* int pass_systemd_get_service_property_as_uint32(const char *unit, const char *property, unsigned int *result); */
-DEFINE_SYSTEMD_GET_PROPERTY(service, uint32, uint)
-/* int pass_systemd_get_service_property_as_int64(const char *unit, const char *property, long long *result); */
-DEFINE_SYSTEMD_GET_PROPERTY(service, int64, long long)
-/* int pass_systemd_get_service_property_as_uint64(const char *unit, const char *property, unsigned long long *result); */
-DEFINE_SYSTEMD_GET_PROPERTY(service, uint64, unsigned long long)
-/* int pass_systemd_get_service_property_as_string(const char *unit, const char *property, char **result); */
-DEFINE_SYSTEMD_GET_PROPERTY(service, string, char*)
-
-int pass_systemd_instance_new_from_template(const char *template,
- const char *instance,
- const char **name)
-{
- /* p point '@' */
- /* e point '.' */
- const char *p, *e;
- char *prefix = NULL, *n = NULL;
- int r;
-
- assert(template);
- p = strchr(template, '@');
- if (!p) {
- r = -EINVAL;
- goto finish;
- }
-
- prefix = strndup(template, p - template + 1);
- if (!prefix) {
- r = -ENOMEM;
- goto finish;
- }
-
- e = strrchr(p + 1, '.');
- if (!e) {
- r = -EINVAL;
- goto finish;
- }
-
- /* verifying template. prefix@.service */
- if (e != p + 1) {
- r = -EINVAL;
- goto finish;
- }
-
- r = asprintf(&n, "%s%s%s", prefix, instance, e);
- if (r < 0) {
- r = -ENOMEM;
- goto finish;
- }
-
- *name = n;
- r = 0;
-finish:
- if (prefix)
- free(prefix);
-
- return r;
-}
+++ /dev/null
-/*
- * PASS
- *
- * Copyright (c) 2014 Samsung Electronics Co., Ltd.
- *
- * Licensed under the Apache License, Version 2.0 (the License);
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-
-#ifndef __PASS_SYSTEMD_H__
-#define __PASS_SYSTEMD_H__
-
-#include <dbus/dbus.h>
-#include <gio/gio.h>
-
-#define DBUS_IFACE_DBUS_PROPERTIES DBUS_SERVICE_DBUS ".Properties"
-
-#define SYSTEMD_DBUS_DEST "org.freedesktop.systemd1"
-#define SYSTEMD_DBUS_IFACE_MANAGER SYSTEMD_DBUS_DEST ".Manager"
-#define SYSTEMD_DBUS_IFACE_UNIT SYSTEMD_DBUS_DEST ".Unit"
-#define SYSTEMD_DBUS_IFACE_SERVICE SYSTEMD_DBUS_DEST ".Service"
-#define SYSTEMD_DBUS_IFACE_TARGET SYSTEMD_DBUS_DEST ".Target"
-
-#define SYSTEMD_DBUS_PATH "/org/freedesktop/systemd1"
-#define SYSTEMD_DBUS_UNIT_PATH SYSTEMD_DBUS_PATH "/unit/"
-
-int pass_systemd_start_unit(char *name);
-int pass_systemd_stop_unit(char *name);
-
-int pass_systemd_get_manager_property(const char *iface, const char *property, GVariant **variant);
-int pass_systemd_get_unit_property(const char *unit, const char *property, GVariant **variant);
-int pass_systemd_get_service_property(const char* unit, const char* property, GVariant **variant);
-
-int pass_systemd_get_manager_property_as_int32(const char *iface, const char *property, int *result);
-int pass_systemd_get_manager_property_as_uint32(const char *iface, const char *property, unsigned int *result);
-int pass_systemd_get_manager_property_as_int64(const char *iface, const char *property, long long *result);
-int pass_systemd_get_manager_property_as_uint64(const char *iface, const char *property, unsigned long long *result);
-int pass_systemd_get_manager_property_as_string(const char *iface, const char *property, char **result);
-int pass_systemd_get_unit_property_as_int32(const char *unit, const char *property, int *result);
-int pass_systemd_get_unit_property_as_uint32(const char *unit, const char *property, unsigned int *result);
-int pass_systemd_get_unit_property_as_int64(const char *unit, const char *property, long long *result);
-int pass_systemd_get_unit_property_as_uint64(const char *unit, const char *property, unsigned long long *result);
-int pass_systemd_get_unit_property_as_string(const char *unit, const char *property, char **result);
-int pass_systemd_get_service_property_as_int32(const char *unit, const char *property, int *result);
-int pass_systemd_get_service_property_as_uint32(const char *unit, const char *property, unsigned int *result);
-int pass_systemd_get_service_property_as_int64(const char *unit, const char *property, long long *result);
-int pass_systemd_get_service_property_as_uint64(const char *unit, const char *property, unsigned long long *result);
-int pass_systemd_get_service_property_as_string(const char *unit, const char *property, char **result);
-
-int pass_systemd_instance_new_from_template(const char *template, const char *instance, const char **name);
-
-#endif
+++ /dev/null
-/*
- * PASS (Power Aware System Service)
- *
- * Copyright (c) 2017 Samsung Electronics Co., Ltd. All rights reserved.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-
-#ifndef __OOM_H__
-#define __OOM_H__
-
-#define OOMADJ_SU (0)
-#define OOMADJ_INIT (100)
-#define OOMADJ_FOREGRD_LOCKED (150)
-#define OOMADJ_FOREGRD_UNLOCKED (200)
-#define OOMADJ_BACKGRD_LOCKED (250)
-#define OOMADJ_BACKGRD_UNLOCKED (300)
-#define OOMADJ_APP_LIMIT OOMADJ_INIT
-
-#endif /* __OOM_H__ */