Commit 42e5209b3e43320554a7e77707cb503111a3142e

Authored by Perry Werneck
1 parent 800fd1f6

Gerando novo módulo IPC capaz de acessar um serviço DBUS sem janela.

src/libpw3270cpp/Makefile.in
@@ -168,7 +168,7 @@ run: \ @@ -168,7 +168,7 @@ run: \
168 .bin/Debug/$(MODULE_NAME)@EXEEXT@ 168 .bin/Debug/$(MODULE_NAME)@EXEEXT@
169 169
170 ifeq ($(VALGRIND),no) 170 ifeq ($(VALGRIND),no)
171 - $(BASEDIR)/.obj/Debug/$(MODULE_NAME)@EXEEXT@ 171 + .bin/Debug/$(MODULE_NAME)@EXEEXT@
172 else 172 else
173 @touch valgrind.suppression 173 @touch valgrind.suppression
174 @$(VALGRIND) \ 174 @$(VALGRIND) \
@@ -176,7 +176,7 @@ else @@ -176,7 +176,7 @@ else
176 --track-origins=yes \ 176 --track-origins=yes \
177 --gen-suppressions=all \ 177 --gen-suppressions=all \
178 --suppressions=valgrind.suppression \ 178 --suppressions=valgrind.suppression \
179 - $(BASEDIR)/.obj/Debug/$(MODULE_NAME)@EXEEXT@ 179 + .bin/Debug/$(MODULE_NAME)@EXEEXT@
180 endif 180 endif
181 181
182 182
src/libpw3270cpp/service.cc
@@ -54,14 +54,19 @@ @@ -54,14 +54,19 @@
54 class client : public session 54 class client : public session
55 { 55 {
56 private: 56 private:
  57 +
  58 + #define DBUS_DESTINATION "br.com.bb.pw3270.service"
  59 + #define DBUS_PATH "/br/com/bb/pw3270/service"
  60 + #define DBUS_INTERFACE "br.com.bb.pw3270.service"
  61 +
57 DBusConnection * conn; 62 DBusConnection * conn;
58 string id; 63 string id;
59 64
60 DBusMessage * createMessage(const char *method) 65 DBusMessage * createMessage(const char *method)
61 { 66 {
62 - DBusMessage * msg = dbus_message_new_method_call( "br.com.bb.pw3270.service", // Destination  
63 - "/br/com/bb/pw3270/service", // Path  
64 - "br.com.bb.pw3270.service", // Interface 67 + DBusMessage * msg = dbus_message_new_method_call( DBUS_DESTINATION, // Destination
  68 + DBUS_PATH, // Path
  69 + DBUS_INTERFACE, // Interface
65 method); // method 70 method); // method
66 71
67 if (!msg) 72 if (!msg)
@@ -129,11 +134,57 @@ @@ -129,11 +134,57 @@
129 134
130 } 135 }
131 136
  137 + int getInteger(DBusMessage *msg) {
  138 +
  139 + if(msg)
  140 + {
  141 + DBusMessageIter iter;
  142 +
  143 + if(dbus_message_iter_init(msg, &iter))
  144 + {
  145 + if(dbus_message_iter_get_arg_type(&iter) == DBUS_TYPE_INT32)
  146 + {
  147 + dbus_int32_t iSigned;
  148 + dbus_message_iter_get_basic(&iter, &iSigned);
  149 + dbus_message_unref(msg);
  150 + return (int) iSigned;
  151 + }
  152 +
  153 + exception e = exception("DBUS Return type was %c, expecting %c",dbus_message_iter_get_arg_type(&iter),DBUS_TYPE_INT32);
  154 +
  155 + dbus_message_unref(msg);
  156 + throw e;
  157 + return -1;
  158 + }
  159 + dbus_message_unref(msg);
  160 + }
  161 + return -1;
  162 +
  163 + }
  164 +
132 string getString(const char *method) 165 string getString(const char *method)
133 { 166 {
134 return getString(call(createMessage(method))); 167 return getString(call(createMessage(method)));
135 } 168 }
136 169
  170 + int getInteger(const char *method)
  171 + {
  172 + return getInteger(call(createMessage(method)));
  173 + }
  174 +
  175 + int getInteger(const char *method, int first_arg_type, ...)
  176 + {
  177 + va_list var_args;
  178 + DBusMessage * msg = createMessage(method);
  179 +
  180 + va_start(var_args, first_arg_type);
  181 + dbus_message_append_args_valist(msg,first_arg_type,var_args);
  182 + va_end(var_args);
  183 +
  184 + return getInteger(call(msg));
  185 + }
  186 +
  187 +
137 protected: 188 protected:
138 189
139 virtual string get_text(int baddr = 0, size_t len = 1) 190 virtual string get_text(int baddr = 0, size_t len = 1)
@@ -203,47 +254,48 @@ @@ -203,47 +254,48 @@
203 254
204 virtual bool is_connected(void) 255 virtual bool is_connected(void)
205 { 256 {
206 - 257 + return getInteger("isConnected", DBUS_TYPE_STRING, this->id.c_str(), DBUS_TYPE_INVALID);
207 } 258 }
208 259
209 virtual bool is_ready(void) 260 virtual bool is_ready(void)
210 { 261 {
211 - 262 + return getInteger("isReady", DBUS_TYPE_STRING, this->id.c_str(), DBUS_TYPE_INVALID);
212 } 263 }
213 264
214 virtual LIB3270_CSTATE get_cstate(void) 265 virtual LIB3270_CSTATE get_cstate(void)
215 { 266 {
216 - 267 + return (LIB3270_CSTATE) getInteger("getConnectionState", DBUS_TYPE_STRING, this->id.c_str(), DBUS_TYPE_INVALID);
217 } 268 }
218 269
219 virtual LIB3270_MESSAGE get_program_message(void) 270 virtual LIB3270_MESSAGE get_program_message(void)
220 { 271 {
221 - 272 + return (LIB3270_MESSAGE) getInteger("getProgramMessage", DBUS_TYPE_STRING, this->id.c_str(), DBUS_TYPE_INVALID);
222 } 273 }
223 274
224 virtual LIB3270_SSL_STATE get_secure(void) 275 virtual LIB3270_SSL_STATE get_secure(void)
225 { 276 {
226 - 277 + return (LIB3270_SSL_STATE) getInteger("getSecureState", DBUS_TYPE_STRING, this->id.c_str(), DBUS_TYPE_INVALID);
227 } 278 }
228 279
229 virtual int get_width(void) 280 virtual int get_width(void)
230 { 281 {
231 - 282 + return getInteger("getScreenWidth", DBUS_TYPE_STRING, this->id.c_str(), DBUS_TYPE_INVALID);
232 } 283 }
233 284
234 virtual int get_height(void) 285 virtual int get_height(void)
235 { 286 {
236 - 287 + return getInteger("getScreenHeight", DBUS_TYPE_STRING, this->id.c_str(), DBUS_TYPE_INVALID);
237 } 288 }
238 289
239 virtual int get_length(void) 290 virtual int get_length(void)
240 { 291 {
241 - 292 + return getInteger("getScreenLength", DBUS_TYPE_STRING, this->id.c_str(), DBUS_TYPE_INVALID);
242 } 293 }
243 294
244 virtual void set_unlock_delay(unsigned short ms) 295 virtual void set_unlock_delay(unsigned short ms)
245 { 296 {
246 - 297 + dbus_int32_t val = (dbus_int32_t) ms;
  298 + getInteger("setUnlockDelay", DBUS_TYPE_STRING, this->id.c_str(), DBUS_TYPE_INT32, val, DBUS_TYPE_INVALID);
247 } 299 }
248 300
249 virtual int set_host_charset(const char *charset) 301 virtual int set_host_charset(const char *charset)
@@ -258,12 +310,12 @@ @@ -258,12 +310,12 @@
258 310
259 virtual int connect(void) 311 virtual int connect(void)
260 { 312 {
261 - 313 + return getInteger("connect", DBUS_TYPE_STRING, this->id.c_str(), DBUS_TYPE_STRING, "", DBUS_TYPE_INVALID);
262 } 314 }
263 315
264 virtual int set_url(const char *hostname) 316 virtual int set_url(const char *hostname)
265 { 317 {
266 - 318 + return getInteger("setURL", DBUS_TYPE_STRING, this->id.c_str(), DBUS_TYPE_STRING, hostname, DBUS_TYPE_INVALID);
267 } 319 }
268 320
269 virtual string get_url() 321 virtual string get_url()
@@ -273,22 +325,47 @@ @@ -273,22 +325,47 @@
273 325
274 virtual int disconnect(void) 326 virtual int disconnect(void)
275 { 327 {
276 - 328 + return getInteger("disconnect", DBUS_TYPE_STRING, this->id.c_str(), DBUS_TYPE_INVALID);
277 } 329 }
278 330
279 virtual int wait_for_ready(int seconds) 331 virtual int wait_for_ready(int seconds)
280 { 332 {
  333 + time_t end = time(0)+seconds;
281 334
  335 + while(time(0) < end)
  336 + {
  337 + if(!is_connected())
  338 + return ENOTCONN;
  339 +
  340 + if(is_ready())
  341 + return 0;
  342 +
  343 + usleep(500);
  344 + }
  345 +
  346 + return ETIMEDOUT;
282 } 347 }
283 348
284 virtual int wait(int seconds) 349 virtual int wait(int seconds)
285 { 350 {
286 351
  352 + time_t end = time(0)+seconds;
  353 +
  354 + while(time(0) < end)
  355 + {
  356 + if(!is_connected())
  357 + return ENOTCONN;
  358 + usleep(500);
  359 + }
  360 +
  361 + return 0;
287 } 362 }
288 363
289 - virtual int iterate(bool wait = true) 364 + virtual int iterate(bool wait)
290 { 365 {
291 - 366 + if(wait)
  367 + usleep(100);
  368 + return 0;
292 } 369 }
293 370
294 virtual const char * asc2ebc(unsigned char *str, int sz = -1) 371 virtual const char * asc2ebc(unsigned char *str, int sz = -1)