aboutsummaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorAndreas Monzner <andreas.monzner@multimedia-labs.de>2007-01-02 14:31:48 +0000
committerAndreas Monzner <andreas.monzner@multimedia-labs.de>2007-01-02 14:31:48 +0000
commit4ca6dd275393344b9a27cfb2e5a755a4d74a414f (patch)
tree18c8ff764744d643c4835dfb14b1f3123be649a8 /lib
parentbfa525d0451df77a28db6ce21ec45f00b89661a8 (diff)
downloadenigma2-4ca6dd275393344b9a27cfb2e5a755a4d74a414f.tar.gz
enigma2-4ca6dd275393344b9a27cfb2e5a755a4d74a414f.zip
add support for python threads (python threads are just running when the mainloop
is idle) add ePythonMessagePump class for interthread communication
Diffstat (limited to 'lib')
-rw-r--r--lib/base/ebase.cpp12
-rw-r--r--lib/base/message.h39
-rw-r--r--lib/python/enigma_python.i4
-rw-r--r--lib/python/python.cpp3
4 files changed, 54 insertions, 4 deletions
diff --git a/lib/base/ebase.cpp b/lib/base/ebase.cpp
index f40bf39e..491ca093 100644
--- a/lib/base/ebase.cpp
+++ b/lib/base/ebase.cpp
@@ -200,8 +200,16 @@ int eMainloop::processOneEvent(unsigned int user_timeout, PyObject **res, ePyObj
pfd[i++].events = PyInt_AsLong(val);
}
}
-
- ret = ::poll(pfd, fdcount, poll_timeout);
+
+ if (this == eApp)
+ {
+ Py_BEGIN_ALLOW_THREADS
+ ret = ::poll(pfd, fdcount, poll_timeout);
+ Py_END_ALLOW_THREADS
+ }
+ else
+ ret = ::poll(pfd, fdcount, poll_timeout);
+
/* ret > 0 means that there are some active poll entries. */
if (ret > 0)
{
diff --git a/lib/base/message.h b/lib/base/message.h
index de14db0f..038fd55d 100644
--- a/lib/base/message.h
+++ b/lib/base/message.h
@@ -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];
@@ -19,6 +23,7 @@ class eMessagePump
public:
eMessagePump(int mt=0);
virtual ~eMessagePump();
+protected:
int send(const void *data, int len);
int recv(void *data, int len); // blockierend
int getInputFD() const;
@@ -61,5 +66,39 @@ public:
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() { if (sn) sn->start(); }
+ void stop() { if (sn) sn->stop(); }
+};
#endif
diff --git a/lib/python/enigma_python.i b/lib/python/enigma_python.i
index 2a3b89fd..a1bb5b28 100644
--- a/lib/python/enigma_python.i
+++ b/lib/python/enigma_python.i
@@ -41,6 +41,7 @@ is usually caused by not marking PSignals as immutable.
#include <lib/base/eerror.h>
#include <lib/base/console.h>
#include <lib/base/nconfig.h>
+#include <lib/base/message.h>
#include <lib/driver/rc.h>
#include <lib/service/iservice.h>
#include <lib/service/service.h>
@@ -151,7 +152,8 @@ typedef long time_t;
%immutable eDVBCI_UI::ciStateChanged;
%immutable eDVBResourceManager::frontendUseMaskChanged;
%immutable eAVSwitch::vcr_sb_notifier;
-
+%immutable ePythonMessagePump::recv_msg;
+%include <lib/base/message.h>
%include <lib/base/console.h>
%include <lib/base/nconfig.h>
%include <lib/driver/rc.h>
diff --git a/lib/python/python.cpp b/lib/python/python.cpp
index b5a7abbf..5ec07dff 100644
--- a/lib/python/python.cpp
+++ b/lib/python/python.cpp
@@ -121,7 +121,8 @@ ePython::ePython()
// Py_OptimizeFlag = 1;
Py_Initialize();
-
+ PyEval_InitThreads();
+
init_enigma();
}