Commit f6378bbec50d81d7eea4bac5a0051bef21122676
1 parent
653a7cdc
Exists in
master
and in
1 other branch
Working on dynamic typed attributes.
Showing
4 changed files
with
83 additions
and
37 deletions
Show diff stats
client/src/core/attribute.cc
| @@ -72,28 +72,25 @@ | @@ -72,28 +72,25 @@ | ||
| 72 | return (bool) attr.get.asInt32(attr, worker) != 0; | 72 | return (bool) attr.get.asInt32(attr, worker) != 0; |
| 73 | }; | 73 | }; |
| 74 | 74 | ||
| 75 | - } | 75 | + set.asString = [](const Attribute & attr, const void *worker, const char *value) { |
| 76 | + throw std::system_error(ENOTSUP, std::system_category()); | ||
| 77 | + }; | ||
| 76 | 78 | ||
| 77 | - Attribute::~Attribute() { | ||
| 78 | - } | 79 | + set.asInt32 = [](const Attribute & attr, const void *worker, const int32_t value) { |
| 80 | + throw std::system_error(ENOTSUP, std::system_category()); | ||
| 81 | + }; | ||
| 79 | 82 | ||
| 80 | - /* | ||
| 81 | - std::string Attribute::getString() const { | ||
| 82 | - printf("*************** %s\n",__FUNCTION__); | ||
| 83 | - throw std::system_error(ENOTSUP, std::system_category()); | ||
| 84 | - } | 83 | + set.asUint32 = [](const Attribute & attr, const void *worker, const uint32_t value) { |
| 84 | + attr.set.asInt32(attr,worker,(int32_t) value); | ||
| 85 | + }; | ||
| 85 | 86 | ||
| 86 | - int32_t Attribute::getInt32() const { | ||
| 87 | - throw std::system_error(ENOTSUP, std::system_category()); | ||
| 88 | - } | 87 | + set.asBoolean = [](const Attribute & attr, const void *worker, const bool value) { |
| 88 | + attr.set.asInt32(attr,worker,(int32_t) value); | ||
| 89 | + }; | ||
| 89 | 90 | ||
| 90 | - uint32_t Attribute::getUint32() const { | ||
| 91 | - throw std::system_error(ENOTSUP, std::system_category()); | ||
| 92 | } | 91 | } |
| 93 | 92 | ||
| 94 | - bool Attribute::getBool() const { | ||
| 95 | - throw std::system_error(ENOTSUP, std::system_category()); | 93 | + Attribute::~Attribute() { |
| 96 | } | 94 | } |
| 97 | - */ | ||
| 98 | 95 | ||
| 99 | } | 96 | } |
client/src/include/lib3270/ipc.h
| @@ -272,12 +272,19 @@ | @@ -272,12 +272,19 @@ | ||
| 272 | std::function <bool (const Attribute & attr, const void *worker)> asBoolean; | 272 | std::function <bool (const Attribute & attr, const void *worker)> asBoolean; |
| 273 | } get; | 273 | } get; |
| 274 | 274 | ||
| 275 | + struct { | ||
| 276 | + std::function <void (const Attribute & attr, const void *worker, const char *value)> asString; | ||
| 277 | + std::function <void (const Attribute & attr, const void *worker, const int32_t value)> asInt32; | ||
| 278 | + std::function <void (const Attribute & attr, const void *worker, const uint32_t value)> asUint32; | ||
| 279 | + std::function <void (const Attribute & attr, const void *worker, const bool value)> asBoolean; | ||
| 280 | + } set; | ||
| 281 | + | ||
| 275 | Attribute(H3270 *hSession, Type type, void * worker); | 282 | Attribute(H3270 *hSession, Type type, void * worker); |
| 276 | 283 | ||
| 277 | public: | 284 | public: |
| 278 | ~Attribute(); | 285 | ~Attribute(); |
| 279 | 286 | ||
| 280 | - inline const H3270 * getTN3270Session() const { | 287 | + inline H3270 * getTN3270Session() const { |
| 281 | return this->hSession; | 288 | return this->hSession; |
| 282 | } | 289 | } |
| 283 | 290 | ||
| @@ -301,6 +308,42 @@ | @@ -301,6 +308,42 @@ | ||
| 301 | return get.asString(*this, worker); | 308 | return get.asString(*this, worker); |
| 302 | } | 309 | } |
| 303 | 310 | ||
| 311 | + inline void setString(const char * value) { | ||
| 312 | + set.asString(*this,worker,value); | ||
| 313 | + } | ||
| 314 | + | ||
| 315 | + inline void setInt32(const int32_t value) { | ||
| 316 | + set.asInt32(*this,worker,value); | ||
| 317 | + } | ||
| 318 | + | ||
| 319 | + inline void setUint32(const uint32_t value) { | ||
| 320 | + set.asUint32(*this,worker,value); | ||
| 321 | + } | ||
| 322 | + | ||
| 323 | + inline void setBoolean(const bool value) { | ||
| 324 | + set.asBoolean(*this,worker,value); | ||
| 325 | + } | ||
| 326 | + | ||
| 327 | + inline Attribute & operator=(const char * value) { | ||
| 328 | + set.asString(*this,worker,value); | ||
| 329 | + return *this; | ||
| 330 | + } | ||
| 331 | + | ||
| 332 | + inline Attribute & operator=(const int32_t value) { | ||
| 333 | + set.asInt32(*this,worker,value); | ||
| 334 | + return *this; | ||
| 335 | + } | ||
| 336 | + | ||
| 337 | + inline Attribute & operator=(const uint32_t value) { | ||
| 338 | + set.asUint32(*this,worker,value); | ||
| 339 | + return *this; | ||
| 340 | + } | ||
| 341 | + | ||
| 342 | + inline Attribute & operator=(const bool value) { | ||
| 343 | + set.asBoolean(*this,worker,value); | ||
| 344 | + return *this; | ||
| 345 | + } | ||
| 346 | + | ||
| 304 | inline bool operator==(Type type) const noexcept { | 347 | inline bool operator==(Type type) const noexcept { |
| 305 | return this->type == type; | 348 | return this->type == type; |
| 306 | } | 349 | } |
client/src/session/local/attribute.cc
| @@ -173,31 +173,40 @@ | @@ -173,31 +173,40 @@ | ||
| 173 | 173 | ||
| 174 | } | 174 | } |
| 175 | 175 | ||
| 176 | - /* | ||
| 177 | - std::string getString() const override { | ||
| 178 | - } | 176 | + }; |
| 179 | 177 | ||
| 180 | - int32_t getInt32() const override { | 178 | + // Toggle attribute |
| 179 | + class ToggleAttribute : public Attribute { | ||
| 180 | + public: | ||
| 181 | + ToggleAttribute(H3270 *hSession, const LIB3270_TOGGLE_ENTRY *worker) : Attribute(hSession, Attribute::Boolean, (void *) worker) { | ||
| 181 | 182 | ||
| 182 | - errno = 0; | ||
| 183 | - int value = ((const LIB3270_INT_PROPERTY *) worker)->get(hSession); | 183 | + get.asString = [](const Attribute & attr, const void *worker) { |
| 184 | + return attr.getBoolean() ? "true" : "false"; | ||
| 185 | + }; | ||
| 184 | 186 | ||
| 185 | - if(errno != 0) { | ||
| 186 | - throw std::system_error(errno, std::system_category()); | ||
| 187 | - } | 187 | + get.asInt32 = [](const Attribute & attr, const void *worker) { |
| 188 | 188 | ||
| 189 | - return ((int32_t) value) != 0; | 189 | + errno = 0; |
| 190 | 190 | ||
| 191 | - } | 191 | + int value = lib3270_get_toggle(attr.getTN3270Session(),((const LIB3270_TOGGLE_ENTRY *) worker)->id); |
| 192 | 192 | ||
| 193 | - uint32_t getUint32() const override { | ||
| 194 | - return (uint32_t) descriptor->get(this->hSession); | ||
| 195 | - } | 193 | + if(errno != 0) { |
| 194 | + throw std::system_error(errno, std::system_category()); | ||
| 195 | + } | ||
| 196 | + | ||
| 197 | + return (int32_t) value; | ||
| 198 | + | ||
| 199 | + }; | ||
| 200 | + | ||
| 201 | + set.asInt32 = [](const Attribute & attr, const void *worker, const int32_t value) { | ||
| 202 | + lib3270_set_toggle(attr.getTN3270Session(),((const LIB3270_TOGGLE_ENTRY *) worker)->id, (int) value); | ||
| 203 | + }; | ||
| 204 | + | ||
| 205 | + set.asBoolean = [](const Attribute & attr, const void *worker, const bool value) { | ||
| 206 | + lib3270_set_toggle(attr.getTN3270Session(),((const LIB3270_TOGGLE_ENTRY *) worker)->id, (int) value); | ||
| 207 | + }; | ||
| 196 | 208 | ||
| 197 | - bool getBool() const override { | ||
| 198 | - return getInt32() != 0; | ||
| 199 | } | 209 | } |
| 200 | - */ | ||
| 201 | 210 | ||
| 202 | }; | 211 | }; |
| 203 | 212 |
client/src/testprogram/testprogram.cc
| @@ -98,7 +98,6 @@ | @@ -98,7 +98,6 @@ | ||
| 98 | << "\tConnected: " << host["Connected"] | 98 | << "\tConnected: " << host["Connected"] |
| 99 | << std::endl; | 99 | << std::endl; |
| 100 | 100 | ||
| 101 | - /* | ||
| 102 | host.connect(nullptr); | 101 | host.connect(nullptr); |
| 103 | 102 | ||
| 104 | cout | 103 | cout |
| @@ -130,8 +129,6 @@ | @@ -130,8 +129,6 @@ | ||
| 130 | 129 | ||
| 131 | host.disconnect(); | 130 | host.disconnect(); |
| 132 | 131 | ||
| 133 | - */ | ||
| 134 | - | ||
| 135 | } catch(const std::exception &e) { | 132 | } catch(const std::exception &e) { |
| 136 | 133 | ||
| 137 | cerr << std::endl << e.what() << std::endl << std::endl; | 134 | cerr << std::endl << e.what() << std::endl << std::endl; |