diff --git a/pw3270.cbp b/pw3270.cbp
index fce6a3a..d9c71c0 100644
--- a/pw3270.cbp
+++ b/pw3270.cbp
@@ -73,6 +73,7 @@
+
@@ -264,7 +265,6 @@
-
diff --git a/src/include/lib3270/log.h b/src/include/lib3270/log.h
index 355862c..e30005b 100644
--- a/src/include/lib3270/log.h
+++ b/src/include/lib3270/log.h
@@ -49,6 +49,10 @@
#define trace(x, ...) // __VA_ARGS__
#else
+
+ #ifdef __cplusplus
+ extern "C" {
+ #endif
LIB3270_EXPORT void lib3270_set_log_handler(void (*loghandler)(H3270 *, const char *, int, const char *, va_list));
LIB3270_EXPORT int lib3270_write_log(H3270 *session, const char *module, const char *fmt, ...) LIB3270_GNUC_FORMAT(3,4);
@@ -61,6 +65,10 @@
#else
#define trace(x, ...) // __VA_ARGS__
#endif
+
+ #ifdef __cplusplus
+ }
+ #endif
#endif // ANDROID
diff --git a/src/include/pw3270/ipcpackets.h b/src/include/pw3270/ipcpackets.h
new file mode 100644
index 0000000..d8eb09d
--- /dev/null
+++ b/src/include/pw3270/ipcpackets.h
@@ -0,0 +1,153 @@
+/*
+ * "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., 59 Temple
+ * Place, Suite 330, Boston, MA, 02111-1307, USA
+ *
+ * Este programa está nomeado como ipcpackets.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)
+ *
+ */
+
+ typedef enum _hllapi_packet
+ {
+ HLLAPI_PACKET_CONNECT,
+ HLLAPI_PACKET_DISCONNECT,
+ HLLAPI_PACKET_GET_PROGRAM_MESSAGE,
+ HLLAPI_PACKET_GET_TEXT_AT_OFFSET,
+ HLLAPI_PACKET_GET_TEXT_AT,
+ HLLAPI_PACKET_SET_TEXT_AT,
+ HLLAPI_PACKET_CMP_TEXT_AT,
+ HLLAPI_PACKET_ENTER,
+ HLLAPI_PACKET_PFKEY,
+ HLLAPI_PACKET_PAKEY,
+ HLLAPI_PACKET_SET_CURSOR_POSITION,
+ HLLAPI_PACKET_GET_CURSOR_POSITION,
+ HLLAPI_PACKET_INPUT_STRING,
+ HLLAPI_PACKET_IS_CONNECTED,
+ HLLAPI_PACKET_SET_CURSOR,
+ HLLAPI_PACKET_GET_CURSOR,
+ HLLAPI_PACKET_EMULATE_INPUT,
+ HLLAPI_PACKET_ERASE_EOF,
+ HLLAPI_PACKET_PRINT,
+
+ HLLAPI_PACKET_INVALID
+
+ } HLLAPI_PACKET;
+
+#pragma pack(1)
+
+struct hllapi_packet_result
+{
+ int rc;
+};
+
+struct hllapi_packet_text_result
+{
+ int rc;
+ char text[1];
+};
+
+struct hllapi_packet_query
+{
+ unsigned char packet_id;
+};
+
+struct hllapi_packet_connect
+{
+ unsigned char packet_id;
+ unsigned char wait;
+ char hostname[1];
+};
+
+struct hllapi_packet_keycode
+{
+ unsigned char packet_id;
+ unsigned short keycode;
+};
+
+struct hllapi_packet_cursor
+{
+ unsigned char packet_id;
+ unsigned short row;
+ unsigned short col;
+};
+
+struct hllapi_packet_text
+{
+ unsigned char packet_id;
+ char text[1];
+};
+
+struct hllapi_packet_at
+{
+ unsigned char packet_id;
+ unsigned short row;
+ unsigned short col;
+ unsigned short len;
+};
+
+struct hllapi_packet_text_at
+{
+ unsigned char packet_id;
+ unsigned short row;
+ unsigned short col;
+ char text[1];
+};
+
+struct hllapi_packet_query_at
+{
+ unsigned char packet_id;
+ unsigned short row;
+ unsigned short col;
+ unsigned short len;
+};
+
+struct hllapi_packet_wait
+{
+ unsigned char packet_id;
+ int timeout;
+};
+
+struct hllapi_packet_addr
+{
+ unsigned char packet_id;
+ unsigned short addr;
+};
+
+struct hllapi_packet_query_offset
+{
+ unsigned char packet_id;
+ unsigned short addr;
+ unsigned short len;
+};
+
+struct hllapi_packet_emulate_input
+{
+ unsigned char packet_id;
+ unsigned short len;
+ unsigned char pasting;
+ char text[1];
+};
+
+
+#pragma pack()
+
diff --git a/src/plugins/hllapi/packets.h b/src/plugins/hllapi/packets.h
deleted file mode 100644
index c36c0de..0000000
--- a/src/plugins/hllapi/packets.h
+++ /dev/null
@@ -1,153 +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., 59 Temple
- * Place, Suite 330, Boston, MA, 02111-1307, USA
- *
- * Este programa está nomeado como packets.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)
- *
- */
-
- typedef enum _hllapi_packet
- {
- HLLAPI_PACKET_CONNECT,
- HLLAPI_PACKET_DISCONNECT,
- HLLAPI_PACKET_GET_PROGRAM_MESSAGE,
- HLLAPI_PACKET_GET_TEXT_AT_OFFSET,
- HLLAPI_PACKET_GET_TEXT_AT,
- HLLAPI_PACKET_SET_TEXT_AT,
- HLLAPI_PACKET_CMP_TEXT_AT,
- HLLAPI_PACKET_ENTER,
- HLLAPI_PACKET_PFKEY,
- HLLAPI_PACKET_PAKEY,
- HLLAPI_PACKET_SET_CURSOR_POSITION,
- HLLAPI_PACKET_GET_CURSOR_POSITION,
- HLLAPI_PACKET_INPUT_STRING,
- HLLAPI_PACKET_IS_CONNECTED,
- HLLAPI_PACKET_SET_CURSOR,
- HLLAPI_PACKET_GET_CURSOR,
- HLLAPI_PACKET_EMULATE_INPUT,
- HLLAPI_PACKET_ERASE_EOF,
- HLLAPI_PACKET_PRINT,
-
- HLLAPI_PACKET_INVALID
-
- } HLLAPI_PACKET;
-
-#pragma pack(1)
-
-struct hllapi_packet_result
-{
- int rc;
-};
-
-struct hllapi_packet_text_result
-{
- int rc;
- char text[1];
-};
-
-struct hllapi_packet_query
-{
- unsigned char packet_id;
-};
-
-struct hllapi_packet_connect
-{
- unsigned char packet_id;
- unsigned char wait;
- char hostname[1];
-};
-
-struct hllapi_packet_keycode
-{
- unsigned char packet_id;
- unsigned short keycode;
-};
-
-struct hllapi_packet_cursor
-{
- unsigned char packet_id;
- unsigned short row;
- unsigned short col;
-};
-
-struct hllapi_packet_text
-{
- unsigned char packet_id;
- char text[1];
-};
-
-struct hllapi_packet_at
-{
- unsigned char packet_id;
- unsigned short row;
- unsigned short col;
- unsigned short len;
-};
-
-struct hllapi_packet_text_at
-{
- unsigned char packet_id;
- unsigned short row;
- unsigned short col;
- char text[1];
-};
-
-struct hllapi_packet_query_at
-{
- unsigned char packet_id;
- unsigned short row;
- unsigned short col;
- unsigned short len;
-};
-
-struct hllapi_packet_wait
-{
- unsigned char packet_id;
- int timeout;
-};
-
-struct hllapi_packet_addr
-{
- unsigned char packet_id;
- unsigned short addr;
-};
-
-struct hllapi_packet_query_offset
-{
- unsigned char packet_id;
- unsigned short addr;
- unsigned short len;
-};
-
-struct hllapi_packet_emulate_input
-{
- unsigned char packet_id;
- unsigned short len;
- unsigned char pasting;
- char text[1];
-};
-
-
-#pragma pack()
-
diff --git a/src/plugins/hllapi/pluginmain.c b/src/plugins/hllapi/pluginmain.c
index 85758aa..eb32611 100644
--- a/src/plugins/hllapi/pluginmain.c
+++ b/src/plugins/hllapi/pluginmain.c
@@ -32,7 +32,7 @@
*/
#include "server.h"
- #include "packets.h"
+ #include
#include
/*--[ Defines ]--------------------------------------------------------------------------------------*/
diff --git a/src/plugins/hllapi/remote.c b/src/plugins/hllapi/remote.c
index 96d4f37..eb9166a 100644
--- a/src/plugins/hllapi/remote.c
+++ b/src/plugins/hllapi/remote.c
@@ -26,347 +26,347 @@
* erico.mendonca@gmail.com (Erico Mascarenhas Mendonça)
*
*/
-
+
#include
#include
#include
#include
- #include
+ #include
#include
- #include
-
- #include "client.h"
- #include "packets.h"
-
+ #include
+ #include
+
+ #include "client.h"
+
/*--[ Globals ]--------------------------------------------------------------------------------------*/
-
+
/*--[ Implement ]------------------------------------------------------------------------------------*/
-
- void * hllapi_pipe_init(const char *id)
- {
+
+ void * hllapi_pipe_init(const char *id)
+ {
HANDLE hPipe = INVALID_HANDLE_VALUE;
static DWORD dwMode = PIPE_READMODE_MESSAGE;
- char buffer[4096];
- char * name = strdup(id);
- char * ptr;
-
- trace("%s(%s)",__FUNCTION__,id);
-
- for(ptr=name;*ptr;ptr++)
- {
- if(*ptr == ':')
- *ptr = '_';
- }
-
- snprintf(buffer,4095,"\\\\.\\pipe\\%s",name);
-
- free(name);
-
- trace("Opening \"%s\"",buffer);
-
- if(!WaitNamedPipe(buffer,NMPWAIT_USE_DEFAULT_WAIT))
- {
- trace("%s: Pipe not found",__FUNCTION__);
- errno = ENOENT;
+ char buffer[4096];
+ char * name = strdup(id);
+ char * ptr;
+
+ trace("%s(%s)",__FUNCTION__,id);
+
+ for(ptr=name;*ptr;ptr++)
+ {
+ if(*ptr == ':')
+ *ptr = '_';
+ }
+
+ snprintf(buffer,4095,"\\\\.\\pipe\\%s",name);
+
+ free(name);
+
+ trace("Opening \"%s\"",buffer);
+
+ if(!WaitNamedPipe(buffer,NMPWAIT_USE_DEFAULT_WAIT))
+ {
+ trace("%s: Pipe not found",__FUNCTION__);
+ errno = ENOENT;
return NULL;
}
hPipe = CreateFile(buffer,GENERIC_WRITE|GENERIC_READ,0,NULL,OPEN_EXISTING,0,NULL);
- if(hPipe == INVALID_HANDLE_VALUE)
- {
- errno = GetLastError();
+ if(hPipe == INVALID_HANDLE_VALUE)
+ {
+ errno = GetLastError();
return NULL;
}
if(!SetNamedPipeHandleState(hPipe,&dwMode,NULL,NULL))
- {
- errno = GetLastError();
+ {
+ errno = GetLastError();
return NULL;
- }
-
- trace("hPipe=%p",(void *) hPipe);
- return hPipe;
- }
-
- void hllapi_pipe_deinit(void *h)
- {
- trace("%s(%p)",__FUNCTION__,h);
-
- if(!h)
- return;
-
+ }
+
+ trace("hPipe=%p",(void *) hPipe);
+ return hPipe;
+ }
+
+ void hllapi_pipe_deinit(void *h)
+ {
+ trace("%s(%p)",__FUNCTION__,h);
+
+ if(!h)
+ return;
+
CloseHandle((HANDLE) h);
- }
-
- const char * hllapi_pipe_get_revision(void)
- {
- return PACKAGE_REVISION;
- }
-
- int hllapi_pipe_connect(void *h, const char *n, int wait)
- {
- struct hllapi_packet_connect * pkt;
- struct hllapi_packet_result response;
- DWORD cbSize;
-
- if(!n)
- n = "";
-
- cbSize = sizeof(struct hllapi_packet_connect)+strlen(n);
- pkt = malloc(cbSize);
-
- pkt->packet_id = HLLAPI_PACKET_CONNECT;
- pkt->wait = (unsigned char) wait;
- strcpy(pkt->hostname,n);
-
- trace("Sending %s",pkt->hostname);
-
- if(!TransactNamedPipe((HANDLE) h,(LPVOID) pkt, cbSize, &response, sizeof(response), &cbSize,NULL))
- {
- errno = GetLastError();
- response.rc = -1;
+ }
+
+ const char * hllapi_pipe_get_revision(void)
+ {
+ return PACKAGE_REVISION;
+ }
+
+ int hllapi_pipe_connect(void *h, const char *n, int wait)
+ {
+ struct hllapi_packet_connect * pkt;
+ struct hllapi_packet_result response;
+ DWORD cbSize;
+
+ if(!n)
+ n = "";
+
+ cbSize = sizeof(struct hllapi_packet_connect)+strlen(n);
+ pkt = malloc(cbSize);
+
+ pkt->packet_id = HLLAPI_PACKET_CONNECT;
+ pkt->wait = (unsigned char) wait;
+ strcpy(pkt->hostname,n);
+
+ trace("Sending %s",pkt->hostname);
+
+ if(!TransactNamedPipe((HANDLE) h,(LPVOID) pkt, cbSize, &response, sizeof(response), &cbSize,NULL))
+ {
+ errno = GetLastError();
+ response.rc = -1;
+ }
+
+ free(pkt);
+
+ return response.rc;
+ }
+
+ void hllapi_pipe_disconnect(void *h)
+ {
+ static const struct hllapi_packet_query query = { HLLAPI_PACKET_DISCONNECT };
+ struct hllapi_packet_result response;
+ DWORD cbSize = sizeof(query);
+ TransactNamedPipe((HANDLE) h,(LPVOID) &query, cbSize, &response, sizeof(response), &cbSize,NULL);
+ }
+
+ LIB3270_MESSAGE hllapi_pipe_get_message(void *h)
+ {
+ static const struct hllapi_packet_query query = { HLLAPI_PACKET_GET_PROGRAM_MESSAGE };
+ struct hllapi_packet_result response;
+ DWORD cbSize = sizeof(query);
+ TransactNamedPipe((HANDLE) h,(LPVOID) &query, cbSize, &response, sizeof(response), &cbSize,NULL);
+ return (LIB3270_MESSAGE) response.rc;
+ }
+
+ char * hllapi_pipe_get_text_at(void *h, int row, int col, int len)
+ {
+ struct hllapi_packet_query_at query = { HLLAPI_PACKET_GET_TEXT_AT, row, col, len };
+ struct hllapi_packet_text * response;
+ DWORD cbSize = sizeof(struct hllapi_packet_text)+len;
+ char * text = NULL;
+
+ response = malloc(cbSize+2);
+ memset(response,0,cbSize+2);
+
+ if(!TransactNamedPipe((HANDLE) h,(LPVOID) &query, sizeof(struct hllapi_packet_query_at), &response, cbSize, &cbSize,NULL))
+ return NULL;
+
+ if(response->packet_id)
+ errno = response->packet_id;
+ else
+ text = strdup(response->text);
+
+ free(response);
+ return text;
+ }
+
+ int hllapi_pipe_enter(void *h)
+ {
+ static const struct hllapi_packet_query query = { HLLAPI_PACKET_ENTER };
+ struct hllapi_packet_result response;
+ DWORD cbSize = sizeof(query);
+ TransactNamedPipe((HANDLE) h,(LPVOID) &query, cbSize, &response, sizeof(response), &cbSize,NULL);
+ return response.rc;
+ }
+
+ int hllapi_pipe_erase_eof(void *h)
+ {
+ static const struct hllapi_packet_query query = { HLLAPI_PACKET_ERASE_EOF };
+ struct hllapi_packet_result response;
+ DWORD cbSize = sizeof(query);
+ TransactNamedPipe((HANDLE) h,(LPVOID) &query, cbSize, &response, sizeof(response), &cbSize,NULL);
+ return response.rc;
+ }
+
+
+ int hllapi_pipe_set_text_at(void *h, int row, int col, const unsigned char *str)
+ {
+ struct hllapi_packet_text_at * query;
+ struct hllapi_packet_result response;
+ DWORD cbSize = sizeof(struct hllapi_packet_text_at)+strlen((const char *) str);
+
+ query = malloc(cbSize);
+ query->packet_id = HLLAPI_PACKET_SET_TEXT_AT;
+ query->row = row;
+ query->col = col;
+ strcpy(query->text,(const char *) str);
+
+ TransactNamedPipe((HANDLE) h,(LPVOID) query, cbSize, &response, sizeof(response), &cbSize,NULL);
+
+ free(query);
+
+ return response.rc;
+ }
+
+ int hllapi_pipe_cmp_text_at(void *h, int row, int col, const char *text)
+ {
+ struct hllapi_packet_text_at * query;
+ struct hllapi_packet_result response;
+ DWORD cbSize = sizeof(struct hllapi_packet_text_at)+strlen(text);
+
+ query = malloc(cbSize);
+ query->packet_id = HLLAPI_PACKET_CMP_TEXT_AT;
+ query->row = row;
+ query->col = col;
+ strcpy(query->text,text);
+
+ TransactNamedPipe((HANDLE) h,(LPVOID) query, cbSize, &response, sizeof(response), &cbSize,NULL);
+
+ free(query);
+
+ return response.rc;
+ }
+
+ int hllapi_pipe_pfkey(void *h, int key)
+ {
+ struct hllapi_packet_keycode query = { HLLAPI_PACKET_PFKEY, key };
+ struct hllapi_packet_result response;
+ DWORD cbSize = sizeof(query);
+ TransactNamedPipe((HANDLE) h,(LPVOID) &query, cbSize, &response, sizeof(response), &cbSize,NULL);
+ return response.rc;
+ }
+
+ int hllapi_pipe_pakey(void *h, int key)
+ {
+ struct hllapi_packet_keycode query = { HLLAPI_PACKET_PAKEY, key };
+ struct hllapi_packet_result response;
+ DWORD cbSize = sizeof(query);
+ TransactNamedPipe((HANDLE) h,(LPVOID) &query, cbSize, &response, sizeof(response), &cbSize,NULL);
+ return response.rc;
+ }
+
+ void hllapi_pipe_release_memory(void *p)
+ {
+ free(p);
+ }
+
+ int hllapi_pipe_wait_for_ready(void *h, int seconds)
+ {
+ time_t end = time(0)+seconds;
+
+ while(time(0) < end)
+ {
+ if(!hllapi_pipe_is_connected(h))
+ return ENOTCONN;
+
+ if(hllapi_pipe_get_message(h) == 0)
+ return 0;
+ Sleep(250);
}
-
- free(pkt);
-
- return response.rc;
+
+ return ETIMEDOUT;
+ }
+
+ int hllapi_pipe_is_connected(void *h)
+ {
+ static const struct hllapi_packet_query query = { HLLAPI_PACKET_IS_CONNECTED };
+ struct hllapi_packet_result response;
+ DWORD cbSize = sizeof(query);
+ TransactNamedPipe((HANDLE) h,(LPVOID) &query, cbSize, &response, sizeof(response), &cbSize,NULL);
+ return (LIB3270_MESSAGE) response.rc;
+ }
+
+ int hllapi_pipe_sleep(void *h, int seconds)
+ {
+ time_t end = time(0)+seconds;
+
+ while(time(0) < end)
+ {
+ if(!hllapi_pipe_is_connected(h))
+ return ENOTCONN;
+ Sleep(500);
+ }
+
+ return 0;
}
-
- void hllapi_pipe_disconnect(void *h)
- {
- static const struct hllapi_packet_query query = { HLLAPI_PACKET_DISCONNECT };
- struct hllapi_packet_result response;
- DWORD cbSize = sizeof(query);
- TransactNamedPipe((HANDLE) h,(LPVOID) &query, cbSize, &response, sizeof(response), &cbSize,NULL);
- }
-
- LIB3270_MESSAGE hllapi_pipe_get_message(void *h)
- {
- static const struct hllapi_packet_query query = { HLLAPI_PACKET_GET_PROGRAM_MESSAGE };
- struct hllapi_packet_result response;
- DWORD cbSize = sizeof(query);
- TransactNamedPipe((HANDLE) h,(LPVOID) &query, cbSize, &response, sizeof(response), &cbSize,NULL);
- return (LIB3270_MESSAGE) response.rc;
- }
-
- char * hllapi_pipe_get_text_at(void *h, int row, int col, int len)
- {
- struct hllapi_packet_query_at query = { HLLAPI_PACKET_GET_TEXT_AT, };
- struct hllapi_packet_text * response;
- DWORD cbSize = sizeof(struct hllapi_packet_text)+len;
- char * text = NULL;
-
- response = malloc(cbSize+2);
- memset(response,0,cbSize+2);
-
- if(!TransactNamedPipe((HANDLE) h,(LPVOID) &query, sizeof(struct hllapi_packet_query_at), &response, cbSize, &cbSize,NULL))
- return NULL;
-
- if(response->packet_id)
- errno = response->packet_id;
- else
- text = strdup(response->text);
-
- free(response);
- return text;
- }
-
- int hllapi_pipe_enter(void *h)
- {
- static const struct hllapi_packet_query query = { HLLAPI_PACKET_ENTER };
- struct hllapi_packet_result response;
- DWORD cbSize = sizeof(query);
- TransactNamedPipe((HANDLE) h,(LPVOID) &query, cbSize, &response, sizeof(response), &cbSize,NULL);
- return response.rc;
- }
-
- int hllapi_pipe_erase_eof(void *h)
- {
- static const struct hllapi_packet_query query = { HLLAPI_PACKET_ERASE_EOF };
- struct hllapi_packet_result response;
- DWORD cbSize = sizeof(query);
- TransactNamedPipe((HANDLE) h,(LPVOID) &query, cbSize, &response, sizeof(response), &cbSize,NULL);
- return response.rc;
- }
-
-
- int hllapi_pipe_set_text_at(void *h, int row, int col, const unsigned char *str)
- {
- struct hllapi_packet_text_at * query;
- struct hllapi_packet_result response;
- DWORD cbSize = sizeof(struct hllapi_packet_text_at)+strlen((const char *) str);
-
- query = malloc(cbSize);
- query->packet_id = HLLAPI_PACKET_SET_TEXT_AT;
- query->row = row;
- query->col = col;
- strcpy(query->text,(const char *) str);
-
- TransactNamedPipe((HANDLE) h,(LPVOID) query, cbSize, &response, sizeof(response), &cbSize,NULL);
-
- free(query);
-
- return response.rc;
- }
-
- int hllapi_pipe_cmp_text_at(void *h, int row, int col, const char *text)
- {
- struct hllapi_packet_text_at * query;
- struct hllapi_packet_result response;
- DWORD cbSize = sizeof(struct hllapi_packet_text_at)+strlen(text);
-
- query = malloc(cbSize);
- query->packet_id = HLLAPI_PACKET_CMP_TEXT_AT;
- query->row = row;
- query->col = col;
- strcpy(query->text,text);
-
- TransactNamedPipe((HANDLE) h,(LPVOID) query, cbSize, &response, sizeof(response), &cbSize,NULL);
-
- free(query);
-
- return response.rc;
- }
-
- int hllapi_pipe_pfkey(void *h, int key)
- {
- struct hllapi_packet_keycode query = { HLLAPI_PACKET_PFKEY, key };
- struct hllapi_packet_result response;
- DWORD cbSize = sizeof(query);
- TransactNamedPipe((HANDLE) h,(LPVOID) &query, cbSize, &response, sizeof(response), &cbSize,NULL);
- return response.rc;
- }
-
- int hllapi_pipe_pakey(void *h, int key)
- {
- struct hllapi_packet_keycode query = { HLLAPI_PACKET_PAKEY, key };
- struct hllapi_packet_result response;
- DWORD cbSize = sizeof(query);
- TransactNamedPipe((HANDLE) h,(LPVOID) &query, cbSize, &response, sizeof(response), &cbSize,NULL);
- return response.rc;
- }
-
- void hllapi_pipe_release_memory(void *p)
- {
- free(p);
- }
-
- int hllapi_pipe_wait_for_ready(void *h, int seconds)
- {
- time_t end = time(0)+seconds;
-
- while(time(0) < end)
- {
- if(!hllapi_pipe_is_connected(h))
- return ENOTCONN;
-
- if(hllapi_pipe_get_message(h) == 0)
- return 0;
- Sleep(250);
- }
-
- return ETIMEDOUT;
- }
-
- int hllapi_pipe_is_connected(void *h)
- {
- static const struct hllapi_packet_query query = { HLLAPI_PACKET_IS_CONNECTED };
- struct hllapi_packet_result response;
- DWORD cbSize = sizeof(query);
- TransactNamedPipe((HANDLE) h,(LPVOID) &query, cbSize, &response, sizeof(response), &cbSize,NULL);
- return (LIB3270_MESSAGE) response.rc;
- }
-
- int hllapi_pipe_sleep(void *h, int seconds)
- {
- time_t end = time(0)+seconds;
-
- while(time(0) < end)
- {
- if(!hllapi_pipe_is_connected(h))
- return ENOTCONN;
- Sleep(500);
- }
-
- return 0;
- }
int hllapi_pipe_getcursor(void *h)
{
- static const struct hllapi_packet_query query = { HLLAPI_PACKET_GET_CURSOR };
- struct hllapi_packet_result response;
- DWORD cbSize = sizeof(query);
-
- trace("%s",__FUNCTION__);
-
- TransactNamedPipe((HANDLE) h,(LPVOID) &query, cbSize, &response, sizeof(response), &cbSize,NULL);
- return (LIB3270_MESSAGE) response.rc;
+ static const struct hllapi_packet_query query = { HLLAPI_PACKET_GET_CURSOR };
+ struct hllapi_packet_result response;
+ DWORD cbSize = sizeof(query);
+
+ trace("%s",__FUNCTION__);
+
+ TransactNamedPipe((HANDLE) h,(LPVOID) &query, cbSize, &response, sizeof(response), &cbSize,NULL);
+ return (LIB3270_MESSAGE) response.rc;
}
int hllapi_pipe_setcursor(void *h, int baddr)
{
- struct hllapi_packet_addr query = { HLLAPI_PACKET_SET_CURSOR, baddr };
- struct hllapi_packet_result response;
- DWORD cbSize = sizeof(query);
-
- trace("%s(%d)",__FUNCTION__,query.addr);
-
- TransactNamedPipe((HANDLE) h,(LPVOID) &query, cbSize, &response, sizeof(response), &cbSize,NULL);
- return response.rc;
+ struct hllapi_packet_addr query = { HLLAPI_PACKET_SET_CURSOR, baddr };
+ struct hllapi_packet_result response;
+ DWORD cbSize = sizeof(query);
+
+ trace("%s(%d)",__FUNCTION__,query.addr);
+
+ TransactNamedPipe((HANDLE) h,(LPVOID) &query, cbSize, &response, sizeof(response), &cbSize,NULL);
+ return response.rc;
}
-
- char * hllapi_pipe_get_text(void *h, int offset, int len)
- {
- struct hllapi_packet_query_offset query = { HLLAPI_PACKET_GET_TEXT_AT_OFFSET, offset, len };
- struct hllapi_packet_text * response;
- DWORD cbSize = sizeof(struct hllapi_packet_text)+len;
- char * text = NULL;
-
- trace("cbSize=%d",(int) cbSize);
-
- response = malloc(cbSize+2);
- memset(response,0,cbSize+2);
-
- if(!TransactNamedPipe((HANDLE) h,(LPVOID) &query, sizeof(query), response, cbSize, &cbSize,NULL))
- return NULL;
-
- trace("rc=%d",response->packet_id);
-
- if(response->packet_id)
- errno = response->packet_id;
- else
- text = strdup(response->text);
-
- free(response);
- return text;
+
+ char * hllapi_pipe_get_text(void *h, int offset, int len)
+ {
+ struct hllapi_packet_query_offset query = { HLLAPI_PACKET_GET_TEXT_AT_OFFSET, offset, len };
+ struct hllapi_packet_text * response;
+ DWORD cbSize = sizeof(struct hllapi_packet_text)+len;
+ char * text = NULL;
+
+ trace("cbSize=%d",(int) cbSize);
+
+ response = malloc(cbSize+2);
+ memset(response,0,cbSize+2);
+
+ if(!TransactNamedPipe((HANDLE) h,(LPVOID) &query, sizeof(query), response, cbSize, &cbSize,NULL))
+ return NULL;
+
+ trace("rc=%d",response->packet_id);
+
+ if(response->packet_id)
+ errno = response->packet_id;
+ else
+ text = strdup(response->text);
+
+ free(response);
+ return text;
}
int hllapi_pipe_emulate_input(void *h, const char *text, int len, int pasting)
{
- struct hllapi_packet_emulate_input * query;
- struct hllapi_packet_result response;
- DWORD cbSize = sizeof(struct hllapi_packet_emulate_input)+strlen(text);
-
- query = malloc(cbSize);
- query->packet_id = HLLAPI_PACKET_EMULATE_INPUT;
- query->len = len;
- query->pasting = pasting;
- strcpy(query->text,text);
-
- TransactNamedPipe((HANDLE) h,(LPVOID) query, cbSize, &response, sizeof(response), &cbSize,NULL);
-
- free(query);
-
- return response.rc;
+ struct hllapi_packet_emulate_input * query;
+ struct hllapi_packet_result response;
+ DWORD cbSize = sizeof(struct hllapi_packet_emulate_input)+strlen(text);
+
+ query = malloc(cbSize);
+ query->packet_id = HLLAPI_PACKET_EMULATE_INPUT;
+ query->len = len;
+ query->pasting = pasting;
+ strcpy(query->text,text);
+
+ TransactNamedPipe((HANDLE) h,(LPVOID) query, cbSize, &response, sizeof(response), &cbSize,NULL);
+
+ free(query);
+
+ return response.rc;
}
int hllapi_pipe_print(void *h)
{
- static const struct hllapi_packet_query query = { HLLAPI_PACKET_PRINT };
- struct hllapi_packet_result response;
- DWORD cbSize = sizeof(query);
- TransactNamedPipe((HANDLE) h,(LPVOID) &query, cbSize, &response, sizeof(response), &cbSize,NULL);
- return response.rc;
+ static const struct hllapi_packet_query query = { HLLAPI_PACKET_PRINT };
+ struct hllapi_packet_result response;
+ DWORD cbSize = sizeof(query);
+ TransactNamedPipe((HANDLE) h,(LPVOID) &query, cbSize, &response, sizeof(response), &cbSize,NULL);
+ return response.rc;
}
diff --git a/src/plugins/rx3270/remote.cc b/src/plugins/rx3270/remote.cc
index 9469914..f3c6448 100644
--- a/src/plugins/rx3270/remote.cc
+++ b/src/plugins/rx3270/remote.cc
@@ -34,6 +34,11 @@
#include
#endif // HAVE_DBUS
+#if defined(WIN32)
+ #include
+#endif // WIN32
+
+ #include
#include
/*--[ Class definition ]-----------------------------------------------------------------------------*/
@@ -70,7 +75,10 @@
private:
#if defined(WIN32)
+ HANDLE hPipe;
+
#elif defined(HAVE_DBUS)
+
DBusConnection * conn;
char * dest;
char * path;
@@ -79,6 +87,7 @@
DBusMessage * call(DBusMessage *msg);
char * query_string(const char *method);
int query_intval(const char *method);
+
#endif
@@ -89,8 +98,6 @@
#if defined(HAVE_DBUS)
static const char * prefix_dest = "br.com.bb.";
static const char * prefix_path = "/br/com/bb/";
-#else
- #error AQUI
#endif // HAVE_DBUS
/*--[ Implement ]------------------------------------------------------------------------------------*/
@@ -120,6 +127,46 @@ rx3270 * rx3270::create_remote(const char *name)
remote::remote(const char *name)
{
#if defined(WIN32)
+ static DWORD dwMode = PIPE_READMODE_MESSAGE;
+ char buffer[4096];
+ char * str = strdup(name);
+ char * ptr;
+
+ hPipe = INVALID_HANDLE_VALUE;
+
+ for(ptr=str;*ptr;ptr++)
+ {
+ if(*ptr == ':')
+ *ptr = '_';
+ }
+
+ snprintf(buffer,4095,"\\\\.\\pipe\\%s",str);
+
+ free(str);
+
+ if(!WaitNamedPipe(buffer,NMPWAIT_USE_DEFAULT_WAIT))
+ {
+ log("%s","Invalid service instance");
+ return;
+ }
+
+ hPipe = CreateFile(buffer,GENERIC_WRITE|GENERIC_READ,0,NULL,OPEN_EXISTING,0,NULL);
+
+ if(hPipe == INVALID_HANDLE_VALUE)
+ {
+ log("%s","Can´t create service pipe");
+ return;
+ }
+
+ if(!SetNamedPipeHandleState(hPipe,&dwMode,NULL,NULL))
+ {
+ log("%s","Can´t set pipe state");
+ CloseHandle(hPipe);
+ hPipe = INVALID_HANDLE_VALUE;
+ return;
+ }
+
+ // Connected
#elif defined(HAVE_DBUS)
DBusError err;
@@ -209,6 +256,9 @@ remote::~remote()
{
#if defined(WIN32)
+ if(hPipe != INVALID_HANDLE_VALUE)
+ CloseHandle(hPipe);
+
#elif defined(HAVE_DBUS)
free(dest);
@@ -303,8 +353,7 @@ char * remote::get_revision(void)
{
#if defined(WIN32)
- return NULL;
-
+ return strdup(PACKAGE_REVISION);
#elif defined(HAVE_DBUS)
@@ -323,6 +372,11 @@ LIB3270_CSTATE remote::get_cstate(void)
{
#if defined(WIN32)
+ if(hPipe != INVALID_HANDLE_VALUE)
+ {
+
+ }
+
return (LIB3270_CSTATE) -1;
#elif defined(HAVE_DBUS)
@@ -341,6 +395,16 @@ int remote::disconnect(void)
{
#if defined(WIN32)
+ if(hPipe != INVALID_HANDLE_VALUE)
+ {
+ static const struct hllapi_packet_query query = { HLLAPI_PACKET_DISCONNECT };
+ struct hllapi_packet_result response;
+ DWORD cbSize = sizeof(query);
+ TransactNamedPipe(hPipe,(LPVOID) &query, cbSize, &response, sizeof(response), &cbSize,NULL);
+ return 0;
+ }
+ return -1;
+
#elif defined(HAVE_DBUS)
return query_intval("disconnect");
@@ -356,6 +420,32 @@ int remote::disconnect(void)
int remote::connect(const char *uri, bool wait)
{
#if defined(WIN32)
+ if(hPipe != INVALID_HANDLE_VALUE)
+ {
+ struct hllapi_packet_connect * pkt;
+ struct hllapi_packet_result response;
+ DWORD cbSize;
+
+ cbSize = sizeof(struct hllapi_packet_connect)+strlen(uri);
+ pkt = (struct hllapi_packet_connect *) malloc(cbSize);
+
+ pkt->packet_id = HLLAPI_PACKET_CONNECT;
+ pkt->wait = (unsigned char) wait;
+ strcpy(pkt->hostname,uri);
+
+ trace("Sending %s",pkt->hostname);
+
+ if(!TransactNamedPipe(hPipe,(LPVOID) pkt, cbSize, &response, sizeof(response), &cbSize,NULL))
+ {
+ errno = GetLastError();
+ response.rc = -1;
+ }
+
+ free(pkt);
+
+ return response.rc;
+
+ }
#elif defined(HAVE_DBUS)
@@ -368,6 +458,15 @@ bool remote::is_connected(void)
{
#if defined(WIN32)
+ if(hPipe != INVALID_HANDLE_VALUE)
+ {
+ static const struct hllapi_packet_query query = { HLLAPI_PACKET_IS_CONNECTED };
+ struct hllapi_packet_result response;
+ DWORD cbSize = sizeof(query);
+ TransactNamedPipe(hPipe,(LPVOID) &query, cbSize, &response, sizeof(response), &cbSize,NULL);
+ return response.rc != 0;
+ }
+
#elif defined(HAVE_DBUS)
#endif
@@ -379,6 +478,11 @@ bool remote::is_ready(void)
{
#if defined(WIN32)
+ if(hPipe != INVALID_HANDLE_VALUE)
+ {
+
+ }
+
#elif defined(HAVE_DBUS)
#endif
@@ -390,6 +494,8 @@ int remote::iterate(bool wait)
{
#if defined(WIN32)
+ return 0;
+
#elif defined(HAVE_DBUS)
return 0;
@@ -403,9 +509,28 @@ int remote::wait(int seconds)
{
#if defined(WIN32)
+ time_t end = time(0)+seconds;
+
+ while(time(0) < end)
+ {
+ if(!is_connected())
+ return ENOTCONN;
+ Sleep(500);
+ }
+
+ return 0;
+
#elif defined(HAVE_DBUS)
- sleep(seconds);
+ time_t end = time(0)+seconds;
+
+ while(time(0) < end)
+ {
+ if(!is_connected())
+ return ENOTCONN;
+ usleep(500);
+ }
+
return 0;
#endif
@@ -417,6 +542,26 @@ int remote::wait_for_ready(int seconds)
{
#if defined(WIN32)
+ if(hPipe != INVALID_HANDLE_VALUE)
+ {
+ time_t end = time(0)+seconds;
+
+ while(time(0) < end)
+ {
+ if(!is_connected())
+ return ENOTCONN;
+
+ if(is_ready())
+ return 0;
+
+ Sleep(250);
+ }
+
+ return ETIMEDOUT;
+
+ }
+
+
#elif defined(HAVE_DBUS)
#endif
@@ -428,6 +573,29 @@ char * remote::get_text_at(int row, int col, size_t sz)
{
#if defined(WIN32)
+ if(hPipe != INVALID_HANDLE_VALUE)
+ {
+ struct hllapi_packet_query_at query = { HLLAPI_PACKET_GET_TEXT_AT, (unsigned short) row, (unsigned short) col, (unsigned short) sz };
+ struct hllapi_packet_text * response;
+ DWORD cbSize = sizeof(struct hllapi_packet_text)+sz;
+ char * text = NULL;
+
+ response = (struct hllapi_packet_text *) malloc(cbSize+2);
+ memset(response,0,cbSize+2);
+
+ if(!TransactNamedPipe(hPipe,(LPVOID) &query, sizeof(struct hllapi_packet_query_at), &response, cbSize, &cbSize,NULL))
+ return NULL;
+
+ if(response->packet_id)
+ errno = response->packet_id;
+ else
+ text = strdup(response->text);
+
+ free(response);
+ return text;
+
+ }
+
#elif defined(HAVE_DBUS)
#endif
@@ -439,6 +607,26 @@ int remote::cmp_text_at(int row, int col, const char *text)
{
#if defined(WIN32)
+ if(hPipe != INVALID_HANDLE_VALUE)
+ {
+ struct hllapi_packet_text_at * query;
+ struct hllapi_packet_result response;
+ DWORD cbSize = sizeof(struct hllapi_packet_text_at)+strlen(text);
+
+ query = (struct hllapi_packet_text_at *) malloc(cbSize);
+ query->packet_id = HLLAPI_PACKET_CMP_TEXT_AT;
+ query->row = row;
+ query->col = col;
+ strcpy(query->text,text);
+
+ TransactNamedPipe(hPipe,(LPVOID) query, cbSize, &response, sizeof(response), &cbSize,NULL);
+
+ free(query);
+
+ return response.rc;
+ }
+
+
#elif defined(HAVE_DBUS)
#endif
@@ -450,6 +638,25 @@ int remote::set_text_at(int row, int col, const char *str)
{
#if defined(WIN32)
+ if(hPipe != INVALID_HANDLE_VALUE)
+ {
+ struct hllapi_packet_text_at * query;
+ struct hllapi_packet_result response;
+ DWORD cbSize = sizeof(struct hllapi_packet_text_at)+strlen((const char *) str);
+
+ query = (struct hllapi_packet_text_at *) malloc(cbSize);
+ query->packet_id = HLLAPI_PACKET_SET_TEXT_AT;
+ query->row = row;
+ query->col = col;
+ strcpy(query->text,(const char *) str);
+
+ TransactNamedPipe(hPipe,(LPVOID) query, cbSize, &response, sizeof(response), &cbSize,NULL);
+
+ free(query);
+
+ return response.rc;
+ }
+
#elif defined(HAVE_DBUS)
#endif
@@ -461,6 +668,11 @@ int remote::set_cursor_position(int row, int col)
{
#if defined(WIN32)
+ if(hPipe != INVALID_HANDLE_VALUE)
+ {
+
+ }
+
#elif defined(HAVE_DBUS)
#endif
@@ -472,6 +684,15 @@ int remote::enter(void)
{
#if defined(WIN32)
+ if(hPipe != INVALID_HANDLE_VALUE)
+ {
+ static const struct hllapi_packet_query query = { HLLAPI_PACKET_ENTER };
+ struct hllapi_packet_result response;
+ DWORD cbSize = sizeof(query);
+ TransactNamedPipe(hPipe,(LPVOID) &query, cbSize, &response, sizeof(response), &cbSize,NULL);
+ return response.rc;
+ }
+
return -1;
#elif defined(HAVE_DBUS)
@@ -490,6 +711,15 @@ int remote::pfkey(int key)
{
#if defined(WIN32)
+ if(hPipe != INVALID_HANDLE_VALUE)
+ {
+ struct hllapi_packet_keycode query = { HLLAPI_PACKET_PFKEY, (unsigned short) key };
+ struct hllapi_packet_result response;
+ DWORD cbSize = sizeof(query);
+ TransactNamedPipe(hPipe,(LPVOID) &query, cbSize, &response, sizeof(response), &cbSize,NULL);
+ return response.rc;
+ }
+
#elif defined(HAVE_DBUS)
#endif
@@ -501,6 +731,15 @@ int remote::pakey(int key)
{
#if defined(WIN32)
+ if(hPipe != INVALID_HANDLE_VALUE)
+ {
+ struct hllapi_packet_keycode query = { HLLAPI_PACKET_PAKEY, (unsigned short) key };
+ struct hllapi_packet_result response;
+ DWORD cbSize = sizeof(query);
+ TransactNamedPipe(hPipe,(LPVOID) &query, cbSize, &response, sizeof(response), &cbSize,NULL);
+ return response.rc;
+ }
+
#elif defined(HAVE_DBUS)
#endif
@@ -512,7 +751,14 @@ void remote::set_toggle(LIB3270_TOGGLE ix, bool value)
{
#if defined(WIN32)
+ if(hPipe != INVALID_HANDLE_VALUE)
+ {
+
+ }
+
#elif defined(HAVE_DBUS)
#endif
+
}
+
--
libgit2 0.21.2