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
42 ePtr<eSocketNotifier> sn;
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=eSocketNotifier::create(context, getOutputFD(), eSocketNotifier::Read);
58 CONNECT(sn->activated, eFixedMessagePump<T>::do_recv);
61 void start() { if (sn) sn->start(); }
62 void stop() { if (sn) sn->stop(); }
66 class ePythonMessagePump: public eMessagePump, public Object
68 ePtr<eSocketNotifier> sn;
72 recv(&msg, sizeof(msg));
73 /*emit*/ recv_msg(msg);
76 PSignal1<void,int> recv_msg;
79 eMessagePump::send(&msg, sizeof(msg));
84 sn=eSocketNotifier::create(eApp, getOutputFD(), eSocketNotifier::Read);
85 CONNECT(sn->activated, ePythonMessagePump::do_recv);
88 void start() { if (sn) sn->start(); }
89 void stop() { if (sn) sn->stop(); }