summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJiyoung Yun <jy910.yun@samsung.com>2015-04-03 17:46:51 +0900
committerJiyoung Yun <jy910.yun@samsung.com>2015-04-06 19:23:52 -0700
commitaac4d99eaa44340e8d283d19a2efeb1a9a4fe804 (patch)
treea742646aec3b324ba6b4d3193e5893bff7451143
parent0a409a7bce9c77cced95c8cb7e3883905b761f31 (diff)
downloaddeviced-aac4d99eaa44340e8d283d19a2efeb1a9a4fe804.tar.gz
deviced-aac4d99eaa44340e8d283d19a2efeb1a9a4fe804.tar.bz2
deviced-aac4d99eaa44340e8d283d19a2efeb1a9a4fe804.zip
udev: Change the device-change-handler to udev module
Sliding keyboard and tvout is not supported currently. These logic will add as per the common kernel interface. Change the device-change-handler to udev module. And remove the unnecessary codes and defines. Remove device-handler.h file. Change-Id: Iecb44fd52cafd7fc3708f3834eecf4f3e7b1df12 Signed-off-by: Jiyoung Yun <jy910.yun@samsung.com>
-rwxr-xr-xCMakeLists.txt2
-rw-r--r--src/battery/lowbat-handler.c1
-rw-r--r--src/battery/power-supply.c3
-rw-r--r--src/core/device-change-handler.c631
-rw-r--r--src/core/device-handler.h31
-rw-r--r--src/core/udev.c342
-rw-r--r--src/core/udev.h16
-rw-r--r--src/display/core.c1
-rw-r--r--src/display/key-filter.c1
-rw-r--r--src/display/poll.c1
-rw-r--r--src/extcon/cradle.c2
-rw-r--r--src/extcon/earjack.c2
-rw-r--r--src/mmc/mmc-handler.c1
-rw-r--r--src/power/power-handler.c1
14 files changed, 351 insertions, 684 deletions
diff --git a/CMakeLists.txt b/CMakeLists.txt
index 9d0aa631..10e7be65 100755
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -24,7 +24,6 @@ SET(SRCS
src/core/common.c
src/core/config-parser.c
src/control/control.c
- src/core/device-change-handler.c
src/core/device-notifier.c
src/core/devices.c
src/core/edbus-handler.c
@@ -33,6 +32,7 @@ SET(SRCS
src/core/log.c
src/core/main.c
src/core/sig-handler.c
+ src/core/udev.c
src/extcon/cradle.c
src/extcon/earjack.c
src/extcon/extcon.c
diff --git a/src/battery/lowbat-handler.c b/src/battery/lowbat-handler.c
index 52baa79c..ede215d9 100644
--- a/src/battery/lowbat-handler.c
+++ b/src/battery/lowbat-handler.c
@@ -28,7 +28,6 @@
#include "core/log.h"
#include "core/launch.h"
#include "core/devices.h"
-#include "core/device-handler.h"
#include "core/device-notifier.h"
#include "core/common.h"
#include "core/list.h"
diff --git a/src/battery/power-supply.c b/src/battery/power-supply.c
index f63b7da9..ea03b1b4 100644
--- a/src/battery/power-supply.c
+++ b/src/battery/power-supply.c
@@ -23,7 +23,6 @@
#include <Ecore.h>
#include <device-node.h>
#include "core/devices.h"
-#include "core/device-handler.h"
#include "core/device-notifier.h"
#include "core/udev.h"
#include "core/log.h"
@@ -85,7 +84,7 @@ static void pm_check_and_change(int bInserted)
static int old = -1;
if (old != bInserted) {
old = bInserted;
- internal_pm_change_state(LCD_NORMAL);
+ pm_change_internal(getpid(), LCD_NORMAL);
}
}
diff --git a/src/core/device-change-handler.c b/src/core/device-change-handler.c
deleted file mode 100644
index 622d4d11..00000000
--- a/src/core/device-change-handler.c
+++ /dev/null
@@ -1,631 +0,0 @@
-/*
- * deviced
- *
- * 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 <stdbool.h>
-#include <stdlib.h>
-#include <fcntl.h>
-#include <dirent.h>
-#include <errno.h>
-#include <vconf.h>
-#include <sys/types.h>
-#include <sys/stat.h>
-#include <sys/mount.h>
-#include <dirent.h>
-#include <fnmatch.h>
-#include "dd-deviced.h"
-#include "log.h"
-#include "device-notifier.h"
-#include "device-handler.h"
-#include "device-node.h"
-#include "display/poll.h"
-#include "devices.h"
-#include "udev.h"
-#include "common.h"
-#include "list.h"
-#include "proc/proc-handler.h"
-#include "edbus-handler.h"
-#include "devices.h"
-#include "display/setting.h"
-#include "display/core.h"
-#include "extcon/extcon.h"
-
-#define PREDEF_DEVICE_CHANGED "device_changed"
-#define PREDEF_POWER_CHANGED POWER_SUBSYSTEM
-#define PREDEF_UDEV_CONTROL UDEV
-
-#define TVOUT_X_BIN "/usr/bin/xberc"
-#define TVOUT_FLAG 0x00000001
-
-#define MOVINAND_MOUNT_POINT "/opt/media"
-
-#ifdef ENABLE_EDBUS_USE
-#include <E_DBus.h>
-static E_DBus_Connection *conn;
-#endif /* ENABLE_EDBUS_USE */
-
-enum snd_jack_types {
- SND_JACK_HEADPHONE = 0x0001,
- SND_JACK_MICROPHONE = 0x0002,
- SND_JACK_HEADSET = SND_JACK_HEADPHONE | SND_JACK_MICROPHONE,
- SND_JACK_LINEOUT = 0x0004,
- SND_JACK_MECHANICAL = 0x0008, /* If detected separately */
- SND_JACK_VIDEOOUT = 0x0010,
- SND_JACK_AVOUT = SND_JACK_LINEOUT | SND_JACK_VIDEOOUT,
-};
-
-#define CHANGE_ACTION "change"
-#define ENV_FILTER "CHGDET"
-
-#define TVOUT_NAME "tvout"
-#define TVOUT_NAME_LEN 5
-
-#define KEYBOARD_NAME "keyboard"
-#define KEYBOARD_NAME_LEN 8
-
-struct ticker_data {
- char *name;
- int type;
-};
-
-struct siop_data {
- int siop;
- int rear;
-};
-
-static int ss_flags = 0;
-
-/* Uevent */
-static struct udev *udev = NULL;
-/* Kernel Uevent */
-static struct udev_monitor *mon = NULL;
-static Ecore_Fd_Handler *ufdh = NULL;
-static int ufd = -1;
-
-enum udev_subsystem_type {
- UDEV_PLATFORM,
- UDEV_SWITCH,
-};
-
-static const struct udev_subsystem {
- const enum udev_subsystem_type type;
- const char *str;
- const char *devtype;
-} udev_subsystems[] = {
- { UDEV_PLATFORM, PLATFORM_SUBSYSTEM, NULL },
- { UDEV_SWITCH, SWITCH_SUBSYSTEM, NULL },
-};
-
-static dd_list *udev_event_list;
-
-static void tvout_chgdet_cb(void *data)
-{
- _I("jack - tvout changed");
- pm_change_internal(getpid(), LCD_NORMAL);
-}
-
-static void keyboard_chgdet_cb(void *data)
-{
- int val = -1;
- int ret = 0;
-
- if (data)
- val = *(int *)data;
- else {
- ret = device_get_property(DEVICE_TYPE_EXTCON, PROP_EXTCON_KEYBOARD_ONLINE, &val);
- if (ret != 0) {
- _E("failed to get status");
- vconf_set_int(VCONFKEY_SYSMAN_SLIDING_KEYBOARD, VCONFKEY_SYSMAN_SLIDING_KEYBOARD_NOT_SUPPORTED);
- return;
- }
- }
- _I("jack - keyboard changed %d", val);
- if(val != 1)
- val = 0;
- vconf_set_int(VCONFKEY_SYSMAN_SLIDING_KEYBOARD, val);
-}
-
-static void ums_unmount_cb(void *data)
-{
- umount(MOVINAND_MOUNT_POINT);
-}
-
-#ifdef ENABLE_EDBUS_USE
-static void cb_xxxxx_signaled(void *data, DBusMessage * msg)
-{
- char *args;
- DBusError err;
-
- dbus_error_init(&err);
- if (dbus_message_get_args
- (msg, &err, DBUS_TYPE_STRING, &args, DBUS_TYPE_INVALID)) {
- if (!strcmp(args, "action")) ; /* action */
- }
-
- return;
-}
-#endif /* ENABLE_EDBUS_USE */
-
-static int siop_execute(const char *siop, const char *rear)
-{
- static const struct device_ops *ops = NULL;
- struct siop_data params;
-
- FIND_DEVICE_INT(ops, PROC_OPS_NAME);
-
- if (!siop)
- params.siop = 0;
- else
- params.siop = atoi(siop);
- if (!rear)
- params.rear = 0;
- else
- params.rear = atoi(rear);
- return ops->execute((void *)&params);
-}
-
-static int changed_device(const char *name, const char *value)
-{
- int val = 0;
- int *state = NULL;
- int i;
-
- if (!name)
- goto out;
-
- if (value) {
- val = atoi(value);
- state = &val;
- }
-
- if (strncmp(name, TVOUT_NAME, TVOUT_NAME_LEN) == 0)
- tvout_chgdet_cb((void *)state);
- else if (strncmp(name, KEYBOARD_NAME, KEYBOARD_NAME_LEN) == 0)
- keyboard_chgdet_cb((void *)state);
-out:
- return 0;
-}
-
-static int booting_done(void *data)
-{
- static int done = 0;
- int ret;
- int val;
-
- if (data == NULL)
- return done;
- done = *(int*)data;
- if (done == 0)
- return done;
-
- _I("booting done");
-
- /* set initial state for devices */
- keyboard_chgdet_cb(NULL);
- return done;
-}
-
-static Eina_Bool uevent_kernel_control_cb(void *data, Ecore_Fd_Handler *fd_handler)
-{
- struct udev_device *dev = NULL;
- struct udev_list_entry *list_entry = NULL;
- struct uevent_handler *l;
- dd_list *elem;
- const char *subsystem = NULL;
- const char *env_name = NULL;
- const char *env_value = NULL;
- const char *devpath;
- const char *devnode;
- const char *action;
- int ret = -1;
- int i, len;
-
- if ((dev = udev_monitor_receive_device(mon)) == NULL)
- return EINA_TRUE;
-
- subsystem = udev_device_get_subsystem(dev);
-
- for (i = 0; i < ARRAY_SIZE(udev_subsystems); i++) {
- len = strlen(udev_subsystems[i].str);
- if (!strncmp(subsystem, udev_subsystems[i].str, len))
- break;
- }
-
- if (i >= ARRAY_SIZE(udev_subsystems))
- goto out;
-
- devpath = udev_device_get_devpath(dev);
-
- switch (udev_subsystems[i].type) {
- case UDEV_SWITCH:
- env_name = udev_device_get_property_value(dev, "SWITCH_NAME");
- env_value = udev_device_get_property_value(dev, "SWITCH_STATE");
- changed_device(env_name, env_value);
- break;
- case UDEV_PLATFORM:
- env_value = udev_device_get_property_value(dev, ENV_FILTER);
- if (!env_value)
- break;
- changed_device(env_value, NULL);
- break;
- }
-
-out:
-
- DD_LIST_FOREACH(udev_event_list, elem, l) {
- if (!strncmp(subsystem, l->subsystem, strlen(subsystem)) &&
- l->uevent_func)
- l->uevent_func(dev);
- }
-
- udev_device_unref(dev);
- return EINA_TRUE;
-}
-
-static int uevent_kernel_control_stop(void)
-{
- struct udev_device *dev = NULL;
-
- if (ufdh) {
- ecore_main_fd_handler_del(ufdh);
- ufdh = NULL;
- }
- if (ufd >= 0) {
- close(ufd);
- ufd = -1;
- }
- if (mon) {
- dev = udev_monitor_receive_device(mon);
- if (dev) {
- udev_device_unref(dev);
- dev = NULL;
- }
- udev_monitor_unref(mon);
- mon = NULL;
- }
- if (udev) {
- udev_unref(udev);
- udev = NULL;
- }
- return 0;
-}
-
-static int uevent_kernel_control_start(void)
-{
- struct uevent_handler *l;
- dd_list *elem;
- int i, ret;
-
- if (udev && mon) {
- _E("uevent control routine is alreay started");
- return -EINVAL;
- }
-
- if (!udev) {
- udev = udev_new();
- if (!udev) {
- _E("error create udev");
- return -EINVAL;
- }
- }
-
- mon = udev_monitor_new_from_netlink(udev, UDEV);
- if (mon == NULL) {
- _E("error udev_monitor create");
- goto stop;
- }
-
- if (udev_monitor_set_receive_buffer_size(mon, UDEV_MONITOR_SIZE) != 0) {
- _E("fail to set receive buffer size");
- goto stop;
- }
-
- for (i = 0; i < ARRAY_SIZE(udev_subsystems); i++) {
- ret = udev_monitor_filter_add_match_subsystem_devtype(mon,
- udev_subsystems[i].str, udev_subsystems[i].devtype);
- if (ret < 0) {
- _E("error apply subsystem filter");
- goto stop;
- }
- }
-
- DD_LIST_FOREACH(udev_event_list, elem, l) {
- ret = udev_monitor_filter_add_match_subsystem_devtype(mon,
- l->subsystem, NULL);
- if (ret < 0) {
- _E("error apply subsystem filter");
- goto stop;
- }
- }
-
- ret = udev_monitor_filter_update(mon);
- if (ret < 0)
- _E("error udev_monitor_filter_update");
-
- ufd = udev_monitor_get_fd(mon);
- if (ufd == -1) {
- _E("error udev_monitor_get_fd");
- goto stop;
- }
-
- ufdh = ecore_main_fd_handler_add(ufd, ECORE_FD_READ,
- uevent_kernel_control_cb, NULL, NULL, NULL);
- if (!ufdh) {
- _E("error ecore_main_fd_handler_add");
- goto stop;
- }
-
- if (udev_monitor_enable_receiving(mon) < 0) {
- _E("error unable to subscribe to udev events");
- goto stop;
- }
-
- return 0;
-stop:
- uevent_kernel_control_stop();
- return -EINVAL;
-
-}
-
-int register_kernel_uevent_control(const struct uevent_handler *uh)
-{
- struct uevent_handler *l;
- dd_list *elem;
- int r;
- bool matched = false;
-
- if (!uh)
- return -EINVAL;
-
- /* if udev is not initialized, it just will be added list */
- if (!udev || !mon)
- goto add_list;
-
- /* check if the same subsystem is already added */
- DD_LIST_FOREACH(udev_event_list, elem, l) {
- if (!strncmp(l->subsystem, uh->subsystem, strlen(l->subsystem))) {
- matched = true;
- break;
- }
- }
-
- /* the first request to add subsystem */
- if (!matched) {
- r = udev_monitor_filter_add_match_subsystem_devtype(mon,
- uh->subsystem, NULL);
- if (r < 0) {
- _E("fail to add %s subsystem : %d", uh->subsystem, r);
- return -EPERM;
- }
- }
-
- r = udev_monitor_filter_update(mon);
- if (r < 0)
- _E("fail to update udev monitor filter : %d", r);
-
-add_list:
- DD_LIST_APPEND(udev_event_list, uh);
- return 0;
-}
-
-int unregister_kernel_uevent_control(const struct uevent_handler *uh)
-{
- struct uevent_handler *l;
- dd_list *n, *next;
-
- DD_LIST_FOREACH_SAFE(udev_event_list, n, next, l) {
- if (!strncmp(l->subsystem, uh->subsystem, strlen(l->subsystem)) &&
- l->uevent_func == uh->uevent_func) {
- DD_LIST_REMOVE(udev_event_list, l);
- return 0;
- }
- }
-
- return -ENOENT;
-}
-
-int uevent_udev_get_path(const char *subsystem, dd_list **list)
-{
- struct udev_enumerate *enumerate = NULL;
- struct udev_list_entry *devices, *dev_list_entry;
- int ret;
-
- if (!udev) {
- udev = udev_new();
- if (!udev) {
- _E("error create udev");
- return -EIO;
- }
- }
-
- enumerate = udev_enumerate_new(udev);
- if (!enumerate)
- return -EIO;
-
- ret = udev_enumerate_add_match_subsystem(enumerate, subsystem);
- if (ret < 0)
- return -EIO;
-
- ret = udev_enumerate_scan_devices(enumerate);
- if (ret < 0)
- return -EIO;
-
- devices = udev_enumerate_get_list_entry(enumerate);
-
- udev_list_entry_foreach(dev_list_entry, devices) {
- const char *path;
- path = udev_list_entry_get_name(dev_list_entry);
- _D("subsystem : %s, path : %s", subsystem, path);
- DD_LIST_APPEND(*list, (void*)path);
- }
-
- return 0;
-}
-
-static DBusMessage *dbus_device_handler(E_DBus_Object *obj, DBusMessage *msg)
-{
- DBusError err;
- DBusMessageIter iter;
- DBusMessage *reply;
- pid_t pid;
- int ret;
- int argc;
- char *type_str;
- char *argv[2];
-
- dbus_error_init(&err);
-
- if (!dbus_message_get_args(msg, &err,
- DBUS_TYPE_STRING, &type_str,
- DBUS_TYPE_INT32, &argc,
- DBUS_TYPE_STRING, &argv[0],
- DBUS_TYPE_STRING, &argv[1], DBUS_TYPE_INVALID)) {
- _E("there is no message");
- ret = -EINVAL;
- goto out;
- }
-
- if (argc < 0) {
- _E("message is invalid!");
- ret = -EINVAL;
- goto out;
- }
-
- pid = get_edbus_sender_pid(msg);
- if (kill(pid, 0) == -1) {
- _E("%d process does not exist, dbus ignored!", pid);
- ret = -ESRCH;
- goto out;
- }
-
- changed_device(argv[0], argv[1]);
-
-out:
- reply = dbus_message_new_method_return(msg);
- dbus_message_iter_init_append(reply, &iter);
- dbus_message_iter_append_basic(&iter, DBUS_TYPE_INT32, &ret);
-
- return reply;
-}
-
-static DBusMessage *dbus_udev_handler(E_DBus_Object *obj, DBusMessage *msg)
-{
- DBusError err;
- DBusMessageIter iter;
- DBusMessage *reply;
- pid_t pid;
- int ret;
- int argc;
- char *type_str;
- char *argv;
-
- dbus_error_init(&err);
-
- if (!dbus_message_get_args(msg, &err,
- DBUS_TYPE_STRING, &type_str,
- DBUS_TYPE_INT32, &argc,
- DBUS_TYPE_STRING, &argv, DBUS_TYPE_INVALID)) {
- _E("there is no message");
- ret = -EINVAL;
- goto out;
- }
-
- if (argc < 0) {
- _E("message is invalid!");
- ret = -EINVAL;
- goto out;
- }
-
- pid = get_edbus_sender_pid(msg);
- if (kill(pid, 0) == -1) {
- _E("%d process does not exist, dbus ignored!", pid);
- ret = -ESRCH;
- goto out;
- }
-
- if (strncmp(argv, "start", strlen("start")) == 0) {
- uevent_kernel_control_start();
- } else if (strncmp(argv, "stop", strlen("stop")) == 0) {
- uevent_kernel_control_stop();
- }
-
-out:
- reply = dbus_message_new_method_return(msg);
- dbus_message_iter_init_append(reply, &iter);
- dbus_message_iter_append_basic(&iter, DBUS_TYPE_INT32, &ret);
-
- return reply;
-}
-
-void internal_pm_change_state(unsigned int s_bits)
-{
- pm_change_internal(getpid(), s_bits);
-}
-
-static const struct edbus_method edbus_methods[] = {
- { PREDEF_DEVICE_CHANGED, "siss", "i", dbus_device_handler },
- { PREDEF_UDEV_CONTROL, "sis","i", dbus_udev_handler },
-};
-
-static int device_change_poweroff(void *data)
-{
- uevent_kernel_control_stop();
- return 0;
-}
-
-static void device_change_init(void *data)
-{
- int ret;
-
- register_notifier(DEVICE_NOTIFIER_POWEROFF, device_change_poweroff);
- register_notifier(DEVICE_NOTIFIER_BOOTING_DONE, booting_done);
- ret = register_edbus_method(DEVICED_PATH_SYSNOTI, edbus_methods, ARRAY_SIZE(edbus_methods));
- if (ret < 0)
- _E("fail to init edbus method(%d)", ret);
-
- /* dbus noti change cb */
-#ifdef ENABLE_EDBUS_USE
- e_dbus_init();
- conn = e_dbus_bus_get(DBUS_BUS_SYSTEM);
- if (!conn)
- _E("check system dbus running!\n");
-
- e_dbus_signal_handler_add(conn, NULL, "/system/uevent/xxxxx",
- "system.uevent.xxxxx",
- "Change", cb_xxxxx_signaled, data);
-#endif /* ENABLE_EDBUS_USE */
- if (uevent_kernel_control_start() != 0) {
- _E("fail uevent control init");
- return;
- }
-}
-
-static void device_change_exit(void *data)
-{
- unregister_notifier(DEVICE_NOTIFIER_POWEROFF, device_change_poweroff);
- unregister_notifier(DEVICE_NOTIFIER_BOOTING_DONE, booting_done);
-}
-
-static const struct device_ops change_device_ops = {
- .priority = DEVICE_PRIORITY_NORMAL,
- .name = "device change",
- .init = device_change_init,
- .exit = device_change_exit,
-};
-
-DEVICE_OPS_REGISTER(&change_device_ops)
diff --git a/src/core/device-handler.h b/src/core/device-handler.h
deleted file mode 100644
index 64db56da..00000000
--- a/src/core/device-handler.h
+++ /dev/null
@@ -1,31 +0,0 @@
-/*
- * deviced
- *
- * 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 __DEVICE_HANDLER_H__
-#define __DEVICE_HANDLER_H__
-
-#include "common.h"
-
-enum dock_type {
- DOCK_NONE = 0,
- DOCK_SOUND = 7,
-};
-
-void internal_pm_change_state(unsigned int s_bits);
-#endif /* __DEVICE_HANDLER_H__ */
diff --git a/src/core/udev.c b/src/core/udev.c
new file mode 100644
index 00000000..2180d2b4
--- /dev/null
+++ b/src/core/udev.c
@@ -0,0 +1,342 @@
+/*
+ * deviced
+ *
+ * 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 <errno.h>
+
+#include "log.h"
+#include "device-notifier.h"
+#include "devices.h"
+#include "udev.h"
+#include "list.h"
+#include "edbus-handler.h"
+
+#define PREDEF_UDEV_CONTROL UDEV
+
+/* Uevent */
+static struct udev *udev;
+/* Kernel Uevent */
+static struct udev_monitor *mon;
+static Ecore_Fd_Handler *ufdh;
+static int ufd = -1;
+
+static dd_list *udev_event_list;
+
+static Eina_Bool uevent_kernel_control_cb(void *data, Ecore_Fd_Handler *fd_handler)
+{
+ struct udev_device *dev;
+ struct uevent_handler *l;
+ dd_list *elem;
+ const char *subsystem;
+
+ if ((dev = udev_monitor_receive_device(mon)) == NULL)
+ return EINA_TRUE;
+
+ subsystem = udev_device_get_subsystem(dev);
+
+ DD_LIST_FOREACH(udev_event_list, elem, l) {
+ if (!strncmp(subsystem, l->subsystem, strlen(subsystem)) &&
+ l->uevent_func)
+ l->uevent_func(dev);
+ }
+
+ udev_device_unref(dev);
+ return EINA_TRUE;
+}
+
+static int uevent_kernel_control_stop(void)
+{
+ struct udev_device *dev = NULL;
+
+ if (ufdh) {
+ ecore_main_fd_handler_del(ufdh);
+ ufdh = NULL;
+ }
+ if (ufd >= 0) {
+ close(ufd);
+ ufd = -1;
+ }
+ if (mon) {
+ dev = udev_monitor_receive_device(mon);
+ if (dev) {
+ udev_device_unref(dev);
+ dev = NULL;
+ }
+ udev_monitor_unref(mon);
+ mon = NULL;
+ }
+ if (udev) {
+ udev_unref(udev);
+ udev = NULL;
+ }
+ return 0;
+}
+
+static int uevent_kernel_control_start(void)
+{
+ struct uevent_handler *l;
+ dd_list *elem;
+ int i, ret;
+
+ if (udev && mon) {
+ _E("uevent control routine is alreay started");
+ return -EINVAL;
+ }
+
+ if (!udev) {
+ udev = udev_new();
+ if (!udev) {
+ _E("error create udev");
+ return -EINVAL;
+ }
+ }
+
+ mon = udev_monitor_new_from_netlink(udev, UDEV);
+ if (mon == NULL) {
+ _E("error udev_monitor create");
+ goto stop;
+ }
+
+ if (udev_monitor_set_receive_buffer_size(mon, UDEV_MONITOR_SIZE) != 0) {
+ _E("fail to set receive buffer size");
+ goto stop;
+ }
+
+ DD_LIST_FOREACH(udev_event_list, elem, l) {
+ ret = udev_monitor_filter_add_match_subsystem_devtype(mon,
+ l->subsystem, NULL);
+ if (ret < 0) {
+ _E("error apply subsystem filter");
+ goto stop;
+ }
+ }
+
+ ret = udev_monitor_filter_update(mon);
+ if (ret < 0)
+ _E("error udev_monitor_filter_update");
+
+ ufd = udev_monitor_get_fd(mon);
+ if (ufd == -1) {
+ _E("error udev_monitor_get_fd");
+ goto stop;
+ }
+
+ ufdh = ecore_main_fd_handler_add(ufd, ECORE_FD_READ,
+ uevent_kernel_control_cb, NULL, NULL, NULL);
+ if (!ufdh) {
+ _E("error ecore_main_fd_handler_add");
+ goto stop;
+ }
+
+ if (udev_monitor_enable_receiving(mon) < 0) {
+ _E("error unable to subscribe to udev events");
+ goto stop;
+ }
+
+ return 0;
+stop:
+ uevent_kernel_control_stop();
+ return -EINVAL;
+
+}
+
+int register_kernel_uevent_control(const struct uevent_handler *uh)
+{
+ struct uevent_handler *l;
+ dd_list *elem;
+ int r;
+ bool matched = false;
+
+ if (!uh)
+ return -EINVAL;
+
+ /* if udev is not initialized, it just will be added list */
+ if (!udev || !mon)
+ goto add_list;
+
+ /* check if the same subsystem is already added */
+ DD_LIST_FOREACH(udev_event_list, elem, l) {
+ if (!strncmp(l->subsystem, uh->subsystem, strlen(l->subsystem))) {
+ matched = true;
+ break;
+ }
+ }
+
+ /* the first request to add subsystem */
+ if (!matched) {
+ r = udev_monitor_filter_add_match_subsystem_devtype(mon,
+ uh->subsystem, NULL);
+ if (r < 0) {
+ _E("fail to add %s subsystem : %d", uh->subsystem, r);
+ return -EPERM;
+ }
+ }
+
+ r = udev_monitor_filter_update(mon);
+ if (r < 0)
+ _E("fail to update udev monitor filter : %d", r);
+
+add_list:
+ DD_LIST_APPEND(udev_event_list, uh);
+ return 0;
+}
+
+int unregister_kernel_uevent_control(const struct uevent_handler *uh)
+{
+ struct uevent_handler *l;
+ dd_list *n, *next;
+
+ DD_LIST_FOREACH_SAFE(udev_event_list, n, next, l) {
+ if (!strncmp(l->subsystem, uh->subsystem, strlen(l->subsystem)) &&
+ l->uevent_func == uh->uevent_func) {
+ DD_LIST_REMOVE(udev_event_list, l);
+ return 0;
+ }
+ }
+
+ return -ENOENT;
+}
+
+int uevent_udev_get_path(const char *subsystem, dd_list **list)
+{
+ struct udev_enumerate *enumerate = NULL;
+ struct udev_list_entry *devices, *dev_list_entry;
+ int ret;
+
+ if (!udev) {
+ udev = udev_new();
+ if (!udev) {
+ _E("error create udev");
+ return -EIO;
+ }
+ }
+
+ enumerate = udev_enumerate_new(udev);
+ if (!enumerate)
+ return -EIO;
+
+ ret = udev_enumerate_add_match_subsystem(enumerate, subsystem);
+ if (ret < 0)
+ return -EIO;
+
+ ret = udev_enumerate_scan_devices(enumerate);
+ if (ret < 0)
+ return -EIO;
+
+ devices = udev_enumerate_get_list_entry(enumerate);
+
+ udev_list_entry_foreach(dev_list_entry, devices) {
+ const char *path;
+ path = udev_list_entry_get_name(dev_list_entry);
+ _D("subsystem : %s, path : %s", subsystem, path);
+ DD_LIST_APPEND(*list, (void*)path);
+ }
+
+ return 0;
+}
+
+static DBusMessage *dbus_udev_handler(E_DBus_Object *obj, DBusMessage *msg)
+{
+ DBusError err;
+ DBusMessageIter iter;
+ DBusMessage *reply;
+ pid_t pid;
+ int ret;
+ int argc;
+ char *type_str;
+ char *argv;
+
+ dbus_error_init(&err);
+
+ if (!dbus_message_get_args(msg, &err,
+ DBUS_TYPE_STRING, &type_str,
+ DBUS_TYPE_INT32, &argc,
+ DBUS_TYPE_STRING, &argv, DBUS_TYPE_INVALID)) {
+ _E("there is no message");
+ ret = -EINVAL;
+ goto out;
+ }
+
+ if (argc < 0) {
+ _E("message is invalid!");
+ ret = -EINVAL;
+ goto out;
+ }
+
+ pid = get_edbus_sender_pid(msg);
+ if (kill(pid, 0) == -1) {
+ _E("%d process does not exist, dbus ignored!", pid);
+ ret = -ESRCH;
+ goto out;
+ }
+
+ if (strncmp(argv, "start", strlen("start")) == 0) {
+ ret = uevent_kernel_control_start();
+ } else if (strncmp(argv, "stop", strlen("stop")) == 0) {
+ ret = uevent_kernel_control_stop();
+ }
+
+out:
+ reply = dbus_message_new_method_return(msg);
+ dbus_message_iter_init_append(reply, &iter);
+ dbus_message_iter_append_basic(&iter, DBUS_TYPE_INT32, &ret);
+
+ return reply;
+}
+
+static const struct edbus_method edbus_methods[] = {
+ { PREDEF_UDEV_CONTROL, "sis","i", dbus_udev_handler },
+};
+
+static int device_change_poweroff(void *data)
+{
+ uevent_kernel_control_stop();
+ return 0;
+}
+
+static void udev_init(void *data)
+{
+ int ret;
+
+ register_notifier(DEVICE_NOTIFIER_POWEROFF, device_change_poweroff);
+
+ ret = register_edbus_method(DEVICED_PATH_SYSNOTI,
+ edbus_methods, ARRAY_SIZE(edbus_methods));
+ if (ret < 0)
+ _E("fail to init edbus method(%d)", ret);
+
+ if (uevent_kernel_control_start() != 0) {
+ _E("fail uevent control init");
+ return;
+ }
+}
+
+static void udev_exit(void *data)
+{
+ unregister_notifier(DEVICE_NOTIFIER_POWEROFF, device_change_poweroff);
+}
+
+static const struct device_ops udev_device_ops = {
+ .priority = DEVICE_PRIORITY_NORMAL,
+ .name = "udev",
+ .init = udev_init,
+ .exit = udev_exit,
+};
+
+DEVICE_OPS_REGISTER(&udev_device_ops)
diff --git a/src/core/udev.h b/src/core/udev.h
index 2c560331..d8d69a6d 100644
--- a/src/core/udev.h
+++ b/src/core/udev.h
@@ -23,9 +23,7 @@
#include <libudev.h>
#define UDEV "kernel"
-#define UDEV_SUBSYSTEM "SUBSYSTEM"
-#define UDEV_ACTION "ACTION"
#define UDEV_CHANGE "change"
#define UDEV_ADD "add"
#define UDEV_REMOVE "remove"
@@ -36,9 +34,6 @@
#define UDEV_MONITOR_SIZE (10*1024)
#define UDEV_MONITOR_SIZE_LARGE (128*1024*1024)
-/* platform */
-#define PLATFORM_SUBSYSTEM "platform"
-
/* battery device */
#define POWER_SUBSYSTEM "power_supply"
#define POWER_PATH "/sys/class/power_supply/battery"
@@ -52,15 +47,9 @@
#define CHARGE_STATUS "POWER_SUPPLY_STATUS"
#define CHARGE_ONLINE "POWER_SUPPLY_ONLINE"
-/* switch device */
-#define SWITCH_SUBSYSTEM "switch"
-
/* extcon */
#define EXTCON_SUBSYSTEM "extcon"
-/* host device */
-#define HOST_SUBSYSTEM "host_notify"
-
/* usb */
#define USB_SUBSYSTEM "usb"
#define USB_INTERFACE_DEVTYPE "usb_interface"
@@ -85,6 +74,11 @@ enum {
POWER_SUPPLY_TYPE_USB,
};
+enum dock_type {
+ DOCK_NONE = 0,
+ DOCK_SOUND = 7,
+};
+
struct uevent_handler {
char *subsystem;
void (*uevent_func)(struct udev_device *dev);
diff --git a/src/display/core.c b/src/display/core.c
index c4eb9881..61e9cb28 100644
--- a/src/display/core.c
+++ b/src/display/core.c
@@ -45,7 +45,6 @@
#include "display-ops.h"
#include "core/devices.h"
#include "core/device-notifier.h"
-#include "core/device-handler.h"
#include "core/udev.h"
#include "core/list.h"
#include "core/common.h"
diff --git a/src/display/key-filter.c b/src/display/key-filter.c
index fa95a5bf..c5611fa4 100644
--- a/src/display/key-filter.c
+++ b/src/display/key-filter.c
@@ -34,7 +34,6 @@
#include "core/devices.h"
#include "core/device-notifier.h"
#include "core/edbus-handler.h"
-#include "core/device-handler.h"
#include "power/power-handler.h"
#include <linux/input.h>
diff --git a/src/display/poll.c b/src/display/poll.c
index 9052d3c9..23697779 100644
--- a/src/display/poll.c
+++ b/src/display/poll.c
@@ -24,7 +24,6 @@
*/
#include <stdio.h>
-#include "core/device-handler.h"
#include "util.h"
#include "core.h"
#include "poll.h"
diff --git a/src/extcon/cradle.c b/src/extcon/cradle.c
index 6aabe5f9..70614d49 100644
--- a/src/extcon/cradle.c
+++ b/src/extcon/cradle.c
@@ -23,7 +23,7 @@
#include "core/log.h"
#include "core/device-notifier.h"
#include "core/edbus-handler.h"
-#include "core/device-handler.h"
+#include "core/udev.h"
#include "display/core.h"
#include "extcon/extcon.h"
diff --git a/src/extcon/earjack.c b/src/extcon/earjack.c
index c5deaeb5..d63c71d9 100644
--- a/src/extcon/earjack.c
+++ b/src/extcon/earjack.c
@@ -50,7 +50,7 @@ static int earjack_update(int status)
vconf_set_int(VCONFKEY_SYSMAN_EARJACK, status);
earjack_send_broadcast(status);
if (status != 0)
- internal_pm_change_state(LCD_NORMAL);
+ pm_change_internal(getpid(), LCD_NORMAL);
}
static struct extcon_ops earjack_extcon_ops = {
diff --git a/src/mmc/mmc-handler.c b/src/mmc/mmc-handler.c
index 5b2f73d9..e7ca722f 100644
--- a/src/mmc/mmc-handler.c
+++ b/src/mmc/mmc-handler.c
@@ -34,7 +34,6 @@
#include <tzplatform_config.h>
#include "core/log.h"
-#include "core/device-handler.h"
#include "core/device-notifier.h"
#include "core/common.h"
#include "core/devices.h"
diff --git a/src/power/power-handler.c b/src/power/power-handler.c
index 9ae300e1..a208851e 100644
--- a/src/power/power-handler.c
+++ b/src/power/power-handler.c
@@ -35,7 +35,6 @@
#include "dd-deviced.h"
#include "core/log.h"
#include "core/launch.h"
-#include "core/device-handler.h"
#include "core/device-notifier.h"
#include "core/common.h"
#include "core/devices.h"