Commit cbf1f7c11a9a60aa9e6da74a857f5d2615ff51ed
1 parent
5cb2c993
Exists in
master
and in
5 other branches
Embutindo objeto de controle para plugins.
Showing
2 changed files
with
62 additions
and
42 deletions
Show diff stats
src/classlib/local.cc
... | ... | @@ -115,12 +115,10 @@ |
115 | 115 | namespace PW3270_NAMESPACE |
116 | 116 | { |
117 | 117 | |
118 | - class local : public session, private module, private recursive_mutex | |
118 | + class local : public session, protected module, protected recursive_mutex | |
119 | 119 | { |
120 | 120 | private: |
121 | 121 | |
122 | - H3270 * hSession; | |
123 | - | |
124 | 122 | // Lib3270 entry points |
125 | 123 | const char * (*_get_version)(void); |
126 | 124 | LIB3270_CSTATE (*_get_connection_state)(H3270 *h); |
... | ... | @@ -173,6 +171,10 @@ |
173 | 171 | const char * (*_ebc2asc)(H3270 *hSession, unsigned char *buffer, int sz); |
174 | 172 | const char * (*_asc2ebc)(H3270 *hSession, unsigned char *buffer, int sz); |
175 | 173 | |
174 | + protected: | |
175 | + | |
176 | + H3270 * hSession; | |
177 | + | |
176 | 178 | void load_methods() { |
177 | 179 | |
178 | 180 | void (*set_log_handler)(void (*loghandler)(H3270 *, const char *, int, const char *, va_list)); |
... | ... | @@ -260,45 +262,10 @@ |
260 | 262 | |
261 | 263 | local() throw(std::exception) : module("lib3270",PACKAGE_VERSION) |
262 | 264 | { |
263 | - H3270 * (*lib3270_new)(const char *) = (H3270 * (*)(const char *)) get_symbol("lib3270_session_new"); | |
264 | - | |
265 | - if(!lib3270_new) | |
266 | - throw exception("Can't find symbol %s","lib3270_session_new"); | |
267 | - | |
268 | - this->hSession = lib3270_new(""); | |
269 | - | |
270 | - load_methods(); | |
271 | - | |
272 | - } | |
273 | - | |
274 | - local(H3270 * hSession) throw(std::exception) : module("lib3270",PACKAGE_VERSION) | |
275 | - { | |
276 | - this->hSession = hSession; | |
277 | - load_methods(); | |
278 | 265 | } |
279 | 266 | |
280 | 267 | virtual ~local() |
281 | 268 | { |
282 | - this->lock(); | |
283 | - | |
284 | - if(is_connected()) { | |
285 | - disconnect(); | |
286 | - } | |
287 | - | |
288 | - try | |
289 | - { | |
290 | - static void (*session_free)(H3270 *h) = (void (*)(H3270 *)) get_symbol("lib3270_session_free"); | |
291 | - | |
292 | - if(session_free && this->hSession) | |
293 | - session_free(this->hSession); | |
294 | - | |
295 | - this->hSession = 0; | |
296 | - | |
297 | - } | |
298 | - catch(exception e) { } | |
299 | - | |
300 | - this->unlock(); | |
301 | - | |
302 | 269 | } |
303 | 270 | |
304 | 271 | bool is_connected(void) |
... | ... | @@ -559,12 +526,65 @@ |
559 | 526 | |
560 | 527 | session * session::create_local(void) throw (std::exception) |
561 | 528 | { |
562 | - return new local(); | |
529 | + class obj : public local { | |
530 | + public: | |
531 | + obj() : local() { | |
532 | + | |
533 | + H3270 * (*lib3270_new)(const char *) = (H3270 * (*)(const char *)) get_symbol("lib3270_session_new"); | |
534 | + | |
535 | + if(!lib3270_new) | |
536 | + throw exception("Can't find symbol %s","lib3270_session_new"); | |
537 | + | |
538 | + this->hSession = lib3270_new(""); | |
539 | + | |
540 | + load_methods(); | |
541 | + | |
542 | + } | |
543 | + | |
544 | + virtual ~obj() { | |
545 | + | |
546 | + this->lock(); | |
547 | + | |
548 | + if(is_connected()) { | |
549 | + disconnect(); | |
550 | + } | |
551 | + | |
552 | + try | |
553 | + { | |
554 | + static void (*session_free)(H3270 *h) = (void (*)(H3270 *)) get_symbol("lib3270_session_free"); | |
555 | + | |
556 | + if(session_free && this->hSession) | |
557 | + session_free(this->hSession); | |
558 | + | |
559 | + this->hSession = 0; | |
560 | + | |
561 | + } | |
562 | + catch(exception e) { } | |
563 | + | |
564 | + this->unlock(); | |
565 | + | |
566 | + } | |
567 | + }; | |
568 | + | |
569 | + return new obj(); | |
563 | 570 | } |
564 | 571 | |
565 | 572 | session * session::create_local(H3270 *hSession) throw (std::exception) |
566 | 573 | { |
567 | - return new local(hSession); | |
574 | + class obj : public local { | |
575 | + public: | |
576 | + obj(H3270 *hSession) : local() | |
577 | + { | |
578 | + this->hSession = hSession; | |
579 | + load_methods(); | |
580 | + } | |
581 | + | |
582 | + virtual ~obj() { | |
583 | + } | |
584 | + | |
585 | + }; | |
586 | + | |
587 | + return new obj(hSession); | |
568 | 588 | } |
569 | 589 | |
570 | 590 | } | ... | ... |
src/include/pw3270/class.h
... | ... | @@ -135,6 +135,8 @@ |
135 | 135 | // Factory methods and settings |
136 | 136 | static session * start(const char *name = 0); |
137 | 137 | static session * create(const char *name = 0) throw (std::exception); |
138 | + static session * create_local(H3270 *hSession) throw (std::exception); | |
139 | + | |
138 | 140 | static session * get_default(void); |
139 | 141 | static bool has_default(void); |
140 | 142 | static void set_plugin(session * (*factory)(const char *name)); |
... | ... | @@ -255,8 +257,6 @@ |
255 | 257 | string get_3270_text(const char *str); |
256 | 258 | string get_local_text(const char *str); |
257 | 259 | |
258 | - static session * create_local(H3270 *hSession) throw (std::exception); | |
259 | - | |
260 | 260 | protected: |
261 | 261 | session(); |
262 | 262 | ... | ... |