From cbf1f7c11a9a60aa9e6da74a857f5d2615ff51ed Mon Sep 17 00:00:00 2001 From: PerryWerneck Date: Sat, 10 Dec 2016 19:16:36 -0200 Subject: [PATCH] Embutindo objeto de controle para plugins. --- src/classlib/local.cc | 100 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++---------------------------------------- src/include/pw3270/class.h | 4 ++-- 2 files changed, 62 insertions(+), 42 deletions(-) diff --git a/src/classlib/local.cc b/src/classlib/local.cc index 678907b..4bb4e6f 100644 --- a/src/classlib/local.cc +++ b/src/classlib/local.cc @@ -115,12 +115,10 @@ namespace PW3270_NAMESPACE { - class local : public session, private module, private recursive_mutex + class local : public session, protected module, protected recursive_mutex { private: - H3270 * hSession; - // Lib3270 entry points const char * (*_get_version)(void); LIB3270_CSTATE (*_get_connection_state)(H3270 *h); @@ -173,6 +171,10 @@ const char * (*_ebc2asc)(H3270 *hSession, unsigned char *buffer, int sz); const char * (*_asc2ebc)(H3270 *hSession, unsigned char *buffer, int sz); + protected: + + H3270 * hSession; + void load_methods() { void (*set_log_handler)(void (*loghandler)(H3270 *, const char *, int, const char *, va_list)); @@ -260,45 +262,10 @@ local() throw(std::exception) : module("lib3270",PACKAGE_VERSION) { - H3270 * (*lib3270_new)(const char *) = (H3270 * (*)(const char *)) get_symbol("lib3270_session_new"); - - if(!lib3270_new) - throw exception("Can't find symbol %s","lib3270_session_new"); - - this->hSession = lib3270_new(""); - - load_methods(); - - } - - local(H3270 * hSession) throw(std::exception) : module("lib3270",PACKAGE_VERSION) - { - this->hSession = hSession; - load_methods(); } virtual ~local() { - this->lock(); - - if(is_connected()) { - disconnect(); - } - - try - { - static void (*session_free)(H3270 *h) = (void (*)(H3270 *)) get_symbol("lib3270_session_free"); - - if(session_free && this->hSession) - session_free(this->hSession); - - this->hSession = 0; - - } - catch(exception e) { } - - this->unlock(); - } bool is_connected(void) @@ -559,12 +526,65 @@ session * session::create_local(void) throw (std::exception) { - return new local(); + class obj : public local { + public: + obj() : local() { + + H3270 * (*lib3270_new)(const char *) = (H3270 * (*)(const char *)) get_symbol("lib3270_session_new"); + + if(!lib3270_new) + throw exception("Can't find symbol %s","lib3270_session_new"); + + this->hSession = lib3270_new(""); + + load_methods(); + + } + + virtual ~obj() { + + this->lock(); + + if(is_connected()) { + disconnect(); + } + + try + { + static void (*session_free)(H3270 *h) = (void (*)(H3270 *)) get_symbol("lib3270_session_free"); + + if(session_free && this->hSession) + session_free(this->hSession); + + this->hSession = 0; + + } + catch(exception e) { } + + this->unlock(); + + } + }; + + return new obj(); } session * session::create_local(H3270 *hSession) throw (std::exception) { - return new local(hSession); + class obj : public local { + public: + obj(H3270 *hSession) : local() + { + this->hSession = hSession; + load_methods(); + } + + virtual ~obj() { + } + + }; + + return new obj(hSession); } } diff --git a/src/include/pw3270/class.h b/src/include/pw3270/class.h index 243093d..36f8bfd 100644 --- a/src/include/pw3270/class.h +++ b/src/include/pw3270/class.h @@ -135,6 +135,8 @@ // Factory methods and settings static session * start(const char *name = 0); static session * create(const char *name = 0) throw (std::exception); + static session * create_local(H3270 *hSession) throw (std::exception); + static session * get_default(void); static bool has_default(void); static void set_plugin(session * (*factory)(const char *name)); @@ -255,8 +257,6 @@ string get_3270_text(const char *str); string get_local_text(const char *str); - static session * create_local(H3270 *hSession) throw (std::exception); - protected: session(); -- libgit2 0.21.2