diff --git a/src/include/lib3270++.h b/src/include/lib3270++.h
index f3d483e..438e296 100644
--- a/src/include/lib3270++.h
+++ b/src/include/lib3270++.h
@@ -64,6 +64,36 @@
class Host;
+ class Event {
+ public:
+ enum Type : uint8_t {
+ All, ///< @brief All events (undefined).
+ Popup, ///< @brief Popup message.
+ Trace, ///< @brief Trace message.
+ Message, ///< @brief Generic message.
+ };
+
+ private:
+ Type type;
+
+ protected:
+ Event(enum Type type) {
+ this->type = type;
+ }
+
+ public:
+ virtual ~Event();
+
+ /// @brief Check event type
+ inline bool is(Event::Type type) const noexcept {
+ return this->type == type;
+ }
+
+ /// @brief Get event description.
+ virtual std::string toString() const = 0;
+
+ };
+
enum ProgramMessage : uint8_t {
MESSAGE_NONE = LIB3270_MESSAGE_NONE, ///< @brief No message
MESSAGE_SYSWAIT = LIB3270_MESSAGE_SYSWAIT, ///< @brief --
@@ -144,6 +174,8 @@
/// @brief Write error to log file.
void error(const char *fmt, ...) const;
+ void fire(const Event &event);
+
public:
/// @brief Create a tn3270 session.
diff --git a/src/lib3270++/lib3270++.cbp b/src/lib3270++/lib3270++.cbp
index bdb02fa..49535d3 100644
--- a/src/lib3270++/lib3270++.cbp
+++ b/src/lib3270++/lib3270++.cbp
@@ -41,6 +41,7 @@
+
diff --git a/src/lib3270++/local.cc b/src/lib3270++/local.cc
index 0865644..11cbd59 100644
--- a/src/lib3270++/local.cc
+++ b/src/lib3270++/local.cc
@@ -39,6 +39,7 @@
#include "private.h"
#include
+ using std::string;
/*---[ Implement ]----------------------------------------------------------------------------------*/
@@ -52,6 +53,56 @@
lib3270_set_user_data(this->hSession,(void *) this);
setCharSet(lib3270_get_display_charset(this->hSession));
+ lib3270_set_popup_handler(this->hSession, popupHandler);
+
+ }
+
+ /// @brief Popup Handler.
+ int LocalSession::popupHandler(H3270 *h3270, LIB3270_NOTIFY type, const char *title, const char *msg, const char *fmt, va_list arg) {
+
+ LocalSession * session = (LocalSession *) lib3270_get_user_data(h3270);
+
+ if(!session) {
+ throw std::runtime_error("Invalid session handler");
+ }
+
+ class PopupEvent : public Event {
+ private:
+ LIB3270_NOTIFY type;
+ string title;
+ string msg;
+ string description;
+
+ public:
+ PopupEvent(LIB3270_NOTIFY type, const char *title, const char *msg, const char *fmt, va_list arg) : Event(Event::Popup) {
+
+ this->type = type;
+ this->title = title;
+ this->msg = msg;
+
+ char * buffer = NULL;
+ if(vasprintf(&buffer,fmt,arg) != -1) {
+ this->description = buffer;
+ free(buffer);
+ }
+
+ }
+
+ virtual ~PopupEvent() {
+ }
+
+ /// @brief Get event description.
+ std::string toString() const override {
+ return msg;
+ }
+
+
+ };
+
+ session->fire(PopupEvent(type,title,msg,fmt,arg));
+
+ return 0;
+
}
LocalSession::~LocalSession() {
diff --git a/src/lib3270++/private.h b/src/lib3270++/private.h
index e0dda3a..71955c8 100644
--- a/src/lib3270++/private.h
+++ b/src/lib3270++/private.h
@@ -43,6 +43,7 @@
#include
#include
#include
+ #include
#include
@@ -108,6 +109,9 @@
/// @brief Mutex to serialize access to lib3270
std::mutex sync;
+ /// @brief Popup Handler.
+ static int popupHandler(H3270 *session, LIB3270_NOTIFY type, const char *title, const char *msg, const char *fmt, va_list arg);
+
public:
LocalSession();
virtual ~LocalSession();
--
libgit2 0.21.2