Merge lp:~mimose/kydevmonit/test into lp:kydevmonit

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

Subscribers

People subscribed via source and target branches

to all changes: