Commit 681143c5e2133eb5fe1dec67dd03aee6f56a3173

Authored by Perry Werneck
1 parent 6f106f40
Exists in master and in 1 other branch develop

Refactoring popup engine.

client/src/session/local/events.cc
... ... @@ -37,6 +37,7 @@
37 37 */
38 38  
39 39 #include "private.h"
  40 + #include <lib3270/popup.h>
40 41  
41 42 extern "C" {
42 43 #include <lib3270/actions.h>
... ... @@ -79,7 +80,7 @@
79 80 namespace TN3270 {
80 81  
81 82 /// @brief Popup Handler.
82   - void Local::Session::popupHandler(H3270 *h3270, LIB3270_NOTIFY type, const char *title, const char *msg, const char *fmt, va_list arg) {
  83 + int Local::Session::popupHandler(H3270 *h3270, const LIB3270_POPUP *popup, unsigned char wait) {
83 84  
84 85 Local::Session * session = (Local::Session *) lib3270_get_user_data(h3270);
85 86  
... ... @@ -91,35 +92,27 @@
91 92 private:
92 93 LIB3270_NOTIFY type;
93 94 string title;
94   - string msg;
95   - string description;
  95 + string summary;
  96 + string body;
96 97  
97 98 public:
98   - PopupEvent(LIB3270_NOTIFY type, const char *title, const char *msg, const char *fmt, va_list arg) : Event(Event::Popup) {
  99 + PopupEvent(LIB3270_NOTIFY type, const char *title, const char *summary, const char *body) : Event(Event::Popup) {
99 100  
100 101 this->type = type;
101   - this->title = title;
102   - this->msg = msg;
103 102  
104   - char * buffer = NULL;
105   -#ifdef _WIN32
106   - if(win32_vasprintf(&buffer,fmt,arg) != -1) {
107   - this->description = buffer;
108   - free(buffer);
109   - }
110   -#else
111   - if(vasprintf(&buffer,fmt,arg) != -1) {
112   - this->description = buffer;
113   - free(buffer);
114   - }
115   -#endif
  103 + if(title)
  104 + this->title = title;
116 105  
117   -#ifdef DEBUG
118   - std::cerr << "Popup:" << std::endl
119   - << "\t" << title << std::endl
120   - << "\t" << msg << std::endl
121   - << "\t" << description << std::endl;
122   -#endif // DEBUG
  106 + if(summary)
  107 + this->summary = summary;
  108 +
  109 + if(body)
  110 + this->body = body;
  111 +
  112 + std::clog << "Popup:" << std::endl
  113 + << "\t" << this->title << std::endl
  114 + << "\t" << this->summary << std::endl
  115 + << "\t" << this->body << std::endl;
123 116  
124 117 }
125 118  
... ... @@ -128,13 +121,15 @@
128 121  
129 122 /// @brief Get event description.
130 123 std::string toString() const override {
131   - return msg;
  124 + return summary;
132 125 }
133 126  
134 127  
135 128 };
136 129  
137   - session->fire(PopupEvent(type,title,msg,fmt,arg));
  130 + session->fire(PopupEvent(popup->type,popup->title,popup->summary,popup->body));
  131 +
  132 + return ECANCELED;
138 133  
139 134 }
140 135  
... ...
client/src/session/local/init.cc
... ... @@ -69,7 +69,7 @@
69 69  
70 70 this->setCharSet(charset);
71 71  
72   - lib3270_set_popup_handler(this->hSession, popupHandler);
  72 + lib3270_set_popup_handler(this->hSession, &popupHandler);
73 73  
74 74 // Setup callbacks
75 75 struct lib3270_session_callbacks *cbk;
... ...
client/src/session/local/private.h
... ... @@ -48,6 +48,7 @@
48 48 #include <lib3270/ipc/action.h>
49 49 #include <string>
50 50 #include <lib3270.h>
  51 + #include <lib3270/popup.h>
51 52 #include <stdexcept>
52 53  
53 54 using std::string;
... ... @@ -83,7 +84,7 @@
83 84 std::mutex sync;
84 85  
85 86 /// @brief Popup Handler.
86   - static void popupHandler(H3270 *session, LIB3270_NOTIFY type, const char *title, const char *msg, const char *fmt, va_list arg);
  87 + static int popupHandler(H3270 *session, const LIB3270_POPUP *popup, unsigned char wait);
87 88  
88 89 /// @brief Connect Handler.
89 90 static void connectHandler(H3270 *session, unsigned char connected);
... ...