Commit 06e0c8a769af2d1e0fb8459f44910979c7ff1955

Authored by perry.werneck@gmail.com
1 parent 79e84de9

Exportando mais funcoes para uso em VB

@@ -244,6 +244,9 @@ @@ -244,6 +244,9 @@
244 <Unit filename="src/plugins/dbus3270/service.h" /> 244 <Unit filename="src/plugins/dbus3270/service.h" />
245 <Unit filename="src/plugins/dbus3270/test.sh" /> 245 <Unit filename="src/plugins/dbus3270/test.sh" />
246 <Unit filename="src/plugins/remotectl/Makefile.in" /> 246 <Unit filename="src/plugins/remotectl/Makefile.in" />
  247 + <Unit filename="src/plugins/remotectl/calls.c">
  248 + <Option compilerVar="CC" />
  249 + </Unit>
247 <Unit filename="src/plugins/remotectl/hllapi.c"> 250 <Unit filename="src/plugins/remotectl/hllapi.c">
248 <Option compilerVar="CC" /> 251 <Option compilerVar="CC" />
249 </Unit> 252 </Unit>
src/include/pw3270/hllapi.h
@@ -67,12 +67,28 @@ extern &quot;C&quot; { @@ -67,12 +67,28 @@ extern &quot;C&quot; {
67 unsigned short rc; /**< Short argument/return code */ 67 unsigned short rc; /**< Short argument/return code */
68 unsigned int value; /**< Requested value */ 68 unsigned int value; /**< Requested value */
69 char string[1]; /**< String argument */ 69 char string[1]; /**< String argument */
70 - } HLLAPI_DATA; 70 + } HLLAPI_DATA;
  71 +
71 #pragma pack() 72 #pragma pack()
72 73
73 #ifdef _WIN32 74 #ifdef _WIN32
74 - // http://www.mingw.org/wiki/Visual_Basic_DLL  
75 - __declspec (dllexport) int __stdcall hllapi(const LPWORD func, LPSTR str, LPWORD length, LPWORD rc); 75 + // http://www.mingw.org/wiki/Visual_Basic_DLL
  76 + __declspec (dllexport) int __stdcall hllapi(const LPWORD func, LPSTR str, LPWORD length, LPWORD rc);
  77 +
  78 + __declspec (dllexport) int __stdcall hllapi_init(LPSTR mode);
  79 + __declspec (dllexport) int __stdcall hllapi_deinit(void);
  80 +
  81 + __declspec (dllexport) int __stdcall hllapi_get_revision(LPDWORD rc);
  82 + __declspec (dllexport) int __stdcall hllapi_connect(LPSTR uri);
  83 + __declspec (dllexport) int __stdcall hllapi_disconnect(LPWORD rc);
  84 + __declspec (dllexport) int __stdcall hllapi_get_message_id(LPWORD rc);
  85 + __declspec (dllexport) int __stdcall hllapi_get_screen_at(WORD row, WORD col, LPSTR buffer);
  86 + __declspec (dllexport) int __stdcall hllapi_enter(LPWORD rc);
  87 + __declspec (dllexport) int __stdcall hllapi_set_text_at(LPWORD rc, WORD row, WORD col, LPSTR text);
  88 + __declspec (dllexport) int __stdcall hllapi_cmp_text_at(LPWORD rc, WORD row, WORD col, LPSTR text);
  89 + __declspec (dllexport) int __stdcall hllapi_wait_for_ready(LPWORD rc, WORD seconds);
  90 + __declspec (dllexport) int __stdcall hllapi_wait(LPWORD rc, WORD seconds);
  91 +
76 #else 92 #else
77 LIB3270_EXPORT int hllapi(const unsigned long *func, char *str, unsigned short *length, unsigned short *rc); 93 LIB3270_EXPORT int hllapi(const unsigned long *func, char *str, unsigned short *length, unsigned short *rc);
78 #endif // _WIN32 94 #endif // _WIN32
src/plugins/remotectl/Makefile.in
@@ -31,7 +31,7 @@ @@ -31,7 +31,7 @@
31 MODULE_NAME=remotectl 31 MODULE_NAME=remotectl
32 DEPENDS=*.h ../../include/*.h ../../include/lib3270/*.h Makefile 32 DEPENDS=*.h ../../include/*.h ../../include/lib3270/*.h Makefile
33 PLUGIN_SRC=remotectl.c pipesource.c 33 PLUGIN_SRC=remotectl.c pipesource.c
34 -HLLAPI_SRC=hllapi.c 34 +HLLAPI_SRC=hllapi.c calls.c
35 35
36 #---[ Paths ]------------------------------------------------------------------ 36 #---[ Paths ]------------------------------------------------------------------
37 37
@@ -58,8 +58,8 @@ XGETTEXT=@XGETTEXT@ @@ -58,8 +58,8 @@ XGETTEXT=@XGETTEXT@
58 DLL_FLAGS=@DLL_FLAGS@ 58 DLL_FLAGS=@DLL_FLAGS@
59 DEBUG_CFLAGS=-DDEBUG=1 -g -Wall 59 DEBUG_CFLAGS=-DDEBUG=1 -g -Wall
60 60
61 -PW3270_LIBS ?= `pkg-config --libs pw3270 lib3270`  
62 -PW3270_CFLAGS ?= `pkg-config --cflags pw3270 lib3270` 61 +PW3270_LIBS ?= `pkg-config --libs lib3270`
  62 +PW3270_CFLAGS ?= `pkg-config --cflags lib3270`
63 GTK_CFLAGS ?= @GTK_CFLAGS@ @GTKMAC_CFLAGS@ 63 GTK_CFLAGS ?= @GTK_CFLAGS@ @GTKMAC_CFLAGS@
64 GTK_LIBS ?= @GTK_LIBS@ @GTKMAC_LIBS@ 64 GTK_LIBS ?= @GTK_LIBS@ @GTKMAC_LIBS@
65 65
src/plugins/remotectl/calls.c 0 → 100644
@@ -0,0 +1,252 @@ @@ -0,0 +1,252 @@
  1 +/*
  2 + * "Software pw3270, desenvolvido com base nos códigos fontes do WC3270 e X3270
  3 + * (Paul Mattes Paul.Mattes@usa.net), de emulação de terminal 3270 para acesso a
  4 + * aplicativos mainframe. Registro no INPI sob o nome G3270.
  5 + *
  6 + * Copyright (C) <2008> <Banco do Brasil S.A.>
  7 + *
  8 + * Este programa é software livre. Você pode redistribuí-lo e/ou modificá-lo sob
  9 + * os termos da GPL v.2 - Licença Pública Geral GNU, conforme publicado pela
  10 + * Free Software Foundation.
  11 + *
  12 + * Este programa é distribuído na expectativa de ser útil, mas SEM QUALQUER
  13 + * GARANTIA; sem mesmo a garantia implícita de COMERCIALIZAÇÃO ou de ADEQUAÇÃO
  14 + * A QUALQUER PROPÓSITO EM PARTICULAR. Consulte a Licença Pública Geral GNU para
  15 + * obter mais detalhes.
  16 + *
  17 + * Você deve ter recebido uma cópia da Licença Pública Geral GNU junto com este
  18 + * programa; se não, escreva para a Free Software Foundation, Inc., 59 Temple
  19 + * Place, Suite 330, Boston, MA, 02111-1307, USA
  20 + *
  21 + * Este programa está nomeado como calls.c e possui - linhas de código.
  22 + *
  23 + * Contatos:
  24 + *
  25 + * perry.werneck@gmail.com (Alexandre Perry de Souza Werneck)
  26 + * erico.mendonca@gmail.com (Erico Mascarenhas Mendonça)
  27 + *
  28 + */
  29 +
  30 + #include <windows.h>
  31 + #include <lib3270.h>
  32 + #include <malloc.h>
  33 + #include <string.h>
  34 + #include <errno.h>
  35 + #include <pw3270/hllapi.h>
  36 + #include <stdio.h>
  37 + #include <lib3270/log.h>
  38 +
  39 +/*--[ Globals ]--------------------------------------------------------------------------------------*/
  40 +
  41 + HMODULE hModule = NULL;
  42 + H3270 * hSession = NULL;
  43 +
  44 + static H3270 * (*session_new)(const char *model) = NULL;
  45 + static void (*session_free)(H3270 *h) = NULL;
  46 + static const char * (*get_revision)(void) = NULL;
  47 + static int (*host_connect)(H3270 *h,const char *n, int wait) = NULL;
  48 + static int (*wait_for_ready)(H3270 *h, int seconds) = NULL;
  49 + static void (*host_disconnect)(H3270 *h) = NULL;
  50 + static int (*script_sleep)(H3270 *h, int seconds) = NULL;
  51 + static LIB3270_MESSAGE (*get_message)(H3270 *h) = NULL;
  52 + static char * (*get_text)(H3270 *h, int row, int col, int len) = NULL;
  53 + static void * (*release_memory)(void *p) = NULL;
  54 + static int (*action_enter)(H3270 *h) = NULL;
  55 + static int (*set_text_at)(H3270 *h, int row, int col, const unsigned char *str) = NULL;
  56 + static int (*cmp_text_at)(H3270 *h, int row, int col, const char *text) = NULL;
  57 +
  58 + static const struct _entry_point
  59 + {
  60 + void **ptr;
  61 + const char * name;
  62 + } entry_point[] =
  63 + {
  64 + { (void **) &session_new, "lib3270_session_new" },
  65 + { (void **) &session_free, "lib3270_session_free" },
  66 + { (void **) &get_revision, "lib3270_get_revision" },
  67 + { (void **) &host_connect, "lib3270_connect" },
  68 + { (void **) &host_disconnect, "lib3270_disconnect" },
  69 + { (void **) &wait_for_ready, "lib3270_wait_for_ready" },
  70 + { (void **) &script_sleep, "lib3270_wait" },
  71 + { (void **) &get_message, "lib3270_get_program_message" },
  72 + { (void **) &get_text, "lib3270_get_text_at" },
  73 + { (void **) &release_memory, "lib3270_free" },
  74 + { (void **) &action_enter, "lib3270_enter" },
  75 + { (void **) &set_text_at, "lib3270_set_string_at" },
  76 + { (void **) &cmp_text_at, "lib3270_cmp_text_at" },
  77 +
  78 + { NULL, NULL }
  79 + };
  80 +
  81 +
  82 +/*--[ Implement ]------------------------------------------------------------------------------------*/
  83 +
  84 + __declspec (dllexport) int __stdcall hllapi_init(LPSTR mode)
  85 + {
  86 + if(!mode)
  87 + return EINVAL;
  88 +
  89 + if(hModule)
  90 + return EBUSY;
  91 +
  92 + if(!*mode)
  93 + {
  94 + // Direct mode, load lib3270.dll, get pointers to the calls
  95 + int f;
  96 +
  97 + hModule = LoadLibrary("lib3270.dll");
  98 + if(hModule == NULL)
  99 + return GetLastError();
  100 +
  101 + // Get library entry pointers
  102 + for(f=0;entry_point[f].name;f++)
  103 + {
  104 + void *ptr = (void *) GetProcAddress(hModule,entry_point[f].name);
  105 + if(!ptr)
  106 + {
  107 + fprintf(stderr,"Can´t load \"%s\"\n",entry_point[f].name);
  108 + hllapi_deinit();
  109 + return ENOENT;
  110 + }
  111 + *entry_point[f].ptr = ptr;
  112 + }
  113 +
  114 + // Get session handle
  115 + hSession = session_new("");
  116 +
  117 + return 0;
  118 + }
  119 +
  120 + // Set entry pointers to pipe based calls
  121 +
  122 +
  123 + return -1;
  124 + }
  125 +
  126 + __declspec (dllexport) int __stdcall hllapi_deinit(void)
  127 + {
  128 + int f;
  129 +
  130 + // Release session
  131 + if(hSession && session_free)
  132 + session_free(hSession);
  133 +
  134 + for(f=0;entry_point[f].name;f++)
  135 + *entry_point[f].ptr = NULL;
  136 +
  137 +
  138 + if(hModule != NULL)
  139 + {
  140 + FreeLibrary(hModule);
  141 + hModule = NULL;
  142 + }
  143 +
  144 + return 0;
  145 + }
  146 +
  147 + __declspec (dllexport) int __stdcall hllapi_get_revision(LPDWORD rc)
  148 + {
  149 + if(!get_revision)
  150 + return EINVAL;
  151 +
  152 + *rc = (DWORD) atoi(get_revision());
  153 +
  154 + return 0;
  155 + }
  156 +
  157 + __declspec (dllexport) int __stdcall hllapi_connect(LPSTR uri)
  158 + {
  159 + if(!(host_connect && hSession && uri))
  160 + return EINVAL;
  161 +
  162 + return host_connect(hSession,uri,0);
  163 + }
  164 +
  165 + __declspec (dllexport) int __stdcall hllapi_disconnect(LPWORD rc)
  166 + {
  167 + if(!(host_disconnect && hSession))
  168 + return EINVAL;
  169 +
  170 + host_disconnect(hSession);
  171 +
  172 + return 0;
  173 + }
  174 +
  175 + __declspec (dllexport) int __stdcall hllapi_wait_for_ready(LPWORD rc, WORD seconds)
  176 + {
  177 + if(!(wait_for_ready && hSession))
  178 + return EINVAL;
  179 +
  180 + *rc = (WORD) wait_for_ready(hSession,(int) seconds);
  181 +
  182 + return 0;
  183 + }
  184 +
  185 + __declspec (dllexport) int __stdcall hllapi_wait(LPWORD rc, WORD seconds)
  186 + {
  187 + if(!(script_sleep && hSession))
  188 + return EINVAL;
  189 +
  190 + *rc = (WORD) script_sleep(hSession,(int) seconds);
  191 +
  192 + return 0;
  193 +
  194 + }
  195 +
  196 + __declspec (dllexport) int __stdcall hllapi_get_message_id(LPWORD rc)
  197 + {
  198 + if(!(get_message && hSession))
  199 + return EINVAL;
  200 + *rc = get_message(hSession);
  201 + return 0;
  202 + }
  203 +
  204 + __declspec (dllexport) int __stdcall hllapi_get_screen_at(WORD row, WORD col, LPSTR buffer)
  205 + {
  206 + char * text;
  207 + int len = strlen(buffer);
  208 +
  209 + if(!(get_text && release_memory && hSession))
  210 + return EINVAL;
  211 +
  212 + text = get_text(hSession,row,col,len);
  213 +
  214 + if(!text)
  215 + return EINVAL;
  216 +
  217 + strncpy(buffer,text,len);
  218 + release_memory(text);
  219 +
  220 + return 0;
  221 + }
  222 +
  223 + __declspec (dllexport) int __stdcall hllapi_enter(LPWORD rc)
  224 + {
  225 + if(!(action_enter && hSession))
  226 + return EINVAL;
  227 +
  228 + *rc = (WORD) action_enter(hSession);
  229 +
  230 + return 0;
  231 + }
  232 +
  233 + __declspec (dllexport) int __stdcall hllapi_set_text_at(LPWORD rc, WORD row, WORD col, LPSTR text)
  234 + {
  235 + if(!(set_text_at && hSession))
  236 + return EINVAL;
  237 +
  238 + *rc = (WORD) set_text_at(hSession,row,col,(const unsigned char *) text);
  239 +
  240 + return 0;
  241 + }
  242 +
  243 + __declspec (dllexport) int __stdcall hllapi_cmp_text_at(LPWORD rc, WORD row, WORD col, LPSTR text)
  244 + {
  245 + if(!(cmp_text_at && hSession))
  246 + return EINVAL;
  247 +
  248 + *rc = (WORD) cmp_text_at(hSession,row,col,(const char *) text);
  249 +
  250 + return 0;
  251 + }
  252 +
src/plugins/remotectl/hllapi.c
@@ -237,4 +237,3 @@ @@ -237,4 +237,3 @@
237 return 0; 237 return 0;
238 } 238 }
239 239
240 -  
src/plugins/remotectl/testprogram.c
@@ -35,7 +35,30 @@ @@ -35,7 +35,30 @@
35 #define BUFFER_LENGTH 8000 35 #define BUFFER_LENGTH 8000
36 36
37 /*---[ Implement ]--------------------------------------------------------------------------------*/ 37 /*---[ Implement ]--------------------------------------------------------------------------------*/
38 - 38 +
  39 + int main(int numpar, char *param[])
  40 + {
  41 + DWORD revision;
  42 + int rc;
  43 +
  44 + rc = hllapi_init("");
  45 + if(rc)
  46 + {
  47 + printf("Init exits with rc=%d\n",rc);
  48 + return rc;
  49 + }
  50 +
  51 + if(!hllapi_get_revision(&revision))
  52 + printf("Library revision is %d\n",(int) revision);
  53 +
  54 +
  55 + printf("Deinit exits with rc=%d\n",rc);
  56 + rc = hllapi_deinit();
  57 +
  58 + return rc;
  59 + }
  60 +
  61 +/*
39 int main(int numpar, char *param[]) 62 int main(int numpar, char *param[])
40 { 63 {
41 char buffer[BUFFER_LENGTH]; 64 char buffer[BUFFER_LENGTH];
@@ -99,3 +122,4 @@ @@ -99,3 +122,4 @@
99 122
100 return 0; 123 return 0;
101 } 124 }
  125 +*/