Commit 19d4f4f6cc5e73d4899805ce546b9db2eae34289
1 parent
75c9305c
Exists in
master
and in
3 other branches
Updating properties and getter/setter c++ methods.
Showing
6 changed files
with
83 additions
and
4 deletions
Show diff stats
src/include/lib3270++.h
| ... | ... | @@ -215,6 +215,7 @@ |
| 215 | 215 | // Get properties. |
| 216 | 216 | virtual void getProperty(const char *name, int &value) const = 0; |
| 217 | 217 | virtual void getProperty(const char *name, std::string &value) const = 0; |
| 218 | + virtual void getProperty(const char *name, bool &value) const = 0; | |
| 218 | 219 | |
| 219 | 220 | virtual std::string getVersion() const = 0; |
| 220 | 221 | virtual std::string getRevision() const = 0; | ... | ... |
src/lib3270++/ipc/session.cc
| ... | ... | @@ -235,6 +235,10 @@ |
| 235 | 235 | |
| 236 | 236 | } |
| 237 | 237 | |
| 238 | + void IPC::Session::getProperty(const char *name, bool &value) const { | |
| 239 | + throw std::system_error(ENOENT, std::system_category()); | |
| 240 | + } | |
| 241 | + | |
| 238 | 242 | /// @brief Get lib3270 version. |
| 239 | 243 | std::string IPC::Session::getVersion() const { |
| 240 | 244 | ... | ... |
src/lib3270++/local/session.cc
| ... | ... | @@ -38,9 +38,10 @@ |
| 38 | 38 | |
| 39 | 39 | #include "../private.h" |
| 40 | 40 | #include <lib3270/actions.h> |
| 41 | + #include <lib3270/properties.h> | |
| 42 | + #include <cstring> | |
| 41 | 43 | |
| 42 | 44 | extern "C" { |
| 43 | - #include <lib3270/actions.h> | |
| 44 | 45 | #include <lib3270/session.h> |
| 45 | 46 | } |
| 46 | 47 | |
| ... | ... | @@ -149,11 +150,68 @@ |
| 149 | 150 | } |
| 150 | 151 | |
| 151 | 152 | void Local::Session::getProperty(const char *name, int &value) const { |
| 152 | - throw std::system_error(ENOTSUP, std::system_category()); | |
| 153 | + | |
| 154 | + const LIB3270_INT_PROPERTY * intprop = lib3270_get_int_properties_list(); | |
| 155 | + for(size_t ix = 0; intprop[ix].name; ix++) { | |
| 156 | + | |
| 157 | + if(!strcasecmp(name,intprop[ix].name)) { | |
| 158 | + | |
| 159 | + std::lock_guard<std::mutex> lock(const_cast<Local::Session *>(this)->sync); | |
| 160 | + | |
| 161 | + value = intprop[ix].get(hSession); | |
| 162 | + | |
| 163 | + if(value < 0 && errno != 0) { | |
| 164 | + throw std::system_error(errno, std::system_category()); | |
| 165 | + } | |
| 166 | + | |
| 167 | + | |
| 168 | + } | |
| 169 | + | |
| 170 | + } | |
| 171 | + | |
| 172 | + throw std::system_error(ENOENT, std::system_category()); | |
| 173 | + | |
| 153 | 174 | } |
| 154 | 175 | |
| 155 | 176 | void Local::Session::getProperty(const char *name, std::string &value) const { |
| 156 | - throw std::system_error(ENOTSUP, std::system_category()); | |
| 177 | + | |
| 178 | + const LIB3270_STRING_PROPERTY * strprop = lib3270_get_string_properties_list(); | |
| 179 | + | |
| 180 | + for(size_t ix = 0; strprop[ix].name; ix++) { | |
| 181 | + | |
| 182 | + if(!strcasecmp(name,strprop[ix].name)) { | |
| 183 | + | |
| 184 | + std::lock_guard<std::mutex> lock(const_cast<Local::Session *>(this)->sync); | |
| 185 | + | |
| 186 | + // Found it! | |
| 187 | + const char * str = strprop[ix].get(hSession); | |
| 188 | + | |
| 189 | + if(str) { | |
| 190 | + value.assign(str); | |
| 191 | + return; | |
| 192 | + } | |
| 193 | + | |
| 194 | + throw std::system_error(errno, std::system_category()); | |
| 195 | + | |
| 196 | + } | |
| 197 | + | |
| 198 | + } | |
| 199 | + | |
| 200 | + throw std::system_error(ENOENT, std::system_category()); | |
| 201 | + } | |
| 202 | + | |
| 203 | + void Local::Session::getProperty(const char *name, bool &value) const { | |
| 204 | + | |
| 205 | + LIB3270_TOGGLE toggle = lib3270_get_toggle_id(name); | |
| 206 | + if(toggle != (LIB3270_TOGGLE) -1) { | |
| 207 | + | |
| 208 | + // Is a Tn3270 toggle, get it! | |
| 209 | + std::lock_guard<std::mutex> lock(const_cast<Local::Session *>(this)->sync); | |
| 210 | + value = lib3270_get_toggle(hSession,toggle); | |
| 211 | + | |
| 212 | + } | |
| 213 | + | |
| 214 | + throw std::system_error(ENOENT, std::system_category()); | |
| 157 | 215 | } |
| 158 | 216 | |
| 159 | 217 | ProgramMessage Local::Session::getProgramMessage() const { | ... | ... |
src/lib3270++/private.h
| ... | ... | @@ -179,6 +179,7 @@ |
| 179 | 179 | // Get properties. |
| 180 | 180 | void getProperty(const char *name, int &value) const override; |
| 181 | 181 | void getProperty(const char *name, std::string &value) const override; |
| 182 | + void getProperty(const char *name, bool &value) const override; | |
| 182 | 183 | |
| 183 | 184 | std::string getVersion() const override; |
| 184 | 185 | std::string getRevision() const override; |
| ... | ... | @@ -312,6 +313,7 @@ |
| 312 | 313 | // Get properties. |
| 313 | 314 | void getProperty(const char *name, int &value) const override; |
| 314 | 315 | void getProperty(const char *name, std::string &value) const override; |
| 316 | + void getProperty(const char *name, bool &value) const override; | |
| 315 | 317 | |
| 316 | 318 | std::string getVersion() const override; |
| 317 | 319 | std::string getRevision() const override; | ... | ... |
src/lib3270++/testprogram/testprogram.cc
src/lib3270/properties.c
| ... | ... | @@ -297,6 +297,20 @@ |
| 297 | 297 | NULL // Set value. |
| 298 | 298 | }, |
| 299 | 299 | |
| 300 | + { | |
| 301 | + "version", // Property name. | |
| 302 | + N_( "lib3270 version" ), // Property description. | |
| 303 | + lib3270_get_version, // Get value. | |
| 304 | + NULL // Set value. | |
| 305 | + }, | |
| 306 | + | |
| 307 | + { | |
| 308 | + "revision", // Property name. | |
| 309 | + N_( "lib3270 revision" ), // Property description. | |
| 310 | + lib3270_get_revision, // Get value. | |
| 311 | + NULL // Set value. | |
| 312 | + }, | |
| 313 | + | |
| 300 | 314 | /* |
| 301 | 315 | { |
| 302 | 316 | "", // Property name. | ... | ... |