summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJiyoung Yun <jy910.yun@samsung.com>2015-02-11 17:27:29 +0900
committerJiyoung Yun <jy910.yun@samsung.com>2015-02-12 20:03:55 -0800
commite7eb568dabd1d8d1c9ec77c774e5e43682c0b93c (patch)
tree8d3a1363b2229606f89c0e8be027df12dac4ffc8
parent578c6966ecec6a76e8d71eed5534e07b5e7ef176 (diff)
downloaddeviced-e7eb568dabd1d8d1c9ec77c774e5e43682c0b93c.tar.gz
deviced-e7eb568dabd1d8d1c9ec77c774e5e43682c0b93c.tar.bz2
deviced-e7eb568dabd1d8d1c9ec77c774e5e43682c0b93c.zip
deviced: Change the way to register edbus object and interface
Each module can register their method using the same interface. In that case, edbus will return error because object is already registered. And there are no ways to get an edbus interface using another information. So I change implementation to register by object and interface string. Edbus logic will maintain each edbus interface in edbus_object_list. Change-Id: I175973b1a7d59088cb93545ed2701b30e3d0fadc Signed-off-by: Jiyoung Yun <jy910.yun@samsung.com>
-rw-r--r--src/battery/power-supply.c8
-rw-r--r--src/core/edbus-handler.c69
-rw-r--r--src/core/edbus-handler.h10
3 files changed, 65 insertions, 22 deletions
diff --git a/src/battery/power-supply.c b/src/battery/power-supply.c
index 2a78d08e..eb459681 100644
--- a/src/battery/power-supply.c
+++ b/src/battery/power-supply.c
@@ -953,16 +953,12 @@ static const struct edbus_method edbus_methods[] = {
{ POWER_SUBSYSTEM, "sisssss", "i", dbus_battery_handler },
};
-static struct edbus_object battery_obj = {
- .path = DEVICED_PATH_BATTERY,
- .interface = DEVICED_INTERFACE_BATTERY,
-};
-
int power_supply_init(void *data)
{
int ret;
- ret = register_edbus_interface_with_method(&battery_obj,
+ ret = register_edbus_interface_and_method(DEVICED_PATH_BATTERY,
+ DEVICED_INTERFACE_BATTERY,
edbus_methods, ARRAY_SIZE(edbus_methods));
if (ret < 0)
_E("fail to init edbus interface and method(%d)", ret);
diff --git a/src/core/edbus-handler.c b/src/core/edbus-handler.c
index 572dd423..3c50ba3f 100644
--- a/src/core/edbus-handler.c
+++ b/src/core/edbus-handler.c
@@ -35,6 +35,13 @@
#define DBUS_REPLY_TIMEOUT (-1)
#define RETRY_MAX 5
+struct edbus_object {
+ const char *path;
+ const char *interface;
+ E_DBus_Object *obj;
+ E_DBus_Interface *iface;
+};
+
struct edbus_list{
char *signal_name;
E_DBus_Signal_Handler *handler;
@@ -60,6 +67,7 @@ static struct edbus_object edbus_objects[] = {
/* Add new object & interface here*/
};
+static dd_list *edbus_object_list;
static dd_list *edbus_owner_list;
static dd_list *edbus_handler_list;
static dd_list *edbus_watch_list;
@@ -475,31 +483,75 @@ static int register_method(E_DBus_Interface *iface,
return 0;
}
-int register_edbus_interface_with_method(struct edbus_object *object,
+int register_edbus_interface_and_method(const char *path,
+ const char *interface,
const struct edbus_method *edbus_methods, int size)
{
+ struct edbus_object *obj;
+ dd_list *elem;
int ret;
- if (!object || !edbus_methods || size < 1) {
+ if (!path || !interface || !edbus_methods || size < 1) {
_E("invalid parameter");
return -EINVAL;
}
- ret = register_edbus_interface(object);
- if (ret < 0) {
- _E("fail to register %s interface(%d)", object->path, ret);
- return ret;
+ /* find matched obj */
+ DD_LIST_FOREACH(edbus_object_list, elem, obj) {
+ if (strncmp(obj->path, path, strlen(obj->path)) == 0 &&
+ strncmp(obj->interface, interface, strlen(obj->interface)) == 0) {
+ _I("found matched item : obj(%p)", obj);
+ break;
+ }
}
- ret = register_method(object->iface, edbus_methods, size);
+ /* if there is no matched obj */
+ if (!obj) {
+ obj = malloc(sizeof(struct edbus_object));
+ if (!obj) {
+ _E("fail to allocate %s interface(%d)", path, ret);
+ return -ENOMEM;
+ }
+
+ obj->path = strdup(path);
+ obj->interface = strdup(interface);
+
+ ret = register_edbus_interface(obj);
+ if (ret < 0) {
+ _E("fail to register %s interface(%d)", obj->path, ret);
+ free(obj->path);
+ free(obj->interface);
+ free(obj);
+ return ret;
+ }
+
+ DD_LIST_APPEND(edbus_object_list, obj);
+ }
+
+ ret = register_method(obj->iface, edbus_methods, size);
if (ret < 0) {
- _E("fail to register %s method(%d)", object->path, ret);
+ _E("fail to register %s method(%d)", obj->path, ret);
return ret;
}
return 0;
}
+int unregister_edbus_interface_all(void)
+{
+ struct edbus_object *obj;
+ dd_list *elem, *n;
+
+ DD_LIST_FOREACH_SAFE(edbus_object_list, elem, n, obj) {
+ DD_LIST_REMOVE(edbus_object_list, obj);
+ free(obj->path);
+ free(obj->interface);
+ free(obj);
+ }
+
+ return 0;
+}
+
int register_edbus_method(const char *path, const struct edbus_method *edbus_methods, int size)
{
E_DBus_Interface *iface;
@@ -709,6 +761,7 @@ void edbus_exit(void *data)
{
unregister_edbus_signal_handle();
unregister_edbus_watch_all();
+ unregister_edbus_interface_all();
e_dbus_connection_close(edbus_conn);
e_dbus_shutdown();
}
diff --git a/src/core/edbus-handler.h b/src/core/edbus-handler.h
index fa84818e..cd2d2660 100644
--- a/src/core/edbus-handler.h
+++ b/src/core/edbus-handler.h
@@ -23,13 +23,6 @@
#include <E_DBus.h>
#include "shared/dbus.h"
-struct edbus_object {
- const char *path;
- const char *interface;
- E_DBus_Object *obj;
- E_DBus_Interface *iface;
-};
-
struct edbus_method {
const char *member;
const char *signature;
@@ -50,7 +43,8 @@ struct watch {
int (*func)(char *name, enum watch_id id);
};
-int register_edbus_interface_with_method(struct edbus_object *object,
+int register_edbus_interface_and_method(const char *path,
+ const char *interface,
const struct edbus_method *edbus_methods, int size);
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,