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
=== added file '.bzrignore'
--- .bzrignore 1970-01-01 00:00:00 +0000
+++ .bzrignore 2017-10-10 00:58:46 +0000
@@ -0,0 +1,10 @@
1kydevmonit
2debian/debhelper-build-stamp
3debian/files
4debian/kydevmonit
5debian/kydevmonit.debhelper.log
6debian/kydevmonit.substvars
7debian/kydevmonit/DEBIAN
8debian/kydevmonit/etc
9debian/kydevmonit/lib
10debian/kydevmonit/usr
011
=== modified file 'Makefile'
--- Makefile 2017-09-05 05:53:02 +0000
+++ Makefile 2017-10-10 00:58:46 +0000
@@ -1,24 +1,30 @@
1all=kydevmonit1all=kydevmonit
2CC=gcc2CC=gcc
33
4INTERLAYER_DIR=./src/interlayer/4MANAGER_LAYER_DIR=./src/managerlayer/
5DBUSLAYER_DIR=./src/dbuslayer/5DBUSLAYER_DIR=./src/dbuslayer/
66
7INCLUDE=-I$(INTERLAYER_DIR) -I$(DBUSLAYER_DIR) -I/usr/include/libxml2/ `pkg-config --cflags glib-2.0 gobject-2.0 dbus-glib-1 dbus-1` 7MY_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`
8LIBS=`pkg-config --libs glib-2.0 gobject-2.0 dbus-glib-1 dbus-1` -lxml2 -ldl8MY_LDFLAGS=$(LDFLAGS) `pkg-config --libs glib-2.0 gobject-2.0 dbus-glib-1 dbus-1` -lxml2 -ldl
99
10SRCS=./src/main.c $(DBUSLAYER_DIR)monitor_dbus.c $(DBUSLAYER_DIR)marshal.c $(INTERLAYER_DIR)interlayer.c10SRCS=./src/main.c $(DBUSLAYER_DIR)monitor_dbus.c $(DBUSLAYER_DIR)marshal.c $(MANAGER_LAYER_DIR)manager.c $(MANAGER_LAYER_DIR)_configure.c
11
11OBJS=$(SRCS:.c=.o)12OBJS=$(SRCS:.c=.o)
12
13kydevmonit:$(OBJS)13kydevmonit:$(OBJS)
14 $(CC) -g -O0 -o $@ $^ $(INCLUDE) $(LIBS)14 $(CC) -g -O0 -o $@ $^ $(MY_CFLAGS) $(MY_LDFLAGS)
15
16monitor_dbus_glue.h:$(DBUSLAYER_DIR)com.jd.test.xml
17 dbus-binding-tool --prefix=monitor --mode=glib-server --output=$(DBUSLAYER_DIR)monitor_dbus_glue.h $^
18
15install:19install:
16 install kydevmonit /usr/bin/20 install -d -m755 $(DESTDIR)/usr/bin/
17 cp kydevmonit.service /lib/systemd/system/21 install -m755 ./kydevmonit $(DESTDIR)/usr/bin/
18 cp com.jd.test.conf /etc/dbus-1/system.d/22 install -d -m755 $(DESTDIR)/lib/systemd/system/
19 systemctl daemon-reload23 install -m644 ./kydevmonit.service $(DESTDIR)/lib/systemd/system/
24 install -d -m755 $(DESTDIR)/etc/dbus-1/system.d/
25 install -m644 ./com.jd.test.conf $(DESTDIR)/etc/dbus-1/system.d/
20clean:26clean:
21 rm -rf $(OBJS) kydevmonit 27 rm -rf $(OBJS) kydevmonit
2228
23%.o:%.c29%.o:%.c
24 $(CC) $(INCLUDE) -o $@ -c $<30 $(CC) $(MY_CFLAGS) -o $@ -c $<
2531
=== removed file 'com.jd.test.xml'
--- com.jd.test.xml 2017-09-05 05:53:02 +0000
+++ com.jd.test.xml 1970-01-01 00:00:00 +0000
@@ -1,15 +0,0 @@
1<?xml version="1.0" encoding="UTF-8" ?>
2<node name="/com/jd/test">
3 <interface name="com.jd.test.interface">
4 <method name="call_monitor_method">
5 <annotation name="org.freedesktop.DBus.GLib.Async" value="" />
6 <arg type="(iiiis)" name="hw_method_t" direction="in" />
7 <arg type="(iis)" name="hw_return_t" direction="out" />
8 </method>
9 <method name="intropect">
10 <annotation name="org.freedesktop.DBus.GLib.Async" value="" />
11 <arg type="s" name="name" direction="in"/>
12 <arg type="s" name="data" direction="out"/>
13 </method>
14 </interface>
15</node>
160
=== added directory 'debian'
=== added file 'debian/changelog'
--- debian/changelog 1970-01-01 00:00:00 +0000
+++ debian/changelog 2017-10-10 00:58:46 +0000
@@ -0,0 +1,5 @@
1kydevmonit (1.0.0kord1) juniper; urgency=medium
2
3 * Initial release.
4
5 -- guoyalong <guoyalong@kylinos.cn> Mon, 25 Sep 2017 11:30:12 +0800
06
=== added file 'debian/compat'
--- debian/compat 1970-01-01 00:00:00 +0000
+++ debian/compat 2017-10-10 00:58:46 +0000
@@ -0,0 +1,1 @@
19
02
=== added file 'debian/control'
--- debian/control 1970-01-01 00:00:00 +0000
+++ debian/control 2017-10-10 00:58:46 +0000
@@ -0,0 +1,15 @@
1Source: kydevmonit
2Section: x11
3Priority: optional
4Maintainer: Ubuntu Kylin Team <ubuntukylin-members@list.launchpad.net>
5Build-Depends: debhelper(>= 9),
6 libxml2-dev,
7 libdbus-glib-1-dev,
8 libglib2.0-dev
9Standards-Version: 3.9.8
10Homepage: https://launchpad.net/kydevmonit
11
12Package: kydevmonit
13Architecture: any
14Depends: ${shlibs:Depends}, ${misc:Depends}
15Description: This is a devices manager based on dbus.
016
=== added file 'debian/copyright'
--- debian/copyright 1970-01-01 00:00:00 +0000
+++ debian/copyright 2017-10-10 00:58:46 +0000
@@ -0,0 +1,1 @@
1
02
=== added file 'debian/rules'
--- debian/rules 1970-01-01 00:00:00 +0000
+++ debian/rules 2017-10-10 00:58:46 +0000
@@ -0,0 +1,8 @@
1#!/usr/bin/make -f
2# debian/rules for kydevmonit
3##
4## Build-tree preparation
5##
6%:
7 dh $@
8
09
=== added directory 'debian/source'
=== added file 'debian/source/format'
--- debian/source/format 1970-01-01 00:00:00 +0000
+++ debian/source/format 2017-10-10 00:58:46 +0000
@@ -0,0 +1,1 @@
13.0 (native)
02
=== added file 'src/dbuslayer/com.jd.test.xml'
--- src/dbuslayer/com.jd.test.xml 1970-01-01 00:00:00 +0000
+++ src/dbuslayer/com.jd.test.xml 2017-10-10 00:58:46 +0000
@@ -0,0 +1,29 @@
1<?xml version="1.0" encoding="UTF-8" ?>
2<node name="/com/jd/test">
3 <interface name="com.jd.test.interface">
4 <method name="dbus_get_all_device_static_info">
5 <annotation name="org.freedesktop.DBus.GLib.Async" value="" />
6 <arg type="a(isi)" name="devices_static_return_t" direction="out"/>
7 </method>
8 <method name="dbus_get_device_interfaces_info">
9 <annotation name="org.freedesktop.DBus.GLib.Async" value="" />
10 <arg type="i" name="device_code" direction="in"/>
11 <arg type="isaav" name="device_interfaces_return_t" direction="out"/>
12 </method>
13 <method name="dbus_call_device_method">
14 <annotation name="org.freedesktop.DBus.GLib.Async" value="" />
15 <arg type="(iiiis)" name="device_method_input_t" direction="in" />
16 <arg type="(iis)" name="dbus_return_t" direction="out" />
17 </method>
18 <method name="dbus_regist_new_device">
19 <annotation name="org.freedesktop.DBus.GLib.Async" value="" />
20 <arg type="i" name="device_code" direction="in"/>
21 <arg type="(iis)" name="dbus_return_t" direction="out"/>
22 </method>
23 <method name="dbus_logout_device">
24 <annotation name="org.freedesktop.DBus.GLib.Async" value="" />
25 <arg type="i" name="device_code" direction="in"/>
26 <arg type="(iis)" name="dbus_return_t" direction="out"/>
27 </method>
28 </interface>
29</node>
030
=== modified file 'src/dbuslayer/monitor_dbus.c'
--- src/dbuslayer/monitor_dbus.c 2017-09-05 05:53:02 +0000
+++ src/dbuslayer/monitor_dbus.c 2017-10-10 00:58:46 +0000
@@ -32,7 +32,7 @@
32#include <malloc.h>32#include <malloc.h>
33#include <unistd.h>33#include <unistd.h>
3434
35#include "../interlayer/interlayer.h"35#include "../managerlayer/manager.h"
3636
37static GMainLoop *loop = NULL;37static GMainLoop *loop = NULL;
38MonitorDbus * dbus;38MonitorDbus * dbus;
@@ -63,75 +63,167 @@
63void monitor_dbus_class_init(MonitorDbusClass * kclass)63void monitor_dbus_class_init(MonitorDbusClass * kclass)
64{64{
65 mnsignals[SIG_DATA_ALERT] = g_signal_new("monitor_alert",65 mnsignals[SIG_DATA_ALERT] = g_signal_new("monitor_alert",
66 G_TYPE_FROM_CLASS(kclass),66 G_TYPE_FROM_CLASS(kclass),
67 G_SIGNAL_RUN_FIRST,67 G_SIGNAL_RUN_FIRST,
68 G_STRUCT_OFFSET(MonitorWarnDbusClass, event),68 G_STRUCT_OFFSET(MonitorWarnDbusClass, event),
69 NULL,69 NULL,
70 NULL,70 NULL,
71 monitor_marshal_VOID__UINT_BOXED,71 monitor_marshal_VOID__UINT_BOXED,
72 G_TYPE_NONE,72 G_TYPE_NONE,
73 3,73 3,
74 G_TYPE_UINT,74 G_TYPE_UINT,
75 G_TYPE_UINT,75 G_TYPE_UINT,
76 G_TYPE_UINT);76 G_TYPE_UINT);
77}77}
7878
7979gint monitor_dbus_get_all_device_static_info(MonitorDbus * dbus, DBusGMethodInvocation * ret_value){
80 GList* value_list_ptr = manager_get_all_device_static_t();
81 guint len = g_list_length(value_list_ptr);
82 GArray * array_return = g_array_new(FALSE,TRUE,sizeof(GValueArray));
83 printf("len=%u\n",len);
84 int i;
85 for(i=0; i<len;i++){
86 manager_device_static_t* ds = (manager_device_static_t*)g_list_nth_data(value_list_ptr,i);
87 GValueArray* static_struct = g_value_array_new(0);
88 GValue device_code={0};
89 GValue device_name={0};
90 GValue is_registed={0};
91 g_value_init (&device_code, G_TYPE_INT);
92 g_value_init (&device_name, G_TYPE_STRING);
93 g_value_init (&is_registed, G_TYPE_INT);
94 g_value_set_int(&device_code, ds->device_code);
95 g_value_set_string(&device_name, ds->device_name);
96 g_value_set_int(&is_registed, ds->is_registed);
97 static_struct = g_value_array_append(static_struct,&device_code);
98 static_struct = g_value_array_append(static_struct,&device_name);
99 static_struct = g_value_array_append(static_struct,&is_registed);
100 array_return = g_array_append_val(array_return,static_struct);
101 printf("0x%.2x %s %d successfully\n",ds->device_code,ds->device_name,ds->is_registed);
102 }
103 dbus_g_method_return(ret_value,array_return);
104 return 1;
105}
106gint monitor_dbus_get_device_interfaces_info(MonitorDbus * dbus, int device_code, DBusGMethodInvocation * ret_value){
107
108}
80109
81//客户端-监控统一入口110//客户端-监控统一入口
82gint monitor_dbus_call_monitor_method(MonitorDbus * dbus,GValueArray * method_value ,DBusGMethodInvocation * ret_value)111gint monitor_dbus_call_device_method(MonitorDbus * dbus,GValueArray * method_value ,DBusGMethodInvocation * ret_value)
83{112{
84 GValue * input[5] = {{0}};113 GValue * input[5] = {{0}};
85 for(int i =0; i < 5;i++){114 dbus_return_t rt={0,0,{0}};// state_code ; exception_code; exception_desc;
86 input[i] = g_value_array_get_nth(method_value, i);115
87 }116 guint size = 5;//g_array_get_element_size(method_value);
88 gint value1 = g_value_get_int(input[0]);117 if(size < 5){
89 gint value2 = g_value_get_int(input[1]);118 rt.state_code = WORK_STATE_UNKNOW;
90 gint value3 = g_value_get_int(input[2]);119 rt.exception_code = 0x30000;
91 gint value4 = g_value_get_int(input[3]);120 snprintf(rt.desc,DESC_BUF_LEN,"The method_value at least 5 elements!\n");
92 gchar * value5 = g_value_dup_string(input[4]);121 }else{
93 printf("input value1: %d\n", value1);122 if(method_value == NULL){
94 printf("input value2: %d\n", value2);123 printf("method_value is null\n");
95 printf("input value3: %d\n", value3);124 }
96 printf("input value4: %d\n", value4);125 /*
97 printf("input value5: %s\n", value5);126 gint device_code = g_array_index(method_value,int,0);
98 127 gint method_code = g_array_index(method_value, int,1);
99128 gint value3 = g_array_index(method_value, int,2);
100 gint statuscode = -1;129 gint value4 = g_array_index(method_value, int,3);
101 gint count = -1;130 gchar* method_param = g_array_index(method_value,char*,4);
102 gchar statusdesc[1024] = {0};131 */
103132 int i;
104 interlayer_call_device_method(value1, value2,value5, &statuscode,&count,statusdesc); 133 for(i =0; i < size;i++){
105134 input[i] = g_value_array_get_nth(method_value, i);
106 GValueArray *struct_return;135 }
107 GValue struct_container[3] = {{0}};136 gint device_code = g_value_get_int(input[0]);
108 137 gint method_code = g_value_get_int(input[1]);
109 g_value_init (&struct_container[0], G_TYPE_INT);138 gint value3 = g_value_get_int(input[2]);
110 g_value_set_int (&struct_container[0], statuscode);139 gint value4 = g_value_get_int(input[3]);
111 g_value_init (&struct_container[1], G_TYPE_INT);140 gchar * method_param = g_value_dup_string(input[4]);
112 g_value_set_int (&struct_container[1], count);141
113 g_value_init (&struct_container[2], G_TYPE_STRING);142 printf("input value1: 0x%.2x\n", device_code);
114 g_value_set_string (&struct_container[2], statusdesc);143 printf("input value2: 0x%.3x\n", method_code);
115144 printf("input value3: %d\n", value3);
116 struct_return = g_value_array_new(0);145 printf("input value4: %d\n", value4);
117 for(int j =0; j <3; j++){146 printf("input value5: %s\n", method_param);
118 struct_return = g_value_array_append(struct_return, &struct_container[j]);147
119 }148 manager_call_device_method(device_code, method_code,(const char*)method_param,&rt);
120149 //interlayer_call_device_method(value1, value2,value5, &statuscode,&count,statusdesc);
121 dbus_g_method_return(ret_value,struct_return); 150 }
122 return 1;151 GValueArray* struct_return;// = g_array_new(TRUE,TRUE,sizeof(GValue));
123}152 GValue struct_container[3] = {{0}};
124gint monitor_dbus_intropect(MonitorDbus* dbus, const char* devicename,DBusGMethodInvocation * ret_value){153
125 //char* message = "hello";154 g_value_init (&struct_container[0], G_TYPE_INT);
126 //GValue data = g_value_set_string("hello");155 g_value_set_int (&struct_container[0], rt.state_code);
127 //printf("devicename= %s\n", devicename);156 g_value_init (&struct_container[1], G_TYPE_INT);
128 char desc[1024];157 g_value_set_int (&struct_container[1], rt.exception_code);
129 memset(desc, 0, 1024);158 g_value_init (&struct_container[2], G_TYPE_STRING);
130 interlayer_get_devices_intropect(LISTEN_DBUS_NAME, LISTEN_DBUS_PATH, devicename,desc); 159 g_value_set_string (&struct_container[2], rt.desc);
131 printf("Desc: %s\n", desc);160
132 dbus_g_method_return(ret_value, desc);161 struct_return = g_value_array_new(0);
133 return 0;162 int j;
134}163 for(j =0; j <3; j++){
164 struct_return = g_value_array_append(struct_return, &struct_container[j]);
165 }
166
167 dbus_g_method_return(ret_value,struct_return);
168 return 1;
169}
170gint monitor_dbus_regist_new_device(MonitorDbus * dbus, int device_code, DBusGMethodInvocation * ret_value){
171
172 //printf("Hello,here, 0x%.2x\n",device_code);
173 //printf("Hello,here\n");
174 dbus_return_t rt={0,0,{0}};// state_code ; exception_code; exception_desc;
175 manager_regist_device(device_code,&rt);
176
177 GValueArray* struct_return;// = g_array_new(TRUE,TRUE,sizeof(GValue));
178 GValue struct_container[3] = {{0}};
179
180 g_value_init (&struct_container[0], G_TYPE_INT);
181 g_value_set_int (&struct_container[0], rt.state_code);
182 g_value_init (&struct_container[1], G_TYPE_INT);
183 g_value_set_int (&struct_container[1], rt.exception_code);
184 g_value_init (&struct_container[2], G_TYPE_STRING);
185 g_value_set_string (&struct_container[2], rt.desc);
186
187 struct_return = g_value_array_new(0);
188 int j;
189 for(j =0; j <3; j++){
190 struct_return = g_value_array_append(struct_return, &struct_container[j]);
191 }
192
193 dbus_g_method_return(ret_value,struct_return);
194 return 1;
195}
196gint monitor_dbus_logout_device(MonitorDbus * dbus, int device_code, DBusGMethodInvocation * ret_value){
197 //printf("Hello,here, 0x%.2x\n",device_code);
198 //printf("Hello,here\n");
199 dbus_return_t rt={0,0,{0}};// state_code ; exception_code; exception_desc;
200 manager_logout_device(device_code,&rt);
201
202 GValueArray* struct_return;// = g_array_new(TRUE,TRUE,sizeof(GValue));
203 GValue struct_container[3] = {{0}};
204
205 g_value_init (&struct_container[0], G_TYPE_INT);
206 g_value_set_int (&struct_container[0], rt.state_code);
207 g_value_init (&struct_container[1], G_TYPE_INT);
208 g_value_set_int (&struct_container[1], rt.exception_code);
209 g_value_init (&struct_container[2], G_TYPE_STRING);
210 g_value_set_string (&struct_container[2], rt.desc);
211
212 struct_return = g_value_array_new(0);
213 int j;
214 for(j =0; j <3; j++){
215 struct_return = g_value_array_append(struct_return, &struct_container[j]);
216 }
217 dbus_g_method_return(ret_value,struct_return);
218 return 1;
219}
220
221
222
223void _send_string_signal(manager_callback_return_t* rt){
224 //
225}
226
135int send_signal(MonitorDbus * dbus, gint s1){227int send_signal(MonitorDbus * dbus, gint s1){
136 g_signal_emit(dbus, mnsignals[SIG_DATA_ALERT], 0, s1);228 g_signal_emit(dbus, mnsignals[SIG_DATA_ALERT], 0, s1);
137 return 0;229 return 0;
@@ -142,7 +234,11 @@
142 send_signal(dbus, 1);234 send_signal(dbus, 1);
143 return 1;235 return 1;
144}236}
145237int dbus_exit(void){
238 manager_exit();
239 g_main_loop_unref(loop);
240 g_object_unref(dbus);
241}
146int dbus_init(void)242int dbus_init(void)
147{243{
148 DBusGConnection * connection = NULL;244 DBusGConnection * connection = NULL;
@@ -158,40 +254,39 @@
158254
159 connection = dbus_g_bus_get(DBUS_BUS_SYSTEM, &error);255 connection = dbus_g_bus_get(DBUS_BUS_SYSTEM, &error);
160 if(connection == NULL){256 if(connection == NULL){
161 g_error("%s", error->message);257 g_error("%s", error->message);
162 goto out;258 goto out;
163 }259 }
164260
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,
166 DBUS_PATH_DBUS, DBUS_INTERFACE_DBUS);262 DBUS_PATH_DBUS, DBUS_INTERFACE_DBUS);
167263
168 ret = dbus_g_proxy_call(dbus_proxy, "RequestName", &error,264 ret = dbus_g_proxy_call(dbus_proxy, "RequestName", &error,
169 G_TYPE_STRING, LISTEN_DBUS_NAME,265 G_TYPE_STRING, LISTEN_DBUS_NAME,
170 G_TYPE_UINT,266 G_TYPE_UINT,
171 DBUS_NAME_FLAG_DO_NOT_QUEUE,267 DBUS_NAME_FLAG_DO_NOT_QUEUE,
172 G_TYPE_INVALID,268 G_TYPE_INVALID,
173 G_TYPE_UINT, &request_name_result,269 G_TYPE_UINT, &request_name_result,
174 G_TYPE_INVALID);270 G_TYPE_INVALID);
175 if(!ret){271 if(!ret){
176 g_error("RequestName failed:%s", error->message);272 g_error("RequestName failed:%s", error->message);
177 g_error_free(error);273 g_error_free(error);
178 exit(EXIT_FAILURE);274 exit(EXIT_FAILURE);
179 }275 }
180276
181 g_object_unref(G_OBJECT(dbus_proxy));277 g_object_unref(G_OBJECT(dbus_proxy));
182278
183 if(request_name_result != DBUS_REQUEST_NAME_REPLY_PRIMARY_OWNER)279 if(request_name_result != DBUS_REQUEST_NAME_REPLY_PRIMARY_OWNER)
184 exit(EXIT_FAILURE);280 exit(EXIT_FAILURE);
185281
186 dbus_g_object_type_install_info(LISTEN_TYPE_DBUS,282 dbus_g_object_type_install_info(LISTEN_TYPE_DBUS,
187 &dbus_glib_monitor_dbus_object_info);283 &dbus_glib_monitor_object_info);
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));
189285
190 // 定时发送signal286 // 定时发送signal
191 //g_timeout_add_seconds(5, (GSourceFunc)send_mnsignals_timer_handler, dbus);287 //g_timeout_add_seconds(5, (GSourceFunc)send_mnsignals_timer_handler, dbus);
192288 //printf("before manager_init\n");
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);
194
195 g_main_loop_run(loop);290 g_main_loop_run(loop);
196out:291out:
197 g_main_loop_unref(loop);292 g_main_loop_unref(loop);
198293
=== modified file 'src/dbuslayer/monitor_dbus.h'
--- src/dbuslayer/monitor_dbus.h 2017-09-05 05:53:02 +0000
+++ src/dbuslayer/monitor_dbus.h 2017-10-10 00:58:46 +0000
@@ -70,14 +70,17 @@
7070
71GType monitor_dbus_get_type(void);71GType monitor_dbus_get_type(void);
72MonitorDbus * monitor_dbus_new(void);72MonitorDbus * monitor_dbus_new(void);
73gint monitor_dbus_call_monitor_method(MonitorDbus * dbus,GValueArray * method_value ,DBusGMethodInvocation * ret_value);73gint monitor_dbus_get_all_device_static_info(MonitorDbus* dbus,DBusGMethodInvocation* ret_value);
74gint monitor_dbus_intropect(MonitorDbus * dbus,const char* devicename,DBusGMethodInvocation * ret_value);74gint monitor_dbus_get_device_interfaces_info(MonitorDbus* dbus, int device_code, DBusGMethodInvocation* ret_value);
75gint monitor_dbus_call_device_method(MonitorDbus * dbus,GValueArray * method_value ,DBusGMethodInvocation * ret_value);
76gint monitor_dbus_regist_new_device(MonitorDbus* dbus, int device_code, DBusGMethodInvocation * ret_value);
77gint monitor_dbus_logout_device(MonitorDbus* dbus, int device_code, DBusGMethodInvocation* ret_value);
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))
7679
77G_END_DECLS80G_END_DECLS
7881
79int dbus_init(void);82int dbus_init(void);
8083int dbus_exit(void);
8184
82void signal_handler();85void signal_handler();
83#endif86#endif
8487
=== added file 'src/dbuslayer/monitor_dbus.h.backup'
--- src/dbuslayer/monitor_dbus.h.backup 1970-01-01 00:00:00 +0000
+++ src/dbuslayer/monitor_dbus.h.backup 2017-10-10 00:58:46 +0000
@@ -0,0 +1,84 @@
1/*
2 * Copyright (C) 2013 National University of Defense Technology(NUDT) & Kylin Ltd.
3 *
4 * Authors:
5 * Kobe Lee kobe24_lixiang@126.com
6 *
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; version 3.
10 *
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License
17 * along with this program. If not, see <http://www.gnu.org/licenses/>.
18 */
19
20#ifndef __LISTEN_DBUS_H__
21#define __LISTEN_DBUS_H__
22
23#include <glib-object.h>
24#include <glib.h>
25#include <dbus/dbus-glib.h>
26#include <dbus/dbus-glib-lowlevel.h>
27#include <gio/gio.h>
28
29G_BEGIN_DECLS
30
31
32enum {
33 SIG_DATA_ALERT,
34 SIG_LAST_SIGNAL,
35};
36
37#define LISTEN_DBUS_NAME "com.jd.test"
38#define LISTEN_DBUS_PATH "/com/jd/test"
39#define LISTEN_DBUS_INTERFACE "com.jd.monitor.test"
40#define LISTEN_DBUS_ACTION_ID "com.jd.monitor.authentication"
41#define LISTEN_TYPE_DBUS (monitor_dbus_get_type())
42
43#define LISTEN_DBUS(o) (G_TYPE_CHECK_INSTANCE_CAST ((o), LISTEN_TYPE_DBUS, MonitorDbus))
44#define LISTEN_DBUS_CLASS(k) (G_TYPE_CHECK_CLASS_CAST((k), LISTEN_TYPE_DBUS, MonitorDbusClass))
45#define LISTEN_IS_DBUS(o) (G_TYPE_CHECK_INSTANCE_TYPE((o), LISTEN_TYPE_DBUS))
46#define LISTEN_IS_DBUS_CLASS(k) (G_TYPE_CHECK_CLASS_TPYE((k), LISTEN_TYPE_DBUS))
47#define LISTEN_DBUS_GET_CLASS(o) (G_TYPE_INSTANCE_GET_CLASS((o), LISTEN_TYPE_DBUS, MonitorClass))
48
49typedef struct _MonitorDbusPrivate MonitorDbusPrivate;
50typedef struct _MonitorDbus MonitorDbus;
51typedef struct _MonitorDbusClass MonitorDbusClass;
52typedef struct _MonitorWarnDbusClass MonitorWarnDbusClass;
53
54struct _MonitorDbus {
55 GObject parent;
56 MonitorDbusPrivate *priv;
57};
58
59struct _MonitorDbusClass {
60 GObjectClass parent_class;
61 void (*event)(MonitorDbus* dbus, guint type, GValue * value);
62
63};
64
65struct _MonitorWarnDbusClass {
66 GObjectClass parent_class;
67 void (*event)(MonitorDbus* dbus, guint tag ,guint type, guint subtype);
68
69};
70
71GType monitor_dbus_get_type(void);
72MonitorDbus * monitor_dbus_new(void);
73gint monitor_dbus_call_monitor_method(MonitorDbus * dbus,GValueArray * method_value ,DBusGMethodInvocation * ret_value);
74gint monitor_dbus_intropect(MonitorDbus * dbus,const char* devicename,DBusGMethodInvocation * ret_value);
75#define DBUS_STRUCT_INT_INT_STRING (dbus_g_type_get_struct("GValueArray", G_TYPE_INT, G_TYPE_INT, G_TYPE_STRING))
76
77G_END_DECLS
78
79int dbus_init(void);
80
81
82void signal_handler();
83#endif
84
085
=== modified file 'src/dbuslayer/monitor_dbus_glue.h'
--- src/dbuslayer/monitor_dbus_glue.h 2017-09-05 05:53:02 +0000
+++ src/dbuslayer/monitor_dbus_glue.h 2017-10-10 00:58:46 +0000
@@ -1,8 +1,8 @@
1/* Generated by dbus-binding-tool; do not edit! */1/* Generated by dbus-binding-tool; do not edit! */
22
33
4#ifndef __dbus_glib_marshal_monitor_dbus_MARSHAL_H__4#ifndef __dbus_glib_marshal_monitor_MARSHAL_H__
5#define __dbus_glib_marshal_monitor_dbus_MARSHAL_H__5#define __dbus_glib_marshal_monitor_MARSHAL_H__
66
7#include <glib-object.h>7#include <glib-object.h>
88
@@ -55,26 +55,30 @@
55#endif /* !G_ENABLE_DEBUG */55#endif /* !G_ENABLE_DEBUG */
5656
5757
58/* NONE:STRING,POINTER */58/* NONE:POINTER */
59extern void dbus_glib_marshal_monitor_dbus_VOID__STRING_POINTER (GClosure *closure,59#define dbus_glib_marshal_monitor_VOID__POINTER g_cclosure_marshal_VOID__POINTER
60 GValue *return_value,60#define dbus_glib_marshal_monitor_NONE__POINTER dbus_glib_marshal_monitor_VOID__POINTER
61 guint n_param_values,61
62 const GValue *param_values,62/* NONE:INT,POINTER */
63 gpointer invocation_hint,63extern void dbus_glib_marshal_monitor_VOID__INT_POINTER (GClosure *closure,
64 gpointer marshal_data);64 GValue *return_value,
65 guint n_param_values,
66 const GValue *param_values,
67 gpointer invocation_hint,
68 gpointer marshal_data);
65void69void
66dbus_glib_marshal_monitor_dbus_VOID__STRING_POINTER (GClosure *closure,70dbus_glib_marshal_monitor_VOID__INT_POINTER (GClosure *closure,
67 GValue *return_value G_GNUC_UNUSED,71 GValue *return_value G_GNUC_UNUSED,
68 guint n_param_values,72 guint n_param_values,
69 const GValue *param_values,73 const GValue *param_values,
70 gpointer invocation_hint G_GNUC_UNUSED,74 gpointer invocation_hint G_GNUC_UNUSED,
71 gpointer marshal_data)75 gpointer marshal_data)
72{76{
73 typedef void (*GMarshalFunc_VOID__STRING_POINTER) (gpointer data1,77 typedef void (*GMarshalFunc_VOID__INT_POINTER) (gpointer data1,
74 gpointer arg_1,78 gint arg_1,
75 gpointer arg_2,79 gpointer arg_2,
76 gpointer data2);80 gpointer data2);
77 GMarshalFunc_VOID__STRING_POINTER callback;81 GMarshalFunc_VOID__INT_POINTER callback;
78 GCClosure *cc = (GCClosure*) closure;82 GCClosure *cc = (GCClosure*) closure;
79 gpointer data1, data2;83 gpointer data1, data2;
8084
@@ -90,29 +94,29 @@
90 data1 = g_value_peek_pointer (param_values + 0);94 data1 = g_value_peek_pointer (param_values + 0);
91 data2 = closure->data;95 data2 = closure->data;
92 }96 }
93 callback = (GMarshalFunc_VOID__STRING_POINTER) (marshal_data ? marshal_data : cc->callback);97 callback = (GMarshalFunc_VOID__INT_POINTER) (marshal_data ? marshal_data : cc->callback);
9498
95 callback (data1,99 callback (data1,
96 g_marshal_value_peek_string (param_values + 1),100 g_marshal_value_peek_int (param_values + 1),
97 g_marshal_value_peek_pointer (param_values + 2),101 g_marshal_value_peek_pointer (param_values + 2),
98 data2);102 data2);
99}103}
100#define dbus_glib_marshal_monitor_dbus_NONE__STRING_POINTER dbus_glib_marshal_monitor_dbus_VOID__STRING_POINTER104#define dbus_glib_marshal_monitor_NONE__INT_POINTER dbus_glib_marshal_monitor_VOID__INT_POINTER
101105
102/* NONE:BOXED,POINTER */106/* NONE:BOXED,POINTER */
103extern void dbus_glib_marshal_monitor_dbus_VOID__BOXED_POINTER (GClosure *closure,107extern void dbus_glib_marshal_monitor_VOID__BOXED_POINTER (GClosure *closure,
104 GValue *return_value,108 GValue *return_value,
105 guint n_param_values,109 guint n_param_values,
106 const GValue *param_values,110 const GValue *param_values,
107 gpointer invocation_hint,111 gpointer invocation_hint,
108 gpointer marshal_data);112 gpointer marshal_data);
109void113void
110dbus_glib_marshal_monitor_dbus_VOID__BOXED_POINTER (GClosure *closure,114dbus_glib_marshal_monitor_VOID__BOXED_POINTER (GClosure *closure,
111 GValue *return_value G_GNUC_UNUSED,115 GValue *return_value G_GNUC_UNUSED,
112 guint n_param_values,116 guint n_param_values,
113 const GValue *param_values,117 const GValue *param_values,
114 gpointer invocation_hint G_GNUC_UNUSED,118 gpointer invocation_hint G_GNUC_UNUSED,
115 gpointer marshal_data)119 gpointer marshal_data)
116{120{
117 typedef void (*GMarshalFunc_VOID__BOXED_POINTER) (gpointer data1,121 typedef void (*GMarshalFunc_VOID__BOXED_POINTER) (gpointer data1,
118 gpointer arg_1,122 gpointer arg_1,
@@ -141,22 +145,25 @@
141 g_marshal_value_peek_pointer (param_values + 2),145 g_marshal_value_peek_pointer (param_values + 2),
142 data2);146 data2);
143}147}
144#define dbus_glib_marshal_monitor_dbus_NONE__BOXED_POINTER dbus_glib_marshal_monitor_dbus_VOID__BOXED_POINTER148#define dbus_glib_marshal_monitor_NONE__BOXED_POINTER dbus_glib_marshal_monitor_VOID__BOXED_POINTER
145149
146G_END_DECLS150G_END_DECLS
147151
148#endif /* __dbus_glib_marshal_monitor_dbus_MARSHAL_H__ */152#endif /* __dbus_glib_marshal_monitor_MARSHAL_H__ */
149153
150#include <dbus/dbus-glib.h>154#include <dbus/dbus-glib.h>
151static const DBusGMethodInfo dbus_glib_monitor_dbus_methods[] = {155static const DBusGMethodInfo dbus_glib_monitor_methods[] = {
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 },
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 },
158 { (GCallback) monitor_dbus_call_device_method, dbus_glib_marshal_monitor_NONE__BOXED_POINTER, 206 },
159 { (GCallback) monitor_dbus_regist_new_device, dbus_glib_marshal_monitor_NONE__INT_POINTER, 313 },
160 { (GCallback) monitor_dbus_logout_device, dbus_glib_marshal_monitor_NONE__INT_POINTER, 403 },
154};161};
155162
156const DBusGObjectInfo dbus_glib_monitor_dbus_object_info = { 1,163const DBusGObjectInfo dbus_glib_monitor_object_info = { 1,
157 dbus_glib_monitor_dbus_methods,164 dbus_glib_monitor_methods,
158 2,165 5,
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",
160"\0",167"\0",
161"\0"168"\0"
162};169};
163170
=== removed directory 'src/interlayer'
=== removed file 'src/interlayer/interlayer.c'
--- src/interlayer/interlayer.c 2017-09-05 05:53:02 +0000
+++ src/interlayer/interlayer.c 1970-01-01 00:00:00 +0000
@@ -1,351 +0,0 @@
1#include "interlayer.h"
2#include <unistd.h>
3#include <stdio.h>
4#include <stdlib.h>
5#include <string.h>
6#include <sys/types.h>
7#include <dlfcn.h>
8#include <dirent.h>
9#include <sys/stat.h>
10#include <fcntl.h>
11#include <glib.h>
12//#include <libxml2/libxml/parser.h>
13//#include <libxml2/libxml/tree.h>
14#include <libxml/parser.h>
15#include <libxml/tree.h>
16
17#define WORK_ROOT_DIR "/etc/kydevmonit/"
18typedef void (*NO_DBUS_INPUT_FUNC)(void* return_t);
19typedef void (*HAS_DBUS_INPUT_FUNC)(const char* input, void* return_t);
20typedef struct{
21 int error_no;
22 int count;
23 char * desc;
24}hw_return_t;
25
26#define NO_DBUS_INPUT_TYPE 0
27#define HAS_DBUS_INPUT_TYPE 1
28typedef struct{
29 void * address;
30 int type;
31}device_method_t;
32
33
34static xmlDocPtr intropectdoc;
35static xmlNodePtr intropectdoc_rootnode;
36static int
37_init_write_devices_intropect_xml(const char* object_name){
38 if(intropectdoc == NULL && intropectdoc_rootnode == NULL) {
39 intropectdoc = xmlNewDoc("1.0");
40 intropectdoc_rootnode = xmlNewNode(NULL, "object");
41 xmlNewProp(intropectdoc_rootnode,"name", object_name);
42 xmlDocSetRootElement(intropectdoc, intropectdoc_rootnode);
43 }
44 return 0;
45}
46static int
47_end_write_devices_intropect_xml(const char* dbus_name){
48 if(intropectdoc == NULL || intropectdoc_rootnode == NULL)
49 return -1;
50 char filename[1024]={0};
51 sprintf(filename,"%sdevices.", WORK_ROOT_DIR);
52 sprintf(filename, "%s%s.xml", filename,dbus_name);
53 printf("intropect xml filename: %s\n", filename);
54 if(xmlSaveFormatFileEnc(filename, intropectdoc, "UTF-8", 1) >=0){
55 printf("Save intropectdoc xml file successful\n");
56 }else{
57 printf("Save intropectdoc xml file failed\n");
58 }
59 xmlFreeDoc(intropectdoc);
60 xmlCleanupParser();
61 return 0;
62}
63static int
64_add_device_to_intropect_xml(const xmlChar* devicename,const char* devicecode){
65 if(intropectdoc == NULL || intropectdoc_rootnode == NULL || devicename == NULL){
66 fprintf(stderr, "doc or node or devicename is null\n");
67 return -1;
68 }
69 xmlNodePtr devicenode = xmlNewChild(intropectdoc_rootnode, NULL, "device", "");
70 xmlNewProp(devicenode, "name", devicename);
71 xmlNewProp(devicenode, "code",devicecode);
72 return 0;
73}
74
75static GHashTable * method_table = NULL;
76static int
77_init_method_hashtable(){
78 if(method_table == NULL){
79 method_table = g_hash_table_new(g_str_hash, g_str_equal);
80 }
81 return 0;
82}
83static int
84_insert_method_hashtable(gpointer key, gpointer value){
85 if(method_table == NULL || key == NULL)
86 return -1;
87 g_hash_table_insert(method_table, key, value);
88 return 0;
89}
90static gpointer
91_get_method_address(gpointer key){
92 if(method_table == NULL || key == NULL){
93 //fprintf(stderr, "ERROR: method_table or key is null\n");
94 return NULL;
95 }
96 return g_hash_table_lookup(method_table,key);
97}
98static void
99_ms_print_key_value(gpointer key, gpointer value, gpointer user_data){
100 printf("key: %s, value: %u\n", key, (unsigned int)value);
101}
102static void
103_ms_display_method_hashtable(){
104 g_hash_table_foreach(method_table, _ms_print_key_value, NULL);
105}
106static int
107_parse_device_xml(const char * filename, const char* object_name){
108 //if(filename == NULL)
109 // return -1;
110 char filepath[1024]={0};
111 sprintf(filepath,"%s",WORK_ROOT_DIR);
112 sprintf(filepath,"%s%s",filepath,filename);
113 xmlNodePtr curnode;
114 xmlDocPtr doc;
115 void * sharelibHandle;
116 xmlInitParser();
117 doc = xmlReadFile(filepath, "UTF-8", XML_PARSE_RECOVER) ;
118 if(doc == NULL){
119 fprintf(stderr, "xmlReadFile %s failed\n", filepath);
120 return -1;
121 }
122 curnode = xmlDocGetRootElement(doc);
123 if(curnode == NULL){
124 fprintf(stderr, "empty document\n");
125 xmlFreeDoc(doc);
126 return -1;
127 }
128 // printf("curnode->name: %s\n", curnode->name);
129 // curnode = curnode->xmlChildrenNode;
130 xmlChar * nodevalue = NULL;
131 xmlChar * devicecode = NULL;
132 xmlChar * methodcode = NULL;
133 xmlChar * devicepath = NULL;
134 int statuscode = 0;
135 while(curnode != NULL){
136 if(xmlStrcmp(curnode->name, (const xmlChar*)"object") == 0){
137 nodevalue = xmlGetProp(curnode, (const xmlChar*)"name");
138 //printf("nodevalue: %s\n", nodevalue);
139 if(xmlStrncmp(nodevalue, object_name, strlen(object_name)) != 0){
140 fprintf(stderr,"The object_name %s is not matched\n", nodevalue);
141 xmlFree(nodevalue);
142 statuscode = -1;
143 break;
144 }else{
145 _init_write_devices_intropect_xml(object_name);
146 xmlFree(nodevalue);
147 curnode = curnode->xmlChildrenNode;
148 continue;
149 }
150 }
151 else if(xmlStrcmp(curnode->name, (const xmlChar*)"device") == 0){
152 nodevalue = xmlGetProp(curnode, "name");
153 if(nodevalue == NULL){
154 fprintf(stderr, "The device hasn't name,this is invailed!\n");
155 statuscode = -1;
156 break;
157 }
158 devicecode = xmlGetProp(curnode, "code");
159 if(devicecode == NULL){
160 fprintf(stderr, "The device hasn't code,this is invailed!\n");
161 xmlFree(nodevalue);
162 statuscode = -1;
163 break;
164 }
165 // load so
166 devicepath = xmlGetProp(curnode, "path");
167 if(devicepath == NULL){
168 fprintf(stderr, "The device hasn't path,this is invailed!\n");
169 statuscode = -1;
170 xmlFree(nodevalue);
171 xmlFree(devicecode);
172 break;
173 }
174 printf("path: %s\n", devicepath);
175 sharelibHandle = dlopen(devicepath, RTLD_NOW);
176 if(sharelibHandle == NULL){
177 fprintf(stderr, "%s sharelibHandle is NULL\n", devicepath);
178 xmlFree(devicepath);
179 xmlFree(nodevalue);
180 xmlFree(devicecode);
181 statuscode = -1;
182 break;
183 }else{
184 _add_device_to_intropect_xml(nodevalue, devicecode);
185 _init_method_hashtable();
186 xmlFree(nodevalue);
187 xmlFree(devicepath);
188 }
189 curnode = curnode->xmlChildrenNode;
190 continue;
191 }else if(xmlStrcmp(curnode->name, (const xmlChar*)"method") == 0){
192 nodevalue = xmlGetProp(curnode, "name");
193 if(nodevalue == NULL){
194 fprintf(stderr, "method hasn't name, this is invaild!\n");
195 curnode = curnode->next;
196 continue;
197 }
198 methodcode = xmlGetProp(curnode, "code");
199 if(methodcode == NULL){
200 fprintf(stderr, "method %s hasn't code, this is invaild!\n", nodevalue);
201 curnode = curnode->next;
202 xmlFree(nodevalue);
203 continue;
204 }
205 void* methodaddr = dlsym(sharelibHandle,nodevalue);
206 char* key = malloc(20*sizeof(char));
207 device_method_t* method_ptr = malloc(sizeof(device_method_t));
208 method_ptr->address = methodaddr;
209 xmlFree(nodevalue);
210
211 nodevalue = xmlGetProp(curnode, "type");
212 if(nodevalue == NULL){
213 fprintf(stderr, "method hasn't type, this is invaild!\n");
214 xmlFree(methodcode);
215 curnode = curnode->next;
216 continue;
217 }
218 else if(xmlStrcmp(nodevalue, "nodbusinput") == 0){
219 method_ptr->type = NO_DBUS_INPUT_TYPE;
220 }else if(xmlStrcmp(nodevalue, "hasdbusinput") == 0){
221 method_ptr->type = HAS_DBUS_INPUT_TYPE;
222 }else{
223
224 }
225
226 sprintf(key, "%s%s", devicecode,methodcode);
227 printf("key: %s len=%lu\n", key, strlen(key));
228 _insert_method_hashtable(key, method_ptr);
229
230 printf("method name : %s, address : %u\n", nodevalue, (unsigned int)methodaddr);
231 xmlFree(nodevalue);
232 xmlFree(methodcode);
233 }
234 curnode = curnode->next;
235 }
236 if(devicecode != NULL)
237 xmlFree(devicecode);
238 if(doc != NULL)
239 xmlFreeDoc(doc);
240
241 return statuscode;
242}
243int interlayer_load_devices(const char* dbus_name, const char* object_name){
244 if(dbus_name == NULL || object_name == NULL){
245 fprintf(stderr, "ERROR: The dbus_name or object_name is null!\n");
246 return -1;
247 }
248 // Loop match xml file
249 DIR *workdp;
250 struct dirent *entry;
251 if((workdp = opendir(WORK_ROOT_DIR)) == NULL){
252 fprintf(stderr, "opendir %s failed,no devices\n", WORK_ROOT_DIR);
253 return -1;
254 }
255 //chdir(WORK_ROOT_DIR);
256 while((entry = readdir(workdp)) != NULL){
257 if(strncmp(dbus_name,entry->d_name, strlen(dbus_name)) == 0){
258
259 if(_parse_device_xml(entry->d_name, object_name) < 0){
260 fprintf(stderr, "%s parse failed!\n", entry->d_name);
261 }
262 else{
263 printf("%s load successful\n", entry->d_name);
264 }
265 }
266 }
267 closedir(workdp);
268 _end_write_devices_intropect_xml(dbus_name);
269 //_ms_display_method_hashtable();
270 return 0;
271}
272
273int interlayer_get_devices_intropect(const char* dbus_name, const char* object_name, const char* devicename,char* ret_desc){
274 if(dbus_name == NULL || object_name == NULL || ret_desc == NULL){
275 fprintf(stderr, "ERROR: The dbus_name or object_name or ret_desc is null!\n");
276 return -1;
277 }
278 char filename[1024];
279 memset(filename, 0, 1024);
280 size_t len=0;
281 if(strlen(devicename) == 0){
282 sprintf(filename,"%sdevices.%s.xml", WORK_ROOT_DIR, dbus_name);
283 printf("filename= %s\n", filename);
284 int fd=open(filename, O_RDONLY);
285 if(fd < 0){
286 fprintf(stderr, "%s open failed\n", filename);
287 return -1;
288 }
289
290 if((len = read(fd, ret_desc, 1024-1)) < 0){
291 fprintf(stderr, "%s read failed\n", filename);
292 close(fd);
293 return -1;
294 }
295 ret_desc[len] = '\0';
296 //printf("ret_desc = %s\n", ret_desc);
297 close(fd) ;
298 }else{
299 memset(filename, 0, 1024);
300 sprintf(filename,"%s%s.%s.xml", WORK_ROOT_DIR, dbus_name,devicename);
301 printf("filename= %s\n", filename);
302 int fd=open(filename, O_RDONLY);
303 if(fd < 0){
304 fprintf(stderr, "%s open failed\n", filename);
305 return -1;
306 }
307
308 if((len = read(fd, ret_desc, 1024-1)) < 0){
309 fprintf(stderr, "%s read failed\n", filename);
310 close(fd);
311 return -1;
312 }
313 ret_desc[len] = '\0';
314 //printf("ret_desc = %s\n", ret_desc);
315 close(fd) ;
316
317 }
318 return 0;
319}
320int interlayer_call_device_method(int devicecode, int methodcode, const char* param, int* statuscode, int * count, char* desc){
321 if(param == NULL || statuscode == NULL || count == NULL || desc == NULL){
322 fprintf(stderr, "ERROR: Please input vaild paramters\n");
323 return -1;
324 }
325 //_ms_display_method_hashtable();
326 char key[20] = {0};
327 sprintf(key,"0x%.2x0x%.2x", devicecode, methodcode);
328 printf("call_key: %s ,len=%lu\n", key, strlen(key));
329 device_method_t * method_ptr = _get_method_address(key);
330 if(method_ptr == NULL){
331 fprintf(stderr,"The method_ptr is NULL\n");
332 return -1;
333 }
334 printf("method address : %u\n", (unsigned int)(method_ptr->address));
335
336 hw_return_t result={0,0,NULL};
337 result.desc = desc;
338
339 if(method_ptr->type == NO_DBUS_INPUT_TYPE){
340 NO_DBUS_INPUT_FUNC method_func = (NO_DBUS_INPUT_FUNC)(method_ptr->address);
341 method_func(&result);
342 }else if(method_ptr->type == HAS_DBUS_INPUT_TYPE){
343 HAS_DBUS_INPUT_FUNC method_func = (HAS_DBUS_INPUT_FUNC)(method_ptr->address);
344 method_func(param,&result);
345 }else{
346 //
347 }
348 *statuscode = result.error_no;
349 *count = result.count;
350 return 0;
351}
3520
=== removed file 'src/interlayer/interlayer.h'
--- src/interlayer/interlayer.h 2017-09-05 05:53:02 +0000
+++ src/interlayer/interlayer.h 1970-01-01 00:00:00 +0000
@@ -1,34 +0,0 @@
1#ifndef __INTER_LAYER_H__
2#define __INTER_LAYER_H__
3
4
5/**
6 * The device's register info at /etc/kydevmonit/ xml file.
7 * This method find and load the device's xml file that match the
8 * dbus_name and object_name.
9 * And load the share library of matched dervice.
10 * @return 0 successful; 1 failed
11 */
12int interlayer_load_devices(const char* dbus_name, const char* object_name);
13
14/**
15 * Return the information to ret_desc about had registered device.
16 * If the len(devicename) == 0 , the information only include device_name,device_code.
17 * else the information include all method's name, method's code, method's type for the
18 * special device by param 'devicename' point.
19 *
20 * @return 0 successful ; 1 failed
21 */
22int interlayer_get_devices_intropect(const char* dbus_name, const char* object_name, const char* devicename,char* ret_desc);
23
24/**
25 * Call the device method by devicecode and methodcode point.
26 * @param If this device method need a param
27 * @error_no the device method invoke return statuscode
28 * @count
29 * @desc The describtion about the error_no
30 * @return 0 successful ; 1 failed
31 */
32int interlayer_call_device_method(int devicecode, int methodcode,const char* param, int* error_no, int* count, char* desc);
33
34#endif
350
=== modified file 'src/main.c'
--- src/main.c 2017-09-05 05:53:02 +0000
+++ src/main.c 2017-10-10 00:58:46 +0000
@@ -1,9 +1,18 @@
1#include <stdio.h>
2#include <stdlib.h>
3#include <string.h>
4#include <unistd.h>
5#include <signal.h>
1#include "./dbuslayer/monitor_dbus.h"6#include "./dbuslayer/monitor_dbus.h"
27
3int main()8void sigint_handler(int sig){
4{9 dbus_exit();
5 // load all device10 printf("dbus_exit here\n");
6 dbus_init();11 exit(EXIT_SUCCESS);
7 return 0;12}
13int main(int argc, char* argv[]){
814
15 signal(SIGINT,sigint_handler);
16 dbus_init();
17 exit(EXIT_SUCCESS);
9}18}
1019
=== added directory 'src/managerlayer'
=== added file 'src/managerlayer/_configure.c'
--- src/managerlayer/_configure.c 1970-01-01 00:00:00 +0000
+++ src/managerlayer/_configure.c 2017-10-10 00:58:46 +0000
@@ -0,0 +1,440 @@
1#include <stdlib.h>
2#include <string.h>
3#include <stdio.h>
4#include <sys/types.h>
5#include <dlfcn.h>
6#include <dirent.h>
7#include <sys/stat.h>
8#include <fcntl.h>
9#include <glib.h>
10//#include <libxml2/libxml/parser.h>
11//#include <libxml2/libxml/tree.h>
12#include <libxml/parser.h>
13#include <libxml/tree.h>
14#include "_configure.h"
15
16#define WORK_ROOT_DIR "/etc/kydevmonit"
17#define CONF_SELFCHECK_METHOD_CODE "0x006"
18
19typedef manager_device_soft_t _conf_device_soft_t;
20typedef manager_device_static_t _conf_device_static_t;
21typedef hw_return_t _conf_hw_return_t;
22
23//static char STOP_STRING[]="\0";
24static char _upstream_dbus_name[DESC_BUF_LEN] = {0};
25static char _upstream_object_name[DESC_BUF_LEN] = {0};
26static CONF_CALLBACK_FUNC _upstream_cb = NULL;
27
28static GHashTable* _sharelibHandle_ht = NULL;
29
30void free_hashTable_key(gpointer data){
31 free(data);
32}
33void free_hashTable_value(gpointer data){
34 free(data);
35}
36void free_hashTable_sharelib_value(gpointer data){
37 dlclose((void*)data);
38}
39int
40_parse_device_conf_xml(
41 GHashTable** devices_static_ht,
42 GHashTable** devices_soft_ht,
43 GHashTable** devices_methods_ht,
44 const char* filename){
45 //if(filename == NULL)
46 // return -1;
47 char filepath[DESC_BUF_LEN]={0};
48 snprintf(filepath,DESC_BUF_LEN,"%s/%s",WORK_ROOT_DIR, filename);
49
50 xmlNodePtr curnode;
51 xmlDocPtr doc;
52 xmlInitParser();
53 doc = xmlReadFile(filepath, "UTF-8", XML_PARSE_RECOVER) ;
54 if(doc == NULL){
55 fprintf(stderr, "xmlReadFile %s failed\n", filepath);
56 return -1;
57 }
58 curnode = xmlDocGetRootElement(doc);
59 if(curnode == NULL){
60 fprintf(stderr, "empty document\n");
61 xmlFreeDoc(doc);
62 return -1;
63 }
64 // printf("curnode->name: %s\n", curnode->name);
65 // curnode = curnode->xmlChildrenNode;
66 xmlChar * nodevalue = NULL;
67 xmlChar * devicecode = NULL;
68 xmlChar * methodcode = NULL;
69 xmlChar * methodtype = NULL;
70 xmlChar * devicedriver = NULL;
71 void * sharelibHandle = NULL;
72 _conf_device_soft_t* soft_value_ptr = NULL;
73 int statuscode = 0;
74 while(curnode != NULL){
75 if(xmlStrcmp(curnode->name, (const xmlChar*)"object") == 0){
76 nodevalue = xmlGetProp(curnode, (const xmlChar*)"name");
77 //printf("nodevalue: %s\n", nodevalue);
78 if(xmlStrncmp(nodevalue, _upstream_object_name, strlen(_upstream_object_name)) != 0){
79 fprintf(stderr,"The object_name %s is not matched\n", nodevalue);
80 statuscode = -1;
81 }else{
82 //_init_write_devices_intropect_xml(object_name);
83 //printf("DEBUG: new device finded\n");
84 if(*devices_static_ht == NULL)
85 *devices_static_ht = g_hash_table_new_full(g_str_hash, g_str_equal,free_hashTable_key,free_hashTable_value);
86 //if(devices_static_ht == NULL)
87 // printf("DEBUG: g_hash_table_new_full failed! devices_static_ht is null\n");
88 if(*devices_soft_ht == NULL)
89 *devices_soft_ht = g_hash_table_new_full(g_str_hash,g_str_equal, free_hashTable_key, free_hashTable_value);
90 if(*devices_methods_ht == NULL)
91 *devices_methods_ht = g_hash_table_new_full(g_str_hash, g_str_equal, free_hashTable_key,free_hashTable_value);
92 }
93 xmlFree(nodevalue);
94 curnode = curnode->xmlChildrenNode;
95 if(statuscode < 0) break;
96 }
97 else if(xmlStrcmp(curnode->name, (const xmlChar*)"device") == 0){
98 devicecode = xmlGetProp(curnode, "code");
99 if(devicecode == NULL){
100 fprintf(stderr, "The device hasn't code,this is invailed!\n");
101 statuscode = -1;
102 break;
103 }
104 // check this device is registed?
105 _conf_device_static_t* ds_value_ptr = (_conf_device_static_t*)g_hash_table_lookup(*devices_static_ht,devicecode);
106 if(ds_value_ptr != NULL && ds_value_ptr->is_registed != 1){
107 xmlFree(devicecode);
108 //statuscode = -1;
109 break; // Skip this device.
110 }
111 nodevalue = xmlGetProp(curnode, "name");
112 if(nodevalue == NULL){
113 fprintf(stderr, "The device hasn't name,this is invailed!\n");
114 statuscode = -1;
115 xmlFree(devicecode);
116 break;
117 }
118 // load so
119 devicedriver = xmlGetProp(curnode, "driver");
120 if(devicedriver == NULL){
121 fprintf(stderr, "The device hasn't driver,this is invailed!\n");
122 statuscode = -1;
123 xmlFree(nodevalue);
124 xmlFree(devicecode);
125 break;
126 }
127 memset(filepath, 0 , DESC_BUF_LEN);
128 snprintf(filepath, DESC_BUF_LEN, "%s/%s",WORK_ROOT_DIR,devicedriver);
129 printf("driver path: %s\n", filepath);
130 sharelibHandle = dlopen(filepath, RTLD_LAZY);
131 if(sharelibHandle == NULL){
132 fprintf(stderr, "%s sharelibHandle is NULL\n", filepath);
133 xmlFree(devicecode);
134 statuscode = -1;
135 }else{
136 //_add_device_to_intropect_xml(nodevalue, devicecode);
137 //_init_method_hashtable();
138 if(ds_value_ptr == NULL){ // new device, add to queue
139 _upstream_cb(CONF_CBTYPE_DRIVER_ADDED,devicecode,nodevalue);
140 dlclose(sharelibHandle);
141 xmlFree(devicecode);
142 xmlFree(nodevalue);
143 xmlFree(devicedriver);
144 break; // Skip this device;
145 }else{
146 if(_sharelibHandle_ht == NULL)
147 _sharelibHandle_ht = g_hash_table_new_full(g_str_hash, g_str_equal,free_hashTable_key,free_hashTable_sharelib_value);
148 char* key_ptr = (char*)malloc(strlen(devicecode)+1);
149 snprintf(key_ptr, sizeof(key_ptr),"%s",devicecode);
150 g_hash_table_insert(_sharelibHandle_ht,key_ptr,sharelibHandle);
151 soft_value_ptr = (_conf_device_soft_t*)malloc(sizeof(_conf_device_soft_t));
152 soft_value_ptr->device_code = strtol(devicecode,NULL,16);
153 soft_value_ptr->is_online = 0;
154 soft_value_ptr->workstate = WORK_STATE_UNKNOW;
155 // other entry unknow.
156 g_hash_table_insert(*devices_soft_ht,strdup(key_ptr),soft_value_ptr); // !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
157 // don't usr the same key_ptr??
158 }
159 }
160 curnode = curnode->xmlChildrenNode;
161 xmlFree(nodevalue);
162 xmlFree(devicedriver);
163
164 if(statuscode < 0) break;
165 else continue;
166 }else if(xmlStrcmp(curnode->name, (const xmlChar*)"method") == 0){
167 nodevalue = xmlGetProp(curnode, "name");
168 if(nodevalue == NULL){
169 fprintf(stderr, "method hasn't name, this is invaild!\n");
170 curnode = curnode->next;
171 continue;
172 }
173 methodcode = xmlGetProp(curnode, "code");
174 if(methodcode == NULL){
175 fprintf(stderr, "method %s hasn't code, this is invaild!\n", nodevalue);
176 curnode = curnode->next;
177 xmlFree(nodevalue);
178 continue;
179 }
180 methodtype = xmlGetProp(curnode, "type");
181 if(methodtype == NULL){
182 fprintf(stderr, "method hasn't type, this is invaild!\n");
183 xmlFree(methodcode);
184 xmlFree(nodevalue);
185 curnode = curnode->next;
186 continue;
187 }
188
189 void* methodaddr = dlsym(sharelibHandle,nodevalue);
190 conf_device_method_t* method_value_ptr = malloc(sizeof(conf_device_method_t));
191 method_value_ptr->address = methodaddr;
192
193 printf("method name : %s, address : %u\n", nodevalue, (unsigned int)methodaddr);
194
195 method_value_ptr->type = strtol(methodtype,NULL,10);
196
197 char* key_ptr = malloc(strlen(devicecode)+strlen(methodcode)+1);
198 sprintf(key_ptr, "%s%s", devicecode,methodcode);
199 printf("key: %s len=%lu\n", key_ptr, strlen(key_ptr));
200 g_hash_table_insert(*devices_methods_ht, key_ptr, method_value_ptr);
201 if(xmlStrcmp(methodcode, CONF_SELFCHECK_METHOD_CODE) == 0){
202 // call self_check;
203
204 _conf_hw_return_t result={0,0,{0}};
205 //result.desc = soft_value_ptr->desc;
206 NO_INPUT_NO_BLOCK_FUNC self_check = (NO_INPUT_NO_BLOCK_FUNC)methodaddr;
207 self_check(&result);
208 soft_value_ptr->workstate = result.state_code;
209 soft_value_ptr->exception_code = result.exception_code;
210 soft_value_ptr->is_online = (result.exception_code == 0x01)?1:0;
211 memset(soft_value_ptr->desc,0,DESC_BUF_LEN);
212 snprintf(soft_value_ptr->desc,DESC_BUF_LEN,"%s",result.desc);
213
214 }
215 xmlFree(methodtype);
216 xmlFree(nodevalue);
217 xmlFree(methodcode);
218 }
219 curnode = curnode->next;
220 }
221 xmlFreeDoc(doc);
222 return statuscode;
223}
224int _parse_devices_state_xml(GHashTable** devices_static_ht){
225 // load state informations for all devices.
226 char path_buf[1024] = {0};
227 snprintf(path_buf, 1024, "%s/devices.%s.xml",WORK_ROOT_DIR,_upstream_dbus_name);
228 printf("DEBUG: static file path: %s\n", path_buf);
229
230 xmlNodePtr curnode;
231 xmlDocPtr doc;
232 int statuscode = 0;
233
234 xmlInitParser();
235 doc = xmlReadFile(path_buf, "UTF-8", XML_PARSE_RECOVER);
236 if(doc == NULL){
237 fprintf(stderr, "%s read failed, it exist?\n", path_buf);
238 devices_static_ht == NULL;
239 return 0;
240 }
241 curnode = xmlDocGetRootElement(doc);
242 if(curnode == NULL){
243 fprintf(stderr, "empty document\n");
244 xmlFreeDoc(doc);
245 return -1;
246 }
247 // printf("curnode->name: %s\n", curnode->name);
248 // curnode = curnode->xmlChildrenNode;
249 xmlChar* namevalue = NULL;
250 xmlChar* codevalue = NULL;
251 xmlChar* registervalue = NULL;
252
253 while(curnode != NULL){
254 if(xmlStrcmp(curnode->name, (const xmlChar*)"object") == 0){
255 namevalue = xmlGetProp(curnode, (const xmlChar*)"name");
256 //printf("nodevalue: %s\n", nodevalue);
257 if(xmlStrncmp(namevalue, _upstream_object_name, strlen(_upstream_object_name)) != 0){
258 fprintf(stderr,"The object_name %s is not matched\n", namevalue);
259 statuscode = -1;
260 }else{
261 // init hashtable
262 *devices_static_ht=g_hash_table_new_full(g_str_hash, g_str_equal, free_hashTable_key, free_hashTable_value);
263 if(*devices_static_ht == NULL){
264 fprintf(stderr,"device_static_ht create failed\n");
265 statuscode = -1;
266 }
267 }
268 xmlFree(namevalue);
269 curnode = curnode->xmlChildrenNode;
270 if(statuscode < 0) break;
271 }
272 else if(xmlStrcmp(curnode->name, (const xmlChar*)"device") == 0){
273 if(devices_static_ht == NULL){
274 fprintf(stderr, "The device_static_ht is NULL, it is invaild!\n");
275 statuscode = -1;
276 break;
277 }
278 namevalue = xmlGetProp(curnode, "name");
279 if(namevalue == NULL){
280 fprintf(stderr, "The device hasn't name,this is invailed!\n");
281 statuscode = -1;
282 break;
283 }
284 codevalue = xmlGetProp(curnode, "code");
285 if(codevalue == NULL){
286 fprintf(stderr, "The device hasn't code,this is invailed!\n");
287 xmlFree(namevalue);
288 statuscode = -1;
289 break;
290 }
291 registervalue = xmlGetProp(curnode, "regist");
292 if(registervalue == NULL){
293 fprintf(stderr, "The device no regist info, this is invailed!\n");
294 xmlFree(namevalue);
295 xmlFree(codevalue);
296 statuscode = -1;
297 break;
298 }
299 _conf_device_static_t* value_ptr = (_conf_device_static_t*)malloc(sizeof(_conf_device_static_t));
300 value_ptr->device_code = strtol(codevalue,NULL,16);
301 snprintf(value_ptr->device_name, sizeof(value_ptr->device_name),"%s",namevalue);
302 value_ptr->is_registed = strtol(registervalue,NULL,10);
303 char* key_ptr = (char*)malloc(strlen(codevalue)+1);
304 snprintf(key_ptr, sizeof(key_ptr),"%s",codevalue);
305
306 g_hash_table_insert(*devices_static_ht, key_ptr, value_ptr);
307
308 xmlFree(namevalue);
309 xmlFree(codevalue);
310 xmlFree(registervalue);
311
312 curnode = curnode->next;
313 }
314 else{
315 fprintf(stderr,"DEBUG: Go to Next node!\n");
316 curnode = curnode->next;
317 }
318 }
319 xmlFreeDoc(doc);
320 return statuscode;
321}
322
323int
324conf_init(const char* dbus_name, const char* object_name,
325 GHashTable** devices_methods_ht,
326 GHashTable** devices_soft_ht,
327 GHashTable** devices_static_ht,
328 CONF_CALLBACK_FUNC upstream_callback){
329 // copy name
330 strncpy(_upstream_dbus_name, dbus_name, MIN(strlen(dbus_name), DESC_BUF_LEN));
331 strncpy(_upstream_object_name,object_name, MIN(strlen(object_name), DESC_BUF_LEN));
332 if(upstream_callback == NULL){
333 fprintf(stderr, "_conf_callback is null!\n");
334 return -1;
335 }
336 _upstream_cb = upstream_callback;
337
338 if(_parse_devices_state_xml(devices_static_ht) < 0){
339 fprintf(stderr, "_parse_devices_state_xml failed!\n");
340 return -1;
341 }
342
343 // Loop match xml file
344 DIR *workdp;
345 struct dirent *entry;
346 if((workdp = opendir(WORK_ROOT_DIR)) == NULL){
347 fprintf(stderr, "opendir %s failed,no devices\n", WORK_ROOT_DIR);
348 return -1;
349 }
350 //chdir(WORK_ROOT_DIR);
351 while((entry = readdir(workdp)) != NULL){
352 if(strncmp(dbus_name,entry->d_name, strlen(dbus_name)) == 0){
353
354 if(_parse_device_conf_xml(devices_static_ht, devices_soft_ht, devices_methods_ht,entry->d_name) < 0){
355 fprintf(stderr, "%s parse failed!\n", entry->d_name);
356 }
357 else{
358 printf("%s load successful\n", entry->d_name);
359 }
360 }
361 }
362 closedir(workdp);
363 if(*devices_static_ht == NULL){
364 printf("After conf_init, devices_static_ht is null\n");
365
366 }
367
368 return 0;
369}
370void _hashtable_foreach_func(gpointer key, gpointer value, gpointer user_data){
371 xmlNodePtr doc_rootnode = (xmlNodePtr)user_data;
372 _conf_device_static_t* value_ptr = (_conf_device_static_t*)value;
373 xmlNodePtr devicenode = xmlNewChild(doc_rootnode, NULL, "device", "");
374 xmlNewProp(devicenode, "name", value_ptr->device_name);
375 char buf[1024] = {0};
376 snprintf(buf,1024,"0x%.2x",value_ptr->device_code);
377 xmlNewProp(devicenode, "code", buf);
378
379 memset(buf, 0, 1024);
380 snprintf(buf,1024,"%d",value_ptr->is_registed);
381 xmlNewProp(devicenode,"regist", buf);
382}
383int
384conf_end_writeToDisk(GHashTable* devices_static_ht){
385 if(devices_static_ht == NULL) return -1;
386 xmlDocPtr doc;
387 xmlNodePtr doc_rootnode;
388
389 doc = xmlNewDoc("1.0");
390 doc_rootnode = xmlNewNode(NULL, "object");
391 xmlNewProp(doc_rootnode,"name", _upstream_object_name);
392 xmlDocSetRootElement(doc,doc_rootnode);
393
394 g_hash_table_foreach(devices_static_ht,_hashtable_foreach_func,doc_rootnode);
395
396 char filename[1024]={0};
397 snprintf(filename,1024,"%s/devices.%s.xml", WORK_ROOT_DIR, _upstream_dbus_name);
398 printf("intropect xml filename: %s\n", filename);
399 if(xmlSaveFormatFileEnc(filename, doc, "UTF-8", 1) >=0){
400 printf("Save intropectdoc xml file successful\n");
401 }else{
402 printf("Save intropectdoc xml file failed\n");
403 }
404 xmlFreeDoc(doc);
405 xmlCleanupParser();
406
407 // free sharelibHandle_ht
408 g_hash_table_destroy(_sharelibHandle_ht);
409 _sharelibHandle_ht = NULL;
410 return 0;
411}
412
413int
414conf_enable_driver(const char* device_name,
415 GHashTable* devices_methods_ht,
416 GHashTable* devices_soft_ht,
417 GHashTable* devices_static_ht){
418 char filename[DESC_BUF_LEN] = {0};
419
420 snprintf(filename, DESC_BUF_LEN,"%s.%s.xml",_upstream_dbus_name,device_name);
421 return _parse_device_conf_xml(&devices_static_ht,&devices_soft_ht,&devices_methods_ht,(const char*)filename);
422}
423
424gboolean _dm_hashTable_HRFunc(gpointer key, gpointer value,gpointer user_data){
425 char* key_ptr = (char*)key;
426 char* codevalue_ptr = (char*)user_data;
427 if(strncmp(key_ptr,codevalue_ptr,strlen(codevalue_ptr)) == 0)
428 return TRUE;
429 else
430 return FALSE;
431}
432int
433conf_disable_driver(GHashTable* devices_methods_ht,int device_code){
434 if(_sharelibHandle_ht == NULL)
435 return 0;
436 char codevalue[10] = {0};
437 snprintf(codevalue, sizeof(codevalue),"0x%.2x",device_code);
438
439 return g_hash_table_foreach_remove(devices_methods_ht,_dm_hashTable_HRFunc,codevalue) && g_hash_table_remove(_sharelibHandle_ht,codevalue);
440}
0441
=== added file 'src/managerlayer/_configure.h'
--- src/managerlayer/_configure.h 1970-01-01 00:00:00 +0000
+++ src/managerlayer/_configure.h 2017-10-10 00:58:46 +0000
@@ -0,0 +1,51 @@
1#ifndef ___CONFIGURE_H__
2#define ___CONFIGURE_H__
3
4#include <glib.h>
5#include "manager.h"
6
7#define CONF_CBTYPE_DRIVER_CHANGED 0
8#define CONF_CBTYPE_DRIVER_ADDED 1
9#define CONF_CBTYPE_DRIVER_REMOVED 2
10
11#define CONF_METHOD_TYPE_HASINPUT 1
12#define CONF_METHOD_TYPE_HASBLOCK 2
13
14
15
16typedef struct{
17 void * address;
18 int type;
19}conf_device_method_t; // This is the value of hashtable device_method_ht, key is
20
21typedef void (*NO_INPUT_NO_BLOCK_FUNC)(void* return_ptr);
22typedef void (*NO_INPUT_BLOCK_FUNC)(void* return_ptr, int time);
23typedef void (*HAS_INPUT_NO_BLOCK_FUNC)(const char* input, void* return_ptr);
24typedef void (*HAS_INPUT_BLOCK_FUNC)(const char* input, void* return_ptr,int time);
25
26
27/**
28 * @param callback_type 0: _CONF_DRIVER_CHANGED, 1: _CONF_DRIVER_ADDED, 2: _CONF_DRIVER_REMOVED
29 */
30typedef void (*CONF_CALLBACK_FUNC)(int callback_type, char* device_code, char* device_name);
31
32
33/**
34 * Load the configure files, then init all data structures.
35 */
36int conf_init(const char* dbus_name, const char* object_name,
37 GHashTable** devices_method_ht,
38 GHashTable** devices_soft_ht,
39 GHashTable** devices_static_ht,
40 CONF_CALLBACK_FUNC);
41
42int conf_end_writeToDisk(GHashTable* devices_static_ht);
43
44int conf_enable_driver(const char* device_name,
45 GHashTable* devices_methods_ht,
46 GHashTable* devices_soft_ht,
47 GHashTable* devices_static_ht);
48
49int conf_disable_driver(GHashTable* devices_methods_ht, int device_code);
50
51#endif // ___CONFIGURE_H__
052
=== added file 'src/managerlayer/manager.c'
--- src/managerlayer/manager.c 1970-01-01 00:00:00 +0000
+++ src/managerlayer/manager.c 2017-10-10 00:58:46 +0000
@@ -0,0 +1,235 @@
1#include <unistd.h>
2#include <stdio.h>
3#include <stdlib.h>
4#include <string.h>
5#include <sys/types.h>
6#include <dlfcn.h>
7#include <dirent.h>
8#include <sys/stat.h>
9#include <fcntl.h>
10#include <glib.h>
11
12#include "manager.h"
13#include "_configure.h"
14
15#define DEVICE_BLOCK_METHOD_TIMEOUT 10 // seconds
16#define EXCEPTION_CODE_NO_DEVICE 0x01
17#define EXCEPTION_CODE_NO_DEVICE_METHOD 0x02
18#define EXCEPTION_CODE_INVAILD_OP 0x04
19
20static MANAGER_CALLBACK_FUNC _upstream_cb = NULL;
21static GHashTable* _devices_static_ht = NULL;
22static GHashTable* _devices_soft_ht = NULL;
23static GHashTable* _devices_methods_ht = NULL;
24
25static void
26_deal_conf_callback(int callback_type, char* device_code, char* device_name){
27 switch(callback_type){
28 case CONF_CBTYPE_DRIVER_ADDED:{
29 manager_device_static_t* value_ptr = (manager_device_static_t*)malloc(sizeof(manager_device_static_t));
30 value_ptr->device_code = strtol(device_code,NULL,16);
31 snprintf(value_ptr->device_name,sizeof(value_ptr->device_name),"%s",device_name);
32 value_ptr->is_registed = 0;
33 char* key_ptr = (char*)malloc(strlen(device_code)+1);
34 snprintf(key_ptr,sizeof(key_ptr),"%s",device_code);
35 g_hash_table_insert(_devices_static_ht,key_ptr,value_ptr);
36 printf("finded new device: 0x%.2x,%s, %d\n",value_ptr->device_code,value_ptr->device_name,value_ptr->is_registed);
37 break;
38 }
39 case CONF_CBTYPE_DRIVER_CHANGED:
40 break;
41 case CONF_CBTYPE_DRIVER_REMOVED:
42 break;
43 default:
44 break;
45 }
46}
47
48/************************** Interfaces ***********************************/
49int
50manager_init(const char* dbus_name, const char* object_name, MANAGER_CALLBACK_FUNC upstream_cb){
51 if(upstream_cb == NULL){
52 fprintf(stderr, "callback_func is null!\n");
53 return -1;
54 }
55 if(dbus_name == NULL || object_name == NULL){
56 fprintf(stderr, "dbus_name or object_name is null!\n");
57 return -1;
58 }
59
60 _upstream_cb = upstream_cb;
61 printf("manager_init here\n");
62 conf_init(dbus_name, object_name,&_devices_methods_ht,&_devices_soft_ht,&_devices_static_ht,(CONF_CALLBACK_FUNC)_deal_conf_callback);
63 if(_devices_static_ht == NULL){
64 printf("After conf_init, _devices_static_ht is null\n");
65
66 }
67 return 0;
68}
69
70int
71manager_call_device_method(int device_code, int method_code, const char* param, dbus_return_t* rt){
72 if(_devices_soft_ht == NULL || _devices_methods_ht == NULL){
73 rt->state_code = WORK_STATE_UNKNOW;
74 rt->exception_code = 0x20000;
75 snprintf(rt->desc, DESC_BUF_LEN, "The hashtable is null!");
76 return -1;
77 }
78 char codevalue[10]={0};
79 snprintf(codevalue,sizeof(codevalue),"0x%.2x",device_code);
80
81 manager_device_soft_t* soft_value_ptr = g_hash_table_lookup(_devices_soft_ht,codevalue);
82 if(soft_value_ptr == NULL){
83 rt->state_code = WORK_STATE_UNKNOW;
84 rt->exception_code = 0x20000 | EXCEPTION_CODE_NO_DEVICE;
85 snprintf(rt->desc, DESC_BUF_LEN, "The device of 0x%.2x hasn't registed.", device_code);
86 //fprintf(stderr,"The soft_value_ptr of %d not exist!\n",device_code);
87 return -1;
88 }
89 if(soft_value_ptr->workstate == WORK_STATE_PROCESSING){
90 rt->state_code = WORK_STATE_PROCESSING;
91 rt->exception_code = 0x20000| EXCEPTION_CODE_INVAILD_OP;
92 snprintf(rt->desc,DESC_BUF_LEN,"This device is processing a job,please wait!\n");
93 return -1;
94 }
95 char key[20] = {0};
96 snprintf(key,sizeof(key),"%s0x%.3x",codevalue, method_code);
97 printf("call_key: %s ,len=%lu\n", key, strlen(key));
98
99 conf_device_method_t* method_ptr = g_hash_table_lookup(_devices_methods_ht,key);
100 if(method_ptr == NULL){
101 rt->state_code = WORK_STATE_UNKNOW;
102 rt->exception_code = 0x20000 | EXCEPTION_CODE_NO_DEVICE_METHOD;
103 snprintf(rt->desc,DESC_BUF_LEN,"The method 0x%.3x don't exist!", method_code);
104 return -1;
105 }
106
107 if(method_ptr->type == CONF_METHOD_TYPE_HASINPUT)
108 ((HAS_INPUT_NO_BLOCK_FUNC)(method_ptr->address))(param,rt);
109 else if(method_ptr->type == CONF_METHOD_TYPE_HASBLOCK)
110 ((NO_INPUT_BLOCK_FUNC)(method_ptr->address))(rt,_upstream_cb);// !!!
111 else if(method_ptr->type == (CONF_METHOD_TYPE_HASBLOCK | CONF_METHOD_TYPE_HASINPUT))
112 ((HAS_INPUT_BLOCK_FUNC)(method_ptr->address))(param,rt,_upstream_cb);
113 else // 0
114 ((NO_INPUT_NO_BLOCK_FUNC)(method_ptr->address))(rt);
115 rt->exception_code = rt->exception_code | 0x10000;
116 rt->exception_code = rt->exception_code | (device_code<<8);
117 soft_value_ptr->workstate = rt->state_code;
118 soft_value_ptr->exception_code = rt->exception_code;
119 memset(soft_value_ptr->desc,0,DESC_BUF_LEN);
120 snprintf(soft_value_ptr->desc, DESC_BUF_LEN, "%s",rt->desc);
121
122 return 0;
123}
124const manager_device_soft_t* manager_get_device_soft_t(int device_code){
125 if(_devices_soft_ht == NULL){
126 fprintf(stderr, "This devices_soft_ht is null!!\n");
127 return NULL;
128 }
129 char codevalue[10] = {0};
130 snprintf(codevalue, sizeof(codevalue),"0x%.2x",device_code);
131 return (const manager_device_soft_t*)g_hash_table_lookup(_devices_soft_ht, codevalue);
132}
133const GList* manager_get_all_device_soft_t(){
134 if(_devices_soft_ht == NULL){
135 fprintf(stderr, "This devices_soft_ht is null!!\n");
136 return NULL;
137 }
138 return (const GList*)g_hash_table_get_values(_devices_soft_ht);
139}
140
141const manager_device_static_t* manager_get_device_static_t(int device_code){
142 if(_devices_static_ht == NULL){
143 fprintf(stderr, "This devices_static_ht is null!!\n");
144 return NULL;
145 }
146 char codevalue[10] = {0};
147 snprintf(codevalue, sizeof(codevalue),"0x%.2x",device_code);
148 return (const manager_device_static_t*)g_hash_table_lookup(_devices_static_ht, codevalue);
149}
150const GList* manager_get_all_device_static_t(){
151 if(_devices_static_ht == NULL){
152 fprintf(stderr, "This devices_static_ht is null!!\n");
153 return NULL;
154 }
155 return (GList*)g_hash_table_get_values(_devices_static_ht);
156}
157int
158manager_regist_device(int device_code, dbus_return_t* rt){
159
160 char codevalue[10] = {0};
161 snprintf(codevalue, sizeof(codevalue),"0x%.2x",device_code);
162 manager_device_static_t* ds = g_hash_table_lookup(_devices_static_ht,codevalue);
163 if(ds == NULL){
164 rt->state_code = WORK_STATE_UNKNOW;
165 rt->exception_code = 0x20000 | EXCEPTION_CODE_NO_DEVICE;
166 snprintf(rt->desc, DESC_BUF_LEN, "The device's driver of 0x%.2x not exist!.", device_code);
167 return -1;
168 }
169 if(ds->is_registed == 1){// had registed
170 rt->state_code = WORK_STATE_UNKNOW;
171 rt->exception_code = 0x20000 | EXCEPTION_CODE_INVAILD_OP;
172 snprintf(rt->desc, DESC_BUF_LEN, "The device of 0x%.2x had registed!.", device_code);
173 return -1;
174 }
175 ds->is_registed = 1;
176 if(conf_enable_driver(ds->device_name,_devices_methods_ht,_devices_soft_ht,_devices_static_ht) < 0){
177 rt->state_code = WORK_STATE_UNKNOW;
178 rt->exception_code = 0x20000 | 0x05;
179 snprintf(rt->desc, DESC_BUF_LEN, "conf_enable_driver failed!");
180 }else{
181 printf("conf_enable_driver successfully\n");
182 manager_device_soft_t * dsoft = g_hash_table_lookup(_devices_soft_ht,codevalue);
183 if(dsoft == NULL){
184 printf("dsoft is null\n");
185 rt->state_code = WORK_STATE_UNKNOW;
186 rt->exception_code = 0x20000 | EXCEPTION_CODE_NO_DEVICE;
187 }else{
188 rt->state_code = dsoft->workstate;
189 rt->exception_code = dsoft->exception_code | 0x10000;
190 rt->exception_code |= (device_code<<8);
191 snprintf(rt->desc, DESC_BUF_LEN,"%s",dsoft->desc);
192 }
193 }
194
195 return 0;
196}
197void manager_logout_device(int device_code,dbus_return_t * rt){
198 char codevalue[10] = {0};
199 snprintf(codevalue, sizeof(codevalue),"0x%.2x",device_code);
200 manager_device_static_t* ds = g_hash_table_lookup(_devices_static_ht,codevalue);
201 if(ds == NULL){
202 rt->state_code = WORK_STATE_UNKNOW;
203 rt->exception_code = 0x20000 | EXCEPTION_CODE_NO_DEVICE;
204 snprintf(rt->desc, DESC_BUF_LEN, "The device's driver of 0x%.2x not exist!.", device_code);
205 return -1;
206 }
207 if(ds->is_registed == 0){// had logouted
208 rt->state_code = WORK_STATE_UNKNOW;
209 rt->exception_code = 0x20000 | EXCEPTION_CODE_INVAILD_OP;
210 snprintf(rt->desc, DESC_BUF_LEN, "The device of 0x%.2x had logouted!.", device_code);
211 return -1;
212 }
213 if(conf_disable_driver(_devices_methods_ht,device_code) < 0){
214 rt->state_code = WORK_STATE_UNKNOW;
215 rt->exception_code = 0x20000 | 0x05;
216 snprintf(rt->desc, DESC_BUF_LEN, "conf_disable_driver failed!");
217 return;
218 }else{
219 rt->state_code = WORK_STATE_UNKNOW;
220 rt->exception_code = 0x00000;
221 }
222 g_hash_table_remove(_devices_soft_ht,codevalue);
223 ds->is_registed = 0;
224
225}
226int
227manager_get_device_interfaces_info(int device_code, char* ret_desc){
228 //
229}
230int manager_exit(){
231 g_hash_table_destroy(_devices_soft_ht);
232 g_hash_table_destroy(_devices_methods_ht);
233 conf_end_writeToDisk(_devices_static_ht);
234 return 0;
235}
0236
=== added file 'src/managerlayer/manager.h'
--- src/managerlayer/manager.h 1970-01-01 00:00:00 +0000
+++ src/managerlayer/manager.h 2017-10-10 00:58:46 +0000
@@ -0,0 +1,91 @@
1#ifndef __MANAGER_H__
2#define __MANAGER_H__
3
4#define DESC_BUF_LEN 1024
5
6#define WORK_STATE_CLOSED 0
7#define WORK_STATE_IDLE 1
8#define WORK_STATE_PROCESSING 2
9#define WORK_STATE_EXCEPTION 3
10#define WORK_STATE_UNKNOW 4
11
12#define RETURN_ERRNO_OK 0
13#define RETURN_ERRNO_WARNING 1
14#define RETURN_ERRNO_EXCEPTION 2
15#define RETURN_ERRNO_UNKNOW 4
16
17
18typedef struct{
19 int device_code; // Example : 0x02
20 int is_online; // true or false
21 int workstate; // every device has a state machine 0: closed 1: idle 2: Processing 3: Exception
22 int exception_code; // if state=Exception, exception_code is the specific exception code.
23 char desc[DESC_BUF_LEN];// the decription of exception;
24
25}manager_device_soft_t; // There infomations will be updated by software at most case.
26
27typedef struct{
28 int device_code;
29 char device_name[5] ; // The simple name. Example: idr, br, prt
30 //char manufactire[100];
31 //char serial[100];
32 int is_registed; // true or false
33}manager_device_static_t; // There infomation is static at most case.
34
35typedef struct{
36 int state_code;
37 int exception_code;
38 char desc[DESC_BUF_LEN];
39}dbus_return_t;
40
41typedef dbus_return_t hw_return_t;
42
43typedef struct{
44 int error_no;
45 int device_code;
46 int method_code;
47 char* info;
48}manager_callback_return_t;
49
50typedef void (*MANAGER_CALLBACK_FUNC)(manager_callback_return_t*);
51/**
52 * Load all device's configure file, then build the
53 * main data structures: device_method hashtable,
54 * device_state struct array.
55 * @param dbus_name the name of dbus, Example : com.jd.test
56 * @param object_name the one object of dbus_name
57 * @param CALLBACK_FUNC initiative feedback infomations to upstearm caller.
58 * @return 0 successful, 1 failed.
59 */
60int manager_init(const char* dbus_name, const char* object_name, MANAGER_CALLBACK_FUNC);
61
62/**
63 * Call the device method by devicecode and methodcode point.
64 * @param If this device method need a param
65 * @error_no the device method invoke return statuscode
66 * @count
67 * @desc The describtion about the error_no
68 * @return 0 successful ; 1 failed
69 */
70int manager_call_device_method(int devicecode, int methodcode,const char* param, dbus_return_t*);
71
72/**
73 * Get the current device's info struct.
74 */
75const manager_device_soft_t* manager_get_device_soft_t(int device_code);
76const GList* manager_get_all_device_soft_t();
77
78const manager_device_static_t* manager_get_device_static_t(int device_code);
79const GList* manager_get_all_device_static_t();
80
81int manager_regist_device(int device_code,dbus_return_t*);
82void manager_logout_device(int device_code,dbus_return_t*);
83/**
84 * Get the device's interfaces info.
85 * @param device_code, the code of device
86 * @param ret_desc, the infomation storage location.
87 * @return 0 successful; -1 failed
88 */
89int manager_get_device_interfaces_info(int device_code, char* ret_desc);
90int manager_exit();
91#endif // __MANAGER_H__

Subscribers

People subscribed via source and target branches

to all changes: