Commit 75c9305c792b1f828519b8b265fe9f4809ac35ee
1 parent
47073ded
Exists in
master
and in
3 other branches
Implementing getters for the C++ base library used for language
bindings.
Showing
6 changed files
with
113 additions
and
10 deletions
Show diff stats
src/include/lib3270++.h
| ... | ... | @@ -213,6 +213,9 @@ |
| 213 | 213 | } |
| 214 | 214 | |
| 215 | 215 | // Get properties. |
| 216 | + virtual void getProperty(const char *name, int &value) const = 0; | |
| 217 | + virtual void getProperty(const char *name, std::string &value) const = 0; | |
| 218 | + | |
| 216 | 219 | virtual std::string getVersion() const = 0; |
| 217 | 220 | virtual std::string getRevision() const = 0; |
| 218 | 221 | ... | ... |
src/lib3270++/ipc/session.cc
| ... | ... | @@ -137,11 +137,19 @@ |
| 137 | 137 | } |
| 138 | 138 | |
| 139 | 139 | ProgramMessage IPC::Session::getProgramMessage() const { |
| 140 | - throw std::system_error(EINVAL, std::system_category()); | |
| 140 | + | |
| 141 | + int program_message; | |
| 142 | + getProperty("program_message",program_message); | |
| 143 | + return (ProgramMessage) program_message; | |
| 144 | + | |
| 141 | 145 | } |
| 142 | 146 | |
| 143 | 147 | ConnectionState IPC::Session::getConnectionState() const { |
| 144 | - throw std::system_error(EINVAL, std::system_category()); | |
| 148 | + | |
| 149 | + int cstate; | |
| 150 | + getProperty("cstate",cstate); | |
| 151 | + return (ConnectionState) cstate; | |
| 152 | + | |
| 145 | 153 | } |
| 146 | 154 | |
| 147 | 155 | /// @brief Set field at current position, jumps to next writable field. |
| ... | ... | @@ -211,21 +219,38 @@ |
| 211 | 219 | |
| 212 | 220 | } |
| 213 | 221 | |
| 222 | + void IPC::Session::getProperty(const char *name, int &value) const { | |
| 223 | + | |
| 224 | + Request(*this,false,name) | |
| 225 | + .call() | |
| 226 | + .pop(value); | |
| 227 | + | |
| 228 | + } | |
| 229 | + | |
| 230 | + void IPC::Session::getProperty(const char *name, std::string &value) const { | |
| 231 | + | |
| 232 | + Request(*this,false,name) | |
| 233 | + .call() | |
| 234 | + .pop(value); | |
| 235 | + | |
| 236 | + } | |
| 237 | + | |
| 214 | 238 | /// @brief Get lib3270 version. |
| 215 | 239 | std::string IPC::Session::getVersion() const { |
| 216 | 240 | |
| 217 | 241 | string rc; |
| 218 | - | |
| 219 | - Request request{*this,false,"version"}; | |
| 220 | - request.call().pop(rc); | |
| 221 | - | |
| 242 | + getProperty("version",rc); | |
| 222 | 243 | return rc; |
| 244 | + | |
| 223 | 245 | } |
| 224 | 246 | |
| 225 | 247 | /// @brief Get lib3270 revision. |
| 226 | 248 | std::string IPC::Session::getRevision() const { |
| 227 | - throw std::system_error(ENOTSUP, std::system_category()); | |
| 228 | - return ""; | |
| 249 | + | |
| 250 | + string rc; | |
| 251 | + getProperty("revision",rc); | |
| 252 | + return rc; | |
| 253 | + | |
| 229 | 254 | } |
| 230 | 255 | |
| 231 | 256 | } | ... | ... |
src/lib3270++/linux/request.cc
| ... | ... | @@ -177,6 +177,8 @@ |
| 177 | 177 | |
| 178 | 178 | } |
| 179 | 179 | |
| 180 | + dbus_message_iter_next(&msg.iter); | |
| 181 | + | |
| 180 | 182 | value.assign(str); |
| 181 | 183 | |
| 182 | 184 | debug(__FUNCTION__,"= \"",str,"\""); |
| ... | ... | @@ -184,6 +186,60 @@ |
| 184 | 186 | return *this; |
| 185 | 187 | } |
| 186 | 188 | |
| 189 | + static int getIntValue(DBusMessageIter &iter) { | |
| 190 | + | |
| 191 | + if(dbus_message_iter_get_arg_type(&iter) == DBUS_TYPE_INT32) { | |
| 192 | + | |
| 193 | + dbus_int32_t rc = 0; | |
| 194 | + dbus_message_iter_get_basic(&iter, &rc); | |
| 195 | + return (int) rc; | |
| 196 | + | |
| 197 | + } else if(dbus_message_iter_get_arg_type(&iter) == DBUS_TYPE_INT16) { | |
| 198 | + | |
| 199 | + dbus_int16_t rc = 0; | |
| 200 | + dbus_message_iter_get_basic(&iter, &rc); | |
| 201 | + return (int) rc; | |
| 202 | + | |
| 203 | + } else if(dbus_message_iter_get_arg_type(&iter) == DBUS_TYPE_VARIANT) { | |
| 204 | + | |
| 205 | + DBusMessageIter sub; | |
| 206 | + int current_type; | |
| 207 | + | |
| 208 | + dbus_message_iter_recurse(&iter, &sub); | |
| 209 | + | |
| 210 | + while ((current_type = dbus_message_iter_get_arg_type(&sub)) != DBUS_TYPE_INVALID) { | |
| 211 | + | |
| 212 | + if (current_type == DBUS_TYPE_INT32) { | |
| 213 | + | |
| 214 | + dbus_int32_t rc = 0; | |
| 215 | + dbus_message_iter_get_basic(&sub, &rc); | |
| 216 | + return (int) rc; | |
| 217 | + | |
| 218 | + } else if (current_type == DBUS_TYPE_INT16) { | |
| 219 | + dbus_int16_t rc = 0; | |
| 220 | + dbus_message_iter_get_basic(&sub, &rc); | |
| 221 | + return (int) rc; | |
| 222 | + | |
| 223 | + } | |
| 224 | + dbus_message_iter_next(&sub); | |
| 225 | + } | |
| 226 | + | |
| 227 | + } | |
| 228 | + | |
| 229 | + debug("Argument type is ", ((char) dbus_message_iter_get_arg_type(&iter)) ); | |
| 230 | + throw std::runtime_error("Expected an integer data type"); | |
| 231 | + | |
| 232 | + } | |
| 233 | + | |
| 234 | + IPC::Request & IPC::Request::Request::pop(int &value) { | |
| 235 | + | |
| 236 | + value = getIntValue(msg.iter); | |
| 237 | + dbus_message_iter_next(&msg.iter); | |
| 238 | + debug(__FUNCTION__,"= \"",value,"\""); | |
| 239 | + | |
| 240 | + return *this; | |
| 241 | + | |
| 242 | + } | |
| 187 | 243 | |
| 188 | 244 | } |
| 189 | 245 | ... | ... |
src/lib3270++/local/session.cc
| ... | ... | @@ -148,6 +148,14 @@ |
| 148 | 148 | return rc; |
| 149 | 149 | } |
| 150 | 150 | |
| 151 | + void Local::Session::getProperty(const char *name, int &value) const { | |
| 152 | + throw std::system_error(ENOTSUP, std::system_category()); | |
| 153 | + } | |
| 154 | + | |
| 155 | + void Local::Session::getProperty(const char *name, std::string &value) const { | |
| 156 | + throw std::system_error(ENOTSUP, std::system_category()); | |
| 157 | + } | |
| 158 | + | |
| 151 | 159 | ProgramMessage Local::Session::getProgramMessage() const { |
| 152 | 160 | std::lock_guard<std::mutex> lock(const_cast<Local::Session *>(this)->sync); |
| 153 | 161 | return (ProgramMessage) lib3270_get_program_message(this->hSession); | ... | ... |
src/lib3270++/private.h
| ... | ... | @@ -177,6 +177,9 @@ |
| 177 | 177 | void waitForReady(time_t timeout = 5) throw() override; |
| 178 | 178 | |
| 179 | 179 | // Get properties. |
| 180 | + void getProperty(const char *name, int &value) const override; | |
| 181 | + void getProperty(const char *name, std::string &value) const override; | |
| 182 | + | |
| 180 | 183 | std::string getVersion() const override; |
| 181 | 184 | std::string getRevision() const override; |
| 182 | 185 | |
| ... | ... | @@ -270,8 +273,8 @@ |
| 270 | 273 | Request & push(const char *arg); |
| 271 | 274 | |
| 272 | 275 | // Pop values |
| 273 | - | |
| 274 | 276 | Request & pop(std::string &value); |
| 277 | + Request & pop(int &value); | |
| 275 | 278 | |
| 276 | 279 | }; |
| 277 | 280 | |
| ... | ... | @@ -307,6 +310,9 @@ |
| 307 | 310 | void waitForReady(time_t timeout = 5) throw() override; |
| 308 | 311 | |
| 309 | 312 | // Get properties. |
| 313 | + void getProperty(const char *name, int &value) const override; | |
| 314 | + void getProperty(const char *name, std::string &value) const override; | |
| 315 | + | |
| 310 | 316 | std::string getVersion() const override; |
| 311 | 317 | std::string getRevision() const override; |
| 312 | 318 | ... | ... |
src/lib3270++/testprogram/testprogram.cc
| ... | ... | @@ -49,7 +49,12 @@ |
| 49 | 49 | |
| 50 | 50 | cout |
| 51 | 51 | << "Version: " << host.getVersion() |
| 52 | -// << " Revision: " << host.getRevision() | |
| 52 | + << "\tRevision: " << host.getRevision() | |
| 53 | + << std::endl; | |
| 54 | + | |
| 55 | + cout | |
| 56 | + << "Connection state is " << host.getConnectionState() | |
| 57 | + << "\tProgram message is " << host.getProgramMessage() | |
| 53 | 58 | << std::endl; |
| 54 | 59 | |
| 55 | 60 | // host.connect(getenv("LIB3270_DEFAULT_HOST")); | ... | ... |