Status: | Merged |
---|---|
Approved by: | guoyalong |
Approved revision: | 11 |
Merge reported by: | guoyalong |
Merged at revision: | not available |
Proposed branch: | lp:~mimose/kydevmonit/test |
Merge into: | lp:kydevmonit |
Diff against target: |
2014 lines (+1239/-548) 21 files modified
.bzrignore (+10/-0) Makefile (+18/-12) com.jd.test.xml (+0/-15) debian/changelog (+5/-0) debian/compat (+1/-0) debian/control (+15/-0) debian/copyright (+1/-0) debian/rules (+8/-0) debian/source/format (+1/-0) src/dbuslayer/com.jd.test.xml (+29/-0) src/dbuslayer/monitor_dbus.c (+179/-84) src/dbuslayer/monitor_dbus.h (+6/-3) src/dbuslayer/monitor_dbus.h.backup (+84/-0) src/dbuslayer/monitor_dbus_glue.h (+51/-44) src/interlayer/interlayer.c (+0/-351) src/interlayer/interlayer.h (+0/-34) src/main.c (+14/-5) src/managerlayer/_configure.c (+440/-0) src/managerlayer/_configure.h (+51/-0) src/managerlayer/manager.c (+235/-0) src/managerlayer/manager.h (+91/-0) |
To merge this branch: | bzr merge lp:~mimose/kydevmonit/test |
Related bugs: |
Reviewer | Review Type | Date Requested | Status |
---|---|---|---|
guoyalong | Approve | ||
Review via email:
|
Commit message
Description of the change
To post a comment you must log in.
Revision history for this message
![](/+icing/build/overlay/assets/skins/sam/images/close.gif)
guoyalong (mimose) : | # |
review:
Approve
Preview Diff
[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1 | === added file '.bzrignore' | |||
2 | --- .bzrignore 1970-01-01 00:00:00 +0000 | |||
3 | +++ .bzrignore 2017-10-10 00:58:46 +0000 | |||
4 | @@ -0,0 +1,10 @@ | |||
5 | 1 | kydevmonit | ||
6 | 2 | debian/debhelper-build-stamp | ||
7 | 3 | debian/files | ||
8 | 4 | debian/kydevmonit | ||
9 | 5 | debian/kydevmonit.debhelper.log | ||
10 | 6 | debian/kydevmonit.substvars | ||
11 | 7 | debian/kydevmonit/DEBIAN | ||
12 | 8 | debian/kydevmonit/etc | ||
13 | 9 | debian/kydevmonit/lib | ||
14 | 10 | debian/kydevmonit/usr | ||
15 | 0 | 11 | ||
16 | === modified file 'Makefile' | |||
17 | --- Makefile 2017-09-05 05:53:02 +0000 | |||
18 | +++ Makefile 2017-10-10 00:58:46 +0000 | |||
19 | @@ -1,24 +1,30 @@ | |||
20 | 1 | all=kydevmonit | 1 | all=kydevmonit |
21 | 2 | CC=gcc | 2 | CC=gcc |
22 | 3 | 3 | ||
24 | 4 | INTERLAYER_DIR=./src/interlayer/ | 4 | MANAGER_LAYER_DIR=./src/managerlayer/ |
25 | 5 | DBUSLAYER_DIR=./src/dbuslayer/ | 5 | DBUSLAYER_DIR=./src/dbuslayer/ |
26 | 6 | 6 | ||
31 | 7 | INCLUDE=-I$(INTERLAYER_DIR) -I$(DBUSLAYER_DIR) -I/usr/include/libxml2/ `pkg-config --cflags glib-2.0 gobject-2.0 dbus-glib-1 dbus-1` | 7 | MY_CFLAGS= $(CFLAGS) -I$(MANAGER_LAYER_DIR) -I$(DBUSLAYER_DIR) -I/usr/include/libxml2/ `pkg-config --cflags glib-2.0 gobject-2.0 dbus-glib-1 dbus-1` |
32 | 8 | LIBS=`pkg-config --libs glib-2.0 gobject-2.0 dbus-glib-1 dbus-1` -lxml2 -ldl | 8 | MY_LDFLAGS=$(LDFLAGS) `pkg-config --libs glib-2.0 gobject-2.0 dbus-glib-1 dbus-1` -lxml2 -ldl |
33 | 9 | 9 | ||
34 | 10 | SRCS=./src/main.c $(DBUSLAYER_DIR)monitor_dbus.c $(DBUSLAYER_DIR)marshal.c $(INTERLAYER_DIR)interlayer.c | 10 | SRCS=./src/main.c $(DBUSLAYER_DIR)monitor_dbus.c $(DBUSLAYER_DIR)marshal.c $(MANAGER_LAYER_DIR)manager.c $(MANAGER_LAYER_DIR)_configure.c |
35 | 11 | |||
36 | 11 | OBJS=$(SRCS:.c=.o) | 12 | OBJS=$(SRCS:.c=.o) |
37 | 12 | |||
38 | 13 | kydevmonit:$(OBJS) | 13 | kydevmonit:$(OBJS) |
40 | 14 | $(CC) -g -O0 -o $@ $^ $(INCLUDE) $(LIBS) | 14 | $(CC) -g -O0 -o $@ $^ $(MY_CFLAGS) $(MY_LDFLAGS) |
41 | 15 | |||
42 | 16 | monitor_dbus_glue.h:$(DBUSLAYER_DIR)com.jd.test.xml | ||
43 | 17 | dbus-binding-tool --prefix=monitor --mode=glib-server --output=$(DBUSLAYER_DIR)monitor_dbus_glue.h $^ | ||
44 | 18 | |||
45 | 15 | install: | 19 | install: |
50 | 16 | install kydevmonit /usr/bin/ | 20 | install -d -m755 $(DESTDIR)/usr/bin/ |
51 | 17 | cp kydevmonit.service /lib/systemd/system/ | 21 | install -m755 ./kydevmonit $(DESTDIR)/usr/bin/ |
52 | 18 | cp com.jd.test.conf /etc/dbus-1/system.d/ | 22 | install -d -m755 $(DESTDIR)/lib/systemd/system/ |
53 | 19 | systemctl daemon-reload | 23 | install -m644 ./kydevmonit.service $(DESTDIR)/lib/systemd/system/ |
54 | 24 | install -d -m755 $(DESTDIR)/etc/dbus-1/system.d/ | ||
55 | 25 | install -m644 ./com.jd.test.conf $(DESTDIR)/etc/dbus-1/system.d/ | ||
56 | 20 | clean: | 26 | clean: |
57 | 21 | rm -rf $(OBJS) kydevmonit | 27 | rm -rf $(OBJS) kydevmonit |
58 | 22 | 28 | ||
59 | 23 | %.o:%.c | 29 | %.o:%.c |
61 | 24 | $(CC) $(INCLUDE) -o $@ -c $< | 30 | $(CC) $(MY_CFLAGS) -o $@ -c $< |
62 | 25 | 31 | ||
63 | === removed file 'com.jd.test.xml' | |||
64 | --- com.jd.test.xml 2017-09-05 05:53:02 +0000 | |||
65 | +++ com.jd.test.xml 1970-01-01 00:00:00 +0000 | |||
66 | @@ -1,15 +0,0 @@ | |||
67 | 1 | <?xml version="1.0" encoding="UTF-8" ?> | ||
68 | 2 | <node name="/com/jd/test"> | ||
69 | 3 | <interface name="com.jd.test.interface"> | ||
70 | 4 | <method name="call_monitor_method"> | ||
71 | 5 | <annotation name="org.freedesktop.DBus.GLib.Async" value="" /> | ||
72 | 6 | <arg type="(iiiis)" name="hw_method_t" direction="in" /> | ||
73 | 7 | <arg type="(iis)" name="hw_return_t" direction="out" /> | ||
74 | 8 | </method> | ||
75 | 9 | <method name="intropect"> | ||
76 | 10 | <annotation name="org.freedesktop.DBus.GLib.Async" value="" /> | ||
77 | 11 | <arg type="s" name="name" direction="in"/> | ||
78 | 12 | <arg type="s" name="data" direction="out"/> | ||
79 | 13 | </method> | ||
80 | 14 | </interface> | ||
81 | 15 | </node> | ||
82 | 16 | 0 | ||
83 | === added directory 'debian' | |||
84 | === added file 'debian/changelog' | |||
85 | --- debian/changelog 1970-01-01 00:00:00 +0000 | |||
86 | +++ debian/changelog 2017-10-10 00:58:46 +0000 | |||
87 | @@ -0,0 +1,5 @@ | |||
88 | 1 | kydevmonit (1.0.0kord1) juniper; urgency=medium | ||
89 | 2 | |||
90 | 3 | * Initial release. | ||
91 | 4 | |||
92 | 5 | -- guoyalong <guoyalong@kylinos.cn> Mon, 25 Sep 2017 11:30:12 +0800 | ||
93 | 0 | 6 | ||
94 | === added file 'debian/compat' | |||
95 | --- debian/compat 1970-01-01 00:00:00 +0000 | |||
96 | +++ debian/compat 2017-10-10 00:58:46 +0000 | |||
97 | @@ -0,0 +1,1 @@ | |||
98 | 1 | 9 | ||
99 | 0 | 2 | ||
100 | === added file 'debian/control' | |||
101 | --- debian/control 1970-01-01 00:00:00 +0000 | |||
102 | +++ debian/control 2017-10-10 00:58:46 +0000 | |||
103 | @@ -0,0 +1,15 @@ | |||
104 | 1 | Source: kydevmonit | ||
105 | 2 | Section: x11 | ||
106 | 3 | Priority: optional | ||
107 | 4 | Maintainer: Ubuntu Kylin Team <ubuntukylin-members@list.launchpad.net> | ||
108 | 5 | Build-Depends: debhelper(>= 9), | ||
109 | 6 | libxml2-dev, | ||
110 | 7 | libdbus-glib-1-dev, | ||
111 | 8 | libglib2.0-dev | ||
112 | 9 | Standards-Version: 3.9.8 | ||
113 | 10 | Homepage: https://launchpad.net/kydevmonit | ||
114 | 11 | |||
115 | 12 | Package: kydevmonit | ||
116 | 13 | Architecture: any | ||
117 | 14 | Depends: ${shlibs:Depends}, ${misc:Depends} | ||
118 | 15 | Description: This is a devices manager based on dbus. | ||
119 | 0 | 16 | ||
120 | === added file 'debian/copyright' | |||
121 | --- debian/copyright 1970-01-01 00:00:00 +0000 | |||
122 | +++ debian/copyright 2017-10-10 00:58:46 +0000 | |||
123 | @@ -0,0 +1,1 @@ | |||
124 | 1 | |||
125 | 0 | 2 | ||
126 | === added file 'debian/rules' | |||
127 | --- debian/rules 1970-01-01 00:00:00 +0000 | |||
128 | +++ debian/rules 2017-10-10 00:58:46 +0000 | |||
129 | @@ -0,0 +1,8 @@ | |||
130 | 1 | #!/usr/bin/make -f | ||
131 | 2 | # debian/rules for kydevmonit | ||
132 | 3 | ## | ||
133 | 4 | ## Build-tree preparation | ||
134 | 5 | ## | ||
135 | 6 | %: | ||
136 | 7 | dh $@ | ||
137 | 8 | |||
138 | 0 | 9 | ||
139 | === added directory 'debian/source' | |||
140 | === added file 'debian/source/format' | |||
141 | --- debian/source/format 1970-01-01 00:00:00 +0000 | |||
142 | +++ debian/source/format 2017-10-10 00:58:46 +0000 | |||
143 | @@ -0,0 +1,1 @@ | |||
144 | 1 | 3.0 (native) | ||
145 | 0 | 2 | ||
146 | === added file 'src/dbuslayer/com.jd.test.xml' | |||
147 | --- src/dbuslayer/com.jd.test.xml 1970-01-01 00:00:00 +0000 | |||
148 | +++ src/dbuslayer/com.jd.test.xml 2017-10-10 00:58:46 +0000 | |||
149 | @@ -0,0 +1,29 @@ | |||
150 | 1 | <?xml version="1.0" encoding="UTF-8" ?> | ||
151 | 2 | <node name="/com/jd/test"> | ||
152 | 3 | <interface name="com.jd.test.interface"> | ||
153 | 4 | <method name="dbus_get_all_device_static_info"> | ||
154 | 5 | <annotation name="org.freedesktop.DBus.GLib.Async" value="" /> | ||
155 | 6 | <arg type="a(isi)" name="devices_static_return_t" direction="out"/> | ||
156 | 7 | </method> | ||
157 | 8 | <method name="dbus_get_device_interfaces_info"> | ||
158 | 9 | <annotation name="org.freedesktop.DBus.GLib.Async" value="" /> | ||
159 | 10 | <arg type="i" name="device_code" direction="in"/> | ||
160 | 11 | <arg type="isaav" name="device_interfaces_return_t" direction="out"/> | ||
161 | 12 | </method> | ||
162 | 13 | <method name="dbus_call_device_method"> | ||
163 | 14 | <annotation name="org.freedesktop.DBus.GLib.Async" value="" /> | ||
164 | 15 | <arg type="(iiiis)" name="device_method_input_t" direction="in" /> | ||
165 | 16 | <arg type="(iis)" name="dbus_return_t" direction="out" /> | ||
166 | 17 | </method> | ||
167 | 18 | <method name="dbus_regist_new_device"> | ||
168 | 19 | <annotation name="org.freedesktop.DBus.GLib.Async" value="" /> | ||
169 | 20 | <arg type="i" name="device_code" direction="in"/> | ||
170 | 21 | <arg type="(iis)" name="dbus_return_t" direction="out"/> | ||
171 | 22 | </method> | ||
172 | 23 | <method name="dbus_logout_device"> | ||
173 | 24 | <annotation name="org.freedesktop.DBus.GLib.Async" value="" /> | ||
174 | 25 | <arg type="i" name="device_code" direction="in"/> | ||
175 | 26 | <arg type="(iis)" name="dbus_return_t" direction="out"/> | ||
176 | 27 | </method> | ||
177 | 28 | </interface> | ||
178 | 29 | </node> | ||
179 | 0 | 30 | ||
180 | === modified file 'src/dbuslayer/monitor_dbus.c' | |||
181 | --- src/dbuslayer/monitor_dbus.c 2017-09-05 05:53:02 +0000 | |||
182 | +++ src/dbuslayer/monitor_dbus.c 2017-10-10 00:58:46 +0000 | |||
183 | @@ -32,7 +32,7 @@ | |||
184 | 32 | #include <malloc.h> | 32 | #include <malloc.h> |
185 | 33 | #include <unistd.h> | 33 | #include <unistd.h> |
186 | 34 | 34 | ||
188 | 35 | #include "../interlayer/interlayer.h" | 35 | #include "../managerlayer/manager.h" |
189 | 36 | 36 | ||
190 | 37 | static GMainLoop *loop = NULL; | 37 | static GMainLoop *loop = NULL; |
191 | 38 | MonitorDbus * dbus; | 38 | MonitorDbus * dbus; |
192 | @@ -63,75 +63,167 @@ | |||
193 | 63 | void monitor_dbus_class_init(MonitorDbusClass * kclass) | 63 | void monitor_dbus_class_init(MonitorDbusClass * kclass) |
194 | 64 | { | 64 | { |
195 | 65 | mnsignals[SIG_DATA_ALERT] = g_signal_new("monitor_alert", | 65 | mnsignals[SIG_DATA_ALERT] = g_signal_new("monitor_alert", |
210 | 66 | G_TYPE_FROM_CLASS(kclass), | 66 | G_TYPE_FROM_CLASS(kclass), |
211 | 67 | G_SIGNAL_RUN_FIRST, | 67 | G_SIGNAL_RUN_FIRST, |
212 | 68 | G_STRUCT_OFFSET(MonitorWarnDbusClass, event), | 68 | G_STRUCT_OFFSET(MonitorWarnDbusClass, event), |
213 | 69 | NULL, | 69 | NULL, |
214 | 70 | NULL, | 70 | NULL, |
215 | 71 | monitor_marshal_VOID__UINT_BOXED, | 71 | monitor_marshal_VOID__UINT_BOXED, |
216 | 72 | G_TYPE_NONE, | 72 | G_TYPE_NONE, |
217 | 73 | 3, | 73 | 3, |
218 | 74 | G_TYPE_UINT, | 74 | G_TYPE_UINT, |
219 | 75 | G_TYPE_UINT, | 75 | G_TYPE_UINT, |
220 | 76 | G_TYPE_UINT); | 76 | G_TYPE_UINT); |
221 | 77 | } | 77 | } |
222 | 78 | 78 | ||
223 | 79 | 79 | gint monitor_dbus_get_all_device_static_info(MonitorDbus * dbus, DBusGMethodInvocation * ret_value){ | |
224 | 80 | GList* value_list_ptr = manager_get_all_device_static_t(); | ||
225 | 81 | guint len = g_list_length(value_list_ptr); | ||
226 | 82 | GArray * array_return = g_array_new(FALSE,TRUE,sizeof(GValueArray)); | ||
227 | 83 | printf("len=%u\n",len); | ||
228 | 84 | int i; | ||
229 | 85 | for(i=0; i<len;i++){ | ||
230 | 86 | manager_device_static_t* ds = (manager_device_static_t*)g_list_nth_data(value_list_ptr,i); | ||
231 | 87 | GValueArray* static_struct = g_value_array_new(0); | ||
232 | 88 | GValue device_code={0}; | ||
233 | 89 | GValue device_name={0}; | ||
234 | 90 | GValue is_registed={0}; | ||
235 | 91 | g_value_init (&device_code, G_TYPE_INT); | ||
236 | 92 | g_value_init (&device_name, G_TYPE_STRING); | ||
237 | 93 | g_value_init (&is_registed, G_TYPE_INT); | ||
238 | 94 | g_value_set_int(&device_code, ds->device_code); | ||
239 | 95 | g_value_set_string(&device_name, ds->device_name); | ||
240 | 96 | g_value_set_int(&is_registed, ds->is_registed); | ||
241 | 97 | static_struct = g_value_array_append(static_struct,&device_code); | ||
242 | 98 | static_struct = g_value_array_append(static_struct,&device_name); | ||
243 | 99 | static_struct = g_value_array_append(static_struct,&is_registed); | ||
244 | 100 | array_return = g_array_append_val(array_return,static_struct); | ||
245 | 101 | printf("0x%.2x %s %d successfully\n",ds->device_code,ds->device_name,ds->is_registed); | ||
246 | 102 | } | ||
247 | 103 | dbus_g_method_return(ret_value,array_return); | ||
248 | 104 | return 1; | ||
249 | 105 | } | ||
250 | 106 | gint monitor_dbus_get_device_interfaces_info(MonitorDbus * dbus, int device_code, DBusGMethodInvocation * ret_value){ | ||
251 | 107 | |||
252 | 108 | } | ||
253 | 80 | 109 | ||
254 | 81 | //客户端-监控统一入口 | 110 | //客户端-监控统一入口 |
256 | 82 | gint monitor_dbus_call_monitor_method(MonitorDbus * dbus,GValueArray * method_value ,DBusGMethodInvocation * ret_value) | 111 | gint monitor_dbus_call_device_method(MonitorDbus * dbus,GValueArray * method_value ,DBusGMethodInvocation * ret_value) |
257 | 83 | { | 112 | { |
258 | 84 | GValue * input[5] = {{0}}; | 113 | GValue * input[5] = {{0}}; |
309 | 85 | for(int i =0; i < 5;i++){ | 114 | dbus_return_t rt={0,0,{0}};// state_code ; exception_code; exception_desc; |
310 | 86 | input[i] = g_value_array_get_nth(method_value, i); | 115 | |
311 | 87 | } | 116 | guint size = 5;//g_array_get_element_size(method_value); |
312 | 88 | gint value1 = g_value_get_int(input[0]); | 117 | if(size < 5){ |
313 | 89 | gint value2 = g_value_get_int(input[1]); | 118 | rt.state_code = WORK_STATE_UNKNOW; |
314 | 90 | gint value3 = g_value_get_int(input[2]); | 119 | rt.exception_code = 0x30000; |
315 | 91 | gint value4 = g_value_get_int(input[3]); | 120 | snprintf(rt.desc,DESC_BUF_LEN,"The method_value at least 5 elements!\n"); |
316 | 92 | gchar * value5 = g_value_dup_string(input[4]); | 121 | }else{ |
317 | 93 | printf("input value1: %d\n", value1); | 122 | if(method_value == NULL){ |
318 | 94 | printf("input value2: %d\n", value2); | 123 | printf("method_value is null\n"); |
319 | 95 | printf("input value3: %d\n", value3); | 124 | } |
320 | 96 | printf("input value4: %d\n", value4); | 125 | /* |
321 | 97 | printf("input value5: %s\n", value5); | 126 | gint device_code = g_array_index(method_value,int,0); |
322 | 98 | 127 | gint method_code = g_array_index(method_value, int,1); | |
323 | 99 | 128 | gint value3 = g_array_index(method_value, int,2); | |
324 | 100 | gint statuscode = -1; | 129 | gint value4 = g_array_index(method_value, int,3); |
325 | 101 | gint count = -1; | 130 | gchar* method_param = g_array_index(method_value,char*,4); |
326 | 102 | gchar statusdesc[1024] = {0}; | 131 | */ |
327 | 103 | 132 | int i; | |
328 | 104 | interlayer_call_device_method(value1, value2,value5, &statuscode,&count,statusdesc); | 133 | for(i =0; i < size;i++){ |
329 | 105 | 134 | input[i] = g_value_array_get_nth(method_value, i); | |
330 | 106 | GValueArray *struct_return; | 135 | } |
331 | 107 | GValue struct_container[3] = {{0}}; | 136 | gint device_code = g_value_get_int(input[0]); |
332 | 108 | 137 | gint method_code = g_value_get_int(input[1]); | |
333 | 109 | g_value_init (&struct_container[0], G_TYPE_INT); | 138 | gint value3 = g_value_get_int(input[2]); |
334 | 110 | g_value_set_int (&struct_container[0], statuscode); | 139 | gint value4 = g_value_get_int(input[3]); |
335 | 111 | g_value_init (&struct_container[1], G_TYPE_INT); | 140 | gchar * method_param = g_value_dup_string(input[4]); |
336 | 112 | g_value_set_int (&struct_container[1], count); | 141 | |
337 | 113 | g_value_init (&struct_container[2], G_TYPE_STRING); | 142 | printf("input value1: 0x%.2x\n", device_code); |
338 | 114 | g_value_set_string (&struct_container[2], statusdesc); | 143 | printf("input value2: 0x%.3x\n", method_code); |
339 | 115 | 144 | printf("input value3: %d\n", value3); | |
340 | 116 | struct_return = g_value_array_new(0); | 145 | printf("input value4: %d\n", value4); |
341 | 117 | for(int j =0; j <3; j++){ | 146 | printf("input value5: %s\n", method_param); |
342 | 118 | struct_return = g_value_array_append(struct_return, &struct_container[j]); | 147 | |
343 | 119 | } | 148 | manager_call_device_method(device_code, method_code,(const char*)method_param,&rt); |
344 | 120 | 149 | //interlayer_call_device_method(value1, value2,value5, &statuscode,&count,statusdesc); | |
345 | 121 | dbus_g_method_return(ret_value,struct_return); | 150 | } |
346 | 122 | return 1; | 151 | GValueArray* struct_return;// = g_array_new(TRUE,TRUE,sizeof(GValue)); |
347 | 123 | } | 152 | GValue struct_container[3] = {{0}}; |
348 | 124 | gint monitor_dbus_intropect(MonitorDbus* dbus, const char* devicename,DBusGMethodInvocation * ret_value){ | 153 | |
349 | 125 | //char* message = "hello"; | 154 | g_value_init (&struct_container[0], G_TYPE_INT); |
350 | 126 | //GValue data = g_value_set_string("hello"); | 155 | g_value_set_int (&struct_container[0], rt.state_code); |
351 | 127 | //printf("devicename= %s\n", devicename); | 156 | g_value_init (&struct_container[1], G_TYPE_INT); |
352 | 128 | char desc[1024]; | 157 | g_value_set_int (&struct_container[1], rt.exception_code); |
353 | 129 | memset(desc, 0, 1024); | 158 | g_value_init (&struct_container[2], G_TYPE_STRING); |
354 | 130 | interlayer_get_devices_intropect(LISTEN_DBUS_NAME, LISTEN_DBUS_PATH, devicename,desc); | 159 | g_value_set_string (&struct_container[2], rt.desc); |
355 | 131 | printf("Desc: %s\n", desc); | 160 | |
356 | 132 | dbus_g_method_return(ret_value, desc); | 161 | struct_return = g_value_array_new(0); |
357 | 133 | return 0; | 162 | int j; |
358 | 134 | } | 163 | for(j =0; j <3; j++){ |
359 | 164 | struct_return = g_value_array_append(struct_return, &struct_container[j]); | ||
360 | 165 | } | ||
361 | 166 | |||
362 | 167 | dbus_g_method_return(ret_value,struct_return); | ||
363 | 168 | return 1; | ||
364 | 169 | } | ||
365 | 170 | gint monitor_dbus_regist_new_device(MonitorDbus * dbus, int device_code, DBusGMethodInvocation * ret_value){ | ||
366 | 171 | |||
367 | 172 | //printf("Hello,here, 0x%.2x\n",device_code); | ||
368 | 173 | //printf("Hello,here\n"); | ||
369 | 174 | dbus_return_t rt={0,0,{0}};// state_code ; exception_code; exception_desc; | ||
370 | 175 | manager_regist_device(device_code,&rt); | ||
371 | 176 | |||
372 | 177 | GValueArray* struct_return;// = g_array_new(TRUE,TRUE,sizeof(GValue)); | ||
373 | 178 | GValue struct_container[3] = {{0}}; | ||
374 | 179 | |||
375 | 180 | g_value_init (&struct_container[0], G_TYPE_INT); | ||
376 | 181 | g_value_set_int (&struct_container[0], rt.state_code); | ||
377 | 182 | g_value_init (&struct_container[1], G_TYPE_INT); | ||
378 | 183 | g_value_set_int (&struct_container[1], rt.exception_code); | ||
379 | 184 | g_value_init (&struct_container[2], G_TYPE_STRING); | ||
380 | 185 | g_value_set_string (&struct_container[2], rt.desc); | ||
381 | 186 | |||
382 | 187 | struct_return = g_value_array_new(0); | ||
383 | 188 | int j; | ||
384 | 189 | for(j =0; j <3; j++){ | ||
385 | 190 | struct_return = g_value_array_append(struct_return, &struct_container[j]); | ||
386 | 191 | } | ||
387 | 192 | |||
388 | 193 | dbus_g_method_return(ret_value,struct_return); | ||
389 | 194 | return 1; | ||
390 | 195 | } | ||
391 | 196 | gint monitor_dbus_logout_device(MonitorDbus * dbus, int device_code, DBusGMethodInvocation * ret_value){ | ||
392 | 197 | //printf("Hello,here, 0x%.2x\n",device_code); | ||
393 | 198 | //printf("Hello,here\n"); | ||
394 | 199 | dbus_return_t rt={0,0,{0}};// state_code ; exception_code; exception_desc; | ||
395 | 200 | manager_logout_device(device_code,&rt); | ||
396 | 201 | |||
397 | 202 | GValueArray* struct_return;// = g_array_new(TRUE,TRUE,sizeof(GValue)); | ||
398 | 203 | GValue struct_container[3] = {{0}}; | ||
399 | 204 | |||
400 | 205 | g_value_init (&struct_container[0], G_TYPE_INT); | ||
401 | 206 | g_value_set_int (&struct_container[0], rt.state_code); | ||
402 | 207 | g_value_init (&struct_container[1], G_TYPE_INT); | ||
403 | 208 | g_value_set_int (&struct_container[1], rt.exception_code); | ||
404 | 209 | g_value_init (&struct_container[2], G_TYPE_STRING); | ||
405 | 210 | g_value_set_string (&struct_container[2], rt.desc); | ||
406 | 211 | |||
407 | 212 | struct_return = g_value_array_new(0); | ||
408 | 213 | int j; | ||
409 | 214 | for(j =0; j <3; j++){ | ||
410 | 215 | struct_return = g_value_array_append(struct_return, &struct_container[j]); | ||
411 | 216 | } | ||
412 | 217 | dbus_g_method_return(ret_value,struct_return); | ||
413 | 218 | return 1; | ||
414 | 219 | } | ||
415 | 220 | |||
416 | 221 | |||
417 | 222 | |||
418 | 223 | void _send_string_signal(manager_callback_return_t* rt){ | ||
419 | 224 | // | ||
420 | 225 | } | ||
421 | 226 | |||
422 | 135 | int send_signal(MonitorDbus * dbus, gint s1){ | 227 | int send_signal(MonitorDbus * dbus, gint s1){ |
423 | 136 | g_signal_emit(dbus, mnsignals[SIG_DATA_ALERT], 0, s1); | 228 | g_signal_emit(dbus, mnsignals[SIG_DATA_ALERT], 0, s1); |
424 | 137 | return 0; | 229 | return 0; |
425 | @@ -142,7 +234,11 @@ | |||
426 | 142 | send_signal(dbus, 1); | 234 | send_signal(dbus, 1); |
427 | 143 | return 1; | 235 | return 1; |
428 | 144 | } | 236 | } |
430 | 145 | 237 | int dbus_exit(void){ | |
431 | 238 | manager_exit(); | ||
432 | 239 | g_main_loop_unref(loop); | ||
433 | 240 | g_object_unref(dbus); | ||
434 | 241 | } | ||
435 | 146 | int dbus_init(void) | 242 | int dbus_init(void) |
436 | 147 | { | 243 | { |
437 | 148 | DBusGConnection * connection = NULL; | 244 | DBusGConnection * connection = NULL; |
438 | @@ -158,40 +254,39 @@ | |||
439 | 158 | 254 | ||
440 | 159 | connection = dbus_g_bus_get(DBUS_BUS_SYSTEM, &error); | 255 | connection = dbus_g_bus_get(DBUS_BUS_SYSTEM, &error); |
441 | 160 | if(connection == NULL){ | 256 | if(connection == NULL){ |
444 | 161 | g_error("%s", error->message); | 257 | g_error("%s", error->message); |
445 | 162 | goto out; | 258 | goto out; |
446 | 163 | } | 259 | } |
447 | 164 | 260 | ||
448 | 165 | dbus_proxy = dbus_g_proxy_new_for_name(connection, DBUS_SERVICE_DBUS, | 261 | dbus_proxy = dbus_g_proxy_new_for_name(connection, DBUS_SERVICE_DBUS, |
450 | 166 | DBUS_PATH_DBUS, DBUS_INTERFACE_DBUS); | 262 | DBUS_PATH_DBUS, DBUS_INTERFACE_DBUS); |
451 | 167 | 263 | ||
452 | 168 | ret = dbus_g_proxy_call(dbus_proxy, "RequestName", &error, | 264 | ret = dbus_g_proxy_call(dbus_proxy, "RequestName", &error, |
459 | 169 | G_TYPE_STRING, LISTEN_DBUS_NAME, | 265 | G_TYPE_STRING, LISTEN_DBUS_NAME, |
460 | 170 | G_TYPE_UINT, | 266 | G_TYPE_UINT, |
461 | 171 | DBUS_NAME_FLAG_DO_NOT_QUEUE, | 267 | DBUS_NAME_FLAG_DO_NOT_QUEUE, |
462 | 172 | G_TYPE_INVALID, | 268 | G_TYPE_INVALID, |
463 | 173 | G_TYPE_UINT, &request_name_result, | 269 | G_TYPE_UINT, &request_name_result, |
464 | 174 | G_TYPE_INVALID); | 270 | G_TYPE_INVALID); |
465 | 175 | if(!ret){ | 271 | if(!ret){ |
469 | 176 | g_error("RequestName failed:%s", error->message); | 272 | g_error("RequestName failed:%s", error->message); |
470 | 177 | g_error_free(error); | 273 | g_error_free(error); |
471 | 178 | exit(EXIT_FAILURE); | 274 | exit(EXIT_FAILURE); |
472 | 179 | } | 275 | } |
473 | 180 | 276 | ||
474 | 181 | g_object_unref(G_OBJECT(dbus_proxy)); | 277 | g_object_unref(G_OBJECT(dbus_proxy)); |
475 | 182 | 278 | ||
476 | 183 | if(request_name_result != DBUS_REQUEST_NAME_REPLY_PRIMARY_OWNER) | 279 | if(request_name_result != DBUS_REQUEST_NAME_REPLY_PRIMARY_OWNER) |
478 | 184 | exit(EXIT_FAILURE); | 280 | exit(EXIT_FAILURE); |
479 | 185 | 281 | ||
480 | 186 | dbus_g_object_type_install_info(LISTEN_TYPE_DBUS, | 282 | dbus_g_object_type_install_info(LISTEN_TYPE_DBUS, |
482 | 187 | &dbus_glib_monitor_dbus_object_info); | 283 | &dbus_glib_monitor_object_info); |
483 | 188 | dbus_g_connection_register_g_object(connection, LISTEN_DBUS_PATH,G_OBJECT(dbus)); | 284 | dbus_g_connection_register_g_object(connection, LISTEN_DBUS_PATH,G_OBJECT(dbus)); |
484 | 189 | 285 | ||
485 | 190 | // 定时发送signal | 286 | // 定时发送signal |
486 | 191 | //g_timeout_add_seconds(5, (GSourceFunc)send_mnsignals_timer_handler, dbus); | 287 | //g_timeout_add_seconds(5, (GSourceFunc)send_mnsignals_timer_handler, dbus); |
490 | 192 | 288 | //printf("before manager_init\n"); | |
491 | 193 | interlayer_load_devices(LISTEN_DBUS_NAME, LISTEN_DBUS_PATH); | 289 | manager_init(LISTEN_DBUS_NAME, LISTEN_DBUS_PATH,(MANAGER_CALLBACK_FUNC)_send_string_signal); |
489 | 194 | |||
492 | 195 | g_main_loop_run(loop); | 290 | g_main_loop_run(loop); |
493 | 196 | out: | 291 | out: |
494 | 197 | g_main_loop_unref(loop); | 292 | g_main_loop_unref(loop); |
495 | 198 | 293 | ||
496 | === modified file 'src/dbuslayer/monitor_dbus.h' | |||
497 | --- src/dbuslayer/monitor_dbus.h 2017-09-05 05:53:02 +0000 | |||
498 | +++ src/dbuslayer/monitor_dbus.h 2017-10-10 00:58:46 +0000 | |||
499 | @@ -70,14 +70,17 @@ | |||
500 | 70 | 70 | ||
501 | 71 | GType monitor_dbus_get_type(void); | 71 | GType monitor_dbus_get_type(void); |
502 | 72 | MonitorDbus * monitor_dbus_new(void); | 72 | MonitorDbus * monitor_dbus_new(void); |
505 | 73 | gint monitor_dbus_call_monitor_method(MonitorDbus * dbus,GValueArray * method_value ,DBusGMethodInvocation * ret_value); | 73 | gint monitor_dbus_get_all_device_static_info(MonitorDbus* dbus,DBusGMethodInvocation* ret_value); |
506 | 74 | gint monitor_dbus_intropect(MonitorDbus * dbus,const char* devicename,DBusGMethodInvocation * ret_value); | 74 | gint monitor_dbus_get_device_interfaces_info(MonitorDbus* dbus, int device_code, DBusGMethodInvocation* ret_value); |
507 | 75 | gint monitor_dbus_call_device_method(MonitorDbus * dbus,GValueArray * method_value ,DBusGMethodInvocation * ret_value); | ||
508 | 76 | gint monitor_dbus_regist_new_device(MonitorDbus* dbus, int device_code, DBusGMethodInvocation * ret_value); | ||
509 | 77 | gint monitor_dbus_logout_device(MonitorDbus* dbus, int device_code, DBusGMethodInvocation* ret_value); | ||
510 | 75 | #define DBUS_STRUCT_INT_INT_STRING (dbus_g_type_get_struct("GValueArray", G_TYPE_INT, G_TYPE_INT, G_TYPE_STRING)) | 78 | #define DBUS_STRUCT_INT_INT_STRING (dbus_g_type_get_struct("GValueArray", G_TYPE_INT, G_TYPE_INT, G_TYPE_STRING)) |
511 | 76 | 79 | ||
512 | 77 | G_END_DECLS | 80 | G_END_DECLS |
513 | 78 | 81 | ||
514 | 79 | int dbus_init(void); | 82 | int dbus_init(void); |
516 | 80 | 83 | int dbus_exit(void); | |
517 | 81 | 84 | ||
518 | 82 | void signal_handler(); | 85 | void signal_handler(); |
519 | 83 | #endif | 86 | #endif |
520 | 84 | 87 | ||
521 | === added file 'src/dbuslayer/monitor_dbus.h.backup' | |||
522 | --- src/dbuslayer/monitor_dbus.h.backup 1970-01-01 00:00:00 +0000 | |||
523 | +++ src/dbuslayer/monitor_dbus.h.backup 2017-10-10 00:58:46 +0000 | |||
524 | @@ -0,0 +1,84 @@ | |||
525 | 1 | /* | ||
526 | 2 | * Copyright (C) 2013 National University of Defense Technology(NUDT) & Kylin Ltd. | ||
527 | 3 | * | ||
528 | 4 | * Authors: | ||
529 | 5 | * Kobe Lee kobe24_lixiang@126.com | ||
530 | 6 | * | ||
531 | 7 | * This program is free software; you can redistribute it and/or modify | ||
532 | 8 | * it under the terms of the GNU General Public License as published by | ||
533 | 9 | * the Free Software Foundation; version 3. | ||
534 | 10 | * | ||
535 | 11 | * This program is distributed in the hope that it will be useful, | ||
536 | 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
537 | 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
538 | 14 | * GNU General Public License for more details. | ||
539 | 15 | * | ||
540 | 16 | * You should have received a copy of the GNU General Public License | ||
541 | 17 | * along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
542 | 18 | */ | ||
543 | 19 | |||
544 | 20 | #ifndef __LISTEN_DBUS_H__ | ||
545 | 21 | #define __LISTEN_DBUS_H__ | ||
546 | 22 | |||
547 | 23 | #include <glib-object.h> | ||
548 | 24 | #include <glib.h> | ||
549 | 25 | #include <dbus/dbus-glib.h> | ||
550 | 26 | #include <dbus/dbus-glib-lowlevel.h> | ||
551 | 27 | #include <gio/gio.h> | ||
552 | 28 | |||
553 | 29 | G_BEGIN_DECLS | ||
554 | 30 | |||
555 | 31 | |||
556 | 32 | enum { | ||
557 | 33 | SIG_DATA_ALERT, | ||
558 | 34 | SIG_LAST_SIGNAL, | ||
559 | 35 | }; | ||
560 | 36 | |||
561 | 37 | #define LISTEN_DBUS_NAME "com.jd.test" | ||
562 | 38 | #define LISTEN_DBUS_PATH "/com/jd/test" | ||
563 | 39 | #define LISTEN_DBUS_INTERFACE "com.jd.monitor.test" | ||
564 | 40 | #define LISTEN_DBUS_ACTION_ID "com.jd.monitor.authentication" | ||
565 | 41 | #define LISTEN_TYPE_DBUS (monitor_dbus_get_type()) | ||
566 | 42 | |||
567 | 43 | #define LISTEN_DBUS(o) (G_TYPE_CHECK_INSTANCE_CAST ((o), LISTEN_TYPE_DBUS, MonitorDbus)) | ||
568 | 44 | #define LISTEN_DBUS_CLASS(k) (G_TYPE_CHECK_CLASS_CAST((k), LISTEN_TYPE_DBUS, MonitorDbusClass)) | ||
569 | 45 | #define LISTEN_IS_DBUS(o) (G_TYPE_CHECK_INSTANCE_TYPE((o), LISTEN_TYPE_DBUS)) | ||
570 | 46 | #define LISTEN_IS_DBUS_CLASS(k) (G_TYPE_CHECK_CLASS_TPYE((k), LISTEN_TYPE_DBUS)) | ||
571 | 47 | #define LISTEN_DBUS_GET_CLASS(o) (G_TYPE_INSTANCE_GET_CLASS((o), LISTEN_TYPE_DBUS, MonitorClass)) | ||
572 | 48 | |||
573 | 49 | typedef struct _MonitorDbusPrivate MonitorDbusPrivate; | ||
574 | 50 | typedef struct _MonitorDbus MonitorDbus; | ||
575 | 51 | typedef struct _MonitorDbusClass MonitorDbusClass; | ||
576 | 52 | typedef struct _MonitorWarnDbusClass MonitorWarnDbusClass; | ||
577 | 53 | |||
578 | 54 | struct _MonitorDbus { | ||
579 | 55 | GObject parent; | ||
580 | 56 | MonitorDbusPrivate *priv; | ||
581 | 57 | }; | ||
582 | 58 | |||
583 | 59 | struct _MonitorDbusClass { | ||
584 | 60 | GObjectClass parent_class; | ||
585 | 61 | void (*event)(MonitorDbus* dbus, guint type, GValue * value); | ||
586 | 62 | |||
587 | 63 | }; | ||
588 | 64 | |||
589 | 65 | struct _MonitorWarnDbusClass { | ||
590 | 66 | GObjectClass parent_class; | ||
591 | 67 | void (*event)(MonitorDbus* dbus, guint tag ,guint type, guint subtype); | ||
592 | 68 | |||
593 | 69 | }; | ||
594 | 70 | |||
595 | 71 | GType monitor_dbus_get_type(void); | ||
596 | 72 | MonitorDbus * monitor_dbus_new(void); | ||
597 | 73 | gint monitor_dbus_call_monitor_method(MonitorDbus * dbus,GValueArray * method_value ,DBusGMethodInvocation * ret_value); | ||
598 | 74 | gint monitor_dbus_intropect(MonitorDbus * dbus,const char* devicename,DBusGMethodInvocation * ret_value); | ||
599 | 75 | #define DBUS_STRUCT_INT_INT_STRING (dbus_g_type_get_struct("GValueArray", G_TYPE_INT, G_TYPE_INT, G_TYPE_STRING)) | ||
600 | 76 | |||
601 | 77 | G_END_DECLS | ||
602 | 78 | |||
603 | 79 | int dbus_init(void); | ||
604 | 80 | |||
605 | 81 | |||
606 | 82 | void signal_handler(); | ||
607 | 83 | #endif | ||
608 | 84 | |||
609 | 0 | 85 | ||
610 | === modified file 'src/dbuslayer/monitor_dbus_glue.h' | |||
611 | --- src/dbuslayer/monitor_dbus_glue.h 2017-09-05 05:53:02 +0000 | |||
612 | +++ src/dbuslayer/monitor_dbus_glue.h 2017-10-10 00:58:46 +0000 | |||
613 | @@ -1,8 +1,8 @@ | |||
614 | 1 | /* Generated by dbus-binding-tool; do not edit! */ | 1 | /* Generated by dbus-binding-tool; do not edit! */ |
615 | 2 | 2 | ||
616 | 3 | 3 | ||
619 | 4 | #ifndef __dbus_glib_marshal_monitor_dbus_MARSHAL_H__ | 4 | #ifndef __dbus_glib_marshal_monitor_MARSHAL_H__ |
620 | 5 | #define __dbus_glib_marshal_monitor_dbus_MARSHAL_H__ | 5 | #define __dbus_glib_marshal_monitor_MARSHAL_H__ |
621 | 6 | 6 | ||
622 | 7 | #include <glib-object.h> | 7 | #include <glib-object.h> |
623 | 8 | 8 | ||
624 | @@ -55,26 +55,30 @@ | |||
625 | 55 | #endif /* !G_ENABLE_DEBUG */ | 55 | #endif /* !G_ENABLE_DEBUG */ |
626 | 56 | 56 | ||
627 | 57 | 57 | ||
635 | 58 | /* NONE:STRING,POINTER */ | 58 | /* NONE:POINTER */ |
636 | 59 | extern void dbus_glib_marshal_monitor_dbus_VOID__STRING_POINTER (GClosure *closure, | 59 | #define dbus_glib_marshal_monitor_VOID__POINTER g_cclosure_marshal_VOID__POINTER |
637 | 60 | GValue *return_value, | 60 | #define dbus_glib_marshal_monitor_NONE__POINTER dbus_glib_marshal_monitor_VOID__POINTER |
638 | 61 | guint n_param_values, | 61 | |
639 | 62 | const GValue *param_values, | 62 | /* NONE:INT,POINTER */ |
640 | 63 | gpointer invocation_hint, | 63 | extern void dbus_glib_marshal_monitor_VOID__INT_POINTER (GClosure *closure, |
641 | 64 | gpointer marshal_data); | 64 | GValue *return_value, |
642 | 65 | guint n_param_values, | ||
643 | 66 | const GValue *param_values, | ||
644 | 67 | gpointer invocation_hint, | ||
645 | 68 | gpointer marshal_data); | ||
646 | 65 | void | 69 | void |
653 | 66 | dbus_glib_marshal_monitor_dbus_VOID__STRING_POINTER (GClosure *closure, | 70 | dbus_glib_marshal_monitor_VOID__INT_POINTER (GClosure *closure, |
654 | 67 | GValue *return_value G_GNUC_UNUSED, | 71 | GValue *return_value G_GNUC_UNUSED, |
655 | 68 | guint n_param_values, | 72 | guint n_param_values, |
656 | 69 | const GValue *param_values, | 73 | const GValue *param_values, |
657 | 70 | gpointer invocation_hint G_GNUC_UNUSED, | 74 | gpointer invocation_hint G_GNUC_UNUSED, |
658 | 71 | gpointer marshal_data) | 75 | gpointer marshal_data) |
659 | 72 | { | 76 | { |
665 | 73 | typedef void (*GMarshalFunc_VOID__STRING_POINTER) (gpointer data1, | 77 | typedef void (*GMarshalFunc_VOID__INT_POINTER) (gpointer data1, |
666 | 74 | gpointer arg_1, | 78 | gint arg_1, |
667 | 75 | gpointer arg_2, | 79 | gpointer arg_2, |
668 | 76 | gpointer data2); | 80 | gpointer data2); |
669 | 77 | GMarshalFunc_VOID__STRING_POINTER callback; | 81 | GMarshalFunc_VOID__INT_POINTER callback; |
670 | 78 | GCClosure *cc = (GCClosure*) closure; | 82 | GCClosure *cc = (GCClosure*) closure; |
671 | 79 | gpointer data1, data2; | 83 | gpointer data1, data2; |
672 | 80 | 84 | ||
673 | @@ -90,29 +94,29 @@ | |||
674 | 90 | data1 = g_value_peek_pointer (param_values + 0); | 94 | data1 = g_value_peek_pointer (param_values + 0); |
675 | 91 | data2 = closure->data; | 95 | data2 = closure->data; |
676 | 92 | } | 96 | } |
678 | 93 | callback = (GMarshalFunc_VOID__STRING_POINTER) (marshal_data ? marshal_data : cc->callback); | 97 | callback = (GMarshalFunc_VOID__INT_POINTER) (marshal_data ? marshal_data : cc->callback); |
679 | 94 | 98 | ||
680 | 95 | callback (data1, | 99 | callback (data1, |
682 | 96 | g_marshal_value_peek_string (param_values + 1), | 100 | g_marshal_value_peek_int (param_values + 1), |
683 | 97 | g_marshal_value_peek_pointer (param_values + 2), | 101 | g_marshal_value_peek_pointer (param_values + 2), |
684 | 98 | data2); | 102 | data2); |
685 | 99 | } | 103 | } |
687 | 100 | #define dbus_glib_marshal_monitor_dbus_NONE__STRING_POINTER dbus_glib_marshal_monitor_dbus_VOID__STRING_POINTER | 104 | #define dbus_glib_marshal_monitor_NONE__INT_POINTER dbus_glib_marshal_monitor_VOID__INT_POINTER |
688 | 101 | 105 | ||
689 | 102 | /* NONE:BOXED,POINTER */ | 106 | /* NONE:BOXED,POINTER */ |
696 | 103 | extern void dbus_glib_marshal_monitor_dbus_VOID__BOXED_POINTER (GClosure *closure, | 107 | extern void dbus_glib_marshal_monitor_VOID__BOXED_POINTER (GClosure *closure, |
697 | 104 | GValue *return_value, | 108 | GValue *return_value, |
698 | 105 | guint n_param_values, | 109 | guint n_param_values, |
699 | 106 | const GValue *param_values, | 110 | const GValue *param_values, |
700 | 107 | gpointer invocation_hint, | 111 | gpointer invocation_hint, |
701 | 108 | gpointer marshal_data); | 112 | gpointer marshal_data); |
702 | 109 | void | 113 | void |
709 | 110 | dbus_glib_marshal_monitor_dbus_VOID__BOXED_POINTER (GClosure *closure, | 114 | dbus_glib_marshal_monitor_VOID__BOXED_POINTER (GClosure *closure, |
710 | 111 | GValue *return_value G_GNUC_UNUSED, | 115 | GValue *return_value G_GNUC_UNUSED, |
711 | 112 | guint n_param_values, | 116 | guint n_param_values, |
712 | 113 | const GValue *param_values, | 117 | const GValue *param_values, |
713 | 114 | gpointer invocation_hint G_GNUC_UNUSED, | 118 | gpointer invocation_hint G_GNUC_UNUSED, |
714 | 115 | gpointer marshal_data) | 119 | gpointer marshal_data) |
715 | 116 | { | 120 | { |
716 | 117 | typedef void (*GMarshalFunc_VOID__BOXED_POINTER) (gpointer data1, | 121 | typedef void (*GMarshalFunc_VOID__BOXED_POINTER) (gpointer data1, |
717 | 118 | gpointer arg_1, | 122 | gpointer arg_1, |
718 | @@ -141,22 +145,25 @@ | |||
719 | 141 | g_marshal_value_peek_pointer (param_values + 2), | 145 | g_marshal_value_peek_pointer (param_values + 2), |
720 | 142 | data2); | 146 | data2); |
721 | 143 | } | 147 | } |
723 | 144 | #define dbus_glib_marshal_monitor_dbus_NONE__BOXED_POINTER dbus_glib_marshal_monitor_dbus_VOID__BOXED_POINTER | 148 | #define dbus_glib_marshal_monitor_NONE__BOXED_POINTER dbus_glib_marshal_monitor_VOID__BOXED_POINTER |
724 | 145 | 149 | ||
725 | 146 | G_END_DECLS | 150 | G_END_DECLS |
726 | 147 | 151 | ||
728 | 148 | #endif /* __dbus_glib_marshal_monitor_dbus_MARSHAL_H__ */ | 152 | #endif /* __dbus_glib_marshal_monitor_MARSHAL_H__ */ |
729 | 149 | 153 | ||
730 | 150 | #include <dbus/dbus-glib.h> | 154 | #include <dbus/dbus-glib.h> |
734 | 151 | static const DBusGMethodInfo dbus_glib_monitor_dbus_methods[] = { | 155 | static const DBusGMethodInfo dbus_glib_monitor_methods[] = { |
735 | 152 | { (GCallback) monitor_dbus_call_monitor_method, dbus_glib_marshal_monitor_dbus_NONE__BOXED_POINTER, 0 }, | 156 | { (GCallback) monitor_dbus_get_all_device_static_info, dbus_glib_marshal_monitor_NONE__POINTER, 0 }, |
736 | 153 | { (GCallback) monitor_dbus_intropect, dbus_glib_marshal_monitor_dbus_NONE__STRING_POINTER, 91 }, | 157 | { (GCallback) monitor_dbus_get_device_interfaces_info, dbus_glib_marshal_monitor_NONE__INT_POINTER, 94 }, |
737 | 158 | { (GCallback) monitor_dbus_call_device_method, dbus_glib_marshal_monitor_NONE__BOXED_POINTER, 206 }, | ||
738 | 159 | { (GCallback) monitor_dbus_regist_new_device, dbus_glib_marshal_monitor_NONE__INT_POINTER, 313 }, | ||
739 | 160 | { (GCallback) monitor_dbus_logout_device, dbus_glib_marshal_monitor_NONE__INT_POINTER, 403 }, | ||
740 | 154 | }; | 161 | }; |
741 | 155 | 162 | ||
746 | 156 | const DBusGObjectInfo dbus_glib_monitor_dbus_object_info = { 1, | 163 | const DBusGObjectInfo dbus_glib_monitor_object_info = { 1, |
747 | 157 | dbus_glib_monitor_dbus_methods, | 164 | dbus_glib_monitor_methods, |
748 | 158 | 2, | 165 | 5, |
749 | 159 | "com.jd.test.interface\0call_monitor_method\0A\0hw_method_t\0I\0(iiiis)\0hw_return_t\0O\0F\0N\0(iis)\0\0com.jd.test.interface\0intropect\0A\0name\0I\0s\0data\0O\0F\0N\0s\0\0\0", | 166 | "com.jd.test.interface\0dbus_get_all_device_static_info\0A\0devices_static_return_t\0O\0F\0N\0a(isi)\0\0com.jd.test.interface\0dbus_get_device_interfaces_info\0A\0device_code\0I\0i\0device_interfaces_return_t\0O\0F\0N\0isaav\0\0com.jd.test.interface\0dbus_call_device_method\0A\0device_method_input_t\0I\0(iiiis)\0dbus_return_t\0O\0F\0N\0(iis)\0\0com.jd.test.interface\0dbus_regist_new_device\0A\0device_code\0I\0i\0dbus_return_t\0O\0F\0N\0(iis)\0\0com.jd.test.interface\0dbus_logout_device\0A\0device_code\0I\0i\0dbus_return_t\0O\0F\0N\0(iis)\0\0\0", |
750 | 160 | "\0", | 167 | "\0", |
751 | 161 | "\0" | 168 | "\0" |
752 | 162 | }; | 169 | }; |
753 | 163 | 170 | ||
754 | === removed directory 'src/interlayer' | |||
755 | === removed file 'src/interlayer/interlayer.c' | |||
756 | --- src/interlayer/interlayer.c 2017-09-05 05:53:02 +0000 | |||
757 | +++ src/interlayer/interlayer.c 1970-01-01 00:00:00 +0000 | |||
758 | @@ -1,351 +0,0 @@ | |||
759 | 1 | #include "interlayer.h" | ||
760 | 2 | #include <unistd.h> | ||
761 | 3 | #include <stdio.h> | ||
762 | 4 | #include <stdlib.h> | ||
763 | 5 | #include <string.h> | ||
764 | 6 | #include <sys/types.h> | ||
765 | 7 | #include <dlfcn.h> | ||
766 | 8 | #include <dirent.h> | ||
767 | 9 | #include <sys/stat.h> | ||
768 | 10 | #include <fcntl.h> | ||
769 | 11 | #include <glib.h> | ||
770 | 12 | //#include <libxml2/libxml/parser.h> | ||
771 | 13 | //#include <libxml2/libxml/tree.h> | ||
772 | 14 | #include <libxml/parser.h> | ||
773 | 15 | #include <libxml/tree.h> | ||
774 | 16 | |||
775 | 17 | #define WORK_ROOT_DIR "/etc/kydevmonit/" | ||
776 | 18 | typedef void (*NO_DBUS_INPUT_FUNC)(void* return_t); | ||
777 | 19 | typedef void (*HAS_DBUS_INPUT_FUNC)(const char* input, void* return_t); | ||
778 | 20 | typedef struct{ | ||
779 | 21 | int error_no; | ||
780 | 22 | int count; | ||
781 | 23 | char * desc; | ||
782 | 24 | }hw_return_t; | ||
783 | 25 | |||
784 | 26 | #define NO_DBUS_INPUT_TYPE 0 | ||
785 | 27 | #define HAS_DBUS_INPUT_TYPE 1 | ||
786 | 28 | typedef struct{ | ||
787 | 29 | void * address; | ||
788 | 30 | int type; | ||
789 | 31 | }device_method_t; | ||
790 | 32 | |||
791 | 33 | |||
792 | 34 | static xmlDocPtr intropectdoc; | ||
793 | 35 | static xmlNodePtr intropectdoc_rootnode; | ||
794 | 36 | static int | ||
795 | 37 | _init_write_devices_intropect_xml(const char* object_name){ | ||
796 | 38 | if(intropectdoc == NULL && intropectdoc_rootnode == NULL) { | ||
797 | 39 | intropectdoc = xmlNewDoc("1.0"); | ||
798 | 40 | intropectdoc_rootnode = xmlNewNode(NULL, "object"); | ||
799 | 41 | xmlNewProp(intropectdoc_rootnode,"name", object_name); | ||
800 | 42 | xmlDocSetRootElement(intropectdoc, intropectdoc_rootnode); | ||
801 | 43 | } | ||
802 | 44 | return 0; | ||
803 | 45 | } | ||
804 | 46 | static int | ||
805 | 47 | _end_write_devices_intropect_xml(const char* dbus_name){ | ||
806 | 48 | if(intropectdoc == NULL || intropectdoc_rootnode == NULL) | ||
807 | 49 | return -1; | ||
808 | 50 | char filename[1024]={0}; | ||
809 | 51 | sprintf(filename,"%sdevices.", WORK_ROOT_DIR); | ||
810 | 52 | sprintf(filename, "%s%s.xml", filename,dbus_name); | ||
811 | 53 | printf("intropect xml filename: %s\n", filename); | ||
812 | 54 | if(xmlSaveFormatFileEnc(filename, intropectdoc, "UTF-8", 1) >=0){ | ||
813 | 55 | printf("Save intropectdoc xml file successful\n"); | ||
814 | 56 | }else{ | ||
815 | 57 | printf("Save intropectdoc xml file failed\n"); | ||
816 | 58 | } | ||
817 | 59 | xmlFreeDoc(intropectdoc); | ||
818 | 60 | xmlCleanupParser(); | ||
819 | 61 | return 0; | ||
820 | 62 | } | ||
821 | 63 | static int | ||
822 | 64 | _add_device_to_intropect_xml(const xmlChar* devicename,const char* devicecode){ | ||
823 | 65 | if(intropectdoc == NULL || intropectdoc_rootnode == NULL || devicename == NULL){ | ||
824 | 66 | fprintf(stderr, "doc or node or devicename is null\n"); | ||
825 | 67 | return -1; | ||
826 | 68 | } | ||
827 | 69 | xmlNodePtr devicenode = xmlNewChild(intropectdoc_rootnode, NULL, "device", ""); | ||
828 | 70 | xmlNewProp(devicenode, "name", devicename); | ||
829 | 71 | xmlNewProp(devicenode, "code",devicecode); | ||
830 | 72 | return 0; | ||
831 | 73 | } | ||
832 | 74 | |||
833 | 75 | static GHashTable * method_table = NULL; | ||
834 | 76 | static int | ||
835 | 77 | _init_method_hashtable(){ | ||
836 | 78 | if(method_table == NULL){ | ||
837 | 79 | method_table = g_hash_table_new(g_str_hash, g_str_equal); | ||
838 | 80 | } | ||
839 | 81 | return 0; | ||
840 | 82 | } | ||
841 | 83 | static int | ||
842 | 84 | _insert_method_hashtable(gpointer key, gpointer value){ | ||
843 | 85 | if(method_table == NULL || key == NULL) | ||
844 | 86 | return -1; | ||
845 | 87 | g_hash_table_insert(method_table, key, value); | ||
846 | 88 | return 0; | ||
847 | 89 | } | ||
848 | 90 | static gpointer | ||
849 | 91 | _get_method_address(gpointer key){ | ||
850 | 92 | if(method_table == NULL || key == NULL){ | ||
851 | 93 | //fprintf(stderr, "ERROR: method_table or key is null\n"); | ||
852 | 94 | return NULL; | ||
853 | 95 | } | ||
854 | 96 | return g_hash_table_lookup(method_table,key); | ||
855 | 97 | } | ||
856 | 98 | static void | ||
857 | 99 | _ms_print_key_value(gpointer key, gpointer value, gpointer user_data){ | ||
858 | 100 | printf("key: %s, value: %u\n", key, (unsigned int)value); | ||
859 | 101 | } | ||
860 | 102 | static void | ||
861 | 103 | _ms_display_method_hashtable(){ | ||
862 | 104 | g_hash_table_foreach(method_table, _ms_print_key_value, NULL); | ||
863 | 105 | } | ||
864 | 106 | static int | ||
865 | 107 | _parse_device_xml(const char * filename, const char* object_name){ | ||
866 | 108 | //if(filename == NULL) | ||
867 | 109 | // return -1; | ||
868 | 110 | char filepath[1024]={0}; | ||
869 | 111 | sprintf(filepath,"%s",WORK_ROOT_DIR); | ||
870 | 112 | sprintf(filepath,"%s%s",filepath,filename); | ||
871 | 113 | xmlNodePtr curnode; | ||
872 | 114 | xmlDocPtr doc; | ||
873 | 115 | void * sharelibHandle; | ||
874 | 116 | xmlInitParser(); | ||
875 | 117 | doc = xmlReadFile(filepath, "UTF-8", XML_PARSE_RECOVER) ; | ||
876 | 118 | if(doc == NULL){ | ||
877 | 119 | fprintf(stderr, "xmlReadFile %s failed\n", filepath); | ||
878 | 120 | return -1; | ||
879 | 121 | } | ||
880 | 122 | curnode = xmlDocGetRootElement(doc); | ||
881 | 123 | if(curnode == NULL){ | ||
882 | 124 | fprintf(stderr, "empty document\n"); | ||
883 | 125 | xmlFreeDoc(doc); | ||
884 | 126 | return -1; | ||
885 | 127 | } | ||
886 | 128 | // printf("curnode->name: %s\n", curnode->name); | ||
887 | 129 | // curnode = curnode->xmlChildrenNode; | ||
888 | 130 | xmlChar * nodevalue = NULL; | ||
889 | 131 | xmlChar * devicecode = NULL; | ||
890 | 132 | xmlChar * methodcode = NULL; | ||
891 | 133 | xmlChar * devicepath = NULL; | ||
892 | 134 | int statuscode = 0; | ||
893 | 135 | while(curnode != NULL){ | ||
894 | 136 | if(xmlStrcmp(curnode->name, (const xmlChar*)"object") == 0){ | ||
895 | 137 | nodevalue = xmlGetProp(curnode, (const xmlChar*)"name"); | ||
896 | 138 | //printf("nodevalue: %s\n", nodevalue); | ||
897 | 139 | if(xmlStrncmp(nodevalue, object_name, strlen(object_name)) != 0){ | ||
898 | 140 | fprintf(stderr,"The object_name %s is not matched\n", nodevalue); | ||
899 | 141 | xmlFree(nodevalue); | ||
900 | 142 | statuscode = -1; | ||
901 | 143 | break; | ||
902 | 144 | }else{ | ||
903 | 145 | _init_write_devices_intropect_xml(object_name); | ||
904 | 146 | xmlFree(nodevalue); | ||
905 | 147 | curnode = curnode->xmlChildrenNode; | ||
906 | 148 | continue; | ||
907 | 149 | } | ||
908 | 150 | } | ||
909 | 151 | else if(xmlStrcmp(curnode->name, (const xmlChar*)"device") == 0){ | ||
910 | 152 | nodevalue = xmlGetProp(curnode, "name"); | ||
911 | 153 | if(nodevalue == NULL){ | ||
912 | 154 | fprintf(stderr, "The device hasn't name,this is invailed!\n"); | ||
913 | 155 | statuscode = -1; | ||
914 | 156 | break; | ||
915 | 157 | } | ||
916 | 158 | devicecode = xmlGetProp(curnode, "code"); | ||
917 | 159 | if(devicecode == NULL){ | ||
918 | 160 | fprintf(stderr, "The device hasn't code,this is invailed!\n"); | ||
919 | 161 | xmlFree(nodevalue); | ||
920 | 162 | statuscode = -1; | ||
921 | 163 | break; | ||
922 | 164 | } | ||
923 | 165 | // load so | ||
924 | 166 | devicepath = xmlGetProp(curnode, "path"); | ||
925 | 167 | if(devicepath == NULL){ | ||
926 | 168 | fprintf(stderr, "The device hasn't path,this is invailed!\n"); | ||
927 | 169 | statuscode = -1; | ||
928 | 170 | xmlFree(nodevalue); | ||
929 | 171 | xmlFree(devicecode); | ||
930 | 172 | break; | ||
931 | 173 | } | ||
932 | 174 | printf("path: %s\n", devicepath); | ||
933 | 175 | sharelibHandle = dlopen(devicepath, RTLD_NOW); | ||
934 | 176 | if(sharelibHandle == NULL){ | ||
935 | 177 | fprintf(stderr, "%s sharelibHandle is NULL\n", devicepath); | ||
936 | 178 | xmlFree(devicepath); | ||
937 | 179 | xmlFree(nodevalue); | ||
938 | 180 | xmlFree(devicecode); | ||
939 | 181 | statuscode = -1; | ||
940 | 182 | break; | ||
941 | 183 | }else{ | ||
942 | 184 | _add_device_to_intropect_xml(nodevalue, devicecode); | ||
943 | 185 | _init_method_hashtable(); | ||
944 | 186 | xmlFree(nodevalue); | ||
945 | 187 | xmlFree(devicepath); | ||
946 | 188 | } | ||
947 | 189 | curnode = curnode->xmlChildrenNode; | ||
948 | 190 | continue; | ||
949 | 191 | }else if(xmlStrcmp(curnode->name, (const xmlChar*)"method") == 0){ | ||
950 | 192 | nodevalue = xmlGetProp(curnode, "name"); | ||
951 | 193 | if(nodevalue == NULL){ | ||
952 | 194 | fprintf(stderr, "method hasn't name, this is invaild!\n"); | ||
953 | 195 | curnode = curnode->next; | ||
954 | 196 | continue; | ||
955 | 197 | } | ||
956 | 198 | methodcode = xmlGetProp(curnode, "code"); | ||
957 | 199 | if(methodcode == NULL){ | ||
958 | 200 | fprintf(stderr, "method %s hasn't code, this is invaild!\n", nodevalue); | ||
959 | 201 | curnode = curnode->next; | ||
960 | 202 | xmlFree(nodevalue); | ||
961 | 203 | continue; | ||
962 | 204 | } | ||
963 | 205 | void* methodaddr = dlsym(sharelibHandle,nodevalue); | ||
964 | 206 | char* key = malloc(20*sizeof(char)); | ||
965 | 207 | device_method_t* method_ptr = malloc(sizeof(device_method_t)); | ||
966 | 208 | method_ptr->address = methodaddr; | ||
967 | 209 | xmlFree(nodevalue); | ||
968 | 210 | |||
969 | 211 | nodevalue = xmlGetProp(curnode, "type"); | ||
970 | 212 | if(nodevalue == NULL){ | ||
971 | 213 | fprintf(stderr, "method hasn't type, this is invaild!\n"); | ||
972 | 214 | xmlFree(methodcode); | ||
973 | 215 | curnode = curnode->next; | ||
974 | 216 | continue; | ||
975 | 217 | } | ||
976 | 218 | else if(xmlStrcmp(nodevalue, "nodbusinput") == 0){ | ||
977 | 219 | method_ptr->type = NO_DBUS_INPUT_TYPE; | ||
978 | 220 | }else if(xmlStrcmp(nodevalue, "hasdbusinput") == 0){ | ||
979 | 221 | method_ptr->type = HAS_DBUS_INPUT_TYPE; | ||
980 | 222 | }else{ | ||
981 | 223 | |||
982 | 224 | } | ||
983 | 225 | |||
984 | 226 | sprintf(key, "%s%s", devicecode,methodcode); | ||
985 | 227 | printf("key: %s len=%lu\n", key, strlen(key)); | ||
986 | 228 | _insert_method_hashtable(key, method_ptr); | ||
987 | 229 | |||
988 | 230 | printf("method name : %s, address : %u\n", nodevalue, (unsigned int)methodaddr); | ||
989 | 231 | xmlFree(nodevalue); | ||
990 | 232 | xmlFree(methodcode); | ||
991 | 233 | } | ||
992 | 234 | curnode = curnode->next; | ||
993 | 235 | } | ||
994 | 236 | if(devicecode != NULL) | ||
995 | 237 | xmlFree(devicecode); | ||
996 | 238 | if(doc != NULL) | ||
997 | 239 | xmlFreeDoc(doc); | ||
998 | 240 | |||
999 | 241 | return statuscode; | ||
1000 | 242 | } | ||
1001 | 243 | int interlayer_load_devices(const char* dbus_name, const char* object_name){ | ||
1002 | 244 | if(dbus_name == NULL || object_name == NULL){ | ||
1003 | 245 | fprintf(stderr, "ERROR: The dbus_name or object_name is null!\n"); | ||
1004 | 246 | return -1; | ||
1005 | 247 | } | ||
1006 | 248 | // Loop match xml file | ||
1007 | 249 | DIR *workdp; | ||
1008 | 250 | struct dirent *entry; | ||
1009 | 251 | if((workdp = opendir(WORK_ROOT_DIR)) == NULL){ | ||
1010 | 252 | fprintf(stderr, "opendir %s failed,no devices\n", WORK_ROOT_DIR); | ||
1011 | 253 | return -1; | ||
1012 | 254 | } | ||
1013 | 255 | //chdir(WORK_ROOT_DIR); | ||
1014 | 256 | while((entry = readdir(workdp)) != NULL){ | ||
1015 | 257 | if(strncmp(dbus_name,entry->d_name, strlen(dbus_name)) == 0){ | ||
1016 | 258 | |||
1017 | 259 | if(_parse_device_xml(entry->d_name, object_name) < 0){ | ||
1018 | 260 | fprintf(stderr, "%s parse failed!\n", entry->d_name); | ||
1019 | 261 | } | ||
1020 | 262 | else{ | ||
1021 | 263 | printf("%s load successful\n", entry->d_name); | ||
1022 | 264 | } | ||
1023 | 265 | } | ||
1024 | 266 | } | ||
1025 | 267 | closedir(workdp); | ||
1026 | 268 | _end_write_devices_intropect_xml(dbus_name); | ||
1027 | 269 | //_ms_display_method_hashtable(); | ||
1028 | 270 | return 0; | ||
1029 | 271 | } | ||
1030 | 272 | |||
1031 | 273 | int interlayer_get_devices_intropect(const char* dbus_name, const char* object_name, const char* devicename,char* ret_desc){ | ||
1032 | 274 | if(dbus_name == NULL || object_name == NULL || ret_desc == NULL){ | ||
1033 | 275 | fprintf(stderr, "ERROR: The dbus_name or object_name or ret_desc is null!\n"); | ||
1034 | 276 | return -1; | ||
1035 | 277 | } | ||
1036 | 278 | char filename[1024]; | ||
1037 | 279 | memset(filename, 0, 1024); | ||
1038 | 280 | size_t len=0; | ||
1039 | 281 | if(strlen(devicename) == 0){ | ||
1040 | 282 | sprintf(filename,"%sdevices.%s.xml", WORK_ROOT_DIR, dbus_name); | ||
1041 | 283 | printf("filename= %s\n", filename); | ||
1042 | 284 | int fd=open(filename, O_RDONLY); | ||
1043 | 285 | if(fd < 0){ | ||
1044 | 286 | fprintf(stderr, "%s open failed\n", filename); | ||
1045 | 287 | return -1; | ||
1046 | 288 | } | ||
1047 | 289 | |||
1048 | 290 | if((len = read(fd, ret_desc, 1024-1)) < 0){ | ||
1049 | 291 | fprintf(stderr, "%s read failed\n", filename); | ||
1050 | 292 | close(fd); | ||
1051 | 293 | return -1; | ||
1052 | 294 | } | ||
1053 | 295 | ret_desc[len] = '\0'; | ||
1054 | 296 | //printf("ret_desc = %s\n", ret_desc); | ||
1055 | 297 | close(fd) ; | ||
1056 | 298 | }else{ | ||
1057 | 299 | memset(filename, 0, 1024); | ||
1058 | 300 | sprintf(filename,"%s%s.%s.xml", WORK_ROOT_DIR, dbus_name,devicename); | ||
1059 | 301 | printf("filename= %s\n", filename); | ||
1060 | 302 | int fd=open(filename, O_RDONLY); | ||
1061 | 303 | if(fd < 0){ | ||
1062 | 304 | fprintf(stderr, "%s open failed\n", filename); | ||
1063 | 305 | return -1; | ||
1064 | 306 | } | ||
1065 | 307 | |||
1066 | 308 | if((len = read(fd, ret_desc, 1024-1)) < 0){ | ||
1067 | 309 | fprintf(stderr, "%s read failed\n", filename); | ||
1068 | 310 | close(fd); | ||
1069 | 311 | return -1; | ||
1070 | 312 | } | ||
1071 | 313 | ret_desc[len] = '\0'; | ||
1072 | 314 | //printf("ret_desc = %s\n", ret_desc); | ||
1073 | 315 | close(fd) ; | ||
1074 | 316 | |||
1075 | 317 | } | ||
1076 | 318 | return 0; | ||
1077 | 319 | } | ||
1078 | 320 | int interlayer_call_device_method(int devicecode, int methodcode, const char* param, int* statuscode, int * count, char* desc){ | ||
1079 | 321 | if(param == NULL || statuscode == NULL || count == NULL || desc == NULL){ | ||
1080 | 322 | fprintf(stderr, "ERROR: Please input vaild paramters\n"); | ||
1081 | 323 | return -1; | ||
1082 | 324 | } | ||
1083 | 325 | //_ms_display_method_hashtable(); | ||
1084 | 326 | char key[20] = {0}; | ||
1085 | 327 | sprintf(key,"0x%.2x0x%.2x", devicecode, methodcode); | ||
1086 | 328 | printf("call_key: %s ,len=%lu\n", key, strlen(key)); | ||
1087 | 329 | device_method_t * method_ptr = _get_method_address(key); | ||
1088 | 330 | if(method_ptr == NULL){ | ||
1089 | 331 | fprintf(stderr,"The method_ptr is NULL\n"); | ||
1090 | 332 | return -1; | ||
1091 | 333 | } | ||
1092 | 334 | printf("method address : %u\n", (unsigned int)(method_ptr->address)); | ||
1093 | 335 | |||
1094 | 336 | hw_return_t result={0,0,NULL}; | ||
1095 | 337 | result.desc = desc; | ||
1096 | 338 | |||
1097 | 339 | if(method_ptr->type == NO_DBUS_INPUT_TYPE){ | ||
1098 | 340 | NO_DBUS_INPUT_FUNC method_func = (NO_DBUS_INPUT_FUNC)(method_ptr->address); | ||
1099 | 341 | method_func(&result); | ||
1100 | 342 | }else if(method_ptr->type == HAS_DBUS_INPUT_TYPE){ | ||
1101 | 343 | HAS_DBUS_INPUT_FUNC method_func = (HAS_DBUS_INPUT_FUNC)(method_ptr->address); | ||
1102 | 344 | method_func(param,&result); | ||
1103 | 345 | }else{ | ||
1104 | 346 | // | ||
1105 | 347 | } | ||
1106 | 348 | *statuscode = result.error_no; | ||
1107 | 349 | *count = result.count; | ||
1108 | 350 | return 0; | ||
1109 | 351 | } | ||
1110 | 352 | 0 | ||
1111 | === removed file 'src/interlayer/interlayer.h' | |||
1112 | --- src/interlayer/interlayer.h 2017-09-05 05:53:02 +0000 | |||
1113 | +++ src/interlayer/interlayer.h 1970-01-01 00:00:00 +0000 | |||
1114 | @@ -1,34 +0,0 @@ | |||
1115 | 1 | #ifndef __INTER_LAYER_H__ | ||
1116 | 2 | #define __INTER_LAYER_H__ | ||
1117 | 3 | |||
1118 | 4 | |||
1119 | 5 | /** | ||
1120 | 6 | * The device's register info at /etc/kydevmonit/ xml file. | ||
1121 | 7 | * This method find and load the device's xml file that match the | ||
1122 | 8 | * dbus_name and object_name. | ||
1123 | 9 | * And load the share library of matched dervice. | ||
1124 | 10 | * @return 0 successful; 1 failed | ||
1125 | 11 | */ | ||
1126 | 12 | int interlayer_load_devices(const char* dbus_name, const char* object_name); | ||
1127 | 13 | |||
1128 | 14 | /** | ||
1129 | 15 | * Return the information to ret_desc about had registered device. | ||
1130 | 16 | * If the len(devicename) == 0 , the information only include device_name,device_code. | ||
1131 | 17 | * else the information include all method's name, method's code, method's type for the | ||
1132 | 18 | * special device by param 'devicename' point. | ||
1133 | 19 | * | ||
1134 | 20 | * @return 0 successful ; 1 failed | ||
1135 | 21 | */ | ||
1136 | 22 | int interlayer_get_devices_intropect(const char* dbus_name, const char* object_name, const char* devicename,char* ret_desc); | ||
1137 | 23 | |||
1138 | 24 | /** | ||
1139 | 25 | * Call the device method by devicecode and methodcode point. | ||
1140 | 26 | * @param If this device method need a param | ||
1141 | 27 | * @error_no the device method invoke return statuscode | ||
1142 | 28 | * @count | ||
1143 | 29 | * @desc The describtion about the error_no | ||
1144 | 30 | * @return 0 successful ; 1 failed | ||
1145 | 31 | */ | ||
1146 | 32 | int interlayer_call_device_method(int devicecode, int methodcode,const char* param, int* error_no, int* count, char* desc); | ||
1147 | 33 | |||
1148 | 34 | #endif | ||
1149 | 35 | 0 | ||
1150 | === modified file 'src/main.c' | |||
1151 | --- src/main.c 2017-09-05 05:53:02 +0000 | |||
1152 | +++ src/main.c 2017-10-10 00:58:46 +0000 | |||
1153 | @@ -1,9 +1,18 @@ | |||
1154 | 1 | #include <stdio.h> | ||
1155 | 2 | #include <stdlib.h> | ||
1156 | 3 | #include <string.h> | ||
1157 | 4 | #include <unistd.h> | ||
1158 | 5 | #include <signal.h> | ||
1159 | 1 | #include "./dbuslayer/monitor_dbus.h" | 6 | #include "./dbuslayer/monitor_dbus.h" |
1160 | 2 | 7 | ||
1166 | 3 | int main() | 8 | void sigint_handler(int sig){ |
1167 | 4 | { | 9 | dbus_exit(); |
1168 | 5 | // load all device | 10 | printf("dbus_exit here\n"); |
1169 | 6 | dbus_init(); | 11 | exit(EXIT_SUCCESS); |
1170 | 7 | return 0; | 12 | } |
1171 | 13 | int main(int argc, char* argv[]){ | ||
1172 | 8 | 14 | ||
1173 | 15 | signal(SIGINT,sigint_handler); | ||
1174 | 16 | dbus_init(); | ||
1175 | 17 | exit(EXIT_SUCCESS); | ||
1176 | 9 | } | 18 | } |
1177 | 10 | 19 | ||
1178 | === added directory 'src/managerlayer' | |||
1179 | === added file 'src/managerlayer/_configure.c' | |||
1180 | --- src/managerlayer/_configure.c 1970-01-01 00:00:00 +0000 | |||
1181 | +++ src/managerlayer/_configure.c 2017-10-10 00:58:46 +0000 | |||
1182 | @@ -0,0 +1,440 @@ | |||
1183 | 1 | #include <stdlib.h> | ||
1184 | 2 | #include <string.h> | ||
1185 | 3 | #include <stdio.h> | ||
1186 | 4 | #include <sys/types.h> | ||
1187 | 5 | #include <dlfcn.h> | ||
1188 | 6 | #include <dirent.h> | ||
1189 | 7 | #include <sys/stat.h> | ||
1190 | 8 | #include <fcntl.h> | ||
1191 | 9 | #include <glib.h> | ||
1192 | 10 | //#include <libxml2/libxml/parser.h> | ||
1193 | 11 | //#include <libxml2/libxml/tree.h> | ||
1194 | 12 | #include <libxml/parser.h> | ||
1195 | 13 | #include <libxml/tree.h> | ||
1196 | 14 | #include "_configure.h" | ||
1197 | 15 | |||
1198 | 16 | #define WORK_ROOT_DIR "/etc/kydevmonit" | ||
1199 | 17 | #define CONF_SELFCHECK_METHOD_CODE "0x006" | ||
1200 | 18 | |||
1201 | 19 | typedef manager_device_soft_t _conf_device_soft_t; | ||
1202 | 20 | typedef manager_device_static_t _conf_device_static_t; | ||
1203 | 21 | typedef hw_return_t _conf_hw_return_t; | ||
1204 | 22 | |||
1205 | 23 | //static char STOP_STRING[]="\0"; | ||
1206 | 24 | static char _upstream_dbus_name[DESC_BUF_LEN] = {0}; | ||
1207 | 25 | static char _upstream_object_name[DESC_BUF_LEN] = {0}; | ||
1208 | 26 | static CONF_CALLBACK_FUNC _upstream_cb = NULL; | ||
1209 | 27 | |||
1210 | 28 | static GHashTable* _sharelibHandle_ht = NULL; | ||
1211 | 29 | |||
1212 | 30 | void free_hashTable_key(gpointer data){ | ||
1213 | 31 | free(data); | ||
1214 | 32 | } | ||
1215 | 33 | void free_hashTable_value(gpointer data){ | ||
1216 | 34 | free(data); | ||
1217 | 35 | } | ||
1218 | 36 | void free_hashTable_sharelib_value(gpointer data){ | ||
1219 | 37 | dlclose((void*)data); | ||
1220 | 38 | } | ||
1221 | 39 | int | ||
1222 | 40 | _parse_device_conf_xml( | ||
1223 | 41 | GHashTable** devices_static_ht, | ||
1224 | 42 | GHashTable** devices_soft_ht, | ||
1225 | 43 | GHashTable** devices_methods_ht, | ||
1226 | 44 | const char* filename){ | ||
1227 | 45 | //if(filename == NULL) | ||
1228 | 46 | // return -1; | ||
1229 | 47 | char filepath[DESC_BUF_LEN]={0}; | ||
1230 | 48 | snprintf(filepath,DESC_BUF_LEN,"%s/%s",WORK_ROOT_DIR, filename); | ||
1231 | 49 | |||
1232 | 50 | xmlNodePtr curnode; | ||
1233 | 51 | xmlDocPtr doc; | ||
1234 | 52 | xmlInitParser(); | ||
1235 | 53 | doc = xmlReadFile(filepath, "UTF-8", XML_PARSE_RECOVER) ; | ||
1236 | 54 | if(doc == NULL){ | ||
1237 | 55 | fprintf(stderr, "xmlReadFile %s failed\n", filepath); | ||
1238 | 56 | return -1; | ||
1239 | 57 | } | ||
1240 | 58 | curnode = xmlDocGetRootElement(doc); | ||
1241 | 59 | if(curnode == NULL){ | ||
1242 | 60 | fprintf(stderr, "empty document\n"); | ||
1243 | 61 | xmlFreeDoc(doc); | ||
1244 | 62 | return -1; | ||
1245 | 63 | } | ||
1246 | 64 | // printf("curnode->name: %s\n", curnode->name); | ||
1247 | 65 | // curnode = curnode->xmlChildrenNode; | ||
1248 | 66 | xmlChar * nodevalue = NULL; | ||
1249 | 67 | xmlChar * devicecode = NULL; | ||
1250 | 68 | xmlChar * methodcode = NULL; | ||
1251 | 69 | xmlChar * methodtype = NULL; | ||
1252 | 70 | xmlChar * devicedriver = NULL; | ||
1253 | 71 | void * sharelibHandle = NULL; | ||
1254 | 72 | _conf_device_soft_t* soft_value_ptr = NULL; | ||
1255 | 73 | int statuscode = 0; | ||
1256 | 74 | while(curnode != NULL){ | ||
1257 | 75 | if(xmlStrcmp(curnode->name, (const xmlChar*)"object") == 0){ | ||
1258 | 76 | nodevalue = xmlGetProp(curnode, (const xmlChar*)"name"); | ||
1259 | 77 | //printf("nodevalue: %s\n", nodevalue); | ||
1260 | 78 | if(xmlStrncmp(nodevalue, _upstream_object_name, strlen(_upstream_object_name)) != 0){ | ||
1261 | 79 | fprintf(stderr,"The object_name %s is not matched\n", nodevalue); | ||
1262 | 80 | statuscode = -1; | ||
1263 | 81 | }else{ | ||
1264 | 82 | //_init_write_devices_intropect_xml(object_name); | ||
1265 | 83 | //printf("DEBUG: new device finded\n"); | ||
1266 | 84 | if(*devices_static_ht == NULL) | ||
1267 | 85 | *devices_static_ht = g_hash_table_new_full(g_str_hash, g_str_equal,free_hashTable_key,free_hashTable_value); | ||
1268 | 86 | //if(devices_static_ht == NULL) | ||
1269 | 87 | // printf("DEBUG: g_hash_table_new_full failed! devices_static_ht is null\n"); | ||
1270 | 88 | if(*devices_soft_ht == NULL) | ||
1271 | 89 | *devices_soft_ht = g_hash_table_new_full(g_str_hash,g_str_equal, free_hashTable_key, free_hashTable_value); | ||
1272 | 90 | if(*devices_methods_ht == NULL) | ||
1273 | 91 | *devices_methods_ht = g_hash_table_new_full(g_str_hash, g_str_equal, free_hashTable_key,free_hashTable_value); | ||
1274 | 92 | } | ||
1275 | 93 | xmlFree(nodevalue); | ||
1276 | 94 | curnode = curnode->xmlChildrenNode; | ||
1277 | 95 | if(statuscode < 0) break; | ||
1278 | 96 | } | ||
1279 | 97 | else if(xmlStrcmp(curnode->name, (const xmlChar*)"device") == 0){ | ||
1280 | 98 | devicecode = xmlGetProp(curnode, "code"); | ||
1281 | 99 | if(devicecode == NULL){ | ||
1282 | 100 | fprintf(stderr, "The device hasn't code,this is invailed!\n"); | ||
1283 | 101 | statuscode = -1; | ||
1284 | 102 | break; | ||
1285 | 103 | } | ||
1286 | 104 | // check this device is registed? | ||
1287 | 105 | _conf_device_static_t* ds_value_ptr = (_conf_device_static_t*)g_hash_table_lookup(*devices_static_ht,devicecode); | ||
1288 | 106 | if(ds_value_ptr != NULL && ds_value_ptr->is_registed != 1){ | ||
1289 | 107 | xmlFree(devicecode); | ||
1290 | 108 | //statuscode = -1; | ||
1291 | 109 | break; // Skip this device. | ||
1292 | 110 | } | ||
1293 | 111 | nodevalue = xmlGetProp(curnode, "name"); | ||
1294 | 112 | if(nodevalue == NULL){ | ||
1295 | 113 | fprintf(stderr, "The device hasn't name,this is invailed!\n"); | ||
1296 | 114 | statuscode = -1; | ||
1297 | 115 | xmlFree(devicecode); | ||
1298 | 116 | break; | ||
1299 | 117 | } | ||
1300 | 118 | // load so | ||
1301 | 119 | devicedriver = xmlGetProp(curnode, "driver"); | ||
1302 | 120 | if(devicedriver == NULL){ | ||
1303 | 121 | fprintf(stderr, "The device hasn't driver,this is invailed!\n"); | ||
1304 | 122 | statuscode = -1; | ||
1305 | 123 | xmlFree(nodevalue); | ||
1306 | 124 | xmlFree(devicecode); | ||
1307 | 125 | break; | ||
1308 | 126 | } | ||
1309 | 127 | memset(filepath, 0 , DESC_BUF_LEN); | ||
1310 | 128 | snprintf(filepath, DESC_BUF_LEN, "%s/%s",WORK_ROOT_DIR,devicedriver); | ||
1311 | 129 | printf("driver path: %s\n", filepath); | ||
1312 | 130 | sharelibHandle = dlopen(filepath, RTLD_LAZY); | ||
1313 | 131 | if(sharelibHandle == NULL){ | ||
1314 | 132 | fprintf(stderr, "%s sharelibHandle is NULL\n", filepath); | ||
1315 | 133 | xmlFree(devicecode); | ||
1316 | 134 | statuscode = -1; | ||
1317 | 135 | }else{ | ||
1318 | 136 | //_add_device_to_intropect_xml(nodevalue, devicecode); | ||
1319 | 137 | //_init_method_hashtable(); | ||
1320 | 138 | if(ds_value_ptr == NULL){ // new device, add to queue | ||
1321 | 139 | _upstream_cb(CONF_CBTYPE_DRIVER_ADDED,devicecode,nodevalue); | ||
1322 | 140 | dlclose(sharelibHandle); | ||
1323 | 141 | xmlFree(devicecode); | ||
1324 | 142 | xmlFree(nodevalue); | ||
1325 | 143 | xmlFree(devicedriver); | ||
1326 | 144 | break; // Skip this device; | ||
1327 | 145 | }else{ | ||
1328 | 146 | if(_sharelibHandle_ht == NULL) | ||
1329 | 147 | _sharelibHandle_ht = g_hash_table_new_full(g_str_hash, g_str_equal,free_hashTable_key,free_hashTable_sharelib_value); | ||
1330 | 148 | char* key_ptr = (char*)malloc(strlen(devicecode)+1); | ||
1331 | 149 | snprintf(key_ptr, sizeof(key_ptr),"%s",devicecode); | ||
1332 | 150 | g_hash_table_insert(_sharelibHandle_ht,key_ptr,sharelibHandle); | ||
1333 | 151 | soft_value_ptr = (_conf_device_soft_t*)malloc(sizeof(_conf_device_soft_t)); | ||
1334 | 152 | soft_value_ptr->device_code = strtol(devicecode,NULL,16); | ||
1335 | 153 | soft_value_ptr->is_online = 0; | ||
1336 | 154 | soft_value_ptr->workstate = WORK_STATE_UNKNOW; | ||
1337 | 155 | // other entry unknow. | ||
1338 | 156 | g_hash_table_insert(*devices_soft_ht,strdup(key_ptr),soft_value_ptr); // !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! | ||
1339 | 157 | // don't usr the same key_ptr?? | ||
1340 | 158 | } | ||
1341 | 159 | } | ||
1342 | 160 | curnode = curnode->xmlChildrenNode; | ||
1343 | 161 | xmlFree(nodevalue); | ||
1344 | 162 | xmlFree(devicedriver); | ||
1345 | 163 | |||
1346 | 164 | if(statuscode < 0) break; | ||
1347 | 165 | else continue; | ||
1348 | 166 | }else if(xmlStrcmp(curnode->name, (const xmlChar*)"method") == 0){ | ||
1349 | 167 | nodevalue = xmlGetProp(curnode, "name"); | ||
1350 | 168 | if(nodevalue == NULL){ | ||
1351 | 169 | fprintf(stderr, "method hasn't name, this is invaild!\n"); | ||
1352 | 170 | curnode = curnode->next; | ||
1353 | 171 | continue; | ||
1354 | 172 | } | ||
1355 | 173 | methodcode = xmlGetProp(curnode, "code"); | ||
1356 | 174 | if(methodcode == NULL){ | ||
1357 | 175 | fprintf(stderr, "method %s hasn't code, this is invaild!\n", nodevalue); | ||
1358 | 176 | curnode = curnode->next; | ||
1359 | 177 | xmlFree(nodevalue); | ||
1360 | 178 | continue; | ||
1361 | 179 | } | ||
1362 | 180 | methodtype = xmlGetProp(curnode, "type"); | ||
1363 | 181 | if(methodtype == NULL){ | ||
1364 | 182 | fprintf(stderr, "method hasn't type, this is invaild!\n"); | ||
1365 | 183 | xmlFree(methodcode); | ||
1366 | 184 | xmlFree(nodevalue); | ||
1367 | 185 | curnode = curnode->next; | ||
1368 | 186 | continue; | ||
1369 | 187 | } | ||
1370 | 188 | |||
1371 | 189 | void* methodaddr = dlsym(sharelibHandle,nodevalue); | ||
1372 | 190 | conf_device_method_t* method_value_ptr = malloc(sizeof(conf_device_method_t)); | ||
1373 | 191 | method_value_ptr->address = methodaddr; | ||
1374 | 192 | |||
1375 | 193 | printf("method name : %s, address : %u\n", nodevalue, (unsigned int)methodaddr); | ||
1376 | 194 | |||
1377 | 195 | method_value_ptr->type = strtol(methodtype,NULL,10); | ||
1378 | 196 | |||
1379 | 197 | char* key_ptr = malloc(strlen(devicecode)+strlen(methodcode)+1); | ||
1380 | 198 | sprintf(key_ptr, "%s%s", devicecode,methodcode); | ||
1381 | 199 | printf("key: %s len=%lu\n", key_ptr, strlen(key_ptr)); | ||
1382 | 200 | g_hash_table_insert(*devices_methods_ht, key_ptr, method_value_ptr); | ||
1383 | 201 | if(xmlStrcmp(methodcode, CONF_SELFCHECK_METHOD_CODE) == 0){ | ||
1384 | 202 | // call self_check; | ||
1385 | 203 | |||
1386 | 204 | _conf_hw_return_t result={0,0,{0}}; | ||
1387 | 205 | //result.desc = soft_value_ptr->desc; | ||
1388 | 206 | NO_INPUT_NO_BLOCK_FUNC self_check = (NO_INPUT_NO_BLOCK_FUNC)methodaddr; | ||
1389 | 207 | self_check(&result); | ||
1390 | 208 | soft_value_ptr->workstate = result.state_code; | ||
1391 | 209 | soft_value_ptr->exception_code = result.exception_code; | ||
1392 | 210 | soft_value_ptr->is_online = (result.exception_code == 0x01)?1:0; | ||
1393 | 211 | memset(soft_value_ptr->desc,0,DESC_BUF_LEN); | ||
1394 | 212 | snprintf(soft_value_ptr->desc,DESC_BUF_LEN,"%s",result.desc); | ||
1395 | 213 | |||
1396 | 214 | } | ||
1397 | 215 | xmlFree(methodtype); | ||
1398 | 216 | xmlFree(nodevalue); | ||
1399 | 217 | xmlFree(methodcode); | ||
1400 | 218 | } | ||
1401 | 219 | curnode = curnode->next; | ||
1402 | 220 | } | ||
1403 | 221 | xmlFreeDoc(doc); | ||
1404 | 222 | return statuscode; | ||
1405 | 223 | } | ||
1406 | 224 | int _parse_devices_state_xml(GHashTable** devices_static_ht){ | ||
1407 | 225 | // load state informations for all devices. | ||
1408 | 226 | char path_buf[1024] = {0}; | ||
1409 | 227 | snprintf(path_buf, 1024, "%s/devices.%s.xml",WORK_ROOT_DIR,_upstream_dbus_name); | ||
1410 | 228 | printf("DEBUG: static file path: %s\n", path_buf); | ||
1411 | 229 | |||
1412 | 230 | xmlNodePtr curnode; | ||
1413 | 231 | xmlDocPtr doc; | ||
1414 | 232 | int statuscode = 0; | ||
1415 | 233 | |||
1416 | 234 | xmlInitParser(); | ||
1417 | 235 | doc = xmlReadFile(path_buf, "UTF-8", XML_PARSE_RECOVER); | ||
1418 | 236 | if(doc == NULL){ | ||
1419 | 237 | fprintf(stderr, "%s read failed, it exist?\n", path_buf); | ||
1420 | 238 | devices_static_ht == NULL; | ||
1421 | 239 | return 0; | ||
1422 | 240 | } | ||
1423 | 241 | curnode = xmlDocGetRootElement(doc); | ||
1424 | 242 | if(curnode == NULL){ | ||
1425 | 243 | fprintf(stderr, "empty document\n"); | ||
1426 | 244 | xmlFreeDoc(doc); | ||
1427 | 245 | return -1; | ||
1428 | 246 | } | ||
1429 | 247 | // printf("curnode->name: %s\n", curnode->name); | ||
1430 | 248 | // curnode = curnode->xmlChildrenNode; | ||
1431 | 249 | xmlChar* namevalue = NULL; | ||
1432 | 250 | xmlChar* codevalue = NULL; | ||
1433 | 251 | xmlChar* registervalue = NULL; | ||
1434 | 252 | |||
1435 | 253 | while(curnode != NULL){ | ||
1436 | 254 | if(xmlStrcmp(curnode->name, (const xmlChar*)"object") == 0){ | ||
1437 | 255 | namevalue = xmlGetProp(curnode, (const xmlChar*)"name"); | ||
1438 | 256 | //printf("nodevalue: %s\n", nodevalue); | ||
1439 | 257 | if(xmlStrncmp(namevalue, _upstream_object_name, strlen(_upstream_object_name)) != 0){ | ||
1440 | 258 | fprintf(stderr,"The object_name %s is not matched\n", namevalue); | ||
1441 | 259 | statuscode = -1; | ||
1442 | 260 | }else{ | ||
1443 | 261 | // init hashtable | ||
1444 | 262 | *devices_static_ht=g_hash_table_new_full(g_str_hash, g_str_equal, free_hashTable_key, free_hashTable_value); | ||
1445 | 263 | if(*devices_static_ht == NULL){ | ||
1446 | 264 | fprintf(stderr,"device_static_ht create failed\n"); | ||
1447 | 265 | statuscode = -1; | ||
1448 | 266 | } | ||
1449 | 267 | } | ||
1450 | 268 | xmlFree(namevalue); | ||
1451 | 269 | curnode = curnode->xmlChildrenNode; | ||
1452 | 270 | if(statuscode < 0) break; | ||
1453 | 271 | } | ||
1454 | 272 | else if(xmlStrcmp(curnode->name, (const xmlChar*)"device") == 0){ | ||
1455 | 273 | if(devices_static_ht == NULL){ | ||
1456 | 274 | fprintf(stderr, "The device_static_ht is NULL, it is invaild!\n"); | ||
1457 | 275 | statuscode = -1; | ||
1458 | 276 | break; | ||
1459 | 277 | } | ||
1460 | 278 | namevalue = xmlGetProp(curnode, "name"); | ||
1461 | 279 | if(namevalue == NULL){ | ||
1462 | 280 | fprintf(stderr, "The device hasn't name,this is invailed!\n"); | ||
1463 | 281 | statuscode = -1; | ||
1464 | 282 | break; | ||
1465 | 283 | } | ||
1466 | 284 | codevalue = xmlGetProp(curnode, "code"); | ||
1467 | 285 | if(codevalue == NULL){ | ||
1468 | 286 | fprintf(stderr, "The device hasn't code,this is invailed!\n"); | ||
1469 | 287 | xmlFree(namevalue); | ||
1470 | 288 | statuscode = -1; | ||
1471 | 289 | break; | ||
1472 | 290 | } | ||
1473 | 291 | registervalue = xmlGetProp(curnode, "regist"); | ||
1474 | 292 | if(registervalue == NULL){ | ||
1475 | 293 | fprintf(stderr, "The device no regist info, this is invailed!\n"); | ||
1476 | 294 | xmlFree(namevalue); | ||
1477 | 295 | xmlFree(codevalue); | ||
1478 | 296 | statuscode = -1; | ||
1479 | 297 | break; | ||
1480 | 298 | } | ||
1481 | 299 | _conf_device_static_t* value_ptr = (_conf_device_static_t*)malloc(sizeof(_conf_device_static_t)); | ||
1482 | 300 | value_ptr->device_code = strtol(codevalue,NULL,16); | ||
1483 | 301 | snprintf(value_ptr->device_name, sizeof(value_ptr->device_name),"%s",namevalue); | ||
1484 | 302 | value_ptr->is_registed = strtol(registervalue,NULL,10); | ||
1485 | 303 | char* key_ptr = (char*)malloc(strlen(codevalue)+1); | ||
1486 | 304 | snprintf(key_ptr, sizeof(key_ptr),"%s",codevalue); | ||
1487 | 305 | |||
1488 | 306 | g_hash_table_insert(*devices_static_ht, key_ptr, value_ptr); | ||
1489 | 307 | |||
1490 | 308 | xmlFree(namevalue); | ||
1491 | 309 | xmlFree(codevalue); | ||
1492 | 310 | xmlFree(registervalue); | ||
1493 | 311 | |||
1494 | 312 | curnode = curnode->next; | ||
1495 | 313 | } | ||
1496 | 314 | else{ | ||
1497 | 315 | fprintf(stderr,"DEBUG: Go to Next node!\n"); | ||
1498 | 316 | curnode = curnode->next; | ||
1499 | 317 | } | ||
1500 | 318 | } | ||
1501 | 319 | xmlFreeDoc(doc); | ||
1502 | 320 | return statuscode; | ||
1503 | 321 | } | ||
1504 | 322 | |||
1505 | 323 | int | ||
1506 | 324 | conf_init(const char* dbus_name, const char* object_name, | ||
1507 | 325 | GHashTable** devices_methods_ht, | ||
1508 | 326 | GHashTable** devices_soft_ht, | ||
1509 | 327 | GHashTable** devices_static_ht, | ||
1510 | 328 | CONF_CALLBACK_FUNC upstream_callback){ | ||
1511 | 329 | // copy name | ||
1512 | 330 | strncpy(_upstream_dbus_name, dbus_name, MIN(strlen(dbus_name), DESC_BUF_LEN)); | ||
1513 | 331 | strncpy(_upstream_object_name,object_name, MIN(strlen(object_name), DESC_BUF_LEN)); | ||
1514 | 332 | if(upstream_callback == NULL){ | ||
1515 | 333 | fprintf(stderr, "_conf_callback is null!\n"); | ||
1516 | 334 | return -1; | ||
1517 | 335 | } | ||
1518 | 336 | _upstream_cb = upstream_callback; | ||
1519 | 337 | |||
1520 | 338 | if(_parse_devices_state_xml(devices_static_ht) < 0){ | ||
1521 | 339 | fprintf(stderr, "_parse_devices_state_xml failed!\n"); | ||
1522 | 340 | return -1; | ||
1523 | 341 | } | ||
1524 | 342 | |||
1525 | 343 | // Loop match xml file | ||
1526 | 344 | DIR *workdp; | ||
1527 | 345 | struct dirent *entry; | ||
1528 | 346 | if((workdp = opendir(WORK_ROOT_DIR)) == NULL){ | ||
1529 | 347 | fprintf(stderr, "opendir %s failed,no devices\n", WORK_ROOT_DIR); | ||
1530 | 348 | return -1; | ||
1531 | 349 | } | ||
1532 | 350 | //chdir(WORK_ROOT_DIR); | ||
1533 | 351 | while((entry = readdir(workdp)) != NULL){ | ||
1534 | 352 | if(strncmp(dbus_name,entry->d_name, strlen(dbus_name)) == 0){ | ||
1535 | 353 | |||
1536 | 354 | if(_parse_device_conf_xml(devices_static_ht, devices_soft_ht, devices_methods_ht,entry->d_name) < 0){ | ||
1537 | 355 | fprintf(stderr, "%s parse failed!\n", entry->d_name); | ||
1538 | 356 | } | ||
1539 | 357 | else{ | ||
1540 | 358 | printf("%s load successful\n", entry->d_name); | ||
1541 | 359 | } | ||
1542 | 360 | } | ||
1543 | 361 | } | ||
1544 | 362 | closedir(workdp); | ||
1545 | 363 | if(*devices_static_ht == NULL){ | ||
1546 | 364 | printf("After conf_init, devices_static_ht is null\n"); | ||
1547 | 365 | |||
1548 | 366 | } | ||
1549 | 367 | |||
1550 | 368 | return 0; | ||
1551 | 369 | } | ||
1552 | 370 | void _hashtable_foreach_func(gpointer key, gpointer value, gpointer user_data){ | ||
1553 | 371 | xmlNodePtr doc_rootnode = (xmlNodePtr)user_data; | ||
1554 | 372 | _conf_device_static_t* value_ptr = (_conf_device_static_t*)value; | ||
1555 | 373 | xmlNodePtr devicenode = xmlNewChild(doc_rootnode, NULL, "device", ""); | ||
1556 | 374 | xmlNewProp(devicenode, "name", value_ptr->device_name); | ||
1557 | 375 | char buf[1024] = {0}; | ||
1558 | 376 | snprintf(buf,1024,"0x%.2x",value_ptr->device_code); | ||
1559 | 377 | xmlNewProp(devicenode, "code", buf); | ||
1560 | 378 | |||
1561 | 379 | memset(buf, 0, 1024); | ||
1562 | 380 | snprintf(buf,1024,"%d",value_ptr->is_registed); | ||
1563 | 381 | xmlNewProp(devicenode,"regist", buf); | ||
1564 | 382 | } | ||
1565 | 383 | int | ||
1566 | 384 | conf_end_writeToDisk(GHashTable* devices_static_ht){ | ||
1567 | 385 | if(devices_static_ht == NULL) return -1; | ||
1568 | 386 | xmlDocPtr doc; | ||
1569 | 387 | xmlNodePtr doc_rootnode; | ||
1570 | 388 | |||
1571 | 389 | doc = xmlNewDoc("1.0"); | ||
1572 | 390 | doc_rootnode = xmlNewNode(NULL, "object"); | ||
1573 | 391 | xmlNewProp(doc_rootnode,"name", _upstream_object_name); | ||
1574 | 392 | xmlDocSetRootElement(doc,doc_rootnode); | ||
1575 | 393 | |||
1576 | 394 | g_hash_table_foreach(devices_static_ht,_hashtable_foreach_func,doc_rootnode); | ||
1577 | 395 | |||
1578 | 396 | char filename[1024]={0}; | ||
1579 | 397 | snprintf(filename,1024,"%s/devices.%s.xml", WORK_ROOT_DIR, _upstream_dbus_name); | ||
1580 | 398 | printf("intropect xml filename: %s\n", filename); | ||
1581 | 399 | if(xmlSaveFormatFileEnc(filename, doc, "UTF-8", 1) >=0){ | ||
1582 | 400 | printf("Save intropectdoc xml file successful\n"); | ||
1583 | 401 | }else{ | ||
1584 | 402 | printf("Save intropectdoc xml file failed\n"); | ||
1585 | 403 | } | ||
1586 | 404 | xmlFreeDoc(doc); | ||
1587 | 405 | xmlCleanupParser(); | ||
1588 | 406 | |||
1589 | 407 | // free sharelibHandle_ht | ||
1590 | 408 | g_hash_table_destroy(_sharelibHandle_ht); | ||
1591 | 409 | _sharelibHandle_ht = NULL; | ||
1592 | 410 | return 0; | ||
1593 | 411 | } | ||
1594 | 412 | |||
1595 | 413 | int | ||
1596 | 414 | conf_enable_driver(const char* device_name, | ||
1597 | 415 | GHashTable* devices_methods_ht, | ||
1598 | 416 | GHashTable* devices_soft_ht, | ||
1599 | 417 | GHashTable* devices_static_ht){ | ||
1600 | 418 | char filename[DESC_BUF_LEN] = {0}; | ||
1601 | 419 | |||
1602 | 420 | snprintf(filename, DESC_BUF_LEN,"%s.%s.xml",_upstream_dbus_name,device_name); | ||
1603 | 421 | return _parse_device_conf_xml(&devices_static_ht,&devices_soft_ht,&devices_methods_ht,(const char*)filename); | ||
1604 | 422 | } | ||
1605 | 423 | |||
1606 | 424 | gboolean _dm_hashTable_HRFunc(gpointer key, gpointer value,gpointer user_data){ | ||
1607 | 425 | char* key_ptr = (char*)key; | ||
1608 | 426 | char* codevalue_ptr = (char*)user_data; | ||
1609 | 427 | if(strncmp(key_ptr,codevalue_ptr,strlen(codevalue_ptr)) == 0) | ||
1610 | 428 | return TRUE; | ||
1611 | 429 | else | ||
1612 | 430 | return FALSE; | ||
1613 | 431 | } | ||
1614 | 432 | int | ||
1615 | 433 | conf_disable_driver(GHashTable* devices_methods_ht,int device_code){ | ||
1616 | 434 | if(_sharelibHandle_ht == NULL) | ||
1617 | 435 | return 0; | ||
1618 | 436 | char codevalue[10] = {0}; | ||
1619 | 437 | snprintf(codevalue, sizeof(codevalue),"0x%.2x",device_code); | ||
1620 | 438 | |||
1621 | 439 | return g_hash_table_foreach_remove(devices_methods_ht,_dm_hashTable_HRFunc,codevalue) && g_hash_table_remove(_sharelibHandle_ht,codevalue); | ||
1622 | 440 | } | ||
1623 | 0 | 441 | ||
1624 | === added file 'src/managerlayer/_configure.h' | |||
1625 | --- src/managerlayer/_configure.h 1970-01-01 00:00:00 +0000 | |||
1626 | +++ src/managerlayer/_configure.h 2017-10-10 00:58:46 +0000 | |||
1627 | @@ -0,0 +1,51 @@ | |||
1628 | 1 | #ifndef ___CONFIGURE_H__ | ||
1629 | 2 | #define ___CONFIGURE_H__ | ||
1630 | 3 | |||
1631 | 4 | #include <glib.h> | ||
1632 | 5 | #include "manager.h" | ||
1633 | 6 | |||
1634 | 7 | #define CONF_CBTYPE_DRIVER_CHANGED 0 | ||
1635 | 8 | #define CONF_CBTYPE_DRIVER_ADDED 1 | ||
1636 | 9 | #define CONF_CBTYPE_DRIVER_REMOVED 2 | ||
1637 | 10 | |||
1638 | 11 | #define CONF_METHOD_TYPE_HASINPUT 1 | ||
1639 | 12 | #define CONF_METHOD_TYPE_HASBLOCK 2 | ||
1640 | 13 | |||
1641 | 14 | |||
1642 | 15 | |||
1643 | 16 | typedef struct{ | ||
1644 | 17 | void * address; | ||
1645 | 18 | int type; | ||
1646 | 19 | }conf_device_method_t; // This is the value of hashtable device_method_ht, key is | ||
1647 | 20 | |||
1648 | 21 | typedef void (*NO_INPUT_NO_BLOCK_FUNC)(void* return_ptr); | ||
1649 | 22 | typedef void (*NO_INPUT_BLOCK_FUNC)(void* return_ptr, int time); | ||
1650 | 23 | typedef void (*HAS_INPUT_NO_BLOCK_FUNC)(const char* input, void* return_ptr); | ||
1651 | 24 | typedef void (*HAS_INPUT_BLOCK_FUNC)(const char* input, void* return_ptr,int time); | ||
1652 | 25 | |||
1653 | 26 | |||
1654 | 27 | /** | ||
1655 | 28 | * @param callback_type 0: _CONF_DRIVER_CHANGED, 1: _CONF_DRIVER_ADDED, 2: _CONF_DRIVER_REMOVED | ||
1656 | 29 | */ | ||
1657 | 30 | typedef void (*CONF_CALLBACK_FUNC)(int callback_type, char* device_code, char* device_name); | ||
1658 | 31 | |||
1659 | 32 | |||
1660 | 33 | /** | ||
1661 | 34 | * Load the configure files, then init all data structures. | ||
1662 | 35 | */ | ||
1663 | 36 | int conf_init(const char* dbus_name, const char* object_name, | ||
1664 | 37 | GHashTable** devices_method_ht, | ||
1665 | 38 | GHashTable** devices_soft_ht, | ||
1666 | 39 | GHashTable** devices_static_ht, | ||
1667 | 40 | CONF_CALLBACK_FUNC); | ||
1668 | 41 | |||
1669 | 42 | int conf_end_writeToDisk(GHashTable* devices_static_ht); | ||
1670 | 43 | |||
1671 | 44 | int conf_enable_driver(const char* device_name, | ||
1672 | 45 | GHashTable* devices_methods_ht, | ||
1673 | 46 | GHashTable* devices_soft_ht, | ||
1674 | 47 | GHashTable* devices_static_ht); | ||
1675 | 48 | |||
1676 | 49 | int conf_disable_driver(GHashTable* devices_methods_ht, int device_code); | ||
1677 | 50 | |||
1678 | 51 | #endif // ___CONFIGURE_H__ | ||
1679 | 0 | 52 | ||
1680 | === added file 'src/managerlayer/manager.c' | |||
1681 | --- src/managerlayer/manager.c 1970-01-01 00:00:00 +0000 | |||
1682 | +++ src/managerlayer/manager.c 2017-10-10 00:58:46 +0000 | |||
1683 | @@ -0,0 +1,235 @@ | |||
1684 | 1 | #include <unistd.h> | ||
1685 | 2 | #include <stdio.h> | ||
1686 | 3 | #include <stdlib.h> | ||
1687 | 4 | #include <string.h> | ||
1688 | 5 | #include <sys/types.h> | ||
1689 | 6 | #include <dlfcn.h> | ||
1690 | 7 | #include <dirent.h> | ||
1691 | 8 | #include <sys/stat.h> | ||
1692 | 9 | #include <fcntl.h> | ||
1693 | 10 | #include <glib.h> | ||
1694 | 11 | |||
1695 | 12 | #include "manager.h" | ||
1696 | 13 | #include "_configure.h" | ||
1697 | 14 | |||
1698 | 15 | #define DEVICE_BLOCK_METHOD_TIMEOUT 10 // seconds | ||
1699 | 16 | #define EXCEPTION_CODE_NO_DEVICE 0x01 | ||
1700 | 17 | #define EXCEPTION_CODE_NO_DEVICE_METHOD 0x02 | ||
1701 | 18 | #define EXCEPTION_CODE_INVAILD_OP 0x04 | ||
1702 | 19 | |||
1703 | 20 | static MANAGER_CALLBACK_FUNC _upstream_cb = NULL; | ||
1704 | 21 | static GHashTable* _devices_static_ht = NULL; | ||
1705 | 22 | static GHashTable* _devices_soft_ht = NULL; | ||
1706 | 23 | static GHashTable* _devices_methods_ht = NULL; | ||
1707 | 24 | |||
1708 | 25 | static void | ||
1709 | 26 | _deal_conf_callback(int callback_type, char* device_code, char* device_name){ | ||
1710 | 27 | switch(callback_type){ | ||
1711 | 28 | case CONF_CBTYPE_DRIVER_ADDED:{ | ||
1712 | 29 | manager_device_static_t* value_ptr = (manager_device_static_t*)malloc(sizeof(manager_device_static_t)); | ||
1713 | 30 | value_ptr->device_code = strtol(device_code,NULL,16); | ||
1714 | 31 | snprintf(value_ptr->device_name,sizeof(value_ptr->device_name),"%s",device_name); | ||
1715 | 32 | value_ptr->is_registed = 0; | ||
1716 | 33 | char* key_ptr = (char*)malloc(strlen(device_code)+1); | ||
1717 | 34 | snprintf(key_ptr,sizeof(key_ptr),"%s",device_code); | ||
1718 | 35 | g_hash_table_insert(_devices_static_ht,key_ptr,value_ptr); | ||
1719 | 36 | printf("finded new device: 0x%.2x,%s, %d\n",value_ptr->device_code,value_ptr->device_name,value_ptr->is_registed); | ||
1720 | 37 | break; | ||
1721 | 38 | } | ||
1722 | 39 | case CONF_CBTYPE_DRIVER_CHANGED: | ||
1723 | 40 | break; | ||
1724 | 41 | case CONF_CBTYPE_DRIVER_REMOVED: | ||
1725 | 42 | break; | ||
1726 | 43 | default: | ||
1727 | 44 | break; | ||
1728 | 45 | } | ||
1729 | 46 | } | ||
1730 | 47 | |||
1731 | 48 | /************************** Interfaces ***********************************/ | ||
1732 | 49 | int | ||
1733 | 50 | manager_init(const char* dbus_name, const char* object_name, MANAGER_CALLBACK_FUNC upstream_cb){ | ||
1734 | 51 | if(upstream_cb == NULL){ | ||
1735 | 52 | fprintf(stderr, "callback_func is null!\n"); | ||
1736 | 53 | return -1; | ||
1737 | 54 | } | ||
1738 | 55 | if(dbus_name == NULL || object_name == NULL){ | ||
1739 | 56 | fprintf(stderr, "dbus_name or object_name is null!\n"); | ||
1740 | 57 | return -1; | ||
1741 | 58 | } | ||
1742 | 59 | |||
1743 | 60 | _upstream_cb = upstream_cb; | ||
1744 | 61 | printf("manager_init here\n"); | ||
1745 | 62 | conf_init(dbus_name, object_name,&_devices_methods_ht,&_devices_soft_ht,&_devices_static_ht,(CONF_CALLBACK_FUNC)_deal_conf_callback); | ||
1746 | 63 | if(_devices_static_ht == NULL){ | ||
1747 | 64 | printf("After conf_init, _devices_static_ht is null\n"); | ||
1748 | 65 | |||
1749 | 66 | } | ||
1750 | 67 | return 0; | ||
1751 | 68 | } | ||
1752 | 69 | |||
1753 | 70 | int | ||
1754 | 71 | manager_call_device_method(int device_code, int method_code, const char* param, dbus_return_t* rt){ | ||
1755 | 72 | if(_devices_soft_ht == NULL || _devices_methods_ht == NULL){ | ||
1756 | 73 | rt->state_code = WORK_STATE_UNKNOW; | ||
1757 | 74 | rt->exception_code = 0x20000; | ||
1758 | 75 | snprintf(rt->desc, DESC_BUF_LEN, "The hashtable is null!"); | ||
1759 | 76 | return -1; | ||
1760 | 77 | } | ||
1761 | 78 | char codevalue[10]={0}; | ||
1762 | 79 | snprintf(codevalue,sizeof(codevalue),"0x%.2x",device_code); | ||
1763 | 80 | |||
1764 | 81 | manager_device_soft_t* soft_value_ptr = g_hash_table_lookup(_devices_soft_ht,codevalue); | ||
1765 | 82 | if(soft_value_ptr == NULL){ | ||
1766 | 83 | rt->state_code = WORK_STATE_UNKNOW; | ||
1767 | 84 | rt->exception_code = 0x20000 | EXCEPTION_CODE_NO_DEVICE; | ||
1768 | 85 | snprintf(rt->desc, DESC_BUF_LEN, "The device of 0x%.2x hasn't registed.", device_code); | ||
1769 | 86 | //fprintf(stderr,"The soft_value_ptr of %d not exist!\n",device_code); | ||
1770 | 87 | return -1; | ||
1771 | 88 | } | ||
1772 | 89 | if(soft_value_ptr->workstate == WORK_STATE_PROCESSING){ | ||
1773 | 90 | rt->state_code = WORK_STATE_PROCESSING; | ||
1774 | 91 | rt->exception_code = 0x20000| EXCEPTION_CODE_INVAILD_OP; | ||
1775 | 92 | snprintf(rt->desc,DESC_BUF_LEN,"This device is processing a job,please wait!\n"); | ||
1776 | 93 | return -1; | ||
1777 | 94 | } | ||
1778 | 95 | char key[20] = {0}; | ||
1779 | 96 | snprintf(key,sizeof(key),"%s0x%.3x",codevalue, method_code); | ||
1780 | 97 | printf("call_key: %s ,len=%lu\n", key, strlen(key)); | ||
1781 | 98 | |||
1782 | 99 | conf_device_method_t* method_ptr = g_hash_table_lookup(_devices_methods_ht,key); | ||
1783 | 100 | if(method_ptr == NULL){ | ||
1784 | 101 | rt->state_code = WORK_STATE_UNKNOW; | ||
1785 | 102 | rt->exception_code = 0x20000 | EXCEPTION_CODE_NO_DEVICE_METHOD; | ||
1786 | 103 | snprintf(rt->desc,DESC_BUF_LEN,"The method 0x%.3x don't exist!", method_code); | ||
1787 | 104 | return -1; | ||
1788 | 105 | } | ||
1789 | 106 | |||
1790 | 107 | if(method_ptr->type == CONF_METHOD_TYPE_HASINPUT) | ||
1791 | 108 | ((HAS_INPUT_NO_BLOCK_FUNC)(method_ptr->address))(param,rt); | ||
1792 | 109 | else if(method_ptr->type == CONF_METHOD_TYPE_HASBLOCK) | ||
1793 | 110 | ((NO_INPUT_BLOCK_FUNC)(method_ptr->address))(rt,_upstream_cb);// !!! | ||
1794 | 111 | else if(method_ptr->type == (CONF_METHOD_TYPE_HASBLOCK | CONF_METHOD_TYPE_HASINPUT)) | ||
1795 | 112 | ((HAS_INPUT_BLOCK_FUNC)(method_ptr->address))(param,rt,_upstream_cb); | ||
1796 | 113 | else // 0 | ||
1797 | 114 | ((NO_INPUT_NO_BLOCK_FUNC)(method_ptr->address))(rt); | ||
1798 | 115 | rt->exception_code = rt->exception_code | 0x10000; | ||
1799 | 116 | rt->exception_code = rt->exception_code | (device_code<<8); | ||
1800 | 117 | soft_value_ptr->workstate = rt->state_code; | ||
1801 | 118 | soft_value_ptr->exception_code = rt->exception_code; | ||
1802 | 119 | memset(soft_value_ptr->desc,0,DESC_BUF_LEN); | ||
1803 | 120 | snprintf(soft_value_ptr->desc, DESC_BUF_LEN, "%s",rt->desc); | ||
1804 | 121 | |||
1805 | 122 | return 0; | ||
1806 | 123 | } | ||
1807 | 124 | const manager_device_soft_t* manager_get_device_soft_t(int device_code){ | ||
1808 | 125 | if(_devices_soft_ht == NULL){ | ||
1809 | 126 | fprintf(stderr, "This devices_soft_ht is null!!\n"); | ||
1810 | 127 | return NULL; | ||
1811 | 128 | } | ||
1812 | 129 | char codevalue[10] = {0}; | ||
1813 | 130 | snprintf(codevalue, sizeof(codevalue),"0x%.2x",device_code); | ||
1814 | 131 | return (const manager_device_soft_t*)g_hash_table_lookup(_devices_soft_ht, codevalue); | ||
1815 | 132 | } | ||
1816 | 133 | const GList* manager_get_all_device_soft_t(){ | ||
1817 | 134 | if(_devices_soft_ht == NULL){ | ||
1818 | 135 | fprintf(stderr, "This devices_soft_ht is null!!\n"); | ||
1819 | 136 | return NULL; | ||
1820 | 137 | } | ||
1821 | 138 | return (const GList*)g_hash_table_get_values(_devices_soft_ht); | ||
1822 | 139 | } | ||
1823 | 140 | |||
1824 | 141 | const manager_device_static_t* manager_get_device_static_t(int device_code){ | ||
1825 | 142 | if(_devices_static_ht == NULL){ | ||
1826 | 143 | fprintf(stderr, "This devices_static_ht is null!!\n"); | ||
1827 | 144 | return NULL; | ||
1828 | 145 | } | ||
1829 | 146 | char codevalue[10] = {0}; | ||
1830 | 147 | snprintf(codevalue, sizeof(codevalue),"0x%.2x",device_code); | ||
1831 | 148 | return (const manager_device_static_t*)g_hash_table_lookup(_devices_static_ht, codevalue); | ||
1832 | 149 | } | ||
1833 | 150 | const GList* manager_get_all_device_static_t(){ | ||
1834 | 151 | if(_devices_static_ht == NULL){ | ||
1835 | 152 | fprintf(stderr, "This devices_static_ht is null!!\n"); | ||
1836 | 153 | return NULL; | ||
1837 | 154 | } | ||
1838 | 155 | return (GList*)g_hash_table_get_values(_devices_static_ht); | ||
1839 | 156 | } | ||
1840 | 157 | int | ||
1841 | 158 | manager_regist_device(int device_code, dbus_return_t* rt){ | ||
1842 | 159 | |||
1843 | 160 | char codevalue[10] = {0}; | ||
1844 | 161 | snprintf(codevalue, sizeof(codevalue),"0x%.2x",device_code); | ||
1845 | 162 | manager_device_static_t* ds = g_hash_table_lookup(_devices_static_ht,codevalue); | ||
1846 | 163 | if(ds == NULL){ | ||
1847 | 164 | rt->state_code = WORK_STATE_UNKNOW; | ||
1848 | 165 | rt->exception_code = 0x20000 | EXCEPTION_CODE_NO_DEVICE; | ||
1849 | 166 | snprintf(rt->desc, DESC_BUF_LEN, "The device's driver of 0x%.2x not exist!.", device_code); | ||
1850 | 167 | return -1; | ||
1851 | 168 | } | ||
1852 | 169 | if(ds->is_registed == 1){// had registed | ||
1853 | 170 | rt->state_code = WORK_STATE_UNKNOW; | ||
1854 | 171 | rt->exception_code = 0x20000 | EXCEPTION_CODE_INVAILD_OP; | ||
1855 | 172 | snprintf(rt->desc, DESC_BUF_LEN, "The device of 0x%.2x had registed!.", device_code); | ||
1856 | 173 | return -1; | ||
1857 | 174 | } | ||
1858 | 175 | ds->is_registed = 1; | ||
1859 | 176 | if(conf_enable_driver(ds->device_name,_devices_methods_ht,_devices_soft_ht,_devices_static_ht) < 0){ | ||
1860 | 177 | rt->state_code = WORK_STATE_UNKNOW; | ||
1861 | 178 | rt->exception_code = 0x20000 | 0x05; | ||
1862 | 179 | snprintf(rt->desc, DESC_BUF_LEN, "conf_enable_driver failed!"); | ||
1863 | 180 | }else{ | ||
1864 | 181 | printf("conf_enable_driver successfully\n"); | ||
1865 | 182 | manager_device_soft_t * dsoft = g_hash_table_lookup(_devices_soft_ht,codevalue); | ||
1866 | 183 | if(dsoft == NULL){ | ||
1867 | 184 | printf("dsoft is null\n"); | ||
1868 | 185 | rt->state_code = WORK_STATE_UNKNOW; | ||
1869 | 186 | rt->exception_code = 0x20000 | EXCEPTION_CODE_NO_DEVICE; | ||
1870 | 187 | }else{ | ||
1871 | 188 | rt->state_code = dsoft->workstate; | ||
1872 | 189 | rt->exception_code = dsoft->exception_code | 0x10000; | ||
1873 | 190 | rt->exception_code |= (device_code<<8); | ||
1874 | 191 | snprintf(rt->desc, DESC_BUF_LEN,"%s",dsoft->desc); | ||
1875 | 192 | } | ||
1876 | 193 | } | ||
1877 | 194 | |||
1878 | 195 | return 0; | ||
1879 | 196 | } | ||
1880 | 197 | void manager_logout_device(int device_code,dbus_return_t * rt){ | ||
1881 | 198 | char codevalue[10] = {0}; | ||
1882 | 199 | snprintf(codevalue, sizeof(codevalue),"0x%.2x",device_code); | ||
1883 | 200 | manager_device_static_t* ds = g_hash_table_lookup(_devices_static_ht,codevalue); | ||
1884 | 201 | if(ds == NULL){ | ||
1885 | 202 | rt->state_code = WORK_STATE_UNKNOW; | ||
1886 | 203 | rt->exception_code = 0x20000 | EXCEPTION_CODE_NO_DEVICE; | ||
1887 | 204 | snprintf(rt->desc, DESC_BUF_LEN, "The device's driver of 0x%.2x not exist!.", device_code); | ||
1888 | 205 | return -1; | ||
1889 | 206 | } | ||
1890 | 207 | if(ds->is_registed == 0){// had logouted | ||
1891 | 208 | rt->state_code = WORK_STATE_UNKNOW; | ||
1892 | 209 | rt->exception_code = 0x20000 | EXCEPTION_CODE_INVAILD_OP; | ||
1893 | 210 | snprintf(rt->desc, DESC_BUF_LEN, "The device of 0x%.2x had logouted!.", device_code); | ||
1894 | 211 | return -1; | ||
1895 | 212 | } | ||
1896 | 213 | if(conf_disable_driver(_devices_methods_ht,device_code) < 0){ | ||
1897 | 214 | rt->state_code = WORK_STATE_UNKNOW; | ||
1898 | 215 | rt->exception_code = 0x20000 | 0x05; | ||
1899 | 216 | snprintf(rt->desc, DESC_BUF_LEN, "conf_disable_driver failed!"); | ||
1900 | 217 | return; | ||
1901 | 218 | }else{ | ||
1902 | 219 | rt->state_code = WORK_STATE_UNKNOW; | ||
1903 | 220 | rt->exception_code = 0x00000; | ||
1904 | 221 | } | ||
1905 | 222 | g_hash_table_remove(_devices_soft_ht,codevalue); | ||
1906 | 223 | ds->is_registed = 0; | ||
1907 | 224 | |||
1908 | 225 | } | ||
1909 | 226 | int | ||
1910 | 227 | manager_get_device_interfaces_info(int device_code, char* ret_desc){ | ||
1911 | 228 | // | ||
1912 | 229 | } | ||
1913 | 230 | int manager_exit(){ | ||
1914 | 231 | g_hash_table_destroy(_devices_soft_ht); | ||
1915 | 232 | g_hash_table_destroy(_devices_methods_ht); | ||
1916 | 233 | conf_end_writeToDisk(_devices_static_ht); | ||
1917 | 234 | return 0; | ||
1918 | 235 | } | ||
1919 | 0 | 236 | ||
1920 | === added file 'src/managerlayer/manager.h' | |||
1921 | --- src/managerlayer/manager.h 1970-01-01 00:00:00 +0000 | |||
1922 | +++ src/managerlayer/manager.h 2017-10-10 00:58:46 +0000 | |||
1923 | @@ -0,0 +1,91 @@ | |||
1924 | 1 | #ifndef __MANAGER_H__ | ||
1925 | 2 | #define __MANAGER_H__ | ||
1926 | 3 | |||
1927 | 4 | #define DESC_BUF_LEN 1024 | ||
1928 | 5 | |||
1929 | 6 | #define WORK_STATE_CLOSED 0 | ||
1930 | 7 | #define WORK_STATE_IDLE 1 | ||
1931 | 8 | #define WORK_STATE_PROCESSING 2 | ||
1932 | 9 | #define WORK_STATE_EXCEPTION 3 | ||
1933 | 10 | #define WORK_STATE_UNKNOW 4 | ||
1934 | 11 | |||
1935 | 12 | #define RETURN_ERRNO_OK 0 | ||
1936 | 13 | #define RETURN_ERRNO_WARNING 1 | ||
1937 | 14 | #define RETURN_ERRNO_EXCEPTION 2 | ||
1938 | 15 | #define RETURN_ERRNO_UNKNOW 4 | ||
1939 | 16 | |||
1940 | 17 | |||
1941 | 18 | typedef struct{ | ||
1942 | 19 | int device_code; // Example : 0x02 | ||
1943 | 20 | int is_online; // true or false | ||
1944 | 21 | int workstate; // every device has a state machine 0: closed 1: idle 2: Processing 3: Exception | ||
1945 | 22 | int exception_code; // if state=Exception, exception_code is the specific exception code. | ||
1946 | 23 | char desc[DESC_BUF_LEN];// the decription of exception; | ||
1947 | 24 | |||
1948 | 25 | }manager_device_soft_t; // There infomations will be updated by software at most case. | ||
1949 | 26 | |||
1950 | 27 | typedef struct{ | ||
1951 | 28 | int device_code; | ||
1952 | 29 | char device_name[5] ; // The simple name. Example: idr, br, prt | ||
1953 | 30 | //char manufactire[100]; | ||
1954 | 31 | //char serial[100]; | ||
1955 | 32 | int is_registed; // true or false | ||
1956 | 33 | }manager_device_static_t; // There infomation is static at most case. | ||
1957 | 34 | |||
1958 | 35 | typedef struct{ | ||
1959 | 36 | int state_code; | ||
1960 | 37 | int exception_code; | ||
1961 | 38 | char desc[DESC_BUF_LEN]; | ||
1962 | 39 | }dbus_return_t; | ||
1963 | 40 | |||
1964 | 41 | typedef dbus_return_t hw_return_t; | ||
1965 | 42 | |||
1966 | 43 | typedef struct{ | ||
1967 | 44 | int error_no; | ||
1968 | 45 | int device_code; | ||
1969 | 46 | int method_code; | ||
1970 | 47 | char* info; | ||
1971 | 48 | }manager_callback_return_t; | ||
1972 | 49 | |||
1973 | 50 | typedef void (*MANAGER_CALLBACK_FUNC)(manager_callback_return_t*); | ||
1974 | 51 | /** | ||
1975 | 52 | * Load all device's configure file, then build the | ||
1976 | 53 | * main data structures: device_method hashtable, | ||
1977 | 54 | * device_state struct array. | ||
1978 | 55 | * @param dbus_name the name of dbus, Example : com.jd.test | ||
1979 | 56 | * @param object_name the one object of dbus_name | ||
1980 | 57 | * @param CALLBACK_FUNC initiative feedback infomations to upstearm caller. | ||
1981 | 58 | * @return 0 successful, 1 failed. | ||
1982 | 59 | */ | ||
1983 | 60 | int manager_init(const char* dbus_name, const char* object_name, MANAGER_CALLBACK_FUNC); | ||
1984 | 61 | |||
1985 | 62 | /** | ||
1986 | 63 | * Call the device method by devicecode and methodcode point. | ||
1987 | 64 | * @param If this device method need a param | ||
1988 | 65 | * @error_no the device method invoke return statuscode | ||
1989 | 66 | * @count | ||
1990 | 67 | * @desc The describtion about the error_no | ||
1991 | 68 | * @return 0 successful ; 1 failed | ||
1992 | 69 | */ | ||
1993 | 70 | int manager_call_device_method(int devicecode, int methodcode,const char* param, dbus_return_t*); | ||
1994 | 71 | |||
1995 | 72 | /** | ||
1996 | 73 | * Get the current device's info struct. | ||
1997 | 74 | */ | ||
1998 | 75 | const manager_device_soft_t* manager_get_device_soft_t(int device_code); | ||
1999 | 76 | const GList* manager_get_all_device_soft_t(); | ||
2000 | 77 | |||
2001 | 78 | const manager_device_static_t* manager_get_device_static_t(int device_code); | ||
2002 | 79 | const GList* manager_get_all_device_static_t(); | ||
2003 | 80 | |||
2004 | 81 | int manager_regist_device(int device_code,dbus_return_t*); | ||
2005 | 82 | void manager_logout_device(int device_code,dbus_return_t*); | ||
2006 | 83 | /** | ||
2007 | 84 | * Get the device's interfaces info. | ||
2008 | 85 | * @param device_code, the code of device | ||
2009 | 86 | * @param ret_desc, the infomation storage location. | ||
2010 | 87 | * @return 0 successful; -1 failed | ||
2011 | 88 | */ | ||
2012 | 89 | int manager_get_device_interfaces_info(int device_code, char* ret_desc); | ||
2013 | 90 | int manager_exit(); | ||
2014 | 91 | #endif // __MANAGER_H__ |