Commit 2906254bbf400c7b9201da953df9a7d35d129cf7

Authored by Perry Werneck
1 parent 63058b28
Exists in master and in 1 other branch develop

Adding methods to get the list of properties.

client/src/core/attribute.cc
... ... @@ -53,6 +53,10 @@
53 53 this->type = type;
54 54 this->worker = worker;
55 55  
  56 + get.name = [](const void *worker) {
  57 + return "unnamed";
  58 + };
  59 +
56 60 get.asString = [](const Attribute &attr, const void *worker) {
57 61  
58 62 throw std::system_error(ENOTSUP, std::system_category());
... ...
client/src/core/session.cc
... ... @@ -413,10 +413,16 @@
413 413 throw std::system_error(ENOTSUP, std::system_category());
414 414 }
415 415  
416   - void Session::getAttributes(std::vector<Attribute> attributes) const {
  416 + void Session::getAttributes(std::vector<Attribute> & attributes) const {
417 417 throw std::system_error(ENOTSUP, std::system_category());
418 418 }
419 419  
  420 + std::vector<Attribute> Session::getAttributes() const {
  421 + std::vector<Attribute> attributes;
  422 + this->getAttributes(attributes);
  423 + return attributes;
  424 + }
  425 +
420 426 void Session::getAttribute(const char *name, int &value) const {
421 427 value = getAttribute(name).getInt32();
422 428 }
... ...
client/src/host/properties.cc
... ... @@ -48,3 +48,14 @@ TN3270::Attribute TN3270::Host::getAttribute(const char *name) const {
48 48 return this->session->getAttribute(name);
49 49  
50 50 }
  51 +
  52 +std::vector<TN3270::Attribute> TN3270::Host::getAttributes() const {
  53 +
  54 + if(!this->session)
  55 + throw std::system_error(ENODATA, std::system_category());
  56 +
  57 + return this->session->getAttributes();
  58 +
  59 +}
  60 +
  61 +
... ...
client/src/include/lib3270/ipc.h
... ... @@ -266,6 +266,8 @@
266 266 protected:
267 267  
268 268 struct {
  269 + std::function<const char *(const void *worker)> name;
  270 +
269 271 std::function <std::string (const Attribute & attr, const void *worker)> asString;
270 272 std::function <int32_t (const Attribute & attr, const void *worker)> asInt32;
271 273 std::function <uint32_t (const Attribute & attr, const void *worker)> asUint32;
... ... @@ -288,6 +290,10 @@
288 290 return this->hSession;
289 291 }
290 292  
  293 + inline const char * getName() const {
  294 + return this->get.name(this->worker);
  295 + }
  296 +
291 297 inline std::string getString() const {
292 298 return get.asString(*this,worker);
293 299 }
... ... @@ -470,7 +476,8 @@
470 476  
471 477 // Attributes
472 478 virtual Attribute getAttribute(const char *name) const;
473   - virtual void getAttributes(std::vector<Attribute> attributes) const;
  479 + virtual void getAttributes(std::vector<Attribute> & attributes) const;
  480 + std::vector<Attribute> getAttributes() const;
474 481  
475 482 virtual void getAttribute(const char *name, int &value) const;
476 483 virtual void getAttribute(const char *name, unsigned int &value) const;
... ... @@ -705,6 +712,7 @@
705 712  
706 713 // Get properties
707 714 Attribute getAttribute(const char *name) const;
  715 + std::vector<Attribute> getAttributes() const;
708 716  
709 717 inline Attribute operator[](const char *name) const {
710 718 return getAttribute(name);
... ...
client/src/session/local/attribute.cc
... ... @@ -51,6 +51,10 @@
51 51 public:
52 52 IntAttribute(H3270 *hSession, const LIB3270_INT_PROPERTY *worker) : Attribute(hSession, Attribute::Int32, (void *) worker) {
53 53  
  54 + get.name = [](const void *worker) {
  55 + return ((const LIB3270_INT_PROPERTY *) worker)->name;
  56 + };
  57 +
54 58 get.asString = [](const Attribute & attr, const void *worker) {
55 59 return std::to_string(attr.getInt32());
56 60 };
... ... @@ -85,6 +89,10 @@
85 89 public:
86 90 UnsignedIntAttribute(H3270 *hSession, const LIB3270_UINT_PROPERTY *worker) : Attribute(hSession, Attribute::Uint32, (void *) worker) {
87 91  
  92 + get.name = [](const void *worker) {
  93 + return ((const LIB3270_UINT_PROPERTY *) worker)->name;
  94 + };
  95 +
88 96 get.asString = [](const Attribute & attr, const void *worker) {
89 97 return std::to_string(attr.getUint32());
90 98 };
... ... @@ -119,6 +127,10 @@
119 127 public:
120 128 StringAttribute(H3270 *hSession, const LIB3270_STRING_PROPERTY *worker) : Attribute(hSession, Attribute::String, (void *) worker) {
121 129  
  130 + get.name = [](const void *worker) {
  131 + return ((const LIB3270_STRING_PROPERTY *) worker)->name;
  132 + };
  133 +
122 134 get.asString = [](const Attribute & attr, const void *worker) {
123 135  
124 136 const char * str = ((const LIB3270_STRING_PROPERTY *) worker)->get(attr.getTN3270Session());
... ... @@ -152,6 +164,10 @@
152 164 public:
153 165 BooleanAttribute(H3270 *hSession, const LIB3270_INT_PROPERTY *worker) : Attribute(hSession, Attribute::Boolean, (void *) worker) {
154 166  
  167 + get.name = [](const void *worker) {
  168 + return ((const LIB3270_INT_PROPERTY *) worker)->name;
  169 + };
  170 +
155 171 get.asString = [](const Attribute & attr, const void *worker) {
156 172 return attr.getBoolean() ? "true" : "false";
157 173 };
... ... @@ -178,6 +194,10 @@
178 194 public:
179 195 ToggleAttribute(H3270 *hSession, const LIB3270_TOGGLE_ENTRY *worker) : Attribute(hSession, Attribute::Boolean, (void *) worker) {
180 196  
  197 + get.name = [](const void *worker) {
  198 + return ((const LIB3270_TOGGLE_ENTRY *) worker)->name;
  199 + };
  200 +
181 201 get.asString = [](const Attribute & attr, const void *worker) {
182 202 return attr.getBoolean() ? "true" : "false";
183 203 };
... ... @@ -278,7 +298,7 @@
278 298  
279 299 }
280 300  
281   - void Local::Session::getAttributes(std::vector<Attribute> attributes) const {
  301 + void Local::Session::getAttributes(std::vector<Attribute> & attributes) const {
282 302  
283 303 std::lock_guard<std::mutex> lock(const_cast<Local::Session *>(this)->sync);
284 304  
... ...
client/src/session/local/private.h
... ... @@ -114,7 +114,7 @@
114 114  
115 115 // Attributes
116 116 Attribute getAttribute(const char *name) const override;
117   - void getAttributes(std::vector<Attribute> attributes) const override;
  117 + void getAttributes(std::vector<Attribute> & attributes) const override;
118 118  
119 119 std::string getVersion() const override;
120 120 std::string getRevision() const override;
... ...
client/src/testprogram/testprogram.cc
... ... @@ -85,6 +85,30 @@
85 85 }
86 86 */
87 87  
  88 + // Test Attributes
  89 + static void testAttributes(const char *session) {
  90 +
  91 + TN3270::Host host{session,nullptr,10};
  92 +
  93 + for(auto attribute : host.getAttributes()) {
  94 +
  95 + cout << attribute.getName() << ":\t";
  96 +
  97 + try {
  98 +
  99 + cout << attribute.toString();
  100 +
  101 + } catch(const std::exception &e) {
  102 +
  103 + cout << e.what();
  104 + }
  105 +
  106 + cout << endl;
  107 +
  108 + }
  109 +
  110 + }
  111 +
88 112 // test host object
89 113 static void testHost(const char *session) {
90 114  
... ... @@ -166,7 +190,8 @@
166 190  
167 191 cout << "Session: " << session << endl;
168 192  
169   - testHost(session);
  193 + // testHost(session);
  194 + testAttributes(session);
170 195  
171 196 return 0;
172 197 }
... ...