From 6514f2c31c15e835b54030c3120b35eaea0fa0cc Mon Sep 17 00:00:00 2001 From: PerryWerneck Date: Sat, 10 Dec 2016 18:27:21 -0200 Subject: [PATCH] Implementando construção de método API para plugins. --- src/classlib/local.cc | 33 +++++++++++++++++++++++++++------ src/include/pw3270/class.h | 1 + 2 files changed, 28 insertions(+), 6 deletions(-) diff --git a/src/classlib/local.cc b/src/classlib/local.cc index 1ecf97e..678907b 100644 --- a/src/classlib/local.cc +++ b/src/classlib/local.cc @@ -173,11 +173,8 @@ const char * (*_ebc2asc)(H3270 *hSession, unsigned char *buffer, int sz); const char * (*_asc2ebc)(H3270 *hSession, unsigned char *buffer, int sz); - public: + void load_methods() { - local() throw(std::exception) : module("lib3270",PACKAGE_VERSION) - { - H3270 * (*lib3270_new)(const char *); void (*set_log_handler)(void (*loghandler)(H3270 *, const char *, int, const char *, va_list)); void (*set_trace_handler)( void (*handler)(H3270 *session, const char *fmt, va_list args) ); @@ -187,7 +184,6 @@ const char * name; } call[] = { - { (void **) & lib3270_new, "lib3270_session_new" }, { (void **) & set_log_handler, "lib3270_set_log_handler" }, { (void **) & set_trace_handler, "lib3270_set_trace_handler" }, @@ -255,12 +251,32 @@ // Get Session handle, setup base callbacks set_log_handler(loghandler); set_trace_handler(tracehandler); - this->hSession = lib3270_new(""); set_display_charset(); } + public: + + 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(); @@ -546,5 +562,10 @@ return new local(); } + session * session::create_local(H3270 *hSession) throw (std::exception) + { + return new local(hSession); + } + } diff --git a/src/include/pw3270/class.h b/src/include/pw3270/class.h index 4ef83e8..198058e 100644 --- a/src/include/pw3270/class.h +++ b/src/include/pw3270/class.h @@ -278,6 +278,7 @@ static session * create_remote(const char *name) throw (std::exception); static session * create_local(void) throw (std::exception); + static session * create_local(H3270 *hSession) throw (std::exception); #ifdef HAVE_ICONV iconv_t conv2Local; -- libgit2 0.21.2