Commit 833d8b5c247ba463c8d3b36a09daa44dae02e8df
1 parent
37ad659b
Exists in
master
and in
3 other branches
Starting use of events to signal states.
Showing
4 changed files
with
88 additions
and
0 deletions
Show diff stats
src/include/lib3270++.h
@@ -64,6 +64,36 @@ | @@ -64,6 +64,36 @@ | ||
64 | 64 | ||
65 | class Host; | 65 | class Host; |
66 | 66 | ||
67 | + class Event { | ||
68 | + public: | ||
69 | + enum Type : uint8_t { | ||
70 | + All, ///< @brief All events (undefined). | ||
71 | + Popup, ///< @brief Popup message. | ||
72 | + Trace, ///< @brief Trace message. | ||
73 | + Message, ///< @brief Generic message. | ||
74 | + }; | ||
75 | + | ||
76 | + private: | ||
77 | + Type type; | ||
78 | + | ||
79 | + protected: | ||
80 | + Event(enum Type type) { | ||
81 | + this->type = type; | ||
82 | + } | ||
83 | + | ||
84 | + public: | ||
85 | + virtual ~Event(); | ||
86 | + | ||
87 | + /// @brief Check event type | ||
88 | + inline bool is(Event::Type type) const noexcept { | ||
89 | + return this->type == type; | ||
90 | + } | ||
91 | + | ||
92 | + /// @brief Get event description. | ||
93 | + virtual std::string toString() const = 0; | ||
94 | + | ||
95 | + }; | ||
96 | + | ||
67 | enum ProgramMessage : uint8_t { | 97 | enum ProgramMessage : uint8_t { |
68 | MESSAGE_NONE = LIB3270_MESSAGE_NONE, ///< @brief No message | 98 | MESSAGE_NONE = LIB3270_MESSAGE_NONE, ///< @brief No message |
69 | MESSAGE_SYSWAIT = LIB3270_MESSAGE_SYSWAIT, ///< @brief -- | 99 | MESSAGE_SYSWAIT = LIB3270_MESSAGE_SYSWAIT, ///< @brief -- |
@@ -144,6 +174,8 @@ | @@ -144,6 +174,8 @@ | ||
144 | /// @brief Write error to log file. | 174 | /// @brief Write error to log file. |
145 | void error(const char *fmt, ...) const; | 175 | void error(const char *fmt, ...) const; |
146 | 176 | ||
177 | + void fire(const Event &event); | ||
178 | + | ||
147 | public: | 179 | public: |
148 | 180 | ||
149 | /// @brief Create a tn3270 session. | 181 | /// @brief Create a tn3270 session. |
src/lib3270++/lib3270++.cbp
@@ -41,6 +41,7 @@ | @@ -41,6 +41,7 @@ | ||
41 | </Linker> | 41 | </Linker> |
42 | <Unit filename="../include/lib3270++.h" /> | 42 | <Unit filename="../include/lib3270++.h" /> |
43 | <Unit filename="../include/lib3270.h" /> | 43 | <Unit filename="../include/lib3270.h" /> |
44 | + <Unit filename="../include/lib3270/popup.h" /> | ||
44 | <Unit filename="../include/lib3270/session.h" /> | 45 | <Unit filename="../include/lib3270/session.h" /> |
45 | <Unit filename="abstract.cc" /> | 46 | <Unit filename="abstract.cc" /> |
46 | <Unit filename="host.cc" /> | 47 | <Unit filename="host.cc" /> |
src/lib3270++/local.cc
@@ -39,6 +39,7 @@ | @@ -39,6 +39,7 @@ | ||
39 | #include "private.h" | 39 | #include "private.h" |
40 | #include <lib3270/actions.h> | 40 | #include <lib3270/actions.h> |
41 | 41 | ||
42 | + using std::string; | ||
42 | 43 | ||
43 | /*---[ Implement ]----------------------------------------------------------------------------------*/ | 44 | /*---[ Implement ]----------------------------------------------------------------------------------*/ |
44 | 45 | ||
@@ -52,6 +53,56 @@ | @@ -52,6 +53,56 @@ | ||
52 | lib3270_set_user_data(this->hSession,(void *) this); | 53 | lib3270_set_user_data(this->hSession,(void *) this); |
53 | setCharSet(lib3270_get_display_charset(this->hSession)); | 54 | setCharSet(lib3270_get_display_charset(this->hSession)); |
54 | 55 | ||
56 | + lib3270_set_popup_handler(this->hSession, popupHandler); | ||
57 | + | ||
58 | + } | ||
59 | + | ||
60 | + /// @brief Popup Handler. | ||
61 | + int LocalSession::popupHandler(H3270 *h3270, LIB3270_NOTIFY type, const char *title, const char *msg, const char *fmt, va_list arg) { | ||
62 | + | ||
63 | + LocalSession * session = (LocalSession *) lib3270_get_user_data(h3270); | ||
64 | + | ||
65 | + if(!session) { | ||
66 | + throw std::runtime_error("Invalid session handler"); | ||
67 | + } | ||
68 | + | ||
69 | + class PopupEvent : public Event { | ||
70 | + private: | ||
71 | + LIB3270_NOTIFY type; | ||
72 | + string title; | ||
73 | + string msg; | ||
74 | + string description; | ||
75 | + | ||
76 | + public: | ||
77 | + PopupEvent(LIB3270_NOTIFY type, const char *title, const char *msg, const char *fmt, va_list arg) : Event(Event::Popup) { | ||
78 | + | ||
79 | + this->type = type; | ||
80 | + this->title = title; | ||
81 | + this->msg = msg; | ||
82 | + | ||
83 | + char * buffer = NULL; | ||
84 | + if(vasprintf(&buffer,fmt,arg) != -1) { | ||
85 | + this->description = buffer; | ||
86 | + free(buffer); | ||
87 | + } | ||
88 | + | ||
89 | + } | ||
90 | + | ||
91 | + virtual ~PopupEvent() { | ||
92 | + } | ||
93 | + | ||
94 | + /// @brief Get event description. | ||
95 | + std::string toString() const override { | ||
96 | + return msg; | ||
97 | + } | ||
98 | + | ||
99 | + | ||
100 | + }; | ||
101 | + | ||
102 | + session->fire(PopupEvent(type,title,msg,fmt,arg)); | ||
103 | + | ||
104 | + return 0; | ||
105 | + | ||
55 | } | 106 | } |
56 | 107 | ||
57 | LocalSession::~LocalSession() { | 108 | LocalSession::~LocalSession() { |
src/lib3270++/private.h
@@ -43,6 +43,7 @@ | @@ -43,6 +43,7 @@ | ||
43 | #include <config.h> | 43 | #include <config.h> |
44 | #include <mutex> | 44 | #include <mutex> |
45 | #include <lib3270++.h> | 45 | #include <lib3270++.h> |
46 | + #include <lib3270/popup.h> | ||
46 | #include <system_error> | 47 | #include <system_error> |
47 | 48 | ||
48 | 49 | ||
@@ -108,6 +109,9 @@ | @@ -108,6 +109,9 @@ | ||
108 | /// @brief Mutex to serialize access to lib3270 | 109 | /// @brief Mutex to serialize access to lib3270 |
109 | std::mutex sync; | 110 | std::mutex sync; |
110 | 111 | ||
112 | + /// @brief Popup Handler. | ||
113 | + static int popupHandler(H3270 *session, LIB3270_NOTIFY type, const char *title, const char *msg, const char *fmt, va_list arg); | ||
114 | + | ||
111 | public: | 115 | public: |
112 | LocalSession(); | 116 | LocalSession(); |
113 | virtual ~LocalSession(); | 117 | virtual ~LocalSession(); |