1 #ifndef __lib_base_message_h
2 #define __lib_base_message_h
4 #include <lib/base/ebase.h>
5 #include <lib/python/connections.h>
6 #include <lib/python/swig.h>
8 #include <lib/base/elock.h>
12 * \brief A generic messagepump.
14 * You can send and receive messages with this class. Internally a fifo is used,
15 * so you can use them together with a \c eMainloop.
24 eMessagePump(int mt=0);
25 virtual ~eMessagePump();
27 int send(const void *data, int len);
28 int recv(void *data, int len); // blockierend
29 int getInputFD() const;
30 int getOutputFD() const;
34 * \brief A messagepump with fixed-length packets.
36 * Based on \ref eMessagePump, with this class you can send and receive fixed size messages.
37 * Automatically creates a eSocketNotifier and gives you a callback.
40 class eFixedMessagePump: private eMessagePump, public Object
46 recv(&msg, sizeof(msg));
47 /*emit*/ recv_msg(msg);
50 Signal1<void,const T&> recv_msg;
51 void send(const T &msg)
53 eMessagePump::send(&msg, sizeof(msg));
55 eFixedMessagePump(eMainloop *context, int mt): eMessagePump(mt)
57 sn=new eSocketNotifier(context, getOutputFD(), eSocketNotifier::Read);
58 CONNECT(sn->activated, eFixedMessagePump<T>::do_recv);
66 void start() { if (sn) sn->start(); }
67 void stop() { if (sn) sn->stop(); }
71 class ePythonMessagePump: public eMessagePump, public Object
77 recv(&msg, sizeof(msg));
78 /*emit*/ recv_msg(msg);
81 PSignal1<void,int> recv_msg;
84 eMessagePump::send(&msg, sizeof(msg));
89 eDebug("add python messagepump %p", this);
90 sn=new eSocketNotifier(eApp, getOutputFD(), eSocketNotifier::Read);
91 CONNECT(sn->activated, ePythonMessagePump::do_recv);
96 eDebug("remove python messagepump %p", this);
100 void start() { if (sn) sn->start(); }
101 void stop() { if (sn) sn->stop(); }