Commit dc4d26c5a4fe8b6c3afb118137c38dfdf5d9f569
1 parent
dbfb070f
Exists in
master
and in
1 other branch
Adding ipc methods for getting properties.
Showing
9 changed files
with
431 additions
and
6 deletions
Show diff stats
client/ipcclient.cbp
... | ... | @@ -80,6 +80,7 @@ |
80 | 80 | <Unit filename="src/session/local/set.cc" /> |
81 | 81 | <Unit filename="src/session/local/wait.cc" /> |
82 | 82 | <Unit filename="src/session/remote/actions.cc" /> |
83 | + <Unit filename="src/session/remote/attribute.cc" /> | |
83 | 84 | <Unit filename="src/session/remote/get.cc" /> |
84 | 85 | <Unit filename="src/session/remote/linux/request.cc" /> |
85 | 86 | <Unit filename="src/session/remote/linux/session.cc" /> | ... | ... |
client/src/core/linux/request.cc
... | ... | @@ -78,7 +78,7 @@ |
78 | 78 | |
79 | 79 | dbus_message_iter_init(msg.in, &msg.iter); |
80 | 80 | |
81 | - debug(__FUNCTION__," got a valid response"); | |
81 | +// debug(__FUNCTION__," got a valid response"); | |
82 | 82 | |
83 | 83 | return *this; |
84 | 84 | |
... | ... | @@ -196,6 +196,65 @@ |
196 | 196 | |
197 | 197 | } |
198 | 198 | |
199 | + static unsigned int getBooleanValue(DBusMessageIter &iter) { | |
200 | + | |
201 | + if(dbus_message_iter_get_arg_type(&iter) == DBUS_TYPE_UINT32) { | |
202 | + | |
203 | + dbus_uint32_t rc = 0; | |
204 | + dbus_message_iter_get_basic(&iter, &rc); | |
205 | + return rc != 0; | |
206 | + | |
207 | + } else if(dbus_message_iter_get_arg_type(&iter) == DBUS_TYPE_UINT16) { | |
208 | + | |
209 | + dbus_uint16_t rc = 0; | |
210 | + dbus_message_iter_get_basic(&iter, &rc); | |
211 | + return rc != 0; | |
212 | + | |
213 | + } else if(dbus_message_iter_get_arg_type(&iter) == DBUS_TYPE_BOOLEAN) { | |
214 | + | |
215 | + dbus_bool_t rc = 0; | |
216 | + dbus_message_iter_get_basic(&iter, &rc); | |
217 | + return rc; | |
218 | + | |
219 | + } else if(dbus_message_iter_get_arg_type(&iter) == DBUS_TYPE_VARIANT) { | |
220 | + | |
221 | + DBusMessageIter sub; | |
222 | + int current_type; | |
223 | + | |
224 | + dbus_message_iter_recurse(&iter, &sub); | |
225 | + | |
226 | + while ((current_type = dbus_message_iter_get_arg_type(&sub)) != DBUS_TYPE_INVALID) { | |
227 | + | |
228 | + if (current_type == DBUS_TYPE_UINT32) { | |
229 | + | |
230 | + dbus_uint32_t rc = 0; | |
231 | + dbus_message_iter_get_basic(&sub, &rc); | |
232 | + return rc != 0; | |
233 | + | |
234 | + } else if (current_type == DBUS_TYPE_UINT16) { | |
235 | + | |
236 | + dbus_uint16_t rc = 0; | |
237 | + dbus_message_iter_get_basic(&sub, &rc); | |
238 | + return rc != 0; | |
239 | + | |
240 | + } else if (current_type == DBUS_TYPE_BOOLEAN) { | |
241 | + | |
242 | + dbus_bool_t rc = 0; | |
243 | + dbus_message_iter_get_basic(&sub, &rc); | |
244 | + return rc; | |
245 | + | |
246 | + } | |
247 | + | |
248 | + dbus_message_iter_next(&sub); | |
249 | + } | |
250 | + | |
251 | + } | |
252 | + | |
253 | + debug("Argument type is ", ((char) dbus_message_iter_get_arg_type(&iter)) ); | |
254 | + throw std::runtime_error("Expected an integer data type"); | |
255 | + | |
256 | + } | |
257 | + | |
199 | 258 | static int getIntValue(DBusMessageIter &iter) { |
200 | 259 | |
201 | 260 | if(dbus_message_iter_get_arg_type(&iter) == DBUS_TYPE_INT32) { |
... | ... | @@ -247,7 +306,7 @@ |
247 | 306 | |
248 | 307 | value = getIntValue(msg.iter); |
249 | 308 | dbus_message_iter_next(&msg.iter); |
250 | - debug(__FUNCTION__,"= \"",value,"\""); | |
309 | +// debug(__FUNCTION__,"= \"",value,"\""); | |
251 | 310 | |
252 | 311 | return *this; |
253 | 312 | |
... | ... | @@ -257,7 +316,17 @@ |
257 | 316 | |
258 | 317 | value = getUIntValue(msg.iter); |
259 | 318 | dbus_message_iter_next(&msg.iter); |
260 | - debug(__FUNCTION__,"= \"",value,"\""); | |
319 | +// debug(__FUNCTION__,"= \"",value,"\""); | |
320 | + | |
321 | + return *this; | |
322 | + | |
323 | + } | |
324 | + | |
325 | + IPC::Request & IPC::Request::Request::pop(bool &value) { | |
326 | + | |
327 | + value = getBooleanValue(msg.iter); | |
328 | + dbus_message_iter_next(&msg.iter); | |
329 | +// debug(__FUNCTION__,"= \"",value,"\""); | |
261 | 330 | |
262 | 331 | return *this; |
263 | 332 | ... | ... |
client/src/core/session.cc
... | ... | @@ -409,6 +409,7 @@ |
409 | 409 | throw std::system_error(ENOTSUP, std::system_category()); |
410 | 410 | } |
411 | 411 | |
412 | + /* | |
412 | 413 | Attribute Session::getAttribute(const char *name) const { |
413 | 414 | throw std::system_error(ENOTSUP, std::system_category()); |
414 | 415 | } |
... | ... | @@ -416,6 +417,7 @@ |
416 | 417 | void Session::getAttributes(std::vector<Attribute> & attributes) const { |
417 | 418 | throw std::system_error(ENOTSUP, std::system_category()); |
418 | 419 | } |
420 | + */ | |
419 | 421 | |
420 | 422 | std::vector<Attribute> Session::getAttributes() const { |
421 | 423 | std::vector<Attribute> attributes; | ... | ... |
client/src/include/lib3270/ipc.h
... | ... | @@ -496,8 +496,8 @@ |
496 | 496 | LIB3270_KEYBOARD_LOCK_STATE input(const std::string &str, const char control_char = '@'); |
497 | 497 | |
498 | 498 | // Attributes |
499 | - virtual Attribute getAttribute(const char *name) const; | |
500 | - virtual void getAttributes(std::vector<Attribute> & attributes) const; | |
499 | + virtual Attribute getAttribute(const char *name) const = 0; | |
500 | + virtual void getAttributes(std::vector<Attribute> & attributes) const = 0; | |
501 | 501 | std::vector<Attribute> getAttributes() const; |
502 | 502 | |
503 | 503 | virtual void getAttribute(const char *name, int &value) const; | ... | ... |
client/src/include/lib3270/ipc/request.h
client/src/session/local/attribute.cc
... | ... | @@ -156,6 +156,7 @@ |
156 | 156 | |
157 | 157 | }; |
158 | 158 | |
159 | + // Unsigned int attribute | |
159 | 160 | class TN3270_PRIVATE UnsignedIntAttribute : public TemplateAttribute<LIB3270_UINT_PROPERTY> { |
160 | 161 | public: |
161 | 162 | UnsignedIntAttribute(H3270 *hSession, const LIB3270_UINT_PROPERTY *worker) : TemplateAttribute<LIB3270_UINT_PROPERTY>(hSession, Attribute::Boolean, worker) { |
... | ... | @@ -190,6 +191,7 @@ |
190 | 191 | } |
191 | 192 | }; |
192 | 193 | |
194 | + // String attribute | |
193 | 195 | class TN3270_PRIVATE StringAttribute : public TemplateAttribute<LIB3270_STRING_PROPERTY> { |
194 | 196 | public: |
195 | 197 | StringAttribute(H3270 *hSession, const LIB3270_STRING_PROPERTY *worker) : TemplateAttribute<LIB3270_STRING_PROPERTY>(hSession, Attribute::String, worker) { |
... | ... | @@ -226,6 +228,7 @@ |
226 | 228 | } |
227 | 229 | }; |
228 | 230 | |
231 | + // Toggle attribute | |
229 | 232 | class TN3270_PRIVATE ToggleAttribute : public TemplateAttribute<LIB3270_TOGGLE_ENTRY> { |
230 | 233 | public: |
231 | 234 | ToggleAttribute(H3270 *hSession, const LIB3270_TOGGLE_ENTRY *worker) : TemplateAttribute<LIB3270_TOGGLE_ENTRY>(hSession, Attribute::Boolean, worker) { | ... | ... |
... | ... | @@ -0,0 +1,345 @@ |
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 | +/** | |
31 | + * @file | |
32 | + * | |
33 | + * @brief | |
34 | + * | |
35 | + * @author perry.werneck@gmail.com | |
36 | + * | |
37 | + */ | |
38 | + | |
39 | + #include "private.h" | |
40 | + #include <lib3270/ipc.h> | |
41 | + #include <lib3270/properties.h> | |
42 | + #include <lib3270/toggle.h> | |
43 | + #include <cstring> | |
44 | + | |
45 | +/*---[ Implement ]----------------------------------------------------------------------------------*/ | |
46 | + | |
47 | + namespace TN3270 { | |
48 | + | |
49 | + // Class template | |
50 | + template<typename T> | |
51 | + class TN3270_PRIVATE TemplateAttribute : public Attribute { | |
52 | + protected: | |
53 | + | |
54 | + struct Worker { | |
55 | + const T *methods; | |
56 | + IPC::Session * session; | |
57 | + }; | |
58 | + | |
59 | + public: | |
60 | + | |
61 | + TemplateAttribute(const IPC::Session *session, Attribute::Type type, const T *methods) : Attribute(type, sizeof(struct Worker)) { | |
62 | + | |
63 | + getWorker()->session = const_cast<IPC::Session *>(session); | |
64 | + getWorker()->methods = methods; | |
65 | + | |
66 | + get.name = [](const void *worker) { | |
67 | + return ((const struct Worker *) worker)->methods->name; | |
68 | + }; | |
69 | + | |
70 | + get.description = [](const void *worker) { | |
71 | + return ((const struct Worker *) worker)->methods->description; | |
72 | + }; | |
73 | + | |
74 | + } | |
75 | + | |
76 | + inline struct Worker * getWorker() { | |
77 | + return (struct Worker *) this->data; | |
78 | + } | |
79 | + | |
80 | + }; | |
81 | + | |
82 | + // Signed int attribute | |
83 | + class TN3270_PRIVATE IntAttribute : public TemplateAttribute<LIB3270_INT_PROPERTY> { | |
84 | + public: | |
85 | + IntAttribute(const IPC::Session *session, const LIB3270_INT_PROPERTY *worker) : TemplateAttribute<LIB3270_INT_PROPERTY>(session, Attribute::Int32, worker) { | |
86 | + | |
87 | + get.asString = [](const Attribute & attr, const void *worker) { | |
88 | + return std::to_string(attr.getInt32()); | |
89 | + }; | |
90 | + | |
91 | + get.asInt32 = [](const Attribute & attr, const void *worker) { | |
92 | + | |
93 | + const struct Worker * w = (const struct Worker *) worker; | |
94 | + | |
95 | + int value; | |
96 | + | |
97 | + IPC::Request(*w->session,false,w->methods->name) | |
98 | + .call() | |
99 | + .pop(value); | |
100 | + | |
101 | + return (int32_t) value; | |
102 | + | |
103 | + }; | |
104 | + | |
105 | + get.asUint32 = [](const Attribute & attr, const void *worker) { | |
106 | + return (uint32_t) attr.getInt32(); | |
107 | + }; | |
108 | + | |
109 | + get.asBoolean = [](const Attribute & attr, const void *worker) { | |
110 | + return (attr.getInt32() != 0); | |
111 | + }; | |
112 | + | |
113 | + | |
114 | + } | |
115 | + | |
116 | + }; | |
117 | + | |
118 | + // Boolean attribute | |
119 | + class TN3270_PRIVATE BooleanAttribute : public TemplateAttribute<LIB3270_INT_PROPERTY> { | |
120 | + public: | |
121 | + BooleanAttribute(const IPC::Session *session, const LIB3270_INT_PROPERTY *worker) : TemplateAttribute<LIB3270_INT_PROPERTY>(session, Attribute::Boolean, worker) { | |
122 | + | |
123 | + get.asString = [](const Attribute & attr, const void *worker) { | |
124 | + return attr.getBoolean() ? "true" : "false"; | |
125 | + }; | |
126 | + | |
127 | + get.asInt32 = [](const Attribute & attr, const void *worker) { | |
128 | + return (uint32_t) attr.getBoolean(); | |
129 | + }; | |
130 | + | |
131 | + get.asUint32 = [](const Attribute & attr, const void *worker) { | |
132 | + return (uint32_t) attr.getInt32(); | |
133 | + }; | |
134 | + | |
135 | + get.asBoolean = [](const Attribute & attr, const void *worker) { | |
136 | + | |
137 | + const struct Worker * w = (const struct Worker *) worker; | |
138 | + | |
139 | + bool value; | |
140 | + | |
141 | + IPC::Request(*w->session,false,w->methods->name) | |
142 | + .call() | |
143 | + .pop(value); | |
144 | + | |
145 | + return value; | |
146 | + }; | |
147 | + | |
148 | + | |
149 | + } | |
150 | + | |
151 | + }; | |
152 | + | |
153 | + // Unsigned int attribute | |
154 | + class TN3270_PRIVATE UnsignedIntAttribute : public TemplateAttribute<LIB3270_UINT_PROPERTY> { | |
155 | + public: | |
156 | + UnsignedIntAttribute(const IPC::Session *session, const LIB3270_UINT_PROPERTY *worker) : TemplateAttribute<LIB3270_UINT_PROPERTY>(session, Attribute::Boolean, worker) { | |
157 | + | |
158 | + get.asString = [](const Attribute & attr, const void *worker) { | |
159 | + return std::to_string(attr.getUint32()); | |
160 | + }; | |
161 | + | |
162 | + get.asInt32 = [](const Attribute & attr, const void *worker) { | |
163 | + return (int32_t) attr.getUint32(); | |
164 | + }; | |
165 | + | |
166 | + get.asUint32 = [](const Attribute & attr, const void *worker) { | |
167 | + | |
168 | + const struct Worker * w = (const struct Worker *) worker; | |
169 | + | |
170 | + unsigned int value; | |
171 | + | |
172 | + IPC::Request(*w->session,false,w->methods->name) | |
173 | + .call() | |
174 | + .pop(value); | |
175 | + | |
176 | + return (uint32_t) value; | |
177 | + | |
178 | + }; | |
179 | + | |
180 | + get.asBoolean = [](const Attribute & attr, const void *worker) { | |
181 | + return (attr.getUint32() != 0); | |
182 | + }; | |
183 | + | |
184 | + } | |
185 | + }; | |
186 | + | |
187 | + // String attribute | |
188 | + class TN3270_PRIVATE StringAttribute : public TemplateAttribute<LIB3270_STRING_PROPERTY> { | |
189 | + public: | |
190 | + StringAttribute(const IPC::Session *session, const LIB3270_STRING_PROPERTY *worker) : TemplateAttribute<LIB3270_STRING_PROPERTY>(session, Attribute::String, worker) { | |
191 | + | |
192 | + get.asString = [](const Attribute & attr, const void *worker) { | |
193 | + | |
194 | + | |
195 | + const struct Worker * w = (const struct Worker *) worker; | |
196 | + string value; | |
197 | + | |
198 | + IPC::Request(*w->session,false,w->methods->name) | |
199 | + .call() | |
200 | + .pop(value); | |
201 | + | |
202 | + return value; | |
203 | + | |
204 | + }; | |
205 | + | |
206 | + get.asInt32 = [](const Attribute & attr, const void *worker) { | |
207 | + | |
208 | + const struct Worker * w = (const struct Worker *) worker; | |
209 | + string value; | |
210 | + | |
211 | + IPC::Request(*w->session,false,w->methods->name) | |
212 | + .call() | |
213 | + .pop(value); | |
214 | + | |
215 | + return atoi(value.c_str()); | |
216 | + | |
217 | + }; | |
218 | + | |
219 | + | |
220 | + } | |
221 | + }; | |
222 | + | |
223 | + Attribute IPC::Session::getAttribute(const char *name) const { | |
224 | + | |
225 | + // Check for integer properties. | |
226 | + { | |
227 | + const LIB3270_INT_PROPERTY * intprop = lib3270_get_int_properties_list(); | |
228 | + for(size_t ix = 0; intprop[ix].name; ix++) { | |
229 | + | |
230 | + if(!strcasecmp(name,intprop[ix].name)) { | |
231 | + return IntAttribute(this,&intprop[ix]); | |
232 | + } | |
233 | + | |
234 | + } | |
235 | + } | |
236 | + | |
237 | + // Check for unsigned int properties | |
238 | + { | |
239 | + const LIB3270_UINT_PROPERTY * intprop = lib3270_get_unsigned_properties_list(); | |
240 | + for(size_t ix = 0; intprop[ix].name; ix++) { | |
241 | + | |
242 | + if(!strcasecmp(name,intprop[ix].name)) { | |
243 | + return UnsignedIntAttribute(this,&intprop[ix]); | |
244 | + } | |
245 | + | |
246 | + } | |
247 | + | |
248 | + } | |
249 | + | |
250 | + // Check for string properties | |
251 | + { | |
252 | + const LIB3270_STRING_PROPERTY * strprop = lib3270_get_string_properties_list(); | |
253 | + | |
254 | + for(size_t ix = 0; strprop[ix].name; ix++) { | |
255 | + | |
256 | + if(!strcasecmp(name,strprop[ix].name)) { | |
257 | + return StringAttribute(this,&strprop[ix]); | |
258 | + } | |
259 | + | |
260 | + } | |
261 | + | |
262 | + } | |
263 | + | |
264 | + // Check for boolean properties | |
265 | + { | |
266 | + /* | |
267 | + const LIB3270_TOGGLE_ENTRY *toggles = lib3270_get_toggle_list(); | |
268 | + for(size_t ix = 0; toggles[ix].name; ix++) { | |
269 | + | |
270 | + if(!strcasecmp(name,toggles[ix].name)) { | |
271 | + return ToggleAttribute(this,&toggles[ix]); | |
272 | + } | |
273 | + | |
274 | + } | |
275 | + */ | |
276 | + | |
277 | + const LIB3270_INT_PROPERTY * intprop = lib3270_get_boolean_properties_list(); | |
278 | + for(size_t ix = 0; intprop[ix].name; ix++) { | |
279 | + | |
280 | + if(!strcasecmp(name,intprop[ix].name)) { | |
281 | + return BooleanAttribute(this,&intprop[ix]); | |
282 | + } | |
283 | + | |
284 | + } | |
285 | + | |
286 | + } | |
287 | + | |
288 | + | |
289 | + // Not found! | |
290 | + throw std::runtime_error("Invalid attribute"); | |
291 | + | |
292 | + } | |
293 | + | |
294 | + void IPC::Session::getAttributes(std::vector<Attribute> & attributes) const { | |
295 | + | |
296 | + // Add integer properties. | |
297 | + { | |
298 | + const LIB3270_INT_PROPERTY * intprop = lib3270_get_int_properties_list(); | |
299 | + for(size_t ix = 0; intprop[ix].name; ix++) { | |
300 | + attributes.push_back(IntAttribute(this,&intprop[ix])); | |
301 | + } | |
302 | + } | |
303 | + | |
304 | + // Add unsigned int properties | |
305 | + { | |
306 | + const LIB3270_UINT_PROPERTY * intprop = lib3270_get_unsigned_properties_list(); | |
307 | + for(size_t ix = 0; intprop[ix].name; ix++) { | |
308 | + attributes.push_back(UnsignedIntAttribute(this,&intprop[ix])); | |
309 | + } | |
310 | + | |
311 | + } | |
312 | + | |
313 | + // Add string properties | |
314 | + { | |
315 | + const LIB3270_STRING_PROPERTY * strprop = lib3270_get_string_properties_list(); | |
316 | + | |
317 | + for(size_t ix = 0; strprop[ix].name; ix++) { | |
318 | + attributes.push_back(StringAttribute(this,&strprop[ix])); | |
319 | + } | |
320 | + | |
321 | + } | |
322 | + | |
323 | + // Add boolean properties | |
324 | + { | |
325 | + /* | |
326 | + const LIB3270_TOGGLE_ENTRY *toggles = lib3270_get_toggle_list(); | |
327 | + for(size_t ix = 0; toggles[ix].name; ix++) { | |
328 | + attributes.push_back(ToggleAttribute(this,&toggles[ix])); | |
329 | + } | |
330 | + */ | |
331 | + | |
332 | + const LIB3270_INT_PROPERTY * intprop = lib3270_get_boolean_properties_list(); | |
333 | + for(size_t ix = 0; intprop[ix].name; ix++) { | |
334 | + attributes.push_back(BooleanAttribute(this,&intprop[ix])); | |
335 | + } | |
336 | + | |
337 | + } | |
338 | + | |
339 | + } | |
340 | + | |
341 | + | |
342 | + | |
343 | + } | |
344 | + | |
345 | + | ... | ... |
client/src/session/remote/private.h
... | ... | @@ -122,6 +122,10 @@ |
122 | 122 | void setAttribute(const char *name, const int value) override; |
123 | 123 | void setAttribute(const char *name, const char *value) override; |
124 | 124 | |
125 | + // Attributes | |
126 | + Attribute getAttribute(const char *name) const override; | |
127 | + void getAttributes(std::vector<Attribute> & attributes) const override; | |
128 | + | |
125 | 129 | std::string getVersion() const override; |
126 | 130 | std::string getRevision() const override; |
127 | 131 | std::string getLUName() const override; | ... | ... |
client/src/testprogram/testprogram.cc