Commit 526082bca9a757859cb61295433c3c7d38b3e6bb
1 parent
2906254b
Exists in
master
and in
1 other branch
Fixing attribute management engine.
Showing
6 changed files
with
266 additions
and
90 deletions
Show diff stats
client/ipcclient.cbp
| ... | ... | @@ -45,6 +45,7 @@ |
| 45 | 45 | <Unit filename="src/core/attribute.cc" /> |
| 46 | 46 | <Unit filename="src/core/constants.cc" /> |
| 47 | 47 | <Unit filename="src/core/events.cc" /> |
| 48 | + <Unit filename="src/core/linux/attribute.cc" /> | |
| 48 | 49 | <Unit filename="src/core/linux/request.cc" /> |
| 49 | 50 | <Unit filename="src/core/session.cc" /> |
| 50 | 51 | <Unit filename="src/core/windows/pop.cc" /> | ... | ... |
client/src/core/attribute.cc
| ... | ... | @@ -47,11 +47,52 @@ |
| 47 | 47 | |
| 48 | 48 | namespace TN3270 { |
| 49 | 49 | |
| 50 | - Attribute::Attribute(H3270 *hSession, Type type, void * worker) { | |
| 50 | + Attribute::Attribute(const Attribute &src) { | |
| 51 | 51 | |
| 52 | - this->hSession = hSession; | |
| 53 | - this->type = type; | |
| 54 | - this->worker = worker; | |
| 52 | + this->type = src.type; | |
| 53 | + this->szData = src.szData; | |
| 54 | + this->get = src.get; | |
| 55 | + this->set = src.set; | |
| 56 | + | |
| 57 | + if(this->szData) { | |
| 58 | + this->data = new uint8_t[this->szData]; | |
| 59 | + memcpy(this->data,src.data,this->szData); | |
| 60 | + } else { | |
| 61 | + this->data = nullptr; | |
| 62 | + } | |
| 63 | + | |
| 64 | + } | |
| 65 | + | |
| 66 | + Attribute::Attribute(const Attribute *src) { | |
| 67 | + | |
| 68 | + this->type = src->type; | |
| 69 | + this->szData = src->szData; | |
| 70 | + | |
| 71 | + this->get = src->get; | |
| 72 | + this->set = src->set; | |
| 73 | + | |
| 74 | + if(this->szData) { | |
| 75 | + this->data = new uint8_t[this->szData]; | |
| 76 | + memcpy(this->data,src->data,this->szData); | |
| 77 | + } else { | |
| 78 | + this->data = nullptr; | |
| 79 | + } | |
| 80 | + | |
| 81 | + } | |
| 82 | + | |
| 83 | + Attribute::Attribute(Type type, size_t szWorker) { | |
| 84 | + | |
| 85 | + this->type = type; | |
| 86 | + this->szData = szWorker; | |
| 87 | + | |
| 88 | + if(this->szData) { | |
| 89 | + this->data = new uint8_t[this->szData]; | |
| 90 | + memset(this->data,0,this->szData); | |
| 91 | + } else { | |
| 92 | + this->data = nullptr; | |
| 93 | + } | |
| 94 | + | |
| 95 | + debug("worker=",((void *) this->data)," length=",szWorker); | |
| 55 | 96 | |
| 56 | 97 | get.name = [](const void *worker) { |
| 57 | 98 | return "unnamed"; |
| ... | ... | @@ -95,6 +136,11 @@ |
| 95 | 136 | } |
| 96 | 137 | |
| 97 | 138 | Attribute::~Attribute() { |
| 139 | + | |
| 140 | + if(data) { | |
| 141 | + delete[] data; | |
| 142 | + } | |
| 143 | + | |
| 98 | 144 | } |
| 99 | 145 | |
| 100 | 146 | } | ... | ... |
| ... | ... | @@ -0,0 +1,74 @@ |
| 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 src/os/linux/attribute.cc | |
| 32 | + * | |
| 33 | + * @brief Implements methods for static attribute management. | |
| 34 | + * | |
| 35 | + * @author perry.werneck@gmail.com | |
| 36 | + * | |
| 37 | + */ | |
| 38 | + | |
| 39 | + #include <lib3270/ipc.h> | |
| 40 | + #include <lib3270/toggle.h> | |
| 41 | + #include <lib3270/properties.h> | |
| 42 | + | |
| 43 | +/*---[ Implement ]----------------------------------------------------------------------------------*/ | |
| 44 | + | |
| 45 | + std::vector<const LIB3270_PROPERTY *> TN3270::getAttributes() noexcept { | |
| 46 | + | |
| 47 | + std::vector<const LIB3270_PROPERTY *> attributes; | |
| 48 | + | |
| 49 | + for(auto prop = lib3270_get_int_properties_list(); prop->name; prop++) { | |
| 50 | + attributes.push_back((const LIB3270_PROPERTY *) prop); | |
| 51 | + } | |
| 52 | + | |
| 53 | + for(auto prop = lib3270_get_unsigned_properties_list(); prop->name; prop++) { | |
| 54 | + attributes.push_back((const LIB3270_PROPERTY *) prop); | |
| 55 | + } | |
| 56 | + | |
| 57 | + for(auto prop = lib3270_get_string_properties_list(); prop->name; prop++) { | |
| 58 | + attributes.push_back((const LIB3270_PROPERTY *) prop); | |
| 59 | + } | |
| 60 | + | |
| 61 | + for(auto prop = lib3270_get_toggle_list(); prop->name; prop++) { | |
| 62 | + attributes.push_back((const LIB3270_PROPERTY *) prop); | |
| 63 | + } | |
| 64 | + | |
| 65 | + for(auto prop = lib3270_get_boolean_properties_list(); prop->name; prop++) { | |
| 66 | + attributes.push_back((const LIB3270_PROPERTY *) prop); | |
| 67 | + } | |
| 68 | + | |
| 69 | + return attributes; | |
| 70 | + | |
| 71 | + } | |
| 72 | + | |
| 73 | + | |
| 74 | + | ... | ... |
client/src/include/lib3270/ipc.h
| ... | ... | @@ -86,6 +86,12 @@ |
| 86 | 86 | */ |
| 87 | 87 | TN3270_PUBLIC const char * getRevision(); |
| 88 | 88 | |
| 89 | + /** | |
| 90 | + * @brief Get list of attributes. | |
| 91 | + * | |
| 92 | + */ | |
| 93 | + TN3270_PUBLIC std::vector<const LIB3270_PROPERTY *> getAttributes() noexcept; | |
| 94 | + | |
| 89 | 95 | class TN3270_PUBLIC Event { |
| 90 | 96 | public: |
| 91 | 97 | |
| ... | ... | @@ -259,14 +265,17 @@ |
| 259 | 265 | Uint64 = 't' |
| 260 | 266 | }; |
| 261 | 267 | |
| 268 | + private: | |
| 262 | 269 | Type type; ///< @brief Data type. |
| 263 | - H3270 * hSession; ///< @brief TN3270 Session which "owns" this attribute. | |
| 264 | - void * worker; ///< @brief Internal worker. | |
| 265 | 270 | |
| 266 | 271 | protected: |
| 267 | 272 | |
| 273 | + size_t szData; | |
| 274 | + uint8_t * data; ///< @brief Internal worker. | |
| 275 | + | |
| 268 | 276 | struct { |
| 269 | 277 | std::function<const char *(const void *worker)> name; |
| 278 | + std::function<const char *(const void *worker)> description; | |
| 270 | 279 | |
| 271 | 280 | std::function <std::string (const Attribute & attr, const void *worker)> asString; |
| 272 | 281 | std::function <int32_t (const Attribute & attr, const void *worker)> asInt32; |
| ... | ... | @@ -281,72 +290,76 @@ |
| 281 | 290 | std::function <void (const Attribute & attr, const void *worker, const bool value)> asBoolean; |
| 282 | 291 | } set; |
| 283 | 292 | |
| 284 | - Attribute(H3270 *hSession, Type type, void * worker); | |
| 293 | + Attribute(Type type, size_t szWorker = 0); | |
| 285 | 294 | |
| 286 | 295 | public: |
| 296 | + | |
| 297 | + Attribute(const Attribute &src); | |
| 298 | + Attribute(const Attribute *src); | |
| 299 | + | |
| 287 | 300 | ~Attribute(); |
| 288 | 301 | |
| 289 | - inline H3270 * getTN3270Session() const { | |
| 290 | - return this->hSession; | |
| 302 | + inline const char * getName() const { | |
| 303 | + return this->get.name(this->data); | |
| 291 | 304 | } |
| 292 | 305 | |
| 293 | - inline const char * getName() const { | |
| 294 | - return this->get.name(this->worker); | |
| 306 | + inline const char * getDescription() const { | |
| 307 | + return this->get.description(this->data); | |
| 295 | 308 | } |
| 296 | 309 | |
| 297 | 310 | inline std::string getString() const { |
| 298 | - return get.asString(*this,worker); | |
| 311 | + return get.asString(*this,data); | |
| 299 | 312 | } |
| 300 | 313 | |
| 301 | 314 | inline int32_t getInt32() const { |
| 302 | - return get.asInt32(*this,worker); | |
| 315 | + return get.asInt32(*this,data); | |
| 303 | 316 | } |
| 304 | 317 | |
| 305 | 318 | inline uint32_t getUint32() const { |
| 306 | - return get.asUint32(*this,worker); | |
| 319 | + return get.asUint32(*this,data); | |
| 307 | 320 | } |
| 308 | 321 | |
| 309 | 322 | inline bool getBoolean() const { |
| 310 | - return get.asBoolean(*this,worker); | |
| 323 | + return get.asBoolean(*this,data); | |
| 311 | 324 | } |
| 312 | 325 | |
| 313 | 326 | inline std::string toString() const { |
| 314 | - return get.asString(*this, worker); | |
| 327 | + return get.asString(*this, data); | |
| 315 | 328 | } |
| 316 | 329 | |
| 317 | 330 | inline void setString(const char * value) { |
| 318 | - set.asString(*this,worker,value); | |
| 331 | + set.asString(*this,data,value); | |
| 319 | 332 | } |
| 320 | 333 | |
| 321 | 334 | inline void setInt32(const int32_t value) { |
| 322 | - set.asInt32(*this,worker,value); | |
| 335 | + set.asInt32(*this,data,value); | |
| 323 | 336 | } |
| 324 | 337 | |
| 325 | 338 | inline void setUint32(const uint32_t value) { |
| 326 | - set.asUint32(*this,worker,value); | |
| 339 | + set.asUint32(*this,data,value); | |
| 327 | 340 | } |
| 328 | 341 | |
| 329 | 342 | inline void setBoolean(const bool value) { |
| 330 | - set.asBoolean(*this,worker,value); | |
| 343 | + set.asBoolean(*this,data,value); | |
| 331 | 344 | } |
| 332 | 345 | |
| 333 | 346 | inline Attribute & operator=(const char * value) { |
| 334 | - set.asString(*this,worker,value); | |
| 347 | + set.asString(*this,data,value); | |
| 335 | 348 | return *this; |
| 336 | 349 | } |
| 337 | 350 | |
| 338 | 351 | inline Attribute & operator=(const int32_t value) { |
| 339 | - set.asInt32(*this,worker,value); | |
| 352 | + set.asInt32(*this,data,value); | |
| 340 | 353 | return *this; |
| 341 | 354 | } |
| 342 | 355 | |
| 343 | 356 | inline Attribute & operator=(const uint32_t value) { |
| 344 | - set.asUint32(*this,worker,value); | |
| 357 | + set.asUint32(*this,data,value); | |
| 345 | 358 | return *this; |
| 346 | 359 | } |
| 347 | 360 | |
| 348 | 361 | inline Attribute & operator=(const bool value) { |
| 349 | - set.asBoolean(*this,worker,value); | |
| 362 | + set.asBoolean(*this,data,value); | |
| 350 | 363 | return *this; |
| 351 | 364 | } |
| 352 | 365 | ... | ... |
client/src/session/local/attribute.cc
| ... | ... | @@ -46,23 +46,57 @@ |
| 46 | 46 | |
| 47 | 47 | namespace TN3270 { |
| 48 | 48 | |
| 49 | - // Signed int attribute | |
| 50 | - class IntAttribute : public Attribute { | |
| 49 | + // Class template | |
| 50 | + template<typename T> | |
| 51 | + class TN3270_PRIVATE TemplateAttribute : public Attribute { | |
| 52 | + protected: | |
| 53 | + | |
| 54 | + struct Worker { | |
| 55 | + H3270 *hSession; | |
| 56 | + const T *methods; | |
| 57 | + }; | |
| 58 | + | |
| 51 | 59 | public: |
| 52 | - IntAttribute(H3270 *hSession, const LIB3270_INT_PROPERTY *worker) : Attribute(hSession, Attribute::Int32, (void *) worker) { | |
| 60 | + | |
| 61 | + TemplateAttribute(H3270 *hSession, Attribute::Type type, const T *methods) : Attribute(type, sizeof(struct Worker)) { | |
| 62 | + | |
| 63 | + getWorker()->hSession = hSession; | |
| 64 | + getWorker()->methods = methods; | |
| 65 | + | |
| 66 | + debug("hSession=",hSession," methods=",methods); | |
| 53 | 67 | |
| 54 | 68 | get.name = [](const void *worker) { |
| 55 | - return ((const LIB3270_INT_PROPERTY *) worker)->name; | |
| 69 | + return ((const struct Worker *) worker)->methods->name; | |
| 56 | 70 | }; |
| 57 | 71 | |
| 72 | + get.description = [](const void *worker) { | |
| 73 | + return ((const struct Worker *) worker)->methods->description; | |
| 74 | + }; | |
| 75 | + | |
| 76 | + } | |
| 77 | + | |
| 78 | + inline struct Worker * getWorker() { | |
| 79 | + return (struct Worker *) this->data; | |
| 80 | + } | |
| 81 | + | |
| 82 | + }; | |
| 83 | + | |
| 84 | + | |
| 85 | + // Signed int attribute | |
| 86 | + class TN3270_PRIVATE IntAttribute : public TemplateAttribute<LIB3270_INT_PROPERTY> { | |
| 87 | + public: | |
| 88 | + IntAttribute(H3270 *hSession, const LIB3270_INT_PROPERTY *worker) : TemplateAttribute<LIB3270_INT_PROPERTY>(hSession, Attribute::Int32, worker) { | |
| 89 | + | |
| 58 | 90 | get.asString = [](const Attribute & attr, const void *worker) { |
| 59 | 91 | return std::to_string(attr.getInt32()); |
| 60 | 92 | }; |
| 61 | 93 | |
| 62 | 94 | get.asInt32 = [](const Attribute & attr, const void *worker) { |
| 63 | 95 | |
| 96 | + const struct Worker * w = (const struct Worker *) worker; | |
| 97 | + | |
| 64 | 98 | errno = 0; |
| 65 | - int value = ((const LIB3270_INT_PROPERTY *) worker)->get(attr.getTN3270Session()); | |
| 99 | + int value = w->methods->get(w->hSession); | |
| 66 | 100 | |
| 67 | 101 | if(errno != 0) { |
| 68 | 102 | throw std::system_error(errno, std::system_category()); |
| ... | ... | @@ -80,19 +114,52 @@ |
| 80 | 114 | return (attr.getInt32() != 0); |
| 81 | 115 | }; |
| 82 | 116 | |
| 117 | + | |
| 83 | 118 | } |
| 84 | 119 | |
| 85 | 120 | }; |
| 86 | 121 | |
| 87 | - // Unsigned int attribute | |
| 88 | - class UnsignedIntAttribute : public Attribute { | |
| 122 | + // Boolean attribute | |
| 123 | + class TN3270_PRIVATE BooleanAttribute : public TemplateAttribute<LIB3270_INT_PROPERTY> { | |
| 89 | 124 | public: |
| 90 | - UnsignedIntAttribute(H3270 *hSession, const LIB3270_UINT_PROPERTY *worker) : Attribute(hSession, Attribute::Uint32, (void *) worker) { | |
| 125 | + BooleanAttribute(H3270 *hSession, const LIB3270_INT_PROPERTY *worker) : TemplateAttribute<LIB3270_INT_PROPERTY>(hSession, Attribute::Boolean, worker) { | |
| 91 | 126 | |
| 92 | - get.name = [](const void *worker) { | |
| 93 | - return ((const LIB3270_UINT_PROPERTY *) worker)->name; | |
| 127 | + get.asString = [](const Attribute & attr, const void *worker) { | |
| 128 | + return attr.getInt32() ? "true" : "false"; | |
| 129 | + }; | |
| 130 | + | |
| 131 | + get.asInt32 = [](const Attribute & attr, const void *worker) { | |
| 132 | + | |
| 133 | + const struct Worker * w = (const struct Worker *) worker; | |
| 134 | + | |
| 135 | + errno = 0; | |
| 136 | + int value = w->methods->get(w->hSession); | |
| 137 | + | |
| 138 | + if(errno != 0) { | |
| 139 | + throw std::system_error(errno, std::system_category()); | |
| 140 | + } | |
| 141 | + | |
| 142 | + return (int32_t) value; | |
| 143 | + | |
| 144 | + }; | |
| 145 | + | |
| 146 | + get.asUint32 = [](const Attribute & attr, const void *worker) { | |
| 147 | + return (uint32_t) attr.getInt32(); | |
| 148 | + }; | |
| 149 | + | |
| 150 | + get.asBoolean = [](const Attribute & attr, const void *worker) { | |
| 151 | + return (attr.getInt32() != 0); | |
| 94 | 152 | }; |
| 95 | 153 | |
| 154 | + | |
| 155 | + } | |
| 156 | + | |
| 157 | + }; | |
| 158 | + | |
| 159 | + class TN3270_PRIVATE UnsignedIntAttribute : public TemplateAttribute<LIB3270_UINT_PROPERTY> { | |
| 160 | + public: | |
| 161 | + UnsignedIntAttribute(H3270 *hSession, const LIB3270_UINT_PROPERTY *worker) : TemplateAttribute<LIB3270_UINT_PROPERTY>(hSession, Attribute::Boolean, worker) { | |
| 162 | + | |
| 96 | 163 | get.asString = [](const Attribute & attr, const void *worker) { |
| 97 | 164 | return std::to_string(attr.getUint32()); |
| 98 | 165 | }; |
| ... | ... | @@ -103,8 +170,10 @@ |
| 103 | 170 | |
| 104 | 171 | get.asUint32 = [](const Attribute & attr, const void *worker) { |
| 105 | 172 | |
| 173 | + const struct Worker * w = (const struct Worker *) worker; | |
| 174 | + | |
| 106 | 175 | errno = 0; |
| 107 | - unsigned int value = ((const LIB3270_UINT_PROPERTY *) worker)->get(attr.getTN3270Session()); | |
| 176 | + unsigned int value = w->methods->get(w->hSession); | |
| 108 | 177 | |
| 109 | 178 | if(errno != 0) { |
| 110 | 179 | throw std::system_error(errno, std::system_category()); |
| ... | ... | @@ -119,33 +188,28 @@ |
| 119 | 188 | }; |
| 120 | 189 | |
| 121 | 190 | } |
| 122 | - | |
| 123 | 191 | }; |
| 124 | 192 | |
| 125 | - // String attribute | |
| 126 | - class StringAttribute : public Attribute { | |
| 193 | + class TN3270_PRIVATE StringAttribute : public TemplateAttribute<LIB3270_STRING_PROPERTY> { | |
| 127 | 194 | public: |
| 128 | - StringAttribute(H3270 *hSession, const LIB3270_STRING_PROPERTY *worker) : Attribute(hSession, Attribute::String, (void *) worker) { | |
| 129 | - | |
| 130 | - get.name = [](const void *worker) { | |
| 131 | - return ((const LIB3270_STRING_PROPERTY *) worker)->name; | |
| 132 | - }; | |
| 195 | + StringAttribute(H3270 *hSession, const LIB3270_STRING_PROPERTY *worker) : TemplateAttribute<LIB3270_STRING_PROPERTY>(hSession, Attribute::String, worker) { | |
| 133 | 196 | |
| 134 | 197 | get.asString = [](const Attribute & attr, const void *worker) { |
| 135 | 198 | |
| 136 | - const char * str = ((const LIB3270_STRING_PROPERTY *) worker)->get(attr.getTN3270Session()); | |
| 199 | + const struct Worker * w = (const struct Worker *) worker; | |
| 200 | + const char * str = w->methods->get(w->hSession); | |
| 137 | 201 | |
| 138 | 202 | if(str) { |
| 139 | 203 | return string(str); |
| 140 | 204 | } |
| 141 | - | |
| 142 | 205 | throw std::system_error(errno, std::system_category()); |
| 143 | 206 | |
| 144 | 207 | }; |
| 145 | 208 | |
| 146 | 209 | get.asInt32 = [](const Attribute & attr, const void *worker) { |
| 147 | 210 | |
| 148 | - const char * str = ((const LIB3270_STRING_PROPERTY *) worker)->get(attr.getTN3270Session()); | |
| 211 | + const struct Worker * w = (const struct Worker *) worker; | |
| 212 | + const char * str = w->methods->get(w->hSession); | |
| 149 | 213 | |
| 150 | 214 | if(str) { |
| 151 | 215 | return (int32_t) atoi(str); |
| ... | ... | @@ -156,17 +220,11 @@ |
| 156 | 220 | |
| 157 | 221 | |
| 158 | 222 | } |
| 159 | - | |
| 160 | 223 | }; |
| 161 | 224 | |
| 162 | - // Boolean attribute | |
| 163 | - class BooleanAttribute : public Attribute { | |
| 225 | + class TN3270_PRIVATE ToggleAttribute : public TemplateAttribute<LIB3270_TOGGLE_ENTRY> { | |
| 164 | 226 | public: |
| 165 | - BooleanAttribute(H3270 *hSession, const LIB3270_INT_PROPERTY *worker) : Attribute(hSession, Attribute::Boolean, (void *) worker) { | |
| 166 | - | |
| 167 | - get.name = [](const void *worker) { | |
| 168 | - return ((const LIB3270_INT_PROPERTY *) worker)->name; | |
| 169 | - }; | |
| 227 | + ToggleAttribute(H3270 *hSession, const LIB3270_TOGGLE_ENTRY *worker) : TemplateAttribute<LIB3270_TOGGLE_ENTRY>(hSession, Attribute::Boolean, worker) { | |
| 170 | 228 | |
| 171 | 229 | get.asString = [](const Attribute & attr, const void *worker) { |
| 172 | 230 | return attr.getBoolean() ? "true" : "false"; |
| ... | ... | @@ -174,39 +232,11 @@ |
| 174 | 232 | |
| 175 | 233 | get.asInt32 = [](const Attribute & attr, const void *worker) { |
| 176 | 234 | |
| 177 | - errno = 0; | |
| 178 | - int value = ((const LIB3270_INT_PROPERTY *) worker)->get(attr.getTN3270Session()); | |
| 179 | - | |
| 180 | - if(errno != 0) { | |
| 181 | - throw std::system_error(errno, std::system_category()); | |
| 182 | - } | |
| 183 | - | |
| 184 | - return (int32_t) value; | |
| 185 | - | |
| 186 | - }; | |
| 187 | - | |
| 188 | - } | |
| 189 | - | |
| 190 | - }; | |
| 191 | - | |
| 192 | - // Toggle attribute | |
| 193 | - class ToggleAttribute : public Attribute { | |
| 194 | - public: | |
| 195 | - ToggleAttribute(H3270 *hSession, const LIB3270_TOGGLE_ENTRY *worker) : Attribute(hSession, Attribute::Boolean, (void *) worker) { | |
| 196 | - | |
| 197 | - get.name = [](const void *worker) { | |
| 198 | - return ((const LIB3270_TOGGLE_ENTRY *) worker)->name; | |
| 199 | - }; | |
| 200 | - | |
| 201 | - get.asString = [](const Attribute & attr, const void *worker) { | |
| 202 | - return attr.getBoolean() ? "true" : "false"; | |
| 203 | - }; | |
| 204 | - | |
| 205 | - get.asInt32 = [](const Attribute & attr, const void *worker) { | |
| 235 | + const struct Worker * w = (const struct Worker *) worker; | |
| 206 | 236 | |
| 207 | 237 | errno = 0; |
| 208 | 238 | |
| 209 | - int value = lib3270_get_toggle(attr.getTN3270Session(),((const LIB3270_TOGGLE_ENTRY *) worker)->id); | |
| 239 | + int value = lib3270_get_toggle(w->hSession,w->methods->id); | |
| 210 | 240 | |
| 211 | 241 | if(errno != 0) { |
| 212 | 242 | throw std::system_error(errno, std::system_category()); |
| ... | ... | @@ -217,15 +247,16 @@ |
| 217 | 247 | }; |
| 218 | 248 | |
| 219 | 249 | set.asInt32 = [](const Attribute & attr, const void *worker, const int32_t value) { |
| 220 | - lib3270_set_toggle(attr.getTN3270Session(),((const LIB3270_TOGGLE_ENTRY *) worker)->id, (int) value); | |
| 250 | + const struct Worker * w = (const struct Worker *) worker; | |
| 251 | + lib3270_set_toggle(w->hSession,w->methods->id, (int) value); | |
| 221 | 252 | }; |
| 222 | 253 | |
| 223 | 254 | set.asBoolean = [](const Attribute & attr, const void *worker, const bool value) { |
| 224 | - lib3270_set_toggle(attr.getTN3270Session(),((const LIB3270_TOGGLE_ENTRY *) worker)->id, (int) value); | |
| 255 | + const struct Worker * w = (const struct Worker *) worker; | |
| 256 | + lib3270_set_toggle(w->hSession,w->methods->id, (int) value); | |
| 225 | 257 | }; |
| 226 | 258 | |
| 227 | 259 | } |
| 228 | - | |
| 229 | 260 | }; |
| 230 | 261 | |
| 231 | 262 | Attribute Local::Session::getAttribute(const char *name) const { | ... | ... |
client/src/testprogram/testprogram.cc
| ... | ... | @@ -39,6 +39,7 @@ |
| 39 | 39 | #include <config.h> |
| 40 | 40 | #include <getopt.h> |
| 41 | 41 | #include <cstdlib> |
| 42 | + #include <lib3270.h> | |
| 42 | 43 | #include <lib3270/ipc.h> |
| 43 | 44 | |
| 44 | 45 | using namespace std; |
| ... | ... | @@ -118,10 +119,11 @@ |
| 118 | 119 | |
| 119 | 120 | cout |
| 120 | 121 | << "Version: " << host["version"] |
| 121 | - << "\tRevision: " << host["Revision"] | |
| 122 | - << "\tConnected: " << host["Connected"] | |
| 122 | +// << "\tRevision: " << host["Revision"] | |
| 123 | +// << "\tConnected: " << host["Connected"] | |
| 123 | 124 | << std::endl; |
| 124 | 125 | |
| 126 | + /* | |
| 125 | 127 | host.connect(nullptr); |
| 126 | 128 | |
| 127 | 129 | cout |
| ... | ... | @@ -152,6 +154,7 @@ |
| 152 | 154 | host.wait(10); |
| 153 | 155 | |
| 154 | 156 | host.disconnect(); |
| 157 | + */ | |
| 155 | 158 | |
| 156 | 159 | } catch(const std::exception &e) { |
| 157 | 160 | |
| ... | ... | @@ -190,9 +193,17 @@ |
| 190 | 193 | |
| 191 | 194 | cout << "Session: " << session << endl; |
| 192 | 195 | |
| 193 | - // testHost(session); | |
| 196 | + //testHost(session); | |
| 194 | 197 | testAttributes(session); |
| 195 | 198 | |
| 199 | + /* | |
| 200 | + for(auto attribute : TN3270::getAttributes()) { | |
| 201 | + | |
| 202 | + cout << attribute->name << ":\t" << attribute->description << endl; | |
| 203 | + | |
| 204 | + } | |
| 205 | + */ | |
| 206 | + | |
| 196 | 207 | return 0; |
| 197 | 208 | } |
| 198 | 209 | ... | ... |