summaryrefslogtreecommitdiff
path: root/src/lib/eldbus
diff options
context:
space:
mode:
authorCedric Bail <cedric@osg.samsung.com>2017-10-25 18:05:19 -0700
committerCedric BAIL <cedric@osg.samsung.com>2018-04-30 14:21:11 -0700
commitddcf8d8b9712e744cc4247eb219ad1f11d1bb455 (patch)
tree1bc20f6fed03e1aa32e2ca25d27db0ade22bb493 /src/lib/eldbus
parent7019b8857b5da8f2a30f33cf4055dc39c8bd1741 (diff)
eldbus: refactor model code.
Diffstat (limited to 'src/lib/eldbus')
-rw-r--r--src/lib/eldbus/eldbus_model.c192
-rw-r--r--src/lib/eldbus/eldbus_model.eo61
-rw-r--r--src/lib/eldbus/eldbus_model_private.h2
3 files changed, 255 insertions, 0 deletions
diff --git a/src/lib/eldbus/eldbus_model.c b/src/lib/eldbus/eldbus_model.c
new file mode 100644
index 0000000..e6d5dcc
--- /dev/null
+++ b/src/lib/eldbus/eldbus_model.c
@@ -0,0 +1,192 @@
1#ifdef HAVE_CONFIG_H
2# include <config.h>
3#endif
4
5#include "eldbus_model_private.h"
6
7#include <Ecore.h>
8#include <Eina.h>
9#include <Eldbus.h>
10
11#define MY_CLASS ELDBUS_MODEL_CLASS
12#define MY_CLASS_NAME "Eldbus_Model"
13
14static void
15eldbus_model_connect_do(Eldbus_Model_Data *pd)
16{
17 if (pd->type == ELDBUS_CONNECTION_TYPE_ADDRESS)
18 {
19 if (pd->private)
20 pd->connection = eldbus_address_connection_get(pd->address);
21 else
22 pd->connection = eldbus_private_address_connection_get(pd->address);
23 }
24 else
25 {
26 if (pd->private)
27 pd->connection = eldbus_private_connection_get(pd->type);
28 else
29 pd->connection = eldbus_connection_get(pd->type);
30 }
31
32 // TODO: Register for disconnection event
33 if (!pd->connection)
34 {
35 DBG("Unable to setup a connection [%i - %s] %i",
36 pd->type, pd->address, pd->private);
37 }
38}
39
40static void
41_eldbus_model_connect(Eo *obj EINA_UNUSED,
42 Eldbus_Model_Data *pd,
43 Eldbus_Connection_Type type,
44 const char *address,
45 Eina_Bool priv)
46{
47 pd->type = type;
48 pd->address = eina_stringshare_add(address);
49 pd->private = priv;
50}
51
52static void
53_eldbus_model_connection_set(Eo *obj EINA_UNUSED,
54 Eldbus_Model_Data *pd,
55 Eldbus_Connection *dbus)
56{
57 eldbus_connection_ref(dbus);
58 if (pd->connection) eldbus_connection_unref(pd->connection);
59 pd->connection = dbus;
60}
61
62static Eldbus_Connection *
63_eldbus_model_connection_get(const Eo *obj EINA_UNUSED, Eldbus_Model_Data *pd)
64{
65 return pd->connection;
66}
67
68static Efl_Object *
69_eldbus_model_efl_object_finalize(Eo *obj, Eldbus_Model_Data *pd)
70{
71 if (!pd->connection) eldbus_model_connect_do(pd);
72 if (!pd->connection) return NULL;
73
74 return efl_finalize(efl_super(obj, ELDBUS_MODEL_CLASS));
75}
76
77static void
78_eldbus_model_efl_object_destructor(Eo *obj, Eldbus_Model_Data *pd)
79{
80 eina_stringshare_del(pd->unique_name);
81 pd->unique_name = NULL;
82
83 eina_stringshare_del(pd->address);
84 pd->address = NULL;
85
86 eldbus_connection_unref(pd->connection);
87 pd->connection = NULL;
88
89 efl_destructor(efl_super(obj, MY_CLASS));
90}
91
92static const char *
93_eldbus_model_address_get(const Eo *obj EINA_UNUSED, Eldbus_Model_Data *pd)
94{
95 return pd->address;
96}
97
98static Eina_Bool
99_eldbus_model_private_get(const Eo *obj EINA_UNUSED, Eldbus_Model_Data *pd)
100{
101 return pd->private;
102}
103
104static Eldbus_Connection_Type
105_eldbus_model_type_get(const Eo *obj EINA_UNUSED, Eldbus_Model_Data *pd)
106{
107 return pd->type;
108}
109
110static Eina_Future *
111_eldbus_model_efl_model_property_set(Eo *obj,
112 Eldbus_Model_Data *pd EINA_UNUSED,
113 const char *property,
114 Eina_Value *value EINA_UNUSED)
115{
116 Eina_Error err = EFL_MODEL_ERROR_READ_ONLY;
117
118 if (!strcmp(property, UNIQUE_NAME_PROPERTY))
119 err = EFL_MODEL_ERROR_NOT_FOUND;
120 return eina_future_rejected(efl_loop_future_scheduler_get(obj), err);
121}
122
123static Eina_Value *
124_eldbus_model_efl_model_property_get(const Eo *obj,
125 Eldbus_Model_Data *pd,
126 const char *property)
127{
128 DBG("(%p): property=%s", obj, property);
129
130 if (strcmp(property, UNIQUE_NAME_PROPERTY) != 0) goto on_error;
131
132 if (!pd->connection) eldbus_model_connect_do(pd);
133
134 if (pd->unique_name == NULL)
135 {
136 const char *unique_name;
137
138 unique_name = eldbus_connection_unique_name_get(pd->connection);
139 if (!unique_name) goto on_error;
140 pd->unique_name = eina_stringshare_add(unique_name);
141 }
142
143 return eina_value_string_new(pd->unique_name);
144
145 on_error:
146 return eina_value_error_new(EFL_MODEL_ERROR_NOT_FOUND);
147}
148
149static Eina_Array *
150_eldbus_model_efl_model_properties_get(const Eo *obj EINA_UNUSED,
151 Eldbus_Model_Data *pd EINA_UNUSED)
152{
153 Eina_Array *r;
154
155 r = eina_array_new(1);
156 eina_array_push(r, UNIQUE_NAME_PROPERTY);
157
158 return r;
159}
160
161static Efl_Object *
162_eldbus_model_efl_model_child_add(Eo *obj EINA_UNUSED,
163 Eldbus_Model_Data *pd EINA_UNUSED)
164{
165 return NULL;
166}
167
168static void
169_eldbus_model_efl_model_child_del(Eo *obj EINA_UNUSED,
170 Eldbus_Model_Data *pd EINA_UNUSED,
171 Efl_Object *child EINA_UNUSED)
172{
173}
174
175static Eina_Future *
176_eldbus_model_efl_model_children_slice_get(Eo *obj EINA_UNUSED,
177 Eldbus_Model_Data *pd EINA_UNUSED,
178 unsigned int start EINA_UNUSED,
179 unsigned int count EINA_UNUSED)
180{
181 return eina_future_rejected(efl_loop_future_scheduler_get(obj),
182 EFL_MODEL_ERROR_NOT_SUPPORTED);
183}
184
185static unsigned int
186_eldbus_model_efl_model_children_count_get(const Eo *obj EINA_UNUSED,
187 Eldbus_Model_Data *pd EINA_UNUSED)
188{
189 return 0;
190}
191
192#include "eldbus_model.eo.c"
diff --git a/src/lib/eldbus/eldbus_model.eo b/src/lib/eldbus/eldbus_model.eo
new file mode 100644
index 0000000..81b0ffe
--- /dev/null
+++ b/src/lib/eldbus/eldbus_model.eo
@@ -0,0 +1,61 @@
1import eldbus_types;
2
3class Eldbus.Model (Efl.Object, Efl.Model) {
4 methods {
5 connect {
6 [[Define connection parameters.
7
8 @since 1.21]]
9 params {
10 @in type: Eldbus.Connection.Type; [[The connection type]]
11 @in address: string; [[Remote address of DBus]]
12 @in priv: bool; [[Non shared dbus connection]]
13 }
14 }
15 @property connection {
16 [[Define the connection.
17
18 @since 1.21]]
19 get { }
20 set { }
21 values {
22 dbus: ptr(Eldbus.Connection); [[The connection]]
23 }
24 }
25 @property type {
26 [[Connection type]]
27 get { }
28 values {
29 type: Eldbus.Connection.Type; [[Connection type]]
30 }
31 }
32 @property address {
33 [[Remote DBus address]]
34 get { }
35 values {
36 address: string; [[Address]]
37 }
38 }
39 @property private {
40 [[Indicate if the DBus connection is shared or private]]
41 get { }
42 values {
43 private_: bool; [[Private DBus connection]]
44 }
45 }
46 }
47 implements {
48 Efl.Object.finalize;
49 Efl.Object.destructor;
50 Efl.Model.property { get; set; }
51 Efl.Model.properties { get; }
52 Efl.Model.child_add;
53 Efl.Model.child_del;
54 Efl.Model.children_slice_get;
55 Efl.Model.children_count { get; }
56 }
57 constructors {
58 .connect;
59 .connection;
60 }
61} \ No newline at end of file
diff --git a/src/lib/eldbus/eldbus_model_private.h b/src/lib/eldbus/eldbus_model_private.h
index 0487b3e..b5f3610 100644
--- a/src/lib/eldbus/eldbus_model_private.h
+++ b/src/lib/eldbus/eldbus_model_private.h
@@ -23,6 +23,8 @@ struct _Eldbus_Property_Promise
23 Efl_Promise* promise; 23 Efl_Promise* promise;
24}; 24};
25 25
26#define UNIQUE_NAME_PROPERTY "unique_name"
27
26/* logging support */ 28/* logging support */
27extern int eldbus_model_log_dom; 29extern int eldbus_model_log_dom;
28 30