diff --git a/src/include/pw3270/hllapi.h b/src/include/pw3270/hllapi.h index a9b324f..85bff64 100644 --- a/src/include/pw3270/hllapi.h +++ b/src/include/pw3270/hllapi.h @@ -38,8 +38,9 @@ extern "C" { #endif - #define HLLAPI_MAXLENGTH 4096 + #define HLLAPI_MAXLENGTH 4096 + /* Function codes */ #define HLLAPI_CMD_CONNECTPS 1 /**< connect presentation space */ #define HLLAPI_CMD_DISCONNECTPS 2 /**< disconnect presentation space */ #define HLLAPI_CMD_INPUTSTRING 3 /**< send string */ @@ -54,6 +55,14 @@ extern "C" { #define HLLAPI_CMD_RECEIVEFILE 91 /**< Receive a file from the host */ #define HLLAPI_CMD_GETREVISION 2000 /**< Get lib3270 revision */ + + + /* Result codes */ + #define HLLAPI_STATUS_SUCESS 0 /**< Good return code */ + #define HLLAPI_STATUS_BAD_PARAMETER 2 /**< Bad parameter or verb not supported */ + #define HLLAPI_STATUS_UNAVAILABLE 11 /**< Resource unavailable at this time */ + + typedef enum _hllapi_packet { diff --git a/src/plugins/remotectl/hllapi.c b/src/plugins/remotectl/hllapi.c index f6e497a..1fdc04f 100644 --- a/src/plugins/remotectl/hllapi.c +++ b/src/plugins/remotectl/hllapi.c @@ -35,9 +35,24 @@ #include #include +/*--[ Prototipes ]-----------------------------------------------------------------------------------*/ + + static int connect_ps(char *buffer, unsigned short *length, unsigned short *rc); + static int disconnect_ps(char *buffer, unsigned short *length, unsigned short *rc); + static int get_library_revision(char *buffer, unsigned short *length, unsigned short *rc); + /*--[ Globals ]--------------------------------------------------------------------------------------*/ -// static HANDLE hPipe = INVALID_HANDLE_VALUE; + static const struct _hllapi_call + { + unsigned long func; + int (*exec)(char *buffer, unsigned short *length, unsigned short *rc); + } hllapi_call[] = + { + { HLLAPI_CMD_CONNECTPS, connect_ps }, + { HLLAPI_CMD_DISCONNECTPS, disconnect_ps }, + { HLLAPI_CMD_GETREVISION, get_library_revision }, + }; /*--[ Implement ]------------------------------------------------------------------------------------*/ @@ -46,56 +61,41 @@ #else LIB3270_EXPORT int hllapi(const unsigned long *func, char *buffer, unsigned short *length, unsigned short *rc) #endif // _WIN32 -{ - switch(*func) - { - case HLLAPI_CMD_CONNECTPS: - break; - - case HLLAPI_CMD_DISCONNECTPS: - break; - - case HLLAPI_CMD_INPUTSTRING: - break; - - case HLLAPI_CMD_WAIT: - break; - - case HLLAPI_CMD_COPYPS: - break; - - case HLLAPI_CMD_SEARCHPS: - break; - - case HLLAPI_CMD_QUERYCURSOR: - break; - - case HLLAPI_CMD_COPYPSTOSTR: - break; - - case HLLAPI_CMD_COPYSTRTOPS: - break; - - case HLLAPI_CMD_SETCURSOR: - break; - - case HLLAPI_CMD_SENDFILE: - break; - - case HLLAPI_CMD_RECEIVEFILE: - break; - - case HLLAPI_CMD_GETREVISION: - break; - - default: - *rc = EINVAL; - return EINVAL; +{ + int f; + + for(f=0;f< (sizeof (hllapi_call) / sizeof ((hllapi_call)[0])));f++) + { + if(hllapi_call[f].func == *func) + return hllapi_call[f].exec(buffer,length,rc); } + *rc = HLLAPI_STATUS_BAD_PARAMETER; - return 0; + return *rc; } + +static int connect_ps(char *buffer, unsigned short *length, unsigned short *rc) +{ + if(hllapi_init(buffer) == 0) + *rc = HLLAPI_STATUS_SUCESS; + else + *rc = HLLAPI_STATUS_UNAVAILABLE; + return 0; +} + +static int disconnect_ps(char *buffer, unsigned short *length, unsigned short *rc) +{ + *rc = hllapi_deinit(); + return 0; +} + +static int get_library_revision(char *buffer, unsigned short *length, unsigned short *rc) +{ + *rc = hllapi_get_revision(); + return 0; +} + /* static int cmd_connect_ps(const char *name) -- libgit2 0.21.2