Commit 6514f2c31c15e835b54030c3120b35eaea0fa0cc

Authored by Perry Werneck
1 parent 07f0e959

Implementando construção de método API para plugins.

src/classlib/local.cc
... ... @@ -173,11 +173,8 @@
173 173 const char * (*_ebc2asc)(H3270 *hSession, unsigned char *buffer, int sz);
174 174 const char * (*_asc2ebc)(H3270 *hSession, unsigned char *buffer, int sz);
175 175  
176   - public:
  176 + void load_methods() {
177 177  
178   - local() throw(std::exception) : module("lib3270",PACKAGE_VERSION)
179   - {
180   - H3270 * (*lib3270_new)(const char *);
181 178 void (*set_log_handler)(void (*loghandler)(H3270 *, const char *, int, const char *, va_list));
182 179 void (*set_trace_handler)( void (*handler)(H3270 *session, const char *fmt, va_list args) );
183 180  
... ... @@ -187,7 +184,6 @@
187 184 const char * name;
188 185 } call[] =
189 186 {
190   - { (void **) & lib3270_new, "lib3270_session_new" },
191 187 { (void **) & set_log_handler, "lib3270_set_log_handler" },
192 188 { (void **) & set_trace_handler, "lib3270_set_trace_handler" },
193 189  
... ... @@ -255,12 +251,32 @@
255 251 // Get Session handle, setup base callbacks
256 252 set_log_handler(loghandler);
257 253 set_trace_handler(tracehandler);
258   - this->hSession = lib3270_new("");
259 254  
260 255 set_display_charset();
261 256  
262 257 }
263 258  
  259 + public:
  260 +
  261 + local() throw(std::exception) : module("lib3270",PACKAGE_VERSION)
  262 + {
  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 + }
  279 +
264 280 virtual ~local()
265 281 {
266 282 this->lock();
... ... @@ -546,5 +562,10 @@
546 562 return new local();
547 563 }
548 564  
  565 + session * session::create_local(H3270 *hSession) throw (std::exception)
  566 + {
  567 + return new local(hSession);
  568 + }
  569 +
549 570 }
550 571  
... ...
src/include/pw3270/class.h
... ... @@ -278,6 +278,7 @@
278 278  
279 279 static session * create_remote(const char *name) throw (std::exception);
280 280 static session * create_local(void) throw (std::exception);
  281 + static session * create_local(H3270 *hSession) throw (std::exception);
281 282  
282 283 #ifdef HAVE_ICONV
283 284 iconv_t conv2Local;
... ...