Commit b8f2f9aae155ccfbeb304432fe16445e7c3558a6

Authored by Perry Werneck
1 parent a3cd3d81

Implementando novo método remoto.

src/include/pw3270cpp.h
@@ -180,8 +180,11 @@ @@ -180,8 +180,11 @@
180 virtual string get_display_charset(void); 180 virtual string get_display_charset(void);
181 181
182 // Connection & Network 182 // Connection & Network
183 - virtual int connect(const char *host = "", time_t wait = 0) = 0; 183 + virtual int connect() = 0;
  184 + virtual int connect(const char *url, time_t wait = 0);
184 int set_host(const char *host); 185 int set_host(const char *host);
  186 + virtual int set_url(const char *uri) = 0;
  187 + virtual string get_url() = 0;
185 188
186 virtual int disconnect(void) = 0; 189 virtual int disconnect(void) = 0;
187 virtual int wait_for_ready(int seconds) = 0; 190 virtual int wait_for_ready(int seconds) = 0;
src/libpw3270cpp/local.cc
@@ -127,7 +127,7 @@ @@ -127,7 +127,7 @@
127 127
128 128
129 int (*_disconnect)(H3270 *h); 129 int (*_disconnect)(H3270 *h);
130 - int (*_connect)(H3270 *h,int wait); 130 + int (*_connect)(H3270 *h, const char *url, int wait);
131 const char (*_set_url)(H3270 *h, const char *n); 131 const char (*_set_url)(H3270 *h, const char *n);
132 const char * (*_get_url)(H3270 *h, char *str, int len); 132 const char * (*_get_url)(H3270 *h, char *str, int len);
133 int (*_is_connected)(H3270 *h); 133 int (*_is_connected)(H3270 *h);
@@ -197,7 +197,7 @@ @@ -197,7 +197,7 @@
197 197
198 { (void **) & _get_version, "lib3270_get_version" }, 198 { (void **) & _get_version, "lib3270_get_version" },
199 { (void **) & _disconnect, "lib3270_disconnect" }, 199 { (void **) & _disconnect, "lib3270_disconnect" },
200 - { (void **) & _connect, "lib3270_connect" }, 200 + { (void **) & _connect, "lib3270_connect_url" },
201 { (void **) & _set_url, "lib3270_set_url" }, 201 { (void **) & _set_url, "lib3270_set_url" },
202 { (void **) & _get_url, "lib3270_get_url" }, 202 { (void **) & _get_url, "lib3270_get_url" },
203 { (void **) & _main_iterate, "lib3270_main_iterate" }, 203 { (void **) & _main_iterate, "lib3270_main_iterate" },
@@ -288,6 +288,18 @@ @@ -288,6 +288,18 @@
288 return _get_secure(hSession); 288 return _get_secure(hSession);
289 }; 289 };
290 290
  291 + int connect(const char *host, time_t wait = 0) {
  292 + this->lock();
  293 + int rc = _connect(hSession,host,wait);
  294 + this->unlock();
  295 + return rc;
  296 + }
  297 +
  298 + int connect() {
  299 + return connect("");
  300 + }
  301 +
  302 + /*
291 int connect(void) 303 int connect(void)
292 { 304 {
293 this->lock(); 305 this->lock();
@@ -296,6 +308,7 @@ @@ -296,6 +308,7 @@
296 308
297 return rc; 309 return rc;
298 } 310 }
  311 + */
299 312
300 int set_url(const char *uri) 313 int set_url(const char *uri)
301 { 314 {
src/libpw3270cpp/remote.cc
@@ -817,7 +817,6 @@ @@ -817,7 +817,6 @@
817 return (LIB3270_SSL_STATE) query_intval(HLLAPI_PACKET_GET_SSL_STATE); 817 return (LIB3270_SSL_STATE) query_intval(HLLAPI_PACKET_GET_SSL_STATE);
818 } 818 }
819 819
820 -  
821 int connect(void) 820 int connect(void)
822 { 821 {
823 int rc; 822 int rc;
src/libpw3270cpp/service.cc
@@ -60,7 +60,8 @@ @@ -60,7 +60,8 @@
60 #define DBUS_INTERFACE "br.com.bb.pw3270.service" 60 #define DBUS_INTERFACE "br.com.bb.pw3270.service"
61 61
62 DBusConnection * conn; 62 DBusConnection * conn;
63 - string id; 63 + string name;
  64 + const char * id;
64 65
65 DBusMessage * createMessage(const char *method) 66 DBusMessage * createMessage(const char *method)
66 { 67 {
@@ -184,6 +185,17 @@ @@ -184,6 +185,17 @@
184 return getInteger(call(msg)); 185 return getInteger(call(msg));
185 } 186 }
186 187
  188 + string getString(const char *method, int first_arg_type, ...)
  189 + {
  190 + va_list var_args;
  191 + DBusMessage * msg = createMessage(method);
  192 +
  193 + va_start(var_args, first_arg_type);
  194 + dbus_message_append_args_valist(msg,first_arg_type,var_args);
  195 + va_end(var_args);
  196 +
  197 + return getString(call(msg));
  198 + }
187 199
188 protected: 200 protected:
189 201
@@ -194,17 +206,43 @@ @@ -194,17 +206,43 @@
194 206
195 virtual string get_text_at(int row, int col, size_t sz) 207 virtual string get_text_at(int row, int col, size_t sz)
196 { 208 {
  209 + dbus_int32_t r = (dbus_int32_t) row;
  210 + dbus_int32_t c = (dbus_int32_t) col;
  211 + dbus_int32_t s = (dbus_int32_t) sz;
  212 +
  213 + return getString( "getTextAt",
  214 + DBUS_TYPE_STRING, this->id,
  215 + DBUS_TYPE_INT32, &r,
  216 + DBUS_TYPE_INT32, &c,
  217 + DBUS_TYPE_INT32, &s,
  218 + DBUS_TYPE_INVALID);
197 219
198 } 220 }
199 221
200 virtual int set_text_at(int row, int col, const char *str) 222 virtual int set_text_at(int row, int col, const char *str)
201 { 223 {
  224 + dbus_int32_t r = (dbus_int32_t) row;
  225 + dbus_int32_t c = (dbus_int32_t) col;
202 226
  227 + return getInteger( "setTextAt",
  228 + DBUS_TYPE_STRING, this->id,
  229 + DBUS_TYPE_INT32, &r,
  230 + DBUS_TYPE_INT32, &c,
  231 + DBUS_TYPE_STRING, str,
  232 + DBUS_TYPE_INVALID);
203 } 233 }
204 234
205 - virtual int cmp_text_at(int row, int col, const char *text) 235 + virtual int cmp_text_at(int row, int col, const char *str)
206 { 236 {
  237 + dbus_int32_t r = (dbus_int32_t) row;
  238 + dbus_int32_t c = (dbus_int32_t) col;
207 239
  240 + return getInteger( "cmpTextAt",
  241 + DBUS_TYPE_STRING, this->id,
  242 + DBUS_TYPE_INT32, &r,
  243 + DBUS_TYPE_INT32, &c,
  244 + DBUS_TYPE_STRING, str,
  245 + DBUS_TYPE_INVALID);
208 } 246 }
209 247
210 virtual int emulate_input(const char *str) 248 virtual int emulate_input(const char *str)
@@ -235,16 +273,17 @@ @@ -235,16 +273,17 @@
235 if(*session != '?') 273 if(*session != '?')
236 { 274 {
237 // Já tem sessão definida, usa. 275 // Já tem sessão definida, usa.
238 - this->id = session; 276 + this->name = session;
239 } 277 }
240 else 278 else
241 { 279 {
242 // Obter um ID de sessão no serviço 280 // Obter um ID de sessão no serviço
243 - this->id = getString("createSession"); 281 + this->name = getString("createSession");
244 } 282 }
245 283
246 - trace("Session=%s",this->id.c_str()); 284 + trace("Session=%s",this->name.c_str());
247 285
  286 + this->id = this->name.c_str();
248 } 287 }
249 288
250 virtual ~client() 289 virtual ~client()
@@ -254,48 +293,48 @@ @@ -254,48 +293,48 @@
254 293
255 virtual bool is_connected(void) 294 virtual bool is_connected(void)
256 { 295 {
257 - return getInteger("isConnected", DBUS_TYPE_STRING, this->id.c_str(), DBUS_TYPE_INVALID); 296 + return getInteger("isConnected", DBUS_TYPE_STRING, &this->id, DBUS_TYPE_INVALID);
258 } 297 }
259 298
260 virtual bool is_ready(void) 299 virtual bool is_ready(void)
261 { 300 {
262 - return getInteger("isReady", DBUS_TYPE_STRING, this->id.c_str(), DBUS_TYPE_INVALID); 301 + return getInteger("isReady", DBUS_TYPE_STRING, &this->id, DBUS_TYPE_INVALID);
263 } 302 }
264 303
265 virtual LIB3270_CSTATE get_cstate(void) 304 virtual LIB3270_CSTATE get_cstate(void)
266 { 305 {
267 - return (LIB3270_CSTATE) getInteger("getConnectionState", DBUS_TYPE_STRING, this->id.c_str(), DBUS_TYPE_INVALID); 306 + return (LIB3270_CSTATE) getInteger("getConnectionState", DBUS_TYPE_STRING, &this->id, DBUS_TYPE_INVALID);
268 } 307 }
269 308
270 virtual LIB3270_MESSAGE get_program_message(void) 309 virtual LIB3270_MESSAGE get_program_message(void)
271 { 310 {
272 - return (LIB3270_MESSAGE) getInteger("getProgramMessage", DBUS_TYPE_STRING, this->id.c_str(), DBUS_TYPE_INVALID); 311 + return (LIB3270_MESSAGE) getInteger("getProgramMessage", DBUS_TYPE_STRING, &this->id, DBUS_TYPE_INVALID);
273 } 312 }
274 313
275 virtual LIB3270_SSL_STATE get_secure(void) 314 virtual LIB3270_SSL_STATE get_secure(void)
276 { 315 {
277 - return (LIB3270_SSL_STATE) getInteger("getSecureState", DBUS_TYPE_STRING, this->id.c_str(), DBUS_TYPE_INVALID); 316 + return (LIB3270_SSL_STATE) getInteger("getSecureState", DBUS_TYPE_STRING, &this->id, DBUS_TYPE_INVALID);
278 } 317 }
279 318
280 virtual int get_width(void) 319 virtual int get_width(void)
281 { 320 {
282 - return getInteger("getScreenWidth", DBUS_TYPE_STRING, this->id.c_str(), DBUS_TYPE_INVALID); 321 + return getInteger("getScreenWidth", DBUS_TYPE_STRING, &this->id, DBUS_TYPE_INVALID);
283 } 322 }
284 323
285 virtual int get_height(void) 324 virtual int get_height(void)
286 { 325 {
287 - return getInteger("getScreenHeight", DBUS_TYPE_STRING, this->id.c_str(), DBUS_TYPE_INVALID); 326 + return getInteger("getScreenHeight", DBUS_TYPE_STRING, &this->id, DBUS_TYPE_INVALID);
288 } 327 }
289 328
290 virtual int get_length(void) 329 virtual int get_length(void)
291 { 330 {
292 - return getInteger("getScreenLength", DBUS_TYPE_STRING, this->id.c_str(), DBUS_TYPE_INVALID); 331 + return getInteger("getScreenLength", DBUS_TYPE_STRING, &this->id, DBUS_TYPE_INVALID);
293 } 332 }
294 333
295 virtual void set_unlock_delay(unsigned short ms) 334 virtual void set_unlock_delay(unsigned short ms)
296 { 335 {
297 dbus_int32_t val = (dbus_int32_t) ms; 336 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); 337 + getInteger("setUnlockDelay", DBUS_TYPE_STRING, &this->id, DBUS_TYPE_INT32, &val, DBUS_TYPE_INVALID);
299 } 338 }
300 339
301 virtual int set_host_charset(const char *charset) 340 virtual int set_host_charset(const char *charset)
@@ -308,14 +347,26 @@ @@ -308,14 +347,26 @@
308 347
309 } 348 }
310 349
311 - virtual int connect(void) 350 + virtual int connect()
312 { 351 {
313 - return getInteger("connect", DBUS_TYPE_STRING, this->id.c_str(), DBUS_TYPE_STRING, "", DBUS_TYPE_INVALID); 352 + return connect("",0);
  353 + }
  354 +
  355 + virtual int connect(const char *url, time_t wait)
  356 + {
  357 + int rc = getInteger("connect", DBUS_TYPE_STRING, &this->id, DBUS_TYPE_STRING, &url, DBUS_TYPE_INVALID);
  358 +
  359 + if(!rc && wait) {
  360 + rc = wait_for_ready(wait);
  361 + }
  362 +
  363 + return rc;
  364 +
314 } 365 }
315 366
316 virtual int set_url(const char *hostname) 367 virtual int set_url(const char *hostname)
317 { 368 {
318 - return getInteger("setURL", DBUS_TYPE_STRING, this->id.c_str(), DBUS_TYPE_STRING, hostname, DBUS_TYPE_INVALID); 369 + return getInteger("setURL", DBUS_TYPE_STRING, &this->id, DBUS_TYPE_STRING, &hostname, DBUS_TYPE_INVALID);
319 } 370 }
320 371
321 virtual string get_url() 372 virtual string get_url()
@@ -325,7 +376,7 @@ @@ -325,7 +376,7 @@
325 376
326 virtual int disconnect(void) 377 virtual int disconnect(void)
327 { 378 {
328 - return getInteger("disconnect", DBUS_TYPE_STRING, this->id.c_str(), DBUS_TYPE_INVALID); 379 + return getInteger("disconnect", DBUS_TYPE_STRING, &this->id, DBUS_TYPE_INVALID);
329 } 380 }
330 381
331 virtual int wait_for_ready(int seconds) 382 virtual int wait_for_ready(int seconds)
@@ -398,27 +449,29 @@ @@ -398,27 +449,29 @@
398 449
399 } 450 }
400 451
401 - virtual int enter(void) 452 + virtual int enter(void)
402 { 453 {
403 - 454 + return getInteger("enter", DBUS_TYPE_STRING, &this->id, DBUS_TYPE_INVALID);
404 } 455 }
405 456
406 - virtual int pfkey(int key) 457 + virtual int pfkey(int key)
407 { 458 {
408 - 459 + dbus_int32_t val = (dbus_int32_t) key;
  460 + getInteger("pfKey", DBUS_TYPE_STRING, &this->id, DBUS_TYPE_INT32, &val, DBUS_TYPE_INVALID);
409 } 461 }
410 462
411 - virtual int pakey(int key) 463 + virtual int pakey(int key)
412 { 464 {
413 - 465 + dbus_int32_t val = (dbus_int32_t) key;
  466 + getInteger("paKey", DBUS_TYPE_STRING, &this->id, DBUS_TYPE_INT32, &val, DBUS_TYPE_INVALID);
414 } 467 }
415 468
416 - virtual int quit(void) 469 + virtual int quit(void)
417 { 470 {
418 471
419 } 472 }
420 473
421 - virtual int action(const char *name) 474 + virtual int action(const char *name)
422 { 475 {
423 476
424 } 477 }
src/libpw3270cpp/session.cc
@@ -621,14 +621,13 @@ @@ -621,14 +621,13 @@
621 return set_url(host); 621 return set_url(host);
622 } 622 }
623 623
624 - int session::connect(const char *host, time_t wait) 624 + int session::connect(const char *url, time_t wait)
625 { 625 {
626 int rc = 0; 626 int rc = 0;
627 627
628 - if(host && *host) 628 + if(url && *url)
629 { 629 {
630 - rc = set_url(host);  
631 - trace("%s: set_url(%s) = %d",__FUNCTION__,host,rc); 630 + set_url(url);
632 } 631 }
633 632
634 rc = connect(); 633 rc = connect();
@@ -636,16 +635,7 @@ @@ -636,16 +635,7 @@
636 635
637 if(!rc && wait) 636 if(!rc && wait)
638 { 637 {
639 - time_t timeout = time(0)+wait;  
640 - rc = ETIMEDOUT;  
641 -  
642 - while(time(0) < timeout && rc == ETIMEDOUT)  
643 - {  
644 - trace("%s: Waiting",__FUNCTION__);  
645 - if(is_connected())  
646 - rc = 0;  
647 - iterate(true);  
648 - } 638 + rc = wait_for_ready(wait);
649 } 639 }
650 640
651 return rc; 641 return rc;
src/libpw3270cpp/testprogram.cc
@@ -46,12 +46,9 @@ @@ -46,12 +46,9 @@
46 // session *session = session::start(""); 46 // session *session = session::start("");
47 // session *session = session::start("new"); 47 // session *session = session::start("new");
48 48
49 - return 0;  
50 -  
51 cout << "pw3270 version: " << session->get_version() << endl; 49 cout << "pw3270 version: " << session->get_version() << endl;
52 cout << "pw3270 revision: " << session->get_revision() << endl << endl; 50 cout << "pw3270 revision: " << session->get_revision() << endl << endl;
53 51
54 - /*  
55 if(session->is_connected()) 52 if(session->is_connected())
56 cout << "\tConnected to host" << endl; 53 cout << "\tConnected to host" << endl;
57 else 54 else
@@ -64,7 +61,8 @@ @@ -64,7 +61,8 @@
64 61
65 s = session->get_host_charset(); 62 s = session->get_host_charset();
66 cout << "\tHost charset: " << s.c_str() << endl; 63 cout << "\tHost charset: " << s.c_str() << endl;
67 - */ 64 +
  65 + return 0;
68 66
69 cout << "Connect: " << session->connect("fandezhi.efglobe.com:23",60) << endl << endl; 67 cout << "Connect: " << session->connect("fandezhi.efglobe.com:23",60) << endl << endl;
70 68