diff --git a/src/include/pw3270.h b/src/include/pw3270.h index f1074ba..4622c3b 100644 --- a/src/include/pw3270.h +++ b/src/include/pw3270.h @@ -61,6 +61,9 @@ LIB3270_EXPORT void pw3270_save_window_size(GtkWidget *widget, const gchar *name); LIB3270_EXPORT void pw3270_restore_window(GtkWidget *widget, const gchar *name); + LIB3270_EXPORT const gchar * pw3270_get_session_name(GtkWidget *widget); + LIB3270_EXPORT void pw3270_set_session_name(GtkWidget *widget, const gchar *name); + #ifdef HAVE_GTKMAC #include LIB3270_EXPORT GtkMacBundle * pw3270_get_bundle(void); diff --git a/src/lib3270/screen.c b/src/lib3270/screen.c index 40a354c..71eab5a 100644 --- a/src/lib3270/screen.c +++ b/src/lib3270/screen.c @@ -418,8 +418,11 @@ int cursor_move(H3270 *h, int baddr) if(ret == baddr) return ret; - h->cursor_addr = baddr; - h->update_cursor(h,(unsigned short) (baddr/h->cols),(unsigned short) (baddr%h->cols),h->text[baddr].chr,h->text[baddr].attr); + if(baddr >= 0) + { + h->cursor_addr = baddr; + h->update_cursor(h,(unsigned short) (baddr/h->cols),(unsigned short) (baddr%h->cols),h->text[baddr].chr,h->text[baddr].attr); + } return ret; } diff --git a/src/plugins/remotectl/hllapi.c b/src/plugins/remotectl/hllapi.c index 3795e0b..535254b 100644 --- a/src/plugins/remotectl/hllapi.c +++ b/src/plugins/remotectl/hllapi.c @@ -35,38 +35,27 @@ #include #include +/*--[ Globals ]--------------------------------------------------------------------------------------*/ + + static char *session_name = NULL; + /*--[ Implement ]------------------------------------------------------------------------------------*/ - LIB3270_EXPORT int hllapi(unsigned long func, char *string, unsigned short length, unsigned short *rc) + static int run_query(unsigned long func, char *string, unsigned short length, unsigned short *rc) { int result = -1; #ifdef WIN32 - - static DWORD dwMode = PIPE_READMODE_MESSAGE; - static const LPTSTR lpszPipeName = TEXT( "\\\\.\\pipe\\pw3270" ); - HANDLE hPipe = INVALID_HANDLE_VALUE; + char PipeName[4096]; if(length < 0 && string) length = strlen(string); - if(!WaitNamedPipe(lpszPipeName,10000)) - return ETIMEDOUT; - - hPipe = CreateFile( lpszPipeName, // pipe name - GENERIC_WRITE|GENERIC_READ, // Read/Write access - 0, // no sharing - NULL, // default security attributes - OPEN_EXISTING, // opens existing pipe - 0, // Attributes - NULL); // no template file - - if(hPipe == INVALID_HANDLE_VALUE) - return -1; + snprintf(PipeName,4095,"\\\\.\\pipe\\%s",session_name); - if(!SetNamedPipeHandleState(hPipe,&dwMode,NULL,NULL)) + if(!WaitNamedPipe(PipeName,NMPWAIT_USE_DEFAULT_WAIT)) { - result = -1; + result = ETIMEDOUT; } else { @@ -82,18 +71,17 @@ if(string && length > 0) memcpy(data->string,string,length); - trace("Sending %d bytes",(int) cbSize); - - if(!TransactNamedPipe(hPipe,(LPVOID) data,cbSize,buffer,HLLAPI_MAXLENGTH,&cbSize,NULL)) + if(!CallNamedPipe(PipeName,(LPVOID)data,cbSize,buffer,HLLAPI_MAXLENGTH,&cbSize,NMPWAIT_USE_DEFAULT_WAIT)) { - result = -1; + result = GetLastError(); } else { + int sz = length < buffer->len ? length : buffer->len; *rc = buffer->rc; - if(string && length > 0) - memcpy(string,buffer->string,length); + if(string && sz > 0) + memcpy(string,buffer->string,sz); result = 0; } @@ -102,8 +90,6 @@ free(buffer); } - CloseHandle(hPipe); - #else #error NOT IMPLEMENTED @@ -112,3 +98,35 @@ return result; } + + static int set_session_name(const char *name) + { + if(!session_name) + free(session_name); + session_name = strdup(name); + + return 0; + } + + LIB3270_EXPORT int hllapi(unsigned long func, char *str, unsigned short length, unsigned short *rc) + { + int result = 1; + switch(func) + { + case HLLAPI_CMD_CONNECTPS: + result = set_session_name(str); + break; + + default: + if(!session_name) + { + if(set_session_name("pw3270")) + return ENOENT; + } + result = run_query(func, str, length, rc); + } + + return result; + } + + diff --git a/src/plugins/remotectl/remotectl.c b/src/plugins/remotectl/remotectl.c index 43a30bc..442a71c 100644 --- a/src/plugins/remotectl/remotectl.c +++ b/src/plugins/remotectl/remotectl.c @@ -32,6 +32,7 @@ */ #include "remotectl.h" + #include #include #include #include @@ -76,31 +77,40 @@ LIB3270_EXPORT int pw3270_plugin_init(GtkWidget *window) { #ifdef WIN32 - static const LPTSTR lpszPipename = TEXT("\\\\.\\pipe\\" PACKAGE_NAME ); - HANDLE hPipe; + char id; - trace("\n\n%s\n\n",__FUNCTION__); - - hPipe = CreateNamedPipe( lpszPipename, // pipe name - PIPE_ACCESS_DUPLEX | // read/write access - FILE_FLAG_OVERLAPPED, // overlapped mode - PIPE_TYPE_MESSAGE | // pipe type - PIPE_READMODE_MESSAGE | // pipe mode - PIPE_WAIT, // blocking mode - 1, // number of instances - PIPE_BUFFER_LENGTH, // output buffer size - PIPE_BUFFER_LENGTH, // input buffer size - 0, // client time-out - NULL); // default security attributes - - - if (hPipe == INVALID_HANDLE_VALUE) + for(id='A';id < 'Z';id++) { - popup_lasterror( _( "Can´t create pipe %s" ),lpszPipename); - return -1; + gchar * pipename = g_strdup_printf("\\\\.\\pipe\\%s%c",pw3270_get_session_name(window),id); + + HANDLE hPipe = CreateNamedPipe( TEXT(pipename), // pipe name + PIPE_ACCESS_DUPLEX | // read/write access + FILE_FLAG_OVERLAPPED, // overlapped mode + PIPE_TYPE_MESSAGE | // pipe type + PIPE_READMODE_MESSAGE | // pipe mode + PIPE_WAIT, // blocking mode + 1, // number of instances + PIPE_BUFFER_LENGTH, // output buffer size + PIPE_BUFFER_LENGTH, // input buffer size + 0, // client time-out + NULL); // default security attributes + + g_free(pipename); + + if(hPipe != INVALID_HANDLE_VALUE) + { + gchar *session = g_strdup_printf("%s:%c",pw3270_get_session_name(window),id); + pw3270_set_session_name(window,session); + g_free(session); + + init_source_pipe(hPipe); + return 0; + } + } - init_source_pipe(hPipe); + popup_lasterror( "%s", _( "Can´t create remote control pipe" )); + return -1; #else @@ -129,6 +139,17 @@ return 0; } + static int cmd_setcursor(unsigned short rc, char *string, unsigned short length) + { + H3270 *hSession = lib3270_get_default_session_handle(); + + if(!lib3270_connected(hSession)) + return ENOTCONN; + + lib3270_set_cursor_address(hSession,(int) rc); + return 0; + } + int run_hllapi(unsigned long function, char *string, unsigned short length, unsigned short rc) { static const struct _cmd @@ -137,7 +158,8 @@ int (*exec)(unsigned short rc, char *string, unsigned short length); } cmd[] = { - { HLLAPI_CMD_GETREVISION, cmd_getrevision } + { HLLAPI_CMD_SETCURSOR, cmd_setcursor }, + { HLLAPI_CMD_GETREVISION, cmd_getrevision } }; int f; diff --git a/src/plugins/remotectl/testprogram.c b/src/plugins/remotectl/testprogram.c index 424d526..9e73799 100644 --- a/src/plugins/remotectl/testprogram.c +++ b/src/plugins/remotectl/testprogram.c @@ -38,6 +38,10 @@ char buffer[1024]; unsigned short rc; + // Set session name + strcpy(buffer,"pw3270"); + printf("ConnectPS exits with %d\n[%s]\n",hllapi(HLLAPI_CMD_CONNECTPS,buffer,1024,&rc),buffer); + // Test for GetRevision call *buffer = 0; printf("GetRevision exits with %d\n[%s]\n",hllapi(HLLAPI_CMD_GETREVISION,buffer,1024,&rc),buffer); diff --git a/src/pw3270/main.c b/src/pw3270/main.c index 83c8d7a..fd2c9ec 100644 --- a/src/pw3270/main.c +++ b/src/pw3270/main.c @@ -122,11 +122,12 @@ static gboolean appname(const gchar *option_name, const gchar *value, gpointer d int main(int argc, char *argv[]) { #if defined( WIN32 ) - static const gchar * appname = PACKAGE_NAME; + static const gchar * appname = PACKAGE_NAME; #endif // WIN32 - static const gchar * host = NULL; - int rc = 0; + static const gchar * session_name = PACKAGE_NAME; + static const gchar * host = NULL; + int rc = 0; #if ! GLIB_CHECK_VERSION(2,32,0) g_thread_init(NULL); @@ -183,17 +184,19 @@ int main(int argc, char *argv[]) static const GOptionEntry app_options[] = { #if ! defined( WIN32 ) - { "appname", 'a', 0, G_OPTION_ARG_CALLBACK, appname, N_( "Application name" ), PACKAGE_NAME }, + { "appname", 'a', 0, G_OPTION_ARG_CALLBACK, appname, N_( "Application name" ), PACKAGE_NAME }, #else - { "appname", 'a', 0, G_OPTION_ARG_STRING, &appname, N_( "Application name" ), PACKAGE_NAME }, + { "appname", 'a', 0, G_OPTION_ARG_STRING, &appname, N_( "Application name" ), PACKAGE_NAME }, #endif // WIN32 - { "host", 'h', 0, G_OPTION_ARG_STRING, &host, N_( "Host to connect"), NULL }, + { "session", 's', 0, G_OPTION_ARG_STRING, &session_name, N_( "Session name" ), PACKAGE_NAME }, + { "host", 'h', 0, G_OPTION_ARG_STRING, &host, N_( "Host to connect"), NULL }, { NULL } }; GOptionContext * options = g_option_context_new (_("- 3270 Emulator for Gtk")); GError * error = NULL; + g_option_context_add_main_entries(options, app_options, NULL); if(!g_option_context_parse( options, &argc, &argv, &error )) @@ -241,6 +244,7 @@ int main(int argc, char *argv[]) } toplevel = pw3270_new(host); + pw3270_set_session_name(toplevel,session_name); toplevel_setup(GTK_WINDOW(toplevel)); diff --git a/src/pw3270/window.c b/src/pw3270/window.c index 0df1f9c..09d11e7 100644 --- a/src/pw3270/window.c +++ b/src/pw3270/window.c @@ -216,6 +216,20 @@ return v3270_get_session(GTK_PW3270(widget)->terminal); } + const gchar * pw3270_get_session_name(GtkWidget *widget) + { + if(widget && GTK_IS_PW3270(widget)) + return v3270_get_session_name(GTK_PW3270(widget)->terminal); + return g_get_application_name(); + } + + LIB3270_EXPORT void pw3270_set_session_name(GtkWidget *widget, const gchar *name) + { + g_return_if_fail(GTK_IS_PW3270(widget)); + v3270_set_session_name(GTK_PW3270(widget)->terminal,name); + gtk_window_set_title(GTK_WINDOW(widget),name); + } + GtkWidget * pw3270_get_terminal_widget(GtkWidget *widget) { g_return_val_if_fail(GTK_IS_PW3270(widget),NULL); -- libgit2 0.21.2