Commit 4e98bbf479173cdc328385c221ebef8340bf86b3

Authored by Perry Werneck
1 parent 12c9a65e
Exists in master and in 1 other branch develop

Refactoring ipç module.

common/src/include/lib3270/ipc-glib.h
@@ -75,7 +75,7 @@ @@ -75,7 +75,7 @@
75 75
76 void ipc3270_response_append_int32(GObject *object, gint32 value); 76 void ipc3270_response_append_int32(GObject *object, gint32 value);
77 void ipc3270_response_append_uint32(GObject *object, guint32 value); 77 void ipc3270_response_append_uint32(GObject *object, guint32 value);
78 - void ipc3270_response_append_3270_string(GObject *object, const char *text, GError **error); 78 + void ipc3270_response_append_string(GObject *object, const gchar *text);
79 gboolean ipc3270_response_has_values(GObject *object); 79 gboolean ipc3270_response_has_values(GObject *object);
80 GVariant * ipc3270_response_steal_value(GObject *object); 80 GVariant * ipc3270_response_steal_value(GObject *object);
81 81
@@ -96,7 +96,7 @@ @@ -96,7 +96,7 @@
96 void ipc3270_export_object(GObject *object, const char *name, GError **error); 96 void ipc3270_export_object(GObject *object, const char *name, GError **error);
97 97
98 /** 98 /**
99 - * @brief Convert UTF-8 string to lib3270 charset. 99 + * @brief Convert from native charset to lib3270 charset.
100 * 100 *
101 * @param object ipc3270 Object. 101 * @param object ipc3270 Object.
102 * @param string UTF-8 string to convert. 102 * @param string UTF-8 string to convert.
@@ -105,7 +105,7 @@ @@ -105,7 +105,7 @@
105 * @return Converted string in lib3270 charset. 105 * @return Converted string in lib3270 charset.
106 * 106 *
107 */ 107 */
108 - gchar * ipc3270_convert_output_string(GObject *object, const gchar *string, GError **error); 108 + gchar * ipc3270_convert_to_3270(GObject *object, const gchar *string, GError **error);
109 109
110 /** 110 /**
111 * @brief Convert lib3270 received string to UTF-8. 111 * @brief Convert lib3270 received string to UTF-8.
@@ -117,7 +117,7 @@ @@ -117,7 +117,7 @@
117 * @return The string converted to UTF-8. 117 * @return The string converted to UTF-8.
118 * 118 *
119 */ 119 */
120 - gchar * ipc3270_convert_input_string(GObject *object, const gchar *string, GError **error); 120 + gchar * ipc3270_convert_from_3270(GObject *object, const gchar *string, GError **error);
121 121
122 /** 122 /**
123 * @brief Create a GVariant from a lib3270 string. 123 * @brief Create a GVariant from a lib3270 string.
@@ -140,7 +140,7 @@ @@ -140,7 +140,7 @@
140 140
141 void ipc3270_set_error(GObject *object, int errcode, GError **error); 141 void ipc3270_set_error(GObject *object, int errcode, GError **error);
142 142
143 - void ipc3270_method_call(GObject *object, const gchar *method_name, GVariant *request, GObject *response, GError **error); 143 + int ipc3270_method_call(GObject *object, const gchar *method_name, GVariant *request, GObject *response, GError **error);
144 gboolean ipc3270_set_property(GObject *object, const gchar *property_name, GVariant *value, GError **error); 144 gboolean ipc3270_set_property(GObject *object, const gchar *property_name, GVariant *value, GError **error);
145 GVariant * ipc3270_get_property(GObject *object, const gchar *property_name, GError **error); 145 GVariant * ipc3270_get_property(GObject *object, const gchar *property_name, GError **error);
146 146
server/pw3270-plugin-ipc.cbp
@@ -82,9 +82,25 @@ @@ -82,9 +82,25 @@
82 <Unit filename="src/core/linux/stop.c"> 82 <Unit filename="src/core/linux/stop.c">
83 <Option compilerVar="CC" /> 83 <Option compilerVar="CC" />
84 </Unit> 84 </Unit>
  85 + <Unit filename="src/core/methods/field.c">
  86 + <Option compilerVar="CC" />
  87 + </Unit>
  88 + <Unit filename="src/core/methods/get.c">
  89 + <Option compilerVar="CC" />
  90 + </Unit>
85 <Unit filename="src/core/methods/methods.c"> 91 <Unit filename="src/core/methods/methods.c">
86 <Option compilerVar="CC" /> 92 <Option compilerVar="CC" />
87 </Unit> 93 </Unit>
  94 + <Unit filename="src/core/methods/network.c">
  95 + <Option compilerVar="CC" />
  96 + </Unit>
  97 + <Unit filename="src/core/methods/private.h" />
  98 + <Unit filename="src/core/methods/set.c">
  99 + <Option compilerVar="CC" />
  100 + </Unit>
  101 + <Unit filename="src/core/methods/wait.c">
  102 + <Option compilerVar="CC" />
  103 + </Unit>
88 <Unit filename="src/core/setproperties.c"> 104 <Unit filename="src/core/setproperties.c">
89 <Option compilerVar="CC" /> 105 <Option compilerVar="CC" />
90 </Unit> 106 </Unit>
server/src/core/linux/gobject.c
@@ -62,6 +62,8 @@ static void ipc3270_finalize(GObject *object) { @@ -62,6 +62,8 @@ static void ipc3270_finalize(GObject *object) {
62 v3270_set_session_name(ipc->terminal,widget_name); 62 v3270_set_session_name(ipc->terminal,widget_name);
63 lib3270_set_session_id(ipc->hSession, 0); 63 lib3270_set_session_id(ipc->hSession, 0);
64 64
  65 + g_free(ipc->charset);
  66 +
65 G_OBJECT_CLASS(ipc3270_parent_class)->finalize(object); 67 G_OBJECT_CLASS(ipc3270_parent_class)->finalize(object);
66 68
67 } 69 }
@@ -82,6 +84,12 @@ static void ipc3270_init(ipc3270 *object) { @@ -82,6 +84,12 @@ static void ipc3270_init(ipc3270 *object) {
82 debug("%s",__FUNCTION__); 84 debug("%s",__FUNCTION__);
83 object->error_domain = g_quark_from_static_string(PACKAGE_NAME); 85 object->error_domain = g_quark_from_static_string(PACKAGE_NAME);
84 86
  87 + // Get charset
  88 + const gchar * scharset = NULL;
  89 + g_get_charset(&scharset);
  90 +
  91 + object->charset = g_strdup(scharset);
  92 +
85 } 93 }
86 94
87 GObject * ipc3270_new() { 95 GObject * ipc3270_new() {
@@ -138,8 +146,8 @@ void ipc3270_add_terminal_introspection(GString *introspection) { @@ -138,8 +146,8 @@ void ipc3270_add_terminal_introspection(GString *introspection) {
138 " <arg type='i' name='result' direction='out' />" \ 146 " <arg type='i' name='result' direction='out' />" \
139 " </method>" \ 147 " </method>" \
140 " <method name= 'getStringAtAddress'>" \ 148 " <method name= 'getStringAtAddress'>" \
141 - " <arg type='u' name='addr' direction='in' />" \  
142 - " <arg type='u' name='len' direction='in' />" \ 149 + " <arg type='i' name='addr' direction='in' />" \
  150 + " <arg type='i' name='len' direction='in' />" \
143 " <arg type='y' name='lf' direction='in' />" \ 151 " <arg type='y' name='lf' direction='in' />" \
144 " <arg type='s' name='text' direction='out' />" \ 152 " <arg type='s' name='text' direction='out' />" \
145 " </method>" \ 153 " </method>" \
@@ -247,10 +255,18 @@ H3270 * ipc3270_get_session(GObject *object) { @@ -247,10 +255,18 @@ H3270 * ipc3270_get_session(GObject *object) {
247 } 255 }
248 256
249 void ipc3270_set_error(GObject *object, int errcode, GError **error) { 257 void ipc3270_set_error(GObject *object, int errcode, GError **error) {
250 - g_set_error(error,IPC3270(object)->error_domain,errcode,"%s",strerror(errcode)); 258 + if(!*error)
  259 + g_set_error(error,IPC3270(object)->error_domain,errcode,"%s",strerror(errcode));
251 } 260 }
252 261
253 GQuark ipc3270_get_error_domain(GObject *object) { 262 GQuark ipc3270_get_error_domain(GObject *object) {
254 return IPC3270(object)->error_domain; 263 return IPC3270(object)->error_domain;
255 } 264 }
256 265
  266 +gchar * ipc3270_convert_to_3270(GObject *object, const gchar *string, GError **error) {
  267 + return g_convert_with_fallback(string,-1,lib3270_get_display_charset(IPC3270(object)->hSession),IPC3270(object)->charset,"?",NULL,NULL,error);
  268 +}
  269 +
  270 +gchar * ipc3270_convert_from_3270(GObject *object, const gchar *string, GError **error) {
  271 + return g_convert_with_fallback(string,-1,IPC3270(object)->charset,lib3270_get_display_charset(IPC3270(object)->hSession),"?",NULL,NULL,error);
  272 +}
server/src/core/linux/gobject.h
@@ -64,6 +64,7 @@ @@ -64,6 +64,7 @@
64 } dbus; 64 } dbus;
65 65
66 H3270 * hSession; 66 H3270 * hSession;
  67 + gchar * charset;
67 GtkWidget * terminal; 68 GtkWidget * terminal;
68 GQuark error_domain; 69 GQuark error_domain;
69 }; 70 };
server/src/core/methods/get.c 0 → 100644
@@ -0,0 +1,84 @@ @@ -0,0 +1,84 @@
  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., 51 Franklin
  19 + * St, Fifth Floor, Boston, MA 02110-1301 USA
  20 + *
  21 + * Este programa está nomeado como - 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 "private.h"
  31 +
  32 +int ipc3270_method_get_string(GObject *session, GVariant *request, GObject *response, GError **error) {
  33 +
  34 + H3270 *hSession = ipc3270_get_session(session);
  35 +
  36 + lib3270_autoptr(char) text = NULL;
  37 +
  38 + switch(g_variant_n_children(request)) {
  39 + case 0: // No arguments
  40 + {
  41 +
  42 + }
  43 + break;
  44 +
  45 + case 3: // address, length, line-delimiter
  46 + {
  47 + gint addr;
  48 + guint len;
  49 + guchar lf;
  50 +
  51 + g_variant_get(request, "(iiy)", &addr, &len, &lf);
  52 +
  53 + text = lib3270_get_string_at_address(hSession, addr, len, lf);
  54 +
  55 + }
  56 + break;
  57 +
  58 + case 4: // row, col, length, line-delimiter
  59 + {
  60 + guint row,col,len;
  61 + guchar lf;
  62 + g_variant_get(request, "(uuuy)", &row, &col, &len, &lf);
  63 +
  64 + text = lib3270_get_string_at(hSession, row, col, len, lf);
  65 +
  66 + }
  67 + break;
  68 +
  69 + default:
  70 + return EINVAL;
  71 + }
  72 +
  73 + debug("text:\n%s\n",text);
  74 +
  75 + if(!text)
  76 + return errno;
  77 +
  78 + g_autofree gchar * converted = ipc3270_convert_from_3270(session,text,error);
  79 + ipc3270_response_append_string(response, converted);
  80 +
  81 + return 0;
  82 +
  83 +}
  84 +
server/src/core/methods/methods.c
@@ -32,183 +32,60 @@ @@ -32,183 +32,60 @@
32 * 32 *
33 */ 33 */
34 34
35 -#include <config.h>  
36 -#include <string.h>  
37 -#include <lib3270/ipc-glib.h>  
38 -#include <lib3270.h> 35 +#include "private.h"
39 #include <lib3270/actions.h> 36 #include <lib3270/actions.h>
40 #include <lib3270/trace.h> 37 #include <lib3270/trace.h>
41 38
42 -void ipc3270_method_call(GObject *object, const gchar *method_name, GVariant *request, GObject *response, GError **error) { 39 +int ipc3270_method_call(GObject *object, const gchar *method_name, GVariant *request, GObject *response, GError **error) {
43 40
44 - size_t ix;  
45 - H3270 * hSession = ipc3270_get_session(object);  
46 -  
47 - lib3270_trace_event(hSession,"Method %s called on session %c\n",method_name,lib3270_get_session_id(hSession));  
48 -  
49 - debug("%s(%s)",__FUNCTION__,method_name);  
50 -  
51 - if(!g_ascii_strcasecmp(method_name,"getString"))  
52 - {  
53 - lib3270_autoptr(char) str = lib3270_get_string_at_address(hSession,0,-1,'\n');  
54 - ipc3270_response_append_3270_string(response,str,error);  
55 - return;  
56 - }  
57 - else if(!g_ascii_strcasecmp(method_name,"setString"))  
58 - {  
59 - gchar *text = NULL;  
60 - g_variant_get(request, "(&s)", &text);  
61 -  
62 - g_autofree gchar * converted = ipc3270_convert_output_string(object, text, error);  
63 - if(lib3270_input_string(hSession,(const unsigned char *) converted, -1))  
64 - {  
65 - // Failed!  
66 - debug("%s failed: %s",method_name,strerror(errno));  
67 - ipc3270_set_error(object,errno,error);  
68 - return;  
69 - }  
70 -  
71 - // Suceeded  
72 - debug("%s Suceeds",method_name);  
73 - ipc3270_response_append_int32(response, 0);  
74 - return;  
75 -  
76 - }  
77 - else if(!g_ascii_strcasecmp(method_name,"setStringAt"))  
78 - {  
79 - guint row,col;  
80 - gchar *text = NULL;  
81 - g_variant_get(request, "(ii&s)", &row, &col, &text);  
82 -  
83 - g_autofree gchar * converted = ipc3270_convert_output_string(object, text, error);  
84 - if(lib3270_set_string_at(hSession,row,col,(const unsigned char *) converted) < 0)  
85 - {  
86 - // Failed!  
87 - ipc3270_set_error(object,errno,error);  
88 - return;  
89 - }  
90 -  
91 - // Suceeded  
92 - ipc3270_response_append_int32(response, 0);  
93 - return;  
94 -  
95 - }  
96 - else if(!g_ascii_strcasecmp(method_name,"getStringAt"))  
97 - {  
98 - guint row,col,len;  
99 - guchar lf;  
100 - g_variant_get(request, "(uuuy)", &row, &col, &len,&lf);  
101 -  
102 - lib3270_autoptr(char) str = lib3270_get_string_at(hSession, row, col, len, lf);  
103 - ipc3270_response_append_3270_string(response,str,error);  
104 - return;  
105 -  
106 - }  
107 - else if(!g_ascii_strcasecmp(method_name,"setStringAtAddress"))  
108 - {  
109 - gint addr;  
110 - gchar *text = NULL;  
111 - g_variant_get(request, "(i&s)", &addr, &text); 41 + static const struct Methods {
  42 + const char *name;
  43 + int (*call)(GObject *session, GVariant *request, GObject *response, GError **error);
  44 + } methods[] = {
112 45
113 - g_autofree gchar * converted = ipc3270_convert_output_string(object, text, error);  
114 - if(lib3270_set_string_at_address(hSession,addr,(unsigned char *) converted, -1) < 0)  
115 - {  
116 - // Failed!  
117 - ipc3270_set_error(object,errno,error);  
118 - return;  
119 - } 46 + { "connect", ipc3270_method_connect },
  47 + { "disconnect", ipc3270_method_disconnect },
120 48
121 - // Suceeded  
122 - ipc3270_response_append_int32(response, 0);  
123 - return; 49 + { "wait", ipc3270_method_wait },
  50 + { "waitforready", ipc3270_method_wait_for_ready },
  51 + { "waitforupdate", ipc3270_method_wait_for_update },
124 52
125 - }  
126 - else if(!g_ascii_strcasecmp(method_name,"getStringAtAddress"))  
127 - {  
128 - gint addr;  
129 - guint len;  
130 - guchar lf;  
131 - g_variant_get(request, "(iuy)", &addr, &len, &lf); 53 + { "getString", ipc3270_method_get_string },
  54 + { "getStringAt", ipc3270_method_get_string },
  55 + { "getStringAtAddress", ipc3270_method_get_string },
132 56
133 - debug("lf=%02x",(int) lf); 57 + { "setString", ipc3270_method_set_string },
  58 + { "setStringAt", ipc3270_method_set_string },
  59 + { "setStringAtAddress", ipc3270_method_set_string },
134 60
135 - lib3270_autoptr(char) str = lib3270_get_string_at_address(hSession, addr, len, lf);  
136 - ipc3270_response_append_3270_string(response,str,error);  
137 - return; 61 + { "getFieldAttribute", ipc3270_method_get_field_attribute },
  62 + { "getFieldAttributeAt", ipc3270_method_get_field_attribute },
  63 + { "getFieldAttributeAtAddress", ipc3270_method_get_field_attribute },
138 64
139 - }  
140 - else if(!g_ascii_strcasecmp(method_name,"waitforready"))  
141 - {  
142 - guint timeout = 1;  
143 - if(request) {  
144 - g_variant_get(request, "(u)", &timeout);  
145 - }  
146 - ipc3270_response_append_int32(response, lib3270_wait_for_ready(hSession,timeout));  
147 - return; 65 + };
148 66
149 - }  
150 - else if(!g_ascii_strcasecmp(method_name,"connect"))  
151 - {  
152 - gchar *text = NULL;  
153 - g_variant_get(request, "(&s)", &text); 67 + size_t ix;
  68 + H3270 * hSession = ipc3270_get_session(object);
154 69
155 - g_autofree gchar * converted = ipc3270_convert_output_string(object, text, error);  
156 - if(lib3270_connect_url(hSession,converted,0))  
157 - {  
158 - // Failed!  
159 - ipc3270_set_error(object,errno,error);  
160 - return NULL;  
161 - } 70 + lib3270_trace_event(hSession,"Method %s called on session %c\n",method_name,lib3270_get_session_id(hSession));
162 71
163 - // Suceeded  
164 - ipc3270_response_append_int32(response, 0);  
165 - return; 72 + for(ix = 0; ix < G_N_ELEMENTS(methods); ix++) {
166 73
167 - }  
168 - else if(!g_ascii_strcasecmp(method_name,"disconnect"))  
169 - {  
170 - if(lib3270_disconnect(hSession))  
171 - {  
172 - // Failed!  
173 - ipc3270_set_error(object,errno,error);  
174 - return;  
175 - } 74 + if(!g_ascii_strcasecmp(methods[ix].name,method_name)) {
176 75
177 - // Suceeded  
178 - ipc3270_response_append_int32(response, 0);  
179 - return; 76 + int rc = methods[ix].call(object,request,response,error);
180 77
181 - }  
182 - else if(!g_ascii_strcasecmp(method_name,"getFieldAttributeAt"))  
183 - {  
184 - guint row,col;  
185 - g_variant_get(request, "(uu)", &row, &col);  
186 - ipc3270_response_append_int32(response, lib3270_get_field_attribute(hSession,lib3270_translate_to_address(hSession,row,col)));  
187 - return;  
188 - }  
189 - else if(!g_ascii_strcasecmp(method_name,"getFieldAttributeAtAddress"))  
190 - {  
191 - gint addr;  
192 - g_variant_get(request, "(i)", &addr); 78 + if(rc)
  79 + ipc3270_set_error(object,rc,error);
193 80
194 - ipc3270_response_append_int32(response, lib3270_get_field_attribute(hSession,addr));  
195 - return;  
196 - }  
197 - else if(!g_ascii_strcasecmp(method_name,"waitForUpdate"))  
198 - {  
199 - guint timeout = 1;  
200 - if(request) {  
201 - g_variant_get(request, "(u)", &timeout); 81 + return 0;
202 } 82 }
203 -  
204 - ipc3270_response_append_int32(response, lib3270_wait_for_update(hSession,timeout));  
205 - return;  
206 } 83 }
207 84
208 - // Check action table. 85 + // Check actions table.
209 const LIB3270_ACTION_ENTRY * actions = lib3270_get_action_table(); 86 const LIB3270_ACTION_ENTRY * actions = lib3270_get_action_table();
210 - for(ix = 0; actions[ix].name; ix++)  
211 - { 87 + for(ix = 0; actions[ix].name; ix++) {
  88 +
212 if(!g_ascii_strcasecmp(actions[ix].name,method_name)) { 89 if(!g_ascii_strcasecmp(actions[ix].name,method_name)) {
213 90
214 int rc = actions[ix].call(hSession); 91 int rc = actions[ix].call(hSession);
@@ -221,16 +98,16 @@ void ipc3270_method_call(GObject *object, const gchar *method_name, GVariant *re @@ -221,16 +98,16 @@ void ipc3270_method_call(GObject *object, const gchar *method_name, GVariant *re
221 98
222 // Suceeded 99 // Suceeded
223 ipc3270_response_append_int32(response, 0); 100 ipc3270_response_append_int32(response, 0);
224 - return; 101 + return 0;
225 102
226 } 103 }
227 } 104 }
228 105
229 - // Check int methods 106 + // Check lib3270 internal methods
230 const IPC_METHOD_INT_ARG * int_methods = ipc3270_get_int_arg_methods(); 107 const IPC_METHOD_INT_ARG * int_methods = ipc3270_get_int_arg_methods();
231 108
232 - for(ix = 0; int_methods[ix].name; ix++)  
233 - { 109 + for(ix = 0; int_methods[ix].name; ix++) {
  110 +
234 if(!g_ascii_strcasecmp(int_methods[ix].name,method_name)) { 111 if(!g_ascii_strcasecmp(int_methods[ix].name,method_name)) {
235 112
236 gint value; 113 gint value;
@@ -246,13 +123,13 @@ void ipc3270_method_call(GObject *object, const gchar *method_name, GVariant *re @@ -246,13 +123,13 @@ void ipc3270_method_call(GObject *object, const gchar *method_name, GVariant *re
246 123
247 // Suceeded 124 // Suceeded
248 ipc3270_response_append_int32(response, 0); 125 ipc3270_response_append_int32(response, 0);
249 - return; 126 + return 0;
250 127
251 } 128 }
252 129
253 } 130 }
254 131
255 g_message("Unknown method \"%s\"",method_name); 132 g_message("Unknown method \"%s\"",method_name);
256 - ipc3270_set_error(object,ENOENT,error); 133 + return ENOENT;
257 134
258 } 135 }
server/src/core/methods/network.c 0 → 100644
@@ -0,0 +1,48 @@ @@ -0,0 +1,48 @@
  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., 51 Franklin
  19 + * St, Fifth Floor, Boston, MA 02110-1301 USA
  20 + *
  21 + * Este programa está nomeado como - 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 "private.h"
  31 +
  32 +int ipc3270_method_connect(GObject *session, GVariant *request, GObject *response, GError **error) {
  33 +
  34 + gchar *text = NULL;
  35 + g_variant_get(request, "(&s)", &text);
  36 +
  37 + g_autofree gchar * converted = ipc3270_convert_to_3270(session,text,error);
  38 +
  39 + if(!*error)
  40 + return lib3270_connect_url(ipc3270_get_session(session),converted,0);
  41 +
  42 + return 0;
  43 +
  44 +}
  45 +
  46 +int ipc3270_method_disconnect(GObject *session, GVariant *request, GObject *response, GError **error) {
  47 + return lib3270_disconnect(ipc3270_get_session(session));
  48 +}
server/src/core/methods/private.h 0 → 100644
@@ -0,0 +1,57 @@ @@ -0,0 +1,57 @@
  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., 51 Franklin
  19 + * St, Fifth Floor, Boston, MA 02110-1301 USA
  20 + *
  21 + * Este programa está nomeado como - e possui - linhas de código.
  22 + *
  23 + * Referências:
  24 + *
  25 + * https://github.com/joprietoe/gdbus/blob/master/gdbus-example-server.c
  26 + * https://github.com/bratsche/glib/blob/master/gio/tests/gdbus-example-export.c
  27 + *
  28 + * Contatos:
  29 + *
  30 + * perry.werneck@gmail.com (Alexandre Perry de Souza Werneck)
  31 + * erico.mendonca@gmail.com (Erico Mascarenhas Mendonça)
  32 + *
  33 + */
  34 +
  35 +#ifndef IPC_METHODS_H_INCLUDED
  36 +
  37 + #define IPC_METHODS_H_INCLUDED
  38 +
  39 + #include <config.h>
  40 + #include <lib3270.h>
  41 + #include <lib3270/ipc-glib.h>
  42 +
  43 + G_GNUC_INTERNAL int ipc3270_method_connect(GObject *session, GVariant *request, GObject *response, GError **error);
  44 + G_GNUC_INTERNAL int ipc3270_method_disconnect(GObject *session, GVariant *request, GObject *response, GError **error);
  45 +
  46 + G_GNUC_INTERNAL int ipc3270_method_get_string(GObject *session, GVariant *request, GObject *response, GError **error);
  47 +
  48 + G_GNUC_INTERNAL int ipc3270_method_set_string(GObject *session, GVariant *request, GObject *response, GError **error);
  49 +
  50 + G_GNUC_INTERNAL int ipc3270_method_wait(GObject *session, GVariant *request, GObject *response, GError **error);
  51 + G_GNUC_INTERNAL int ipc3270_method_wait_for_ready(GObject *session, GVariant *request, GObject *response, GError **error);
  52 + G_GNUC_INTERNAL int ipc3270_method_wait_for_update(GObject *session, GVariant *request, GObject *response, GError **error);
  53 +
  54 + G_GNUC_INTERNAL int ipc3270_method_get_field_attribute(GObject *session, GVariant *request, GObject *response, GError **error);
  55 +
  56 +#endif // IPC_METHODS_H_INCLUDED
  57 +
server/src/core/methods/wait.c 0 → 100644
@@ -0,0 +1,54 @@ @@ -0,0 +1,54 @@
  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., 51 Franklin
  19 + * St, Fifth Floor, Boston, MA 02110-1301 USA
  20 + *
  21 + * Este programa está nomeado como - 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 "private.h"
  31 +
  32 +int ipc3270_method_wait(GObject *session, GVariant *request, GObject *response, GError **error) {
  33 +
  34 + guint seconds = 1;
  35 + g_variant_get(request, "(u)", &seconds);
  36 + return lib3270_wait(ipc3270_get_session(session),seconds);
  37 +
  38 +}
  39 +
  40 +int ipc3270_method_wait_for_ready(GObject *session, GVariant *request, GObject *response, GError **error) {
  41 +
  42 + guint seconds = 1;
  43 + g_variant_get(request, "(u)", &seconds);
  44 + return lib3270_wait_for_ready(ipc3270_get_session(session),seconds);
  45 +
  46 +}
  47 +
  48 +int ipc3270_method_wait_for_update(GObject *session, GVariant *request, GObject *response, GError **error) {
  49 +
  50 + guint seconds = 1;
  51 + g_variant_get(request, "(u)", &seconds);
  52 + return lib3270_wait_for_update(ipc3270_get_session(session),seconds);
  53 +
  54 +}
server/src/core/windows/gobject.c
@@ -107,3 +107,9 @@ GQuark ipc3270_get_error_domain(GObject *object) { @@ -107,3 +107,9 @@ GQuark ipc3270_get_error_domain(GObject *object) {
107 return IPC3270(object)->error_domain; 107 return IPC3270(object)->error_domain;
108 } 108 }
109 109
  110 +gchar * ipc3270_convert_to_3270(GObject *object, const gchar *string, GError **error) {
  111 + return g_convert_with_fallback(string,-1,ipc3270_get_display_charset(object),"UTF-8","?",NULL,NULL,error);
  112 +}
  113 +
  114 +
  115 +
server/testscripts/getstring.sh 0 → 100755
@@ -0,0 +1,12 @@ @@ -0,0 +1,12 @@
  1 +#!/bin/bash
  2 +#
  3 +# https://stackoverflow.com/questions/48648952/set-get-property-using-dbus-send
  4 +#
  5 +
  6 +dbus-send \
  7 + --session \
  8 + --dest=br.com.bb.pw3270.a\
  9 + --print-reply \
  10 + "/br/com/bb/tn3270/session" \
  11 + "br.com.bb.tn3270.session.getString"
  12 +