1 #ifndef __lib_base_message_h
2 #define __lib_base_message_h
4 #include <lib/base/ebase.h>
6 #include <lib/base/elock.h>
9 * \brief A generic messagepump.
11 * You can send and receive messages with this class. Internally a fifo is used,
12 * so you can use them together with a \c eMainloop.
20 eMessagePump(int mt=0);
21 virtual ~eMessagePump();
22 int send(const void *data, int len);
23 int recv(void *data, int len); // blockierend
24 int getInputFD() const;
25 int getOutputFD() const;
29 * \brief A messagepump with fixed-length packets.
31 * Based on \ref eMessagePump, with this class you can send and receive fixed size messages.
32 * Automatically creates a eSocketNotifier and gives you a callback.
35 class eFixedMessagePump: private eMessagePump, public Object
41 recv(&msg, sizeof(msg));
42 /*emit*/ recv_msg(msg);
45 Signal1<void,const T&> recv_msg;
46 void send(const T &msg)
48 eMessagePump::send(&msg, sizeof(msg));
50 eFixedMessagePump(eMainloop *context, int mt): eMessagePump(mt)
52 sn=new eSocketNotifier(context, getOutputFD(), eSocketNotifier::Read);
53 CONNECT(sn->activated, eFixedMessagePump<T>::do_recv);
61 void start() { if (sn) sn->start(); }
62 void stop() { if (sn) sn->stop(); }