#define __lib_base_message_h
#include <lib/base/ebase.h>
+#include <lib/python/connections.h>
+#include <lib/python/swig.h>
#include <unistd.h>
#include <lib/base/elock.h>
+
/**
* \brief A generic messagepump.
*
* You can send and receive messages with this class. Internally a fifo is used,
* so you can use them together with a \c eMainloop.
*/
+#ifndef SWIG
class eMessagePump
{
int fd[2];
int ismt;
public:
eMessagePump(int mt=0);
- ~eMessagePump();
+ virtual ~eMessagePump();
+protected:
int send(const void *data, int len);
int recv(void *data, int len); // blockierend
int getInputFD() const;
template<class T>
class eFixedMessagePump: private eMessagePump, public Object
{
- eSocketNotifier *sn;
+ ePtr<eSocketNotifier> sn;
void do_recv(int)
{
T msg;
}
eFixedMessagePump(eMainloop *context, int mt): eMessagePump(mt)
{
- sn=new eSocketNotifier(context, getOutputFD(), eSocketNotifier::Read);
+ sn=eSocketNotifier::create(context, getOutputFD(), eSocketNotifier::Read);
CONNECT(sn->activated, eFixedMessagePump<T>::do_recv);
sn->start();
}
- ~eFixedMessagePump()
+ void start() { if (sn) sn->start(); }
+ void stop() { if (sn) sn->stop(); }
+};
+#endif
+
+class ePythonMessagePump: public eMessagePump, public Object
+{
+ ePtr<eSocketNotifier> sn;
+ void do_recv(int)
{
- delete sn;
+ int msg;
+ recv(&msg, sizeof(msg));
+ /*emit*/ recv_msg(msg);
+ }
+public:
+ PSignal1<void,int> recv_msg;
+ void send(int msg)
+ {
+ eMessagePump::send(&msg, sizeof(msg));
+ }
+ ePythonMessagePump()
+ :eMessagePump(1)
+ {
+ sn=eSocketNotifier::create(eApp, getOutputFD(), eSocketNotifier::Read);
+ CONNECT(sn->activated, ePythonMessagePump::do_recv);
+ sn->start();
}
- void start() { sn->start(); }
- void stop() { sn->stop(); }
+ void start() { if (sn) sn->start(); }
+ void stop() { if (sn) sn->stop(); }
};
#endif