Device Monitor
@@ -150,7 +150,7 @@ | ||
150 | 150 | |
151 | 151 | -cp -rfp ${SRC}/arch/posix/machine/${MACHINE}/h/std/* image/++PREFIX++/include/std |
152 | 152 | -cp -rfp ${SRC}/arch/posix/machine/${MACHINE}/h/ts/c/* image/++PREFIX++/include/ts/c |
153 | - -cp -rfp ${SRC}/arch/posix/machine/${MACHINE}/h/ts/c++/* image/++PREFIX++/include/ts/c | |
153 | + -cp -rfp ${SRC}/arch/posix/machine/${MACHINE}/h/ts/c++/* image/++PREFIX++/include/ts/c++ | |
154 | 154 | -cp -rfp ${SRC}/arch/posix/machine/${MACHINE}/${RELEASE}/h/std/* image/++PREFIX++/include/std |
155 | 155 | -cp -rfp ${SRC}/arch/posix/machine/${MACHINE}/${RELEASE}/h/ts/c/* image/++PREFIX++/include/ts/c |
156 | 156 | -cp -rfp ${SRC}/arch/posix/machine/${MACHINE}/${RELEASE}/h/ts/c++/* image/++PREFIX++/include/ts/c++ |
@@ -0,0 +1,11 @@ | ||
1 | + | |
2 | +#ifndef ___tsDeviceMonitor_cpp_H___ | |
3 | +#define ___tsDeviceMonitor_cpp_H___ | |
4 | + | |
5 | +#define DM_DEBUG 2 | |
6 | +#define DM_DIS_DEBUG 1 | |
7 | + | |
8 | +#include "_ts/c++/tsDeviceMonitor_pb.h" | |
9 | + | |
10 | +#endif | |
11 | + |
@@ -0,0 +1,221 @@ | ||
1 | + | |
2 | + | |
3 | +#include <stdlib.h> | |
4 | +#include "_ts/c++/tsDeviceMonitor_.h" | |
5 | +#include "ts/c++/tsReadLine.h" | |
6 | +#include "ts/c++/tsLog.h" | |
7 | + | |
8 | +CLASS_TINYSTATE(ts/c++/tsDeviceMonitor,ts/c++/tinyState) | |
9 | + | |
10 | + | |
11 | +#if 0 | |
12 | + | |
13 | +TS_BEGIN_IMPLEMENT | |
14 | + | |
15 | + | |
16 | +#include "ts/c++/tsIOstring.h" | |
17 | +#include "ts/c++/tsDevNull.h" | |
18 | +#include "ts/c++/tsCallBuffer.h" | |
19 | +#include "ts/c++/sTimer.h" | |
20 | +#include "ts/c++/tsSystem.h" | |
21 | +#include <libusb-1.0/libusb.h> | |
22 | + | |
23 | +typedef struct detect_list { | |
24 | + int vendor; | |
25 | + int product; | |
26 | +} DETECT_LIST; | |
27 | + | |
28 | + | |
29 | +class TS_THISCLASS : public TS_BASECLASS { | |
30 | +public: | |
31 | + tsDeviceMonitor_( | |
32 | + tinyState * parent, | |
33 | + int debug=0, | |
34 | + int mode=0); | |
35 | + void inherit( | |
36 | + tinyState * parent, | |
37 | + int debug=0, | |
38 | + int mode=0); | |
39 | + | |
40 | + | |
41 | + int debug; | |
42 | + | |
43 | +private: | |
44 | +protected: | |
45 | + int mode; | |
46 | + tsIOstring * ior; | |
47 | + tsIOstring * iow; | |
48 | + tsIOstring * ioe; | |
49 | + tsCallBuffer * cb; | |
50 | + tsSystem * sys; | |
51 | + | |
52 | + static const char * commandList[]; | |
53 | + const char ** commandListPtr; | |
54 | + sTimer timer; | |
55 | + | |
56 | + unsigned device_updated:1; | |
57 | + | |
58 | + DETECT_LIST * dlist; | |
59 | + int dlist_length; | |
60 | + | |
61 | +}; | |
62 | + | |
63 | +TS_END_IMPLEMENT | |
64 | + | |
65 | +#endif | |
66 | + | |
67 | + | |
68 | +tsDeviceMonitor_::tsDeviceMonitor_( | |
69 | + tinyState * _parent, | |
70 | + int debug, | |
71 | + int mode) | |
72 | + : tinyState_(_parent) | |
73 | +{ | |
74 | + this->mode = mode; | |
75 | + this->debug = debug; | |
76 | +} | |
77 | + | |
78 | +void | |
79 | +tsDeviceMonitor_::inherit( | |
80 | + tinyState * _parent, | |
81 | + int debug, | |
82 | + int mode) | |
83 | +{ | |
84 | + this->TS_BASECLASS::inherit(_parent); | |
85 | +} | |
86 | + | |
87 | + | |
88 | + | |
89 | +/******************************************* | |
90 | + INSTANCE FUNCTIONS | |
91 | +********************************************/ | |
92 | + | |
93 | + | |
94 | + | |
95 | +/******************************************* | |
96 | + STATE MACHINE | |
97 | +********************************************/ | |
98 | + | |
99 | +TS_STATE(INI_START) | |
100 | +{ | |
101 | +tsDeviceMonitor * master; | |
102 | + | |
103 | + master = dynamic_cast<tsDeviceMonitor*>(application | |
104 | + ->get_global(getClass())); | |
105 | + if ( master ) { | |
106 | + if ( debug ) | |
107 | + master->debug = debug; | |
108 | + master->listen(parent,TSE_SIGNAL); | |
109 | + parent->eventHandler( | |
110 | + NEW stdEvent(TSE_SIGNAL, | |
111 | + master, | |
112 | + ((INTEGER64)1))); | |
113 | + return rDO|FIN_START; | |
114 | + } | |
115 | + if ( parent != application ) { | |
116 | + master = NEW tsDeviceMonitor(application,debug,1); | |
117 | + master->listen(parent,TSE_SIGNAL); | |
118 | + parent->eventHandler( | |
119 | + NEW stdEvent(TSE_SIGNAL, | |
120 | + ifThis, | |
121 | + ((INTEGER64)1))); | |
122 | + return rDO|FIN_START; | |
123 | + } | |
124 | + if ( mode == 0 ) { | |
125 | + listen(parent,TSE_SIGNAL); | |
126 | + parent->eventHandler( | |
127 | + NEW stdEvent(TSE_SIGNAL, | |
128 | + ifThis, | |
129 | + ((INTEGER64)1))); | |
130 | + } | |
131 | + application->set_global(getClass(),ifThis); | |
132 | + check_listener = 1; | |
133 | + libusb_init(NULL); | |
134 | + return rDO|ACT_WAIT_HOOK; | |
135 | +} | |
136 | +TS_STATE(ACT_WAIT_HOOK) | |
137 | +{ | |
138 | + if ( listenerCounter(TSE_SIGNAL) == 0 ) | |
139 | + return 0; | |
140 | + return rDO|ACT_START; | |
141 | +} | |
142 | +TS_THREAD(ACT_START) | |
143 | +{ | |
144 | +DETECT_LIST * new_dlist; | |
145 | +int i,count; | |
146 | +libusb_device ** list; | |
147 | + | |
148 | + if ( listenerCounter(TSE_SIGNAL) == 0 ) | |
149 | + return rDO|FIN_MASTER_START; | |
150 | + device_updated = 0; | |
151 | + count = libusb_get_device_list(NULL, &list); | |
152 | + if ( count <= 0 ) { | |
153 | + count = 0; | |
154 | + new_dlist = 0; | |
155 | + } | |
156 | + else { | |
157 | + new_dlist = (DETECT_LIST*)malloc(sizeof(DETECT_LIST)*count); | |
158 | + for ( i = 0 ; i < count ; i ++ ) { | |
159 | + libusb_device *device = list[i]; | |
160 | + libusb_device_descriptor desc = {0}; | |
161 | + libusb_get_device_descriptor(device, &desc); | |
162 | + new_dlist[i].vendor = desc.idVendor; | |
163 | + new_dlist[i].product = desc.idProduct; | |
164 | + } | |
165 | + } | |
166 | + libusb_free_device_list(list,0); | |
167 | + if ( count != dlist_length ) | |
168 | + device_updated = 1; | |
169 | + else for ( i = 0 ; i < count ; i ++ ) | |
170 | + if ( new_dlist[i].vendor != dlist[i].vendor || | |
171 | + new_dlist[i].product != dlist[i].product ) { | |
172 | + device_updated = 1; | |
173 | + break; | |
174 | + } | |
175 | + if ( dlist ) | |
176 | + free(dlist); | |
177 | + dlist = new_dlist; | |
178 | + dlist_length = count; | |
179 | + return rDO|ACT_SEND_EVENT; | |
180 | +} | |
181 | +TS_STATE(ACT_SEND_EVENT) | |
182 | +{ | |
183 | + if ( device_updated ) { | |
184 | + if ( debug == DM_DEBUG ) | |
185 | + tsLog::log_printf(ifThis,LOG_DEBUG,"DeviceMonitor :: INTERRUPT !!\n"); | |
186 | + invoke_listen( | |
187 | + NEW stdEvent(TSE_SIGNAL, | |
188 | + ifThis, | |
189 | + ((INTEGER64)0))); | |
190 | + } | |
191 | + timer.start(ifThis,1000*1000); | |
192 | + return ACT_WAIT; | |
193 | +} | |
194 | +TS_STATE(ACT_WAIT) | |
195 | +{ | |
196 | + if ( destroy_flag || ref_destroy_flag ) | |
197 | + return rDO|FIN_MASTER_START; | |
198 | + if ( !timer.is_expire(ifThis) ) | |
199 | + return 0; | |
200 | + return rDO|ACT_START; | |
201 | +} | |
202 | +TS_STATE(FIN_MASTER_START) | |
203 | +{ | |
204 | + if ( dlist ) | |
205 | + free(dlist); | |
206 | + libusb_exit(NULL); | |
207 | + return rDO|FIN_START; | |
208 | +} | |
209 | + | |
210 | +TS_STATE(FIN_START) | |
211 | +{ | |
212 | + | |
213 | + REF_SET(ior,0); | |
214 | + REF_SET(iow,0); | |
215 | + REF_SET(ioe,0); | |
216 | + REF_SET(cb,0); | |
217 | + REF_SET(sys,0); | |
218 | + return rDO|FIN_TINYSTATE_START; | |
219 | +} | |
220 | + | |
221 | + |
@@ -1,221 +0,0 @@ | ||
1 | - | |
2 | - | |
3 | -#include <stdlib.h> | |
4 | -#include "_ts/c++/tsDeviceMonitor_.h" | |
5 | -#include "ts/c++/tsReadLine.h" | |
6 | -#include "ts/c++/tsLog.h" | |
7 | - | |
8 | -CLASS_TINYSTATE(ts/c++/tsDeviceMonitor,ts/c++/tinyState) | |
9 | - | |
10 | - | |
11 | -#if 0 | |
12 | - | |
13 | -TS_BEGIN_IMPLEMENT | |
14 | - | |
15 | - | |
16 | -#include "ts/c++/tsIOstring.h" | |
17 | -#include "ts/c++/tsDevNull.h" | |
18 | -#include "ts/c++/tsCallBuffer.h" | |
19 | -#include "ts/c++/sTimer.h" | |
20 | -#include "ts/c++/tsSystem.h" | |
21 | -#include <libusb-1.0/libusb.h> | |
22 | - | |
23 | -typedef struct detect_list { | |
24 | - int vendor; | |
25 | - int product; | |
26 | -} DETECT_LIST; | |
27 | - | |
28 | - | |
29 | -class TS_THISCLASS : public TS_BASECLASS { | |
30 | -public: | |
31 | - tsDeviceMonitor_( | |
32 | - tinyState * parent, | |
33 | - int debug=0, | |
34 | - int mode=0); | |
35 | - void inherit( | |
36 | - tinyState * parent, | |
37 | - int debug=0, | |
38 | - int mode=0); | |
39 | - | |
40 | - | |
41 | - int debug; | |
42 | - | |
43 | -private: | |
44 | -protected: | |
45 | - int mode; | |
46 | - tsIOstring * ior; | |
47 | - tsIOstring * iow; | |
48 | - tsIOstring * ioe; | |
49 | - tsCallBuffer * cb; | |
50 | - tsSystem * sys; | |
51 | - | |
52 | - static const char * commandList[]; | |
53 | - const char ** commandListPtr; | |
54 | - sTimer timer; | |
55 | - | |
56 | - unsigned device_updated:1; | |
57 | - | |
58 | - DETECT_LIST * dlist; | |
59 | - int dlist_length; | |
60 | - | |
61 | -}; | |
62 | - | |
63 | -TS_END_IMPLEMENT | |
64 | - | |
65 | -#endif | |
66 | - | |
67 | - | |
68 | -tsDeviceMonitor_::tsDeviceMonitor_( | |
69 | - tinyState * _parent, | |
70 | - int debug, | |
71 | - int mode) | |
72 | - : tinyState_(_parent) | |
73 | -{ | |
74 | - this->mode = mode; | |
75 | - this->debug = debug; | |
76 | -} | |
77 | - | |
78 | -void | |
79 | -tsDeviceMonitor_::inherit( | |
80 | - tinyState * _parent, | |
81 | - int debug, | |
82 | - int mode) | |
83 | -{ | |
84 | - this->TS_BASECLASS::inherit(_parent); | |
85 | -} | |
86 | - | |
87 | - | |
88 | - | |
89 | -/******************************************* | |
90 | - INSTANCE FUNCTIONS | |
91 | -********************************************/ | |
92 | - | |
93 | - | |
94 | - | |
95 | -/******************************************* | |
96 | - STATE MACHINE | |
97 | -********************************************/ | |
98 | - | |
99 | -TS_STATE(INI_START) | |
100 | -{ | |
101 | -tsDeviceMonitor * master; | |
102 | - | |
103 | - master = dynamic_cast<tsDeviceMonitor*>(application | |
104 | - ->get_global(getClass())); | |
105 | - if ( master ) { | |
106 | - if ( debug ) | |
107 | - master->debug = debug; | |
108 | - master->listen(parent,TSE_SIGNAL); | |
109 | - parent->eventHandler( | |
110 | - NEW stdEvent(TSE_SIGNAL, | |
111 | - master, | |
112 | - ((INTEGER64)1))); | |
113 | - return rDO|FIN_START; | |
114 | - } | |
115 | - if ( parent != application ) { | |
116 | - master = NEW tsDeviceMonitor(application,debug,1); | |
117 | - master->listen(parent,TSE_SIGNAL); | |
118 | - parent->eventHandler( | |
119 | - NEW stdEvent(TSE_SIGNAL, | |
120 | - ifThis, | |
121 | - ((INTEGER64)1))); | |
122 | - return rDO|FIN_START; | |
123 | - } | |
124 | - if ( mode == 0 ) { | |
125 | - listen(parent,TSE_SIGNAL); | |
126 | - parent->eventHandler( | |
127 | - NEW stdEvent(TSE_SIGNAL, | |
128 | - ifThis, | |
129 | - ((INTEGER64)1))); | |
130 | - } | |
131 | - application->set_global(getClass(),ifThis); | |
132 | - check_listener = 1; | |
133 | - libusb_init(NULL); | |
134 | - return rDO|ACT_WAIT_HOOK; | |
135 | -} | |
136 | -TS_STATE(ACT_WAIT_HOOK) | |
137 | -{ | |
138 | - if ( listenerCounter(TSE_SIGNAL) == 0 ) | |
139 | - return 0; | |
140 | - return rDO|ACT_START; | |
141 | -} | |
142 | -TS_THREAD(ACT_START) | |
143 | -{ | |
144 | -DETECT_LIST * new_dlist; | |
145 | -int i,count; | |
146 | -libusb_device ** list; | |
147 | - | |
148 | - if ( listenerCounter(TSE_SIGNAL) == 0 ) | |
149 | - return rDO|FIN_MASTER_START; | |
150 | - device_updated = 0; | |
151 | - count = libusb_get_device_list(NULL, &list); | |
152 | - if ( count <= 0 ) { | |
153 | - count = 0; | |
154 | - new_dlist = 0; | |
155 | - } | |
156 | - else { | |
157 | - new_dlist = (DETECT_LIST*)malloc(sizeof(DETECT_LIST)*count); | |
158 | - for ( i = 0 ; i < count ; i ++ ) { | |
159 | - libusb_device *device = list[i]; | |
160 | - libusb_device_descriptor desc = {0}; | |
161 | - libusb_get_device_descriptor(device, &desc); | |
162 | - new_dlist[i].vendor = desc.idVendor; | |
163 | - new_dlist[i].product = desc.idProduct; | |
164 | - } | |
165 | - } | |
166 | - libusb_free_device_list(list,0); | |
167 | - if ( count != dlist_length ) | |
168 | - device_updated = 1; | |
169 | - else for ( i = 0 ; i < count ; i ++ ) | |
170 | - if ( new_dlist[i].vendor != dlist[i].vendor || | |
171 | - new_dlist[i].product != dlist[i].product ) { | |
172 | - device_updated = 1; | |
173 | - break; | |
174 | - } | |
175 | - if ( dlist ) | |
176 | - free(dlist); | |
177 | - dlist = new_dlist; | |
178 | - dlist_length = count; | |
179 | - return rDO|ACT_SEND_EVENT; | |
180 | -} | |
181 | -TS_STATE(ACT_SEND_EVENT) | |
182 | -{ | |
183 | - if ( device_updated ) { | |
184 | - if ( debug == DM_DEBUG ) | |
185 | - tsLog::log_printf(ifThis,LOG_DEBUG,"DeviceMonitor :: INTERRUPT !!\n"); | |
186 | - invoke_listen( | |
187 | - NEW stdEvent(TSE_SIGNAL, | |
188 | - ifThis, | |
189 | - ((INTEGER64)0))); | |
190 | - } | |
191 | - timer.start(ifThis,1000*1000); | |
192 | - return ACT_WAIT; | |
193 | -} | |
194 | -TS_STATE(ACT_WAIT) | |
195 | -{ | |
196 | - if ( destroy_flag || ref_destroy_flag ) | |
197 | - return rDO|FIN_MASTER_START; | |
198 | - if ( !timer.is_expire(ifThis) ) | |
199 | - return 0; | |
200 | - return rDO|ACT_START; | |
201 | -} | |
202 | -TS_STATE(FIN_MASTER_START) | |
203 | -{ | |
204 | - if ( dlist ) | |
205 | - free(dlist); | |
206 | - libusb_exit(NULL); | |
207 | - return rDO|FIN_START; | |
208 | -} | |
209 | - | |
210 | -TS_STATE(FIN_START) | |
211 | -{ | |
212 | - | |
213 | - REF_SET(ior,0); | |
214 | - REF_SET(iow,0); | |
215 | - REF_SET(ioe,0); | |
216 | - REF_SET(cb,0); | |
217 | - REF_SET(sys,0); | |
218 | - return rDO|FIN_TINYSTATE_START; | |
219 | -} | |
220 | - | |
221 | - |
@@ -1,11 +0,0 @@ | ||
1 | - | |
2 | -#ifndef ___tsDeviceMonitor_cpp_H___ | |
3 | -#define ___tsDeviceMonitor_cpp_H___ | |
4 | - | |
5 | -#define DM_DEBUG 2 | |
6 | -#define DM_DIS_DEBUG 1 | |
7 | - | |
8 | -#include "_ts/c++/tsDeviceMonitor_pb.h" | |
9 | - | |
10 | -#endif | |
11 | - |