Commit 01b59a4da5950f7c725b56a1fa23d7d1c7de311a
1 parent
5d954f92
Exists in
master
and in
1 other branch
Fixing "set property" linux method.
Showing
5 changed files
with
53 additions
and
71 deletions
Show diff stats
client/src/core/linux/request.cc
... | ... | @@ -37,6 +37,7 @@ |
37 | 37 | */ |
38 | 38 | |
39 | 39 | #include <ipc-client-internals.h> |
40 | + #include <cstring> | |
40 | 41 | |
41 | 42 | using std::string; |
42 | 43 | |
... | ... | @@ -46,8 +47,10 @@ |
46 | 47 | |
47 | 48 | IPC::Request::Request(DBusConnection * conn) { |
48 | 49 | this->conn = conn; |
49 | - this->response.msg = nullptr; | |
50 | - this->request.msg = nullptr; | |
50 | + | |
51 | + memset(&response,0,sizeof(response)); | |
52 | + memset(&request,0,sizeof(request)); | |
53 | + | |
51 | 54 | } |
52 | 55 | |
53 | 56 | IPC::Request::~Request() { |
... | ... | @@ -87,11 +90,36 @@ |
87 | 90 | |
88 | 91 | IPC::Request & IPC::Request::push(int type, const void *value) { |
89 | 92 | |
90 | - if (!dbus_message_iter_append_basic(&request.iter,type,value)) { | |
91 | - throw std::runtime_error("Can't append value"); | |
92 | - } | |
93 | + if(request.variant) { | |
94 | + | |
95 | + // Is variant | |
96 | + DBusMessageIter iter; | |
97 | + char signature[] = { (char) type, 0 }; | |
98 | + | |
99 | + if(!dbus_message_iter_open_container(&request.iter, DBUS_TYPE_VARIANT, signature, &iter)) { | |
100 | + throw std::runtime_error("Can't open variant"); | |
101 | + } | |
102 | + | |
103 | + if(!dbus_message_iter_append_basic(&iter,type,value)) { | |
104 | + dbus_message_iter_close_container(&request.iter, &iter); | |
105 | + throw std::runtime_error("Can't append variant"); | |
106 | + } | |
107 | + | |
108 | + if (!dbus_message_iter_close_container(&request.iter, &iter)) { | |
109 | + throw std::runtime_error("Can't close variant"); | |
110 | + } | |
111 | + | |
112 | + return *this; | |
113 | + | |
114 | + } else { | |
93 | 115 | |
94 | - return *this; | |
116 | + // Basic type. | |
117 | + if(dbus_message_iter_append_basic(&request.iter,type,value)) | |
118 | + return *this; | |
119 | + | |
120 | + } | |
121 | + | |
122 | + throw std::runtime_error("Can't append value"); | |
95 | 123 | |
96 | 124 | } |
97 | 125 | |
... | ... | @@ -302,7 +330,7 @@ |
302 | 330 | |
303 | 331 | } |
304 | 332 | |
305 | - debug("Argument type is ", ((char) dbus_message_iter_get_arg_type(&iter)) ); | |
333 | + debug("Argument type is %d", ((int) dbus_message_iter_get_arg_type(&iter)) ); | |
306 | 334 | throw std::runtime_error("Expected an integer data type"); |
307 | 335 | |
308 | 336 | } | ... | ... |
client/src/include/lib3270/ipc/request.h
... | ... | @@ -113,9 +113,10 @@ |
113 | 113 | |
114 | 114 | /// @brief Message who will be sent to server. |
115 | 115 | struct { |
116 | - DBusMessage * msg; | |
117 | - DBusMessageIter iter; | |
118 | - } request; | |
116 | + DBusMessage * msg; ///< @brief The request message. | |
117 | + DBusMessageIter iter; ///< @brief Arguments iter. | |
118 | + bool variant; ///< @brief Put arguments as variants? | |
119 | + } request; | |
119 | 120 | |
120 | 121 | DBusConnection * conn; |
121 | 122 | ... | ... |
client/src/session/remote/attribute.cc
... | ... | @@ -115,16 +115,10 @@ |
115 | 115 | set.asInt32 = [](const Attribute & attr, const void *worker, const int32_t value) { |
116 | 116 | |
117 | 117 | const struct Worker * w = (const struct Worker *) worker; |
118 | - int32_t rc; | |
119 | 118 | |
120 | 119 | IPC::Request(*w->session,true,w->methods->name) |
121 | 120 | .push(value) |
122 | - .call() | |
123 | - .pop(rc); | |
124 | - | |
125 | - if(rc) { | |
126 | - throw std::system_error((int) rc, std::system_category()); | |
127 | - } | |
121 | + .call(); | |
128 | 122 | |
129 | 123 | }; |
130 | 124 | |
... | ... | @@ -135,12 +129,7 @@ |
135 | 129 | |
136 | 130 | IPC::Request(*w->session,true,w->methods->name) |
137 | 131 | .push(value) |
138 | - .call() | |
139 | - .pop(rc); | |
140 | - | |
141 | - if(rc) { | |
142 | - throw std::system_error((int) rc, std::system_category()); | |
143 | - } | |
132 | + .call(); | |
144 | 133 | |
145 | 134 | }; |
146 | 135 | |
... | ... | @@ -185,32 +174,20 @@ |
185 | 174 | set.asInt32 = [](const Attribute & attr, const void *worker, const int32_t value) { |
186 | 175 | |
187 | 176 | const struct Worker * w = (const struct Worker *) worker; |
188 | - int32_t rc; | |
189 | 177 | |
190 | 178 | IPC::Request(*w->session,true,w->methods->name) |
191 | 179 | .push(value) |
192 | - .call() | |
193 | - .pop(rc); | |
194 | - | |
195 | - if(rc) { | |
196 | - throw std::system_error((int) rc, std::system_category()); | |
197 | - } | |
180 | + .call(); | |
198 | 181 | |
199 | 182 | }; |
200 | 183 | |
201 | 184 | set.asBoolean = [](const Attribute & attr, const void *worker, const bool value) { |
202 | 185 | |
203 | 186 | const struct Worker * w = (const struct Worker *) worker; |
204 | - int32_t rc; | |
205 | 187 | |
206 | 188 | IPC::Request(*w->session,true,w->methods->name) |
207 | 189 | .push(value) |
208 | - .call() | |
209 | - .pop(rc); | |
210 | - | |
211 | - if(rc) { | |
212 | - throw std::system_error((int) rc, std::system_category()); | |
213 | - } | |
190 | + .call(); | |
214 | 191 | |
215 | 192 | }; |
216 | 193 | } |
... | ... | @@ -259,12 +236,7 @@ |
259 | 236 | |
260 | 237 | IPC::Request(*w->session,true,w->methods->name) |
261 | 238 | .push(value) |
262 | - .call() | |
263 | - .pop(rc); | |
264 | - | |
265 | - if(rc) { | |
266 | - throw std::system_error((int) rc, std::system_category()); | |
267 | - } | |
239 | + .call(); | |
268 | 240 | |
269 | 241 | }; |
270 | 242 | |
... | ... | @@ -275,12 +247,7 @@ |
275 | 247 | |
276 | 248 | IPC::Request(*w->session,true,w->methods->name) |
277 | 249 | .push(value) |
278 | - .call() | |
279 | - .pop(rc); | |
280 | - | |
281 | - if(rc) { | |
282 | - throw std::system_error((int) rc, std::system_category()); | |
283 | - } | |
250 | + .call(); | |
284 | 251 | |
285 | 252 | }; |
286 | 253 | |
... | ... | @@ -328,44 +295,27 @@ |
328 | 295 | |
329 | 296 | IPC::Request(*w->session,true,w->methods->name) |
330 | 297 | .push(value) |
331 | - .call() | |
332 | - .pop(rc); | |
333 | - | |
334 | - if(rc) { | |
335 | - throw std::system_error((int) rc, std::system_category()); | |
336 | - } | |
298 | + .call(); | |
337 | 299 | |
338 | 300 | }; |
339 | 301 | |
340 | 302 | set.asInt32 = [](const Attribute & attr, const void *worker, const int32_t value) { |
341 | 303 | |
342 | 304 | const struct Worker * w = (const struct Worker *) worker; |
343 | - int32_t rc; | |
344 | 305 | |
345 | 306 | IPC::Request(*w->session,true,w->methods->name) |
346 | 307 | .push(std::to_string(value).c_str()) |
347 | - .call() | |
348 | - .pop(rc); | |
349 | - | |
350 | - if(rc) { | |
351 | - throw std::system_error((int) rc, std::system_category()); | |
352 | - } | |
308 | + .call(); | |
353 | 309 | |
354 | 310 | }; |
355 | 311 | |
356 | 312 | set.asUint32 = [](const Attribute & attr, const void *worker, const uint32_t value) { |
357 | 313 | |
358 | 314 | const struct Worker * w = (const struct Worker *) worker; |
359 | - int32_t rc; | |
360 | 315 | |
361 | 316 | IPC::Request(*w->session,true,w->methods->name) |
362 | 317 | .push(std::to_string(value).c_str()) |
363 | - .call() | |
364 | - .pop(rc); | |
365 | - | |
366 | - if(rc) { | |
367 | - throw std::system_error((int) rc, std::system_category()); | |
368 | - } | |
318 | + .call(); | |
369 | 319 | |
370 | 320 | }; |
371 | 321 | ... | ... |
client/src/session/remote/linux/request.cc
client/src/testprogram/testprogram.cc
... | ... | @@ -201,9 +201,9 @@ |
201 | 201 | |
202 | 202 | cout << "pre: " << host["url"] << endl; |
203 | 203 | |
204 | - // host["url"] = "http://www.google.com.br"; | |
204 | + host["url"] = "http://www.google.com.br"; | |
205 | 205 | |
206 | - // cout << "post: " << host["url"] << endl; | |
206 | + cout << "post: " << host["url"] << endl; | |
207 | 207 | } |
208 | 208 | |
209 | 209 | ... | ... |