Commit e815434fbe361bcc2d8bec1e045723680da1abb1
1 parent
7154cff7
Exists in
master
and in
3 other branches
Implementing new IPC API.
Showing
4 changed files
with
53 additions
and
28 deletions
Show diff stats
src/include/lib3270++.h
| ... | ... | @@ -262,6 +262,11 @@ |
| 262 | 262 | /// @brief Insert event listener. |
| 263 | 263 | void insert(Event::Type type, std::function <void(const Event &event)> listener); |
| 264 | 264 | |
| 265 | + // Misc | |
| 266 | + | |
| 267 | + /// @brief Execute action by name. | |
| 268 | + virtual Session & action(const char *action_name) = 0; | |
| 269 | + | |
| 265 | 270 | }; |
| 266 | 271 | |
| 267 | 272 | /// @brief TN3270 Host | ... | ... |
src/lib3270++/ipc/session.cc
| ... | ... | @@ -224,21 +224,11 @@ |
| 224 | 224 | "eraseinput" |
| 225 | 225 | }; |
| 226 | 226 | |
| 227 | - int32_t rc; | |
| 228 | - | |
| 229 | 227 | if( ((size_t) action) > (sizeof(actions)/sizeof(actions[0]))) { |
| 230 | 228 | throw std::system_error(EINVAL, std::system_category()); |
| 231 | 229 | } |
| 232 | 230 | |
| 233 | - Request(*this,actions[(size_t) action]) | |
| 234 | - .call() | |
| 235 | - .pop(rc); | |
| 236 | - | |
| 237 | - if(rc) { | |
| 238 | - throw std::system_error((int) rc, std::system_category()); | |
| 239 | - } | |
| 240 | - | |
| 241 | - return *this; | |
| 231 | + return this->action(actions[action]); | |
| 242 | 232 | |
| 243 | 233 | } |
| 244 | 234 | |
| ... | ... | @@ -353,6 +343,23 @@ |
| 353 | 343 | |
| 354 | 344 | } |
| 355 | 345 | |
| 346 | + /// @brief Execute action by name. | |
| 347 | + TN3270::Session & IPC::Session::action(const char *action_name) { | |
| 348 | + | |
| 349 | + int32_t rc; | |
| 350 | + | |
| 351 | + Request(*this,"action") | |
| 352 | + .push(action_name) | |
| 353 | + .call() | |
| 354 | + .pop(rc); | |
| 355 | + | |
| 356 | + if(rc) { | |
| 357 | + throw std::system_error((int) rc, std::system_category()); | |
| 358 | + } | |
| 359 | + | |
| 360 | + return *this; | |
| 361 | + } | |
| 362 | + | |
| 356 | 363 | } |
| 357 | 364 | |
| 358 | 365 | ... | ... |
src/lib3270++/local/session.cc
| ... | ... | @@ -253,29 +253,27 @@ |
| 253 | 253 | } |
| 254 | 254 | |
| 255 | 255 | TN3270::Session & Local::Session::push(const Action action) { |
| 256 | - std::lock_guard<std::mutex> lock(sync); | |
| 257 | 256 | |
| 258 | - switch(action) { | |
| 259 | - case ENTER: | |
| 260 | - lib3270_enter(hSession); | |
| 261 | - break; | |
| 257 | + typedef int (*ActionCallback)(H3270 *); | |
| 262 | 258 | |
| 263 | - case ERASE: | |
| 264 | - lib3270_erase(hSession); | |
| 265 | - break; | |
| 259 | + static const ActionCallback actions[] = { | |
| 260 | + lib3270_enter, | |
| 261 | + lib3270_erase, | |
| 262 | + lib3270_eraseeof, | |
| 263 | + lib3270_eraseeol, | |
| 264 | + lib3270_eraseinput | |
| 265 | + }; | |
| 266 | 266 | |
| 267 | - case ERASE_EOF: | |
| 268 | - lib3270_eraseeof(hSession); | |
| 269 | - break; | |
| 267 | + if( ((size_t) action) > (sizeof(actions)/sizeof(actions[0]))) { | |
| 268 | + throw std::system_error(EINVAL, std::system_category()); | |
| 269 | + } | |
| 270 | 270 | |
| 271 | - case ERASE_EOL: | |
| 272 | - lib3270_eraseeol(hSession); | |
| 273 | - break; | |
| 271 | + std::lock_guard<std::mutex> lock(sync); | |
| 274 | 272 | |
| 275 | - case ERASE_INPUT: | |
| 276 | - lib3270_eraseinput(hSession); | |
| 277 | - break; | |
| 273 | + int rc = actions[(size_t) action](hSession); | |
| 278 | 274 | |
| 275 | + if(rc) { | |
| 276 | + throw std::system_error(errno, std::system_category()); | |
| 279 | 277 | } |
| 280 | 278 | |
| 281 | 279 | return *this; |
| ... | ... | @@ -376,6 +374,15 @@ |
| 376 | 374 | return lib3270_get_revision(); |
| 377 | 375 | } |
| 378 | 376 | |
| 377 | + /// @brief Execute action by name. | |
| 378 | + TN3270::Session & Local::Session::action(const char *action_name) { | |
| 379 | + | |
| 380 | + if(lib3270_action(hSession,action_name)) { | |
| 381 | + throw std::system_error(errno, std::system_category()); | |
| 382 | + } | |
| 383 | + | |
| 384 | + return *this; | |
| 385 | + } | |
| 379 | 386 | |
| 380 | 387 | } |
| 381 | 388 | ... | ... |
src/lib3270++/private.h
| ... | ... | @@ -209,6 +209,9 @@ |
| 209 | 209 | TN3270::Session & pop(int row, int col, std::string &text) override; |
| 210 | 210 | TN3270::Session & pop(std::string &text) override; |
| 211 | 211 | |
| 212 | + /// @brief Execute action by name. | |
| 213 | + TN3270::Session & action(const char *action_name) override; | |
| 214 | + | |
| 212 | 215 | }; |
| 213 | 216 | |
| 214 | 217 | } |
| ... | ... | @@ -370,6 +373,9 @@ |
| 370 | 373 | TN3270::Session & pop(int row, int col, std::string &text) override; |
| 371 | 374 | TN3270::Session & pop(std::string &text) override; |
| 372 | 375 | |
| 376 | + /// @brief Execute action by name. | |
| 377 | + TN3270::Session & action(const char *action_name) override; | |
| 378 | + | |
| 373 | 379 | }; |
| 374 | 380 | |
| 375 | 381 | } | ... | ... |