Commit 518e10caecf15da92751397cf3b7932d14280232

Authored by Perry Werneck
1 parent 35fcf870
Exists in master and in 1 other branch develop

Implementing IPC response with multiple results.

client/src/session/remote/actions.cc
... ... @@ -151,6 +151,10 @@
151 151 throw std::system_error(ENOTSUP, std::system_category());
152 152 }
153 153  
  154 + Session::Cursor IPC::Session::getCursorPosition() {
  155 + throw std::system_error(ENOTSUP, std::system_category());
  156 + }
  157 +
154 158 }
155 159  
156 160  
... ...
client/src/testprogram/testprogram.cc
... ... @@ -103,7 +103,7 @@
103 103  
104 104 TN3270::Host host{session};
105 105  
106   - // name="url";
  106 + name="url";
107 107  
108 108 cout << endl << endl;
109 109 for(auto attribute : host.getAttributes()) {
... ... @@ -257,37 +257,45 @@
257 257  
258 258 };
259 259  
260   - int long_index =0;
261   - int opt;
262   - while((opt = getopt_long(argc, argv, "s:A", options, &long_index )) != -1) {
  260 + try {
  261 +
  262 + int long_index =0;
  263 + int opt;
  264 + while((opt = getopt_long(argc, argv, "s:A", options, &long_index )) != -1) {
263 265  
264   - switch(opt) {
265   - case 's':
266   - session = optarg;
267   - cout << "Session: " << session << endl;
268   - break;
  266 + switch(opt) {
  267 + case 's':
  268 + session = optarg;
  269 + cout << "Session: " << session << endl;
  270 + break;
269 271  
270   - case 'A':
271   - testAttributes(session,optarg);
272   - break;
  272 + case 'A':
  273 + testAttributes(session,optarg);
  274 + break;
273 275  
274   - case 'U':
275   - url = optarg;
276   - cout << "URL: " << session << endl;
277   - break;
  276 + case 'U':
  277 + url = optarg;
  278 + cout << "URL: " << session << endl;
  279 + break;
278 280  
279   - case 'P':
280   - testPerformance(session,url);
281   - return 0;
  281 + case 'P':
  282 + testPerformance(session,url);
  283 + return 0;
282 284  
283   - case 'I':
284   - testHost(session,url);
285   - return 0;
  285 + case 'I':
  286 + testHost(session,url);
  287 + return 0;
  288 +
  289 + }
286 290  
287 291 }
288 292  
289   - }
  293 + } catch(const std::exception &e) {
290 294  
  295 + cerr << "Error:" << endl << "\t" << e.what() << endl << endl;
  296 + exit(-1);
  297 +
  298 + }
291 299 #else
292 300  
293 301 printf("\nRunning IPC Client tests\n");
... ...
server/pw3270-plugin-ipc.cbp
... ... @@ -121,9 +121,6 @@
121 121 <Unit filename="src/core/windows/resources.rc">
122 122 <Option compilerVar="WINDRES" />
123 123 </Unit>
124   - <Unit filename="src/core/windows/response.c">
125   - <Option compilerVar="CC" />
126   - </Unit>
127 124 <Unit filename="src/core/windows/start.c">
128 125 <Option compilerVar="CC" />
129 126 </Unit>
... ...
server/src/core/response.c
... ... @@ -45,8 +45,10 @@
45 45 #include <lib3270/toggle.h>
46 46 #include <v3270.h>
47 47  
48   -#include <dbus/dbus-glib.h>
49   -#include <dbus/dbus-glib-bindings.h>
  48 +#ifndef _WIN32
  49 + #include <dbus/dbus-glib.h>
  50 + #include <dbus/dbus-glib-bindings.h>
  51 +#endif // _WIN32
50 52  
51 53 /*--[ Widget definition ]----------------------------------------------------------------------------*/
52 54  
... ... @@ -130,6 +132,10 @@ GVariant * ipc3270_response_steal_value(GObject *object) {
130 132 return value;
131 133 }
132 134  
  135 +const GList * ipc3270_get_values(GObject *object) {
  136 + IPC3270_RESPONSE(object)->values;
  137 +}
  138 +
133 139 guint ipc3270_response_length(GObject *object) {
134 140 return g_list_length(IPC3270_RESPONSE(object)->values);
135 141 }
... ...
server/src/core/windows/inout.c
... ... @@ -168,6 +168,40 @@ unsigned char * pack_value(unsigned char *txtptr, GVariant *value) {
168 168  
169 169 }
170 170  
  171 +unsigned char * ipc3270_pack(const gchar *name, GObject *object, int id, size_t * szPacket) {
  172 +
  173 + const GList * node;
  174 + size_t vCount = 0;
  175 +
  176 + g_return_val_if_fail(IS_IPC3270_RESPONSE(object),NULL);
  177 +
  178 + // Set packet size.
  179 + *szPacket =
  180 + strlen(name) + 1
  181 + + (sizeof(guint16) * 2);
  182 +
  183 + for(node = ipc3270_get_values(object); node; node = g_list_next(node)) {
  184 + vCount++;
  185 + *szPacket += g_variant_get_size(node->data)+1;
  186 + }
  187 +
  188 + unsigned char * outputBuffer = g_malloc0(*szPacket);
  189 + unsigned char * txtptr = setup_header(outputBuffer,name,id,vCount);
  190 +
  191 + for(node = ipc3270_get_values(object); node; node = g_list_next(node)) {
  192 + txtptr = pack_value(txtptr, node->data);
  193 + if(!txtptr) {
  194 + g_free(outputBuffer);
  195 + return NULL;
  196 + }
  197 + }
  198 +
  199 + debug("used=%u allocated=%u",(unsigned int) (txtptr-outputBuffer), (unsigned int) *szPacket);
  200 + return outputBuffer;
  201 +
  202 +}
  203 +
  204 +/*
171 205 unsigned char * ipc3270_pack_value(const gchar *name, int id, GVariant *value, size_t * szPacket) {
172 206  
173 207 debug("%s(%s)",__FUNCTION__,name);
... ... @@ -239,6 +273,7 @@ unsigned char * ipc3270_pack(const gchar * name, int id, GVariant *values, size_
239 273  
240 274 return outputBuffer;
241 275 }
  276 +*/
242 277  
243 278 GVariant * ipc3270_unpack(const unsigned char *packet, int *id) {
244 279  
... ... @@ -387,3 +422,4 @@ GVariant * ipc3270_unpack(const unsigned char *packet, int *id) {
387 422 return g_variant_builder_end(&builder);
388 423  
389 424 }
  425 +
... ...
server/src/core/windows/pipesource.c
... ... @@ -109,7 +109,7 @@ static void process_input(IPC3270_PIPE_SOURCE *source, DWORD cbRead) {
109 109 */
110 110  
111 111 g_autoptr (GError) error = NULL;
112   - g_autoptr (GVariant) response = NULL;
  112 + g_autoptr(GObject) response = ipc3270_response_new();
113 113 g_autoptr (GVariant) parameters = ipc3270_unpack(source->buffer, &request_type);
114 114  
115 115 /*
... ... @@ -123,30 +123,16 @@ static void process_input(IPC3270_PIPE_SOURCE *source, DWORD cbRead) {
123 123 // Process query
124 124 switch(request_type) {
125 125 case 1: // getProperty
126   - response = ipc3270_get_property(source->object, request_name, &error);
  126 + ipc3270_response_append(response,ipc3270_get_property(source->object, request_name, &error));
127 127 break;
128 128  
129 129 case 2: // setProperty
130 130 ipc3270_set_property(source->object, request_name, parameters, &error);
131   - response = g_variant_new_int32(0);
  131 + ipc3270_response_append_int32(response,0);
132 132 break;
133 133  
134 134 case 3: // method
135   - {
136   - g_autoptr(GObject) rsp = ipc3270_response_new();
137   -
138   - debug("Parameters: %p", parameters);
139   - debug("rsp: %p", rsp);
140   - debug("Error=%p",error);
141   -
142   - ipc3270_method_call(source->object, request_name, parameters, rsp, &error);
143   -
144   - debug("Error=%p",error);
145   -
146   - if(ipc3270_response_has_values(rsp))
147   - response = ipc3270_response_steal_value(rsp);
148   -
149   - }
  135 + ipc3270_method_call(source->object, request_name, parameters, response, &error);
150 136 break;
151 137  
152 138 default:
... ... @@ -177,7 +163,7 @@ static void process_input(IPC3270_PIPE_SOURCE *source, DWORD cbRead) {
177 163  
178 164 } else {
179 165  
180   - buffer = ipc3270_pack_value(request_name, 0, response, &szPacket);
  166 + buffer = ipc3270_pack(request_name,response,0,&szPacket);
181 167  
182 168 }
183 169  
... ...
server/src/include/ipc-glib.h
... ... @@ -106,7 +106,9 @@
106 106 typedef struct _ipc3270ResponseClass ipc3270ResponseClass;
107 107  
108 108 GObject * ipc3270_response_new();
  109 + GType ipc3270Response_get_type(void);
109 110  
  111 + void ipc3270_response_append(GObject *object, GVariant *value);
110 112 void ipc3270_response_append_int32(GObject *object, gint32 value);
111 113 void ipc3270_response_append_uint32(GObject *object, guint32 value);
112 114 void ipc3270_response_append_string(GObject *object, const gchar *text);
... ... @@ -114,6 +116,7 @@
114 116  
115 117 gboolean ipc3270_response_has_values(GObject *object);
116 118 guint ipc3270_response_length(GObject *object);
  119 + const GList * ipc3270_get_values(GObject *object);
117 120  
118 121 GVariant * ipc3270_response_steal_value(GObject *object);
119 122  
... ... @@ -151,9 +154,10 @@
151 154 GVariant * ipc3270_get_property(GObject *object, const gchar *property_name, GError **error);
152 155  
153 156 #ifdef _WIN32
154   - unsigned char * ipc3270_pack(const gchar *name, int id, GVariant *values, size_t * szPacket);
155   - unsigned char * ipc3270_pack_value(const gchar *name, int id, GVariant *value, size_t * szPacket);
156   - unsigned char * ipc3270_pack_error(const GError *error, size_t * szPacket);
  157 +// unsigned char * ipc3270_pack(const gchar *name, int id, GVariant *values, size_t * szPacket);
  158 +// unsigned char * ipc3270_pack_value(const gchar *name, int id, GVariant *value, size_t * szPacket);
  159 +// unsigned char * ipc3270_pack_error(const GError *error, size_t * szPacket);
  160 + unsigned char * ipc3270_pack(const gchar *name, GObject *object, int id, size_t * szPacket);
157 161 GVariant * ipc3270_unpack(const unsigned char *packet, int *id);
158 162 #endif // _WIN32
159 163  
... ...