whitespace fixes
[enigma2.git] / lib / base / message.h
index 6a9ff43ede2bbc462ed82b44deffd7c99c2719e0..038fd55dba642a3d5b168ab1abf43f32c3b577d5 100644 (file)
@@ -2,15 +2,19 @@
 #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];
@@ -18,7 +22,8 @@ class eMessagePump
        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;
@@ -56,9 +61,44 @@ public:
        ~eFixedMessagePump()
        {
                delete sn;
+               sn=0;
+       }
+       void start() { if (sn) sn->start(); }
+       void stop() { if (sn) sn->stop(); }
+};
+#endif
+
+class ePythonMessagePump: public eMessagePump, public Object
+{
+       eSocketNotifier *sn;
+       void do_recv(int)
+       {
+               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)
+       {
+               eDebug("add python messagepump %p", this);
+               sn=new eSocketNotifier(eApp, getOutputFD(), eSocketNotifier::Read);
+               CONNECT(sn->activated, ePythonMessagePump::do_recv);
+               sn->start();
+       }
+       ~ePythonMessagePump()
+       {
+               eDebug("remove python messagepump %p", this);
+               delete sn;
+               sn=0;
        }
-       void start() { sn->start(); }
-       void stop() { sn->stop(); }
+       void start() { if (sn) sn->start(); }
+       void stop() { if (sn) sn->stop(); }
 };
 
 #endif