diff --git a/pw3270.cbp b/pw3270.cbp index 6b4130e..3b9ead2 100644 --- a/pw3270.cbp +++ b/pw3270.cbp @@ -72,8 +72,8 @@ + - diff --git a/src/include/lib3270/config.h.in b/src/include/lib3270/config.h.in index e5ed01d..e90cd05 100644 --- a/src/include/lib3270/config.h.in +++ b/src/include/lib3270/config.h.in @@ -62,7 +62,6 @@ #define X3270_TRACE #undef HAVE_PRINTER - #undef HAVE_SCRIPT #undef HAVE_MALLOC_H diff --git a/src/include/pw3270.h b/src/include/pw3270.h index 4622c3b..c774d85 100644 --- a/src/include/pw3270.h +++ b/src/include/pw3270.h @@ -57,6 +57,8 @@ LIB3270_EXPORT H3270 * pw3270_get_session(GtkWidget *widget); LIB3270_EXPORT GtkWidget * pw3270_get_terminal_widget(GtkWidget *widget); + LIB3270_EXPORT GtkWidget * pw3270_get_toplevel(void); + LIB3270_EXPORT gchar * pw3270_build_filename(GtkWidget *widget, const gchar *first_element, ...); LIB3270_EXPORT void pw3270_save_window_size(GtkWidget *widget, const gchar *name); LIB3270_EXPORT void pw3270_restore_window(GtkWidget *widget, const gchar *name); diff --git a/src/include/pw3270/hllapi.h b/src/include/pw3270/hllapi.h index 9ccbbd6..64e9338 100644 --- a/src/include/pw3270/hllapi.h +++ b/src/include/pw3270/hllapi.h @@ -61,8 +61,7 @@ extern "C" { } HLLAPI_DATA; #pragma pack() - #warning Remover comentario -// LIB3270_EXPORT int hllapi(unsigned long func, char *str, unsigned short length, unsigned short *rc); + LIB3270_EXPORT int hllapi(const unsigned long *func, char *str, unsigned short *length, unsigned short *rc); #ifdef __cplusplus } /* end of extern "C" */ diff --git a/src/include/pw3270/v3270.h b/src/include/pw3270/v3270.h new file mode 100644 index 0000000..0cc9efd --- /dev/null +++ b/src/include/pw3270/v3270.h @@ -0,0 +1,198 @@ +/* + * "Software pw3270, desenvolvido com base nos códigos fontes do WC3270 e X3270 + * (Paul Mattes Paul.Mattes@usa.net), de emulação de terminal 3270 para acesso a + * aplicativos mainframe. Registro no INPI sob o nome G3270. + * + * Copyright (C) <2008> + * + * Este programa é software livre. Você pode redistribuí-lo e/ou modificá-lo sob + * os termos da GPL v.2 - Licença Pública Geral GNU, conforme publicado pela + * Free Software Foundation. + * + * Este programa é distribuído na expectativa de ser útil, mas SEM QUALQUER + * GARANTIA; sem mesmo a garantia implícita de COMERCIALIZAÇÃO ou de ADEQUAÇÃO + * A QUALQUER PROPÓSITO EM PARTICULAR. Consulte a Licença Pública Geral GNU para + * obter mais detalhes. + * + * Você deve ter recebido uma cópia da Licença Pública Geral GNU junto com este + * programa; se não, escreva para a Free Software Foundation, Inc., 51 Franklin + * St, Fifth Floor, Boston, MA 02110-1301 USA + * + * Este programa está nomeado como v3270.h e possui - linhas de código. + * + * Contatos: + * + * perry.werneck@gmail.com (Alexandre Perry de Souza Werneck) + * erico.mendonca@gmail.com (Erico Mascarenhas Mendonça) + * licinio@bb.com.br (Licínio Luis Branco) + * kraucer@bb.com.br (Kraucer Fernandes Mazuco) + * + */ + +#ifndef V3270_H_INCLUDED + + #include + #include + #include + + #define V3270_H_INCLUDED 1 + + G_BEGIN_DECLS + + #define GTK_TYPE_V3270 (v3270_get_type ()) + #define GTK_V3270(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), GTK_TYPE_V3270, v3270)) + #define GTK_V3270_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), GTK_TYPE_V3270, v3270Class)) + #define GTK_IS_V3270(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), GTK_TYPE_V3270)) + #define GTK_IS_V3270_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), GTK_TYPE_V3270)) + #define GTK_V3270_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), GTK_TYPE_V3270, v3270Class)) + + + typedef struct _v3270 v3270; + typedef struct _v3270Class v3270Class; + + enum V3270_COLOR + { + V3270_COLOR_BACKGROUND, + V3270_COLOR_BLUE, + V3270_COLOR_RED, + V3270_COLOR_PINK, + V3270_COLOR_GREEN, + V3270_COLOR_TURQUOISE, + V3270_COLOR_YELLOW, + V3270_COLOR_WHITE, + V3270_COLOR_BLACK, + V3270_COLOR_DARK_BLUE, + V3270_COLOR_ORANGE, + V3270_COLOR_PURPLE, + V3270_COLOR_DARK_GREEN, + V3270_COLOR_DARK_TURQUOISE, + V3270_COLOR_MUSTARD, + V3270_COLOR_GRAY, + + V3270_COLOR_FIELD, + V3270_COLOR_FIELD_INTENSIFIED, + V3270_COLOR_FIELD_PROTECTED, + V3270_COLOR_FIELD_PROTECTED_INTENSIFIED, + + V3270_COLOR_SELECTED_BG, + V3270_COLOR_SELECTED_FG, + + V3270_COLOR_CROSS_HAIR, + + // Oia Colors (Must be the last block) + V3270_COLOR_OIA_BACKGROUND, + V3270_COLOR_OIA_FOREGROUND, + V3270_COLOR_OIA_SEPARATOR, + V3270_COLOR_OIA_STATUS_OK, + V3270_COLOR_OIA_STATUS_INVALID, + + V3270_COLOR_COUNT + }; + + #define V3270_COLOR_OIA_STATUS_WARNING V3270_COLOR_OIA_STATUS_OK + + typedef enum _v3270_oia_field + { + V3270_OIA_UNDERA, /**< "A" underlined */ + V3270_OIA_CONNECTION, /**< solid box if connected, "?" in a box if not */ + V3270_OIA_MESSAGE, /**< message area */ + V3270_OIA_SSL, /**< SSL Status */ + /**< Meta indication ("M" or blank) */ + V3270_OIA_ALT, /**< Alt indication ("A" or blank) */ + /**< Compose indication ("C" or blank) */ + /**< Compose first character */ + V3270_OIA_SHIFT, /**< Shift Status */ + V3270_OIA_TYPEAHEAD, /**< Typeahead indication ("T" or blank) */ + V3270_OIA_INSERT, /**< Insert mode indication (Special symbol/"I" or blank) */ + V3270_OIA_SCRIPT, /**< Script indication ("S" or blank) */ + V3270_OIA_LUNAME, /**< LU Name */ + V3270_OIA_SPINNER, /**< command timing spinner */ + V3270_OIA_TIMER, /**< command timing (mmm:ss, or blank) */ + V3270_OIA_CURSOR_POSITION, /**< cursor position (rrr/ccc or blank) */ + +// V3270_OIA_CAPS, /**< Caps indication ("A" or blank) */ + +#ifdef HAVE_PRINTER + V3270_OIA_PRINTER, /**< Printer indication ("P" or blank) */ +#endif // HAVE_PRINTER + + V3270_OIA_FIELD_COUNT + + } V3270_OIA_FIELD; + + + #define V3270_COLOR_OIA_SPINNER V3270_COLOR_OIA_FOREGROUND + #define V3270_COLOR_OIA_LUNAME V3270_COLOR_OIA_FOREGROUND + #define V3270_COLOR_OIA_INSERT V3270_COLOR_OIA_FOREGROUND + + #ifndef v3270char + #define v3270char void + #endif // v3270_char + + LIB3270_EXPORT GtkWidget * v3270_new(void); + LIB3270_EXPORT GType v3270_get_type(void); + + LIB3270_EXPORT void v3270_reload(GtkWidget * widget); + + LIB3270_EXPORT void v3270_set_font_family(GtkWidget *widget, const gchar *name); + LIB3270_EXPORT const gchar * v3270_get_font_family(GtkWidget *widget); + + LIB3270_EXPORT H3270 * v3270_get_session(GtkWidget *widget); + + LIB3270_EXPORT int v3270_connect(GtkWidget *widget, const gchar *host); + LIB3270_EXPORT void v3270_disconnect(GtkWidget *widget); + + // Clipboard + typedef enum _v3270_select_format + { + V3270_SELECT_TEXT, + V3270_SELECT_TABLE, + + V3270_SELECT_MAX + } V3270_SELECT_FORMAT; + + LIB3270_EXPORT const gchar * v3270_copy(GtkWidget *widget, V3270_SELECT_FORMAT mode, gboolean cut); + LIB3270_EXPORT const gchar * v3270_copy_append(GtkWidget *widget); + + LIB3270_EXPORT const gchar * v3270_get_selected_text(GtkWidget *widget, gboolean cut); + LIB3270_EXPORT const gchar * v3270_get_copy(GtkWidget *widget); + LIB3270_EXPORT gchar * v3270_get_text(GtkWidget *widget,int offset, int len); + LIB3270_EXPORT gchar * v3270_get_region(GtkWidget *widget, gint start_pos, gint end_pos, gboolean all); + + LIB3270_EXPORT void v3270_set_string(GtkWidget *widget, const gchar *str); + LIB3270_EXPORT void v3270_tab(GtkWidget *widget); + LIB3270_EXPORT void v3270_backtab(GtkWidget *widget); + + // Cut & Paste + LIB3270_EXPORT gboolean v3270_get_selection_bounds(GtkWidget *widget, gint *start, gint *end); + LIB3270_EXPORT void v3270_unselect(GtkWidget *widget); + LIB3270_EXPORT void v3270_paste(GtkWidget *widget); + LIB3270_EXPORT void v3270_paste_string(GtkWidget *widget, const gchar *text, const gchar *encoding); + LIB3270_EXPORT void v3270_select_region(GtkWidget *widget, gint start, gint end); + + // Colors + LIB3270_EXPORT void v3270_set_colors(GtkWidget *widget, const gchar *); + LIB3270_EXPORT void v3270_set_color_table(GdkColor *table, const gchar *colors); + LIB3270_EXPORT const GdkColor * v3270_get_color_table(GtkWidget *widget); + LIB3270_EXPORT void v3270_set_mono_color_table(GdkColor *table, const gchar *fg, const gchar *bg); + LIB3270_EXPORT void v3270_draw_element(cairo_t *cr, unsigned char chr, unsigned short attr, H3270 *session, guint height, GdkRectangle *rect, GdkColor *color); + LIB3270_EXPORT void v3270_set_color(GtkWidget *widget, enum V3270_COLOR id, GdkColor *color); + LIB3270_EXPORT GdkColor * v3270_get_color(GtkWidget *widget, enum V3270_COLOR id); + + // Misc + LIB3270_EXPORT GtkIMContext * v3270_get_im_context(GtkWidget *widget); + LIB3270_EXPORT gboolean v3270_get_toggle(GtkWidget *widget, LIB3270_TOGGLE ix); + LIB3270_EXPORT void v3270_popup_message(GtkWidget *widget, LIB3270_NOTIFY type, const gchar *title, const gchar *message, const gchar *text); + LIB3270_EXPORT const gchar * v3270_get_session_name(GtkWidget *widget); + LIB3270_EXPORT void v3270_set_session_name(GtkWidget *widget, const gchar *name); + LIB3270_EXPORT int v3270_set_script(GtkWidget *widget, const gchar id, unsigned char on); + + LIB3270_EXPORT void v3270_set_host(GtkWidget *widget, const gchar *uri); + + // Keyboard & Mouse special actions + LIB3270_EXPORT gboolean v3270_set_keyboard_action(GtkWidget *widget, const gchar *key_name, GtkAction *action); + LIB3270_EXPORT void v3270_set_scroll_action(GtkWidget *widget, GdkScrollDirection direction, GtkAction *action); + +G_END_DECLS + +#endif // V3270_H_INCLUDED diff --git a/src/include/v3270.h b/src/include/v3270.h deleted file mode 100644 index 3d99c96..0000000 --- a/src/include/v3270.h +++ /dev/null @@ -1,199 +0,0 @@ -/* - * "Software pw3270, desenvolvido com base nos códigos fontes do WC3270 e X3270 - * (Paul Mattes Paul.Mattes@usa.net), de emulação de terminal 3270 para acesso a - * aplicativos mainframe. Registro no INPI sob o nome G3270. - * - * Copyright (C) <2008> - * - * Este programa é software livre. Você pode redistribuí-lo e/ou modificá-lo sob - * os termos da GPL v.2 - Licença Pública Geral GNU, conforme publicado pela - * Free Software Foundation. - * - * Este programa é distribuído na expectativa de ser útil, mas SEM QUALQUER - * GARANTIA; sem mesmo a garantia implícita de COMERCIALIZAÇÃO ou de ADEQUAÇÃO - * A QUALQUER PROPÓSITO EM PARTICULAR. Consulte a Licença Pública Geral GNU para - * obter mais detalhes. - * - * Você deve ter recebido uma cópia da Licença Pública Geral GNU junto com este - * programa; se não, escreva para a Free Software Foundation, Inc., 51 Franklin - * St, Fifth Floor, Boston, MA 02110-1301 USA - * - * Este programa está nomeado como v3270.h e possui - linhas de código. - * - * Contatos: - * - * perry.werneck@gmail.com (Alexandre Perry de Souza Werneck) - * erico.mendonca@gmail.com (Erico Mascarenhas Mendonça) - * licinio@bb.com.br (Licínio Luis Branco) - * kraucer@bb.com.br (Kraucer Fernandes Mazuco) - * - */ - -#ifndef V3270_H_INCLUDED - - #include - #include - #include - - #define V3270_H_INCLUDED 1 - - G_BEGIN_DECLS - - #define GTK_TYPE_V3270 (v3270_get_type ()) - #define GTK_V3270(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), GTK_TYPE_V3270, v3270)) - #define GTK_V3270_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), GTK_TYPE_V3270, v3270Class)) - #define GTK_IS_V3270(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), GTK_TYPE_V3270)) - #define GTK_IS_V3270_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), GTK_TYPE_V3270)) - #define GTK_V3270_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), GTK_TYPE_V3270, v3270Class)) - - - typedef struct _v3270 v3270; - typedef struct _v3270Class v3270Class; - - enum V3270_COLOR - { - V3270_COLOR_BACKGROUND, - V3270_COLOR_BLUE, - V3270_COLOR_RED, - V3270_COLOR_PINK, - V3270_COLOR_GREEN, - V3270_COLOR_TURQUOISE, - V3270_COLOR_YELLOW, - V3270_COLOR_WHITE, - V3270_COLOR_BLACK, - V3270_COLOR_DARK_BLUE, - V3270_COLOR_ORANGE, - V3270_COLOR_PURPLE, - V3270_COLOR_DARK_GREEN, - V3270_COLOR_DARK_TURQUOISE, - V3270_COLOR_MUSTARD, - V3270_COLOR_GRAY, - - V3270_COLOR_FIELD, - V3270_COLOR_FIELD_INTENSIFIED, - V3270_COLOR_FIELD_PROTECTED, - V3270_COLOR_FIELD_PROTECTED_INTENSIFIED, - - V3270_COLOR_SELECTED_BG, - V3270_COLOR_SELECTED_FG, - - V3270_COLOR_CROSS_HAIR, - - // Oia Colors (Must be the last block) - V3270_COLOR_OIA_BACKGROUND, - V3270_COLOR_OIA_FOREGROUND, - V3270_COLOR_OIA_SEPARATOR, - V3270_COLOR_OIA_STATUS_OK, - V3270_COLOR_OIA_STATUS_INVALID, - - V3270_COLOR_COUNT - }; - - #define V3270_COLOR_OIA_STATUS_WARNING V3270_COLOR_OIA_STATUS_OK - - typedef enum _v3270_oia_field - { - V3270_OIA_UNDERA, /**< "A" underlined */ - V3270_OIA_CONNECTION, /**< solid box if connected, "?" in a box if not */ - V3270_OIA_MESSAGE, /**< message area */ - V3270_OIA_SSL, /**< SSL Status */ - /**< Meta indication ("M" or blank) */ - V3270_OIA_ALT, /**< Alt indication ("A" or blank) */ - /**< Compose indication ("C" or blank) */ - /**< Compose first character */ - V3270_OIA_SHIFT, /**< Shift Status */ - V3270_OIA_TYPEAHEAD, /**< Typeahead indication ("T" or blank) */ - V3270_OIA_INSERT, /**< Insert mode indication (Special symbol/"I" or blank) */ -#ifdef HAVE_SCRIPT - V3270_OIA_SCRIPT, /**< Script indication ("S" or blank) */ -#endif // HAVE_SCRIPT - V3270_OIA_LUNAME, /**< LU Name */ - V3270_OIA_SPINNER, /**< command timing spinner */ - V3270_OIA_TIMER, /**< command timing (mmm:ss, or blank) */ - V3270_OIA_CURSOR_POSITION, /**< cursor position (rrr/ccc or blank) */ - -// V3270_OIA_CAPS, /**< Caps indication ("A" or blank) */ - -#ifdef HAVE_PRINTER - V3270_OIA_PRINTER, /**< Printer indication ("P" or blank) */ -#endif // HAVE_PRINTER - - V3270_OIA_FIELD_COUNT - - } V3270_OIA_FIELD; - - - #define V3270_COLOR_OIA_SPINNER V3270_COLOR_OIA_FOREGROUND - #define V3270_COLOR_OIA_LUNAME V3270_COLOR_OIA_FOREGROUND - #define V3270_COLOR_OIA_INSERT V3270_COLOR_OIA_FOREGROUND - - #ifndef v3270char - #define v3270char void - #endif // v3270_char - - LIB3270_EXPORT GtkWidget * v3270_new(void); - LIB3270_EXPORT GType v3270_get_type(void); - - LIB3270_EXPORT void v3270_reload(GtkWidget * widget); - - LIB3270_EXPORT void v3270_set_font_family(GtkWidget *widget, const gchar *name); - LIB3270_EXPORT const gchar * v3270_get_font_family(GtkWidget *widget); - - LIB3270_EXPORT H3270 * v3270_get_session(GtkWidget *widget); - - LIB3270_EXPORT int v3270_connect(GtkWidget *widget, const gchar *host); - LIB3270_EXPORT void v3270_disconnect(GtkWidget *widget); - - // Clipboard - typedef enum _v3270_select_format - { - V3270_SELECT_TEXT, - V3270_SELECT_TABLE, - - V3270_SELECT_MAX - } V3270_SELECT_FORMAT; - - LIB3270_EXPORT const gchar * v3270_copy(GtkWidget *widget, V3270_SELECT_FORMAT mode, gboolean cut); - LIB3270_EXPORT const gchar * v3270_copy_append(GtkWidget *widget); - - LIB3270_EXPORT const gchar * v3270_get_selected_text(GtkWidget *widget, gboolean cut); - LIB3270_EXPORT const gchar * v3270_get_copy(GtkWidget *widget); - LIB3270_EXPORT gchar * v3270_get_text(GtkWidget *widget,int offset, int len); - LIB3270_EXPORT gchar * v3270_get_region(GtkWidget *widget, gint start_pos, gint end_pos, gboolean all); - - LIB3270_EXPORT void v3270_set_string(GtkWidget *widget, const gchar *str); - LIB3270_EXPORT void v3270_tab(GtkWidget *widget); - LIB3270_EXPORT void v3270_backtab(GtkWidget *widget); - - // Cut & Paste - LIB3270_EXPORT gboolean v3270_get_selection_bounds(GtkWidget *widget, gint *start, gint *end); - LIB3270_EXPORT void v3270_unselect(GtkWidget *widget); - LIB3270_EXPORT void v3270_paste(GtkWidget *widget); - LIB3270_EXPORT void v3270_paste_string(GtkWidget *widget, const gchar *text, const gchar *encoding); - LIB3270_EXPORT void v3270_select_region(GtkWidget *widget, gint start, gint end); - - // Colors - LIB3270_EXPORT void v3270_set_colors(GtkWidget *widget, const gchar *); - LIB3270_EXPORT void v3270_set_color_table(GdkColor *table, const gchar *colors); - LIB3270_EXPORT const GdkColor * v3270_get_color_table(GtkWidget *widget); - LIB3270_EXPORT void v3270_set_mono_color_table(GdkColor *table, const gchar *fg, const gchar *bg); - LIB3270_EXPORT void v3270_draw_element(cairo_t *cr, unsigned char chr, unsigned short attr, H3270 *session, guint height, GdkRectangle *rect, GdkColor *color); - LIB3270_EXPORT void v3270_set_color(GtkWidget *widget, enum V3270_COLOR id, GdkColor *color); - LIB3270_EXPORT GdkColor * v3270_get_color(GtkWidget *widget, enum V3270_COLOR id); - - // Misc - LIB3270_EXPORT GtkIMContext * v3270_get_im_context(GtkWidget *widget); - LIB3270_EXPORT gboolean v3270_get_toggle(GtkWidget *widget, LIB3270_TOGGLE ix); - LIB3270_EXPORT void v3270_popup_message(GtkWidget *widget, LIB3270_NOTIFY type, const gchar *title, const gchar *message, const gchar *text); - LIB3270_EXPORT const gchar * v3270_get_session_name(GtkWidget *widget); - LIB3270_EXPORT void v3270_set_session_name(GtkWidget *widget, const gchar *name); - - LIB3270_EXPORT void v3270_set_host(GtkWidget *widget, const gchar *uri); - - // Keyboard & Mouse special actions - LIB3270_EXPORT gboolean v3270_set_keyboard_action(GtkWidget *widget, const gchar *key_name, GtkAction *action); - LIB3270_EXPORT void v3270_set_scroll_action(GtkWidget *widget, GdkScrollDirection direction, GtkAction *action); - -G_END_DECLS - -#endif // V3270_H_INCLUDED diff --git a/src/plugins/remotectl/hllapi.c b/src/plugins/remotectl/hllapi.c index aaf74c6..4f18675 100644 --- a/src/plugins/remotectl/hllapi.c +++ b/src/plugins/remotectl/hllapi.c @@ -37,28 +37,59 @@ /*--[ Globals ]--------------------------------------------------------------------------------------*/ - static char *session_name = NULL; +#ifdef WIN32 + + static HANDLE hPipe = INVALID_HANDLE_VALUE; + +#endif // WIN32 /*--[ Implement ]------------------------------------------------------------------------------------*/ + static int cmd_connect_ps(const char *name) + { +#ifdef WIN32 + + static DWORD dwMode = PIPE_READMODE_MESSAGE; + char PipeName[4096]; + + if(hPipe != INVALID_HANDLE_VALUE) + return EBUSY; + + snprintf(PipeName,4095,"\\\\.\\pipe\\%s",name); + + if(!WaitNamedPipe(PipeName,NMPWAIT_USE_DEFAULT_WAIT)) + return ETIMEDOUT; + + hPipe = CreateFile(PipeName,GENERIC_WRITE|GENERIC_READ,0,NULL,OPEN_EXISTING,0,NULL); + + if(hPipe == INVALID_HANDLE_VALUE) + return GetLastError(); + + if(!SetNamedPipeHandleState(hPipe,&dwMode,NULL,NULL)) + return GetLastError(); + +#else + + #error Not implemented + +#endif // WIN32 + + return 0; + } + + static int run_query(unsigned long func, const char *arg, char *string, unsigned short length, unsigned short *rc) { int result = -1; #ifdef WIN32 - char PipeName[4096]; if(length < 0 && string) length = strlen(string); - if(!session_name) - session_name = strdup("pw3270A"); - - snprintf(PipeName,4095,"\\\\.\\pipe\\%s",session_name); - - if(!WaitNamedPipe(PipeName,NMPWAIT_USE_DEFAULT_WAIT)) + if(hPipe == INVALID_HANDLE_VALUE) { - result = ETIMEDOUT; + result = EPERM; } else { @@ -81,7 +112,7 @@ } memset(buffer,0,HLLAPI_MAXLENGTH); - if(!CallNamedPipe(PipeName,(LPVOID)data,cbSize,buffer,HLLAPI_MAXLENGTH,&cbSize,NMPWAIT_USE_DEFAULT_WAIT)) + if(!TransactNamedPipe(hPipe,(LPVOID) data,cbSize,buffer,HLLAPI_MAXLENGTH,&cbSize,NULL)) { result = GetLastError(); } @@ -112,15 +143,7 @@ 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) + LIB3270_EXPORT int hllapi(const unsigned long *func, char *str, unsigned short *length, unsigned short *rc) { int result = 1; char * arg; @@ -149,18 +172,31 @@ switch(*func) { case HLLAPI_CMD_CONNECTPS: - result = set_session_name(arg); + result = cmd_connect_ps(arg); if(!result) + { result = run_query(*func, arg, str, *length, rc); + if(result || rc) + { + CloseHandle(hPipe); + hPipe = INVALID_HANDLE_VALUE; + } + } break; case HLLAPI_CMD_DISCONNECTPS: - if(session_name) +#ifdef WIN32 + if(hPipe == INVALID_HANDLE_VALUE) + { + result = EINVAL; + } + else { result = run_query(*func, arg, str, *length, rc); - free(session_name); - session_name = NULL; + CloseHandle(hPipe); + hPipe = INVALID_HANDLE_VALUE; } +#endif // WIN32 break; default: diff --git a/src/plugins/remotectl/pipesource.c b/src/plugins/remotectl/pipesource.c index 0f1da87..05f2729 100644 --- a/src/plugins/remotectl/pipesource.c +++ b/src/plugins/remotectl/pipesource.c @@ -26,10 +26,12 @@ * erico.mendonca@gmail.com (Erico Mascarenhas Mendonça) * licinio@bb.com.br (Licínio Luis Branco) * kraucer@bb.com.br (Kraucer Fernandes Mazuco) - * macmiranda@bb.com.br (Marco Aurélio Caldas Miranda) * */ + #include + #include + #ifdef WIN32 #include @@ -64,6 +66,7 @@ static void wait_for_client(pipe_source *source) { + v3270_set_script(pw3270_get_terminal_widget(NULL),'H',0); if(ConnectNamedPipe(source->hPipe,&source->overlap)) { popup_lasterror("%s",_( "Error in ConnectNamedPipe" )); @@ -80,7 +83,8 @@ static void wait_for_client(pipe_source *source) // Client is already connected, so signal an event. case ERROR_PIPE_CONNECTED: - // trace("%s: ERROR_PIPE_CONNECTED",__FUNCTION__); + trace("%s: ERROR_PIPE_CONNECTED",__FUNCTION__); + v3270_set_script(pw3270_get_terminal_widget(NULL),'H',1); if(SetEvent(source->overlap.hEvent)) break; @@ -174,15 +178,21 @@ static void wait_for_client(pipe_source *source) break; case ERROR_BROKEN_PIPE: - // trace("%s: ERROR_BROKEN_PIPE",__FUNCTION__); + trace("%s: ERROR_BROKEN_PIPE",__FUNCTION__); if(!DisconnectNamedPipe(source->hPipe)) + { + v3270_set_script(pw3270_get_terminal_widget(NULL),'H',0); popup_lasterror("%s",_( "Error in DisconnectNamedPipe" )); + } else + { wait_for_client(source); + } break; case ERROR_PIPE_NOT_CONNECTED: - // trace("%s: ERROR_PIPE_NOT_CONNECTED",__FUNCTION__); + trace("%s: ERROR_PIPE_NOT_CONNECTED",__FUNCTION__); + v3270_set_script(pw3270_get_terminal_widget(NULL),'H',0); break; default: @@ -216,7 +226,8 @@ static void wait_for_client(pipe_source *source) case PIPE_STATE_WAITING: if(fSuccess) { - // trace("Pipe connected (cbRet=%d)",(int) cbRead); + trace("Pipe connected (cbRet=%d)",(int) cbRead); + v3270_set_script(pw3270_get_terminal_widget(NULL),'H',1); ((pipe_source *) source)->state = PIPE_STATE_READ; } else diff --git a/src/plugins/remotectl/remotectl.c b/src/plugins/remotectl/remotectl.c index 517fe8b..f1301ca 100644 --- a/src/plugins/remotectl/remotectl.c +++ b/src/plugins/remotectl/remotectl.c @@ -34,6 +34,7 @@ #include "remotectl.h" #include #include + #include #include #include @@ -95,6 +96,7 @@ 0, // client time-out NULL); // default security attributes + trace("%s = %p",pipename,hPipe); g_free(pipename); if(hPipe != INVALID_HANDLE_VALUE) @@ -136,7 +138,7 @@ static int cmd_connectps(H3270 *hSession, unsigned short rc, char *string, unsigned short length) { g_message("%s","HLLAPI ConnectPS request received"); - return 0; + return v3270_set_script(pw3270_get_terminal_widget(NULL),'H',1); } static int cmd_disconnectps(H3270 *hSession, unsigned short rc, char *string, unsigned short length) diff --git a/src/plugins/remotectl/testprogram.c b/src/plugins/remotectl/testprogram.c index 2c927b8..8f0dec9 100644 --- a/src/plugins/remotectl/testprogram.c +++ b/src/plugins/remotectl/testprogram.c @@ -38,19 +38,33 @@ char buffer[1024]; unsigned short rc; - // Set session name - strcpy(buffer,"pw3270A"); - 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); - printf("query rc=%d\n\n",rc); - - // Test for string input - strcpy(buffer,"test"); - printf("InputString exits with %d\n[%s]\n",hllapi(HLLAPI_CMD_INPUTSTRING,buffer,1024,&rc),buffer); - printf("query rc=%d\n\n",rc); + static const struct _cmd + { + const char * name; + unsigned long fn; + const char * arg; + } cmd[] = + { + { "ConnectPS", HLLAPI_CMD_CONNECTPS, "pw3270A" }, + { "GetRevision", HLLAPI_CMD_GETREVISION, "" }, + { "InputString", HLLAPI_CMD_INPUTSTRING, "test" }, + + { "DisconnectPS", HLLAPI_CMD_DISCONNECTPS, "" }, + }; + + int f; + + + for(f=0;f< (sizeof(cmd)/sizeof(struct _cmd)); f++) + { + unsigned short len = 1024; + int result; + + strcpy(buffer,cmd[f].arg); + result = hllapi(&cmd[f].fn,buffer,&len,&rc); + printf("%s exits with %d\n[%s]\n",cmd[f].name,result,buffer); + + } return 0; } diff --git a/src/pw3270/actions.c b/src/pw3270/actions.c index 94c3efd..39735ed 100644 --- a/src/pw3270/actions.c +++ b/src/pw3270/actions.c @@ -31,7 +31,7 @@ #include "globals.h" #include "uiparser/parser.h" - #include + #include #include "filetransfer.h" #include #include diff --git a/src/pw3270/dialog.c b/src/pw3270/dialog.c index 5f29a0c..a7649ae 100644 --- a/src/pw3270/dialog.c +++ b/src/pw3270/dialog.c @@ -30,7 +30,7 @@ */ #include "globals.h" - #include + #include /*--[ Implement ]------------------------------------------------------------------------------------*/ diff --git a/src/pw3270/globals.h b/src/pw3270/globals.h index a250f73..56cbe78 100644 --- a/src/pw3270/globals.h +++ b/src/pw3270/globals.h @@ -37,7 +37,7 @@ #include #include - #include + #include // Special actions enum diff --git a/src/pw3270/main.c b/src/pw3270/main.c index 4a9bdf8..fe7db7e 100644 --- a/src/pw3270/main.c +++ b/src/pw3270/main.c @@ -37,7 +37,7 @@ #include #endif // HAVE_GTKMAC -#include +#include #include "v3270/accessible.h" #include diff --git a/src/pw3270/print.c b/src/pw3270/print.c index 02c124b..ee0bf62 100644 --- a/src/pw3270/print.c +++ b/src/pw3270/print.c @@ -30,7 +30,7 @@ */ #include "globals.h" - #include + #include #include /*--[ Structs ]--------------------------------------------------------------------------------------*/ diff --git a/src/pw3270/uiparser/parser.c b/src/pw3270/uiparser/parser.c index 12da13e..a75689e 100644 --- a/src/pw3270/uiparser/parser.c +++ b/src/pw3270/uiparser/parser.c @@ -30,7 +30,7 @@ */ #include "private.h" - #include + #include #ifdef HAVE_GTKMAC #include diff --git a/src/pw3270/v3270/accessible.c b/src/pw3270/v3270/accessible.c index 4114ef3..2a749ec 100644 --- a/src/pw3270/v3270/accessible.c +++ b/src/pw3270/v3270/accessible.c @@ -38,7 +38,7 @@ #include #include - #include + #include #include "private.h" #include "accessible.h" diff --git a/src/pw3270/v3270/draw.c b/src/pw3270/v3270/draw.c index 3f57aaa..2d78191 100644 --- a/src/pw3270/v3270/draw.c +++ b/src/pw3270/v3270/draw.c @@ -32,7 +32,7 @@ #include #include #include - #include + #include #include "private.h" /*--[ Implement ]------------------------------------------------------------------------------------*/ diff --git a/src/pw3270/v3270/keyboard.c b/src/pw3270/v3270/keyboard.c index 76685e0..bac54cb 100644 --- a/src/pw3270/v3270/keyboard.c +++ b/src/pw3270/v3270/keyboard.c @@ -38,7 +38,7 @@ #include #include - #include + #include #include "private.h" #if GTK_CHECK_VERSION(3,0,0) diff --git a/src/pw3270/v3270/mouse.c b/src/pw3270/v3270/mouse.c index 235c2b8..ce91a66 100644 --- a/src/pw3270/v3270/mouse.c +++ b/src/pw3270/v3270/mouse.c @@ -30,7 +30,7 @@ #include #include #include - #include + #include #include "private.h" #include #include diff --git a/src/pw3270/v3270/oia.c b/src/pw3270/v3270/oia.c index 24c6d3a..0e2c654 100644 --- a/src/pw3270/v3270/oia.c +++ b/src/pw3270/v3270/oia.c @@ -40,7 +40,7 @@ #include #endif // HAVE_LIBM - #include + #include #include "private.h" #include "accessible.h" @@ -505,9 +505,7 @@ void v3270_draw_oia(cairo_t *cr, H3270 *host, int row, int cols, struct v3270_me #ifdef HAVE_PRINTER { V3270_OIA_PRINTER, setup_single_char_right }, #endif // HAVE_PRINTER -#ifdef HAVE_SCRIPT { V3270_OIA_SCRIPT, setup_single_char_right }, -#endif // HAVE_SCRIPT { V3270_OIA_INSERT, setup_insert_position }, { V3270_OIA_TYPEAHEAD, setup_single_char_right }, { V3270_OIA_SHIFT, setup_double_char_position }, @@ -858,10 +856,11 @@ void v3270_draw_shift_status(v3270 *terminal) } -static void update_text_field(v3270 *terminal, gboolean flag, V3270_OIA_FIELD id, const gchar *text) +static void update_text_field(v3270 *terminal, gboolean flag, V3270_OIA_FIELD id, const gchar chr) { - GdkRectangle *r; - cairo_t *cr; + GdkRectangle * r; + cairo_t * cr; + gchar text[] = { chr, 0 }; if(!terminal->surface) return; @@ -882,7 +881,7 @@ static void update_text_field(v3270 *terminal, gboolean flag, V3270_OIA_FIELD id void v3270_draw_alt_status(v3270 *terminal) { - update_text_field(terminal,terminal->keyflags & KEY_FLAG_ALT,V3270_OIA_ALT,"A"); + update_text_field(terminal,terminal->keyflags & KEY_FLAG_ALT,V3270_OIA_ALT,'A'); } void v3270_draw_ins_status(v3270 *terminal) @@ -1050,23 +1049,76 @@ void v3270_update_oia(H3270 *session, LIB3270_FLAG id, unsigned char on) break; case LIB3270_FLAG_TYPEAHEAD: - update_text_field(terminal,on,V3270_OIA_TYPEAHEAD,"T"); + update_text_field(terminal,on,V3270_OIA_TYPEAHEAD,'T'); break; #ifdef HAVE_PRINTER case LIB3270_FLAG_PRINTER: - update_text_field(terminal,on,V3270_OIA_PRINTER,"P"); + update_text_field(terminal,on,V3270_OIA_PRINTER,'P'); break; #endif // HAVE_PRINTER -#ifdef HAVE_SCRIPT +/* case LIB3270_FLAG_SCRIPT: - update_text_field(terminal,on,V3270_OIA_SCRIPT,"S"); + update_text_field(terminal,on,V3270_OIA_SCRIPT,terminal->script_id); break; -#endif // HAVE_SCRIPT +*/ default: return; } } + +static gboolean blink_script(v3270 *widget) +{ + if(!widget->script.id) + return FALSE; + + update_text_field(widget,1,V3270_OIA_SCRIPT,widget->script.blink ? 'S' : ' '); + widget->script.blink = !widget->script.blink; + + return TRUE; +} + +static void release_script(v3270 *widget) +{ + widget->script.timer = NULL; + widget->script.id = 0; +} + +LIB3270_EXPORT int v3270_set_script(GtkWidget *widget, const gchar id, unsigned char on) +{ + v3270 *terminal; + g_return_val_if_fail(GTK_IS_V3270(widget),EINVAL); + + terminal = GTK_V3270(widget); + + if(terminal->script.id && id != terminal->script.id) + return EBUSY; + + terminal->script.id = on ? id : 0; + update_text_field(terminal,on,V3270_OIA_SCRIPT,'S'); + + if(on) + { + if(!terminal->script.timer) + { + terminal->script.timer = g_timeout_source_new(500); + g_source_set_callback(terminal->script.timer,(GSourceFunc) blink_script, terminal, (GDestroyNotify) release_script); + + g_source_attach(terminal->script.timer, NULL); + g_source_unref(terminal->script.timer); + } + } + else if(terminal->script.timer) + { + if(terminal->script.timer->ref_count < 2) + g_source_destroy(terminal->script.timer); + + if(terminal->timer) + g_source_unref(terminal->script.timer); + } + + return 0; +} diff --git a/src/pw3270/v3270/private.h b/src/pw3270/v3270/private.h index f9e1e71..e097107 100644 --- a/src/pw3270/v3270/private.h +++ b/src/pw3270/v3270/private.h @@ -180,6 +180,14 @@ G_BEGIN_DECLS H3270 * host; /**< Related 3270 session */ gchar * session_name; /**< Session name (for window title) */ + // Scripting + struct + { + int blink : 1; + gchar id; /**< Script indicator */ + GSource * timer; + } script; + }; /*--[ Globals ]--------------------------------------------------------------------------------------*/ diff --git a/src/pw3270/v3270/selection.c b/src/pw3270/v3270/selection.c index 60a8ca8..4213745 100644 --- a/src/pw3270/v3270/selection.c +++ b/src/pw3270/v3270/selection.c @@ -29,7 +29,7 @@ #include #include - #include + #include #include "private.h" #include #include diff --git a/src/pw3270/v3270/widget.c b/src/pw3270/v3270/widget.c index 7997340..34ac397 100644 --- a/src/pw3270/v3270/widget.c +++ b/src/pw3270/v3270/widget.c @@ -39,7 +39,7 @@ #include #endif // HAVE_MALLOC_H - #include + #include #include "private.h" #include "accessible.h" #include "marshal.h" @@ -892,6 +892,13 @@ static void v3270_destroy(GtkObject *widget) g_source_unref(terminal->timer); } + if(terminal->script.timer) + { + g_source_destroy(terminal->script.timer); + while(terminal->script.timer) + g_source_unref(terminal->script.timer); + } + if(terminal->cursor.timer) { g_source_destroy(terminal->cursor.timer); diff --git a/src/pw3270/window.c b/src/pw3270/window.c index 09d11e7..f1a143e 100644 --- a/src/pw3270/window.c +++ b/src/pw3270/window.c @@ -230,8 +230,30 @@ gtk_window_set_title(GTK_WINDOW(widget),name); } - GtkWidget * pw3270_get_terminal_widget(GtkWidget *widget) + static void chktoplevel(GtkWidget *window, GtkWidget **widget) { + if(*widget) + return; + + if(GTK_IS_PW3270(window)) + *widget = window; + } + + LIB3270_EXPORT GtkWidget * pw3270_get_toplevel(void) + { + GtkWidget * widget = NULL; + GList * lst = gtk_window_list_toplevels(); + + g_list_foreach(lst, (GFunc) chktoplevel, &widget); + + g_list_free(lst); + return widget; + } + + LIB3270_EXPORT GtkWidget * pw3270_get_terminal_widget(GtkWidget *widget) + { + if(!widget) + widget = pw3270_get_toplevel(); g_return_val_if_fail(GTK_IS_PW3270(widget),NULL); return GTK_PW3270(widget)->terminal; } -- libgit2 0.21.2