diff options
| author | Felix Domke <tmbinc@elitedvb.net> | 2005-01-20 14:35:19 +0000 |
|---|---|---|
| committer | Felix Domke <tmbinc@elitedvb.net> | 2005-01-20 14:35:19 +0000 |
| commit | 9202d4248dd7df2f6e5eb53b4154c8297ec9b1d1 (patch) | |
| tree | 6be7a641506defe96a73e0279f934ac5670aba81 /lib | |
| parent | 13b7a9b397f36ca3195aad3702feb3db4cbb2f3e (diff) | |
| download | enigma2-9202d4248dd7df2f6e5eb53b4154c8297ec9b1d1.tar.gz enigma2-9202d4248dd7df2f6e5eb53b4154c8297ec9b1d1.zip | |
- redraw now in idle
- mainloop called from python (could be changed)
- clock components manages timer
- timer usuable from python
Diffstat (limited to 'lib')
| -rw-r--r-- | lib/base/ebase.cpp | 61 | ||||
| -rw-r--r-- | lib/base/ebase.h | 5 | ||||
| -rw-r--r-- | lib/gdi/fb.cpp | 2 | ||||
| -rw-r--r-- | lib/gui/ewidgetdesktop.cpp | 21 | ||||
| -rw-r--r-- | lib/gui/ewidgetdesktop.h | 9 | ||||
| -rw-r--r-- | lib/gui/ewindowstyle.cpp | 1 | ||||
| -rw-r--r-- | lib/python/Makefile.am | 5 | ||||
| -rw-r--r-- | lib/python/enigma_python.i | 58 | ||||
| -rw-r--r-- | lib/python/python.cpp | 2 |
9 files changed, 143 insertions, 21 deletions
diff --git a/lib/base/ebase.cpp b/lib/base/ebase.cpp index 3babc2eb..b62452d4 100644 --- a/lib/base/ebase.cpp +++ b/lib/base/ebase.cpp @@ -2,6 +2,7 @@ #include <fcntl.h> #include <unistd.h> +#include <errno.h> #include <lib/base/eerror.h> @@ -50,7 +51,8 @@ void eTimer::start(long msek, bool singleShot) } void eTimer::stop() -{ +{ + eDebug("stop timer"); if (bActive) { bActive=false; @@ -74,7 +76,7 @@ void eTimer::changeInterval(long msek) context.addTimer(this); // add Timer to context TimerList } -void eTimer::activate() // Internal Funktion... called from eApplication +void eTimer::activate() // Internal Function... called from eApplication { timeval now; gettimeofday(&now, 0); @@ -107,16 +109,47 @@ void eMainloop::removeSocketNotifier(eSocketNotifier *sn) void eMainloop::processOneEvent() { -// process pending timers... + /* notes: + - we should use epoll(4) + - timer are checked twice. there was a strong reason for it, but i can't remember. (FIXME) + - for each time, we gettimeofday() and check wether the timer should fire. + we should do this all better - we know how long the poll last, so we know which + timers should fire. Problem is that a timer handler could have required so + much time that another timer fired. + + A probably structure could look + + while (1) + { + time = gettimeofday() + timeout = calculate_pending_timers(time); + + doPoll(timeout or infinite); + + if (poll_had_results) + handle_poll_handler(); + else + fire_timers(time + timeout) + } + + the gettimeofday() call is required because fire_timers could last more + than nothing. + + when poll did no timeout, we don't handle timers, as this will be done + in the next iteration (without adding overhead - we had to get the new + time anyway + */ + + // first, process pending timers... long usec=0; while (TimerList && (usec = timeout_usec( TimerList.begin()->getNextActivation() ) ) <= 0 ) TimerList.begin()->activate(); + // build the poll aray int fdAnz = notifiers.size(); pollfd* pfd = new pollfd[fdAnz]; // make new pollfd array -// fill pfd array std::map<int,eSocketNotifier*>::iterator it(notifiers.begin()); for (int i=0; i < fdAnz; i++, it++) { @@ -124,11 +157,11 @@ void eMainloop::processOneEvent() pfd[i].events = it->second->getRequested(); } - int ret=poll(pfd, fdAnz, TimerList ? usec / 1000 : -1); // milli .. not micro seks + // to the poll. When there are no timers, we have an infinite timeout + int ret=poll(pfd, fdAnz, TimerList ? usec / 1000 : -1); // convert to us if (ret>0) { -// eDebug("bin aussem poll raus und da war was"); for (int i=0; i < fdAnz ; i++) { if( notifiers.find(pfd[i].fd) == notifiers.end()) @@ -143,13 +176,17 @@ void eMainloop::processOneEvent() if (!--ret) break; } else if (pfd[i].revents & (POLLERR|POLLHUP|POLLNVAL)) - eDebug("poll: unhandled POLLERR/HUP/NVAL for fd %d(%d)", pfd[i].fd,pfd[i].revents); + eFatal("poll: unhandled POLLERR/HUP/NVAL for fd %d(%d) -> FIX YOUR CODE", pfd[i].fd,pfd[i].revents); } - } - else if (ret<0) - eDebug("poll made error"); + } else if (ret<0) + { + /* when we got a signal, we get EINTR. we do not care, + because we check current time in timers anyway. */ + if (errno != EINTR) + eDebug("poll made error (%m)"); + } - // check Timers... + // check timer... while ( TimerList && timeout_usec( TimerList.begin()->getNextActivation() ) <= 0 ) TimerList.begin()->activate(); @@ -167,6 +204,8 @@ int eMainloop::exec() return retval; } + /* use with care! better: don't use it anymore. it was used for gui stuff, but + doesn't allow multiple paths (or active dialogs, if you want it that way.) */ void eMainloop::enter_loop() { loop_level++; diff --git a/lib/base/ebase.h b/lib/base/ebase.h index b929cb6d..187f9548 100644 --- a/lib/base/ebase.h +++ b/lib/base/ebase.h @@ -9,6 +9,7 @@ #include <time.h> #include <lib/base/eptrlist.h> +#include <lib/python/connections.h> #include <libsig_comp.h> class eApplication; @@ -158,7 +159,7 @@ public: eSocketNotifier(eMainloop *context, int fd, int req, bool startnow=true); ~eSocketNotifier(); - Signal1<void, int> activated; + PSignal1<void, int> activated; void activate(int what) { /*emit*/ activated(what); } void start(); @@ -193,7 +194,7 @@ public: eTimer(eMainloop *context): context(*context), bActive(false) { } ~eTimer() { if (bActive) stop(); } - Signal0<void> timeout; + PSignal0<void> timeout; void activate(); bool isActive() { return bActive; } diff --git a/lib/gdi/fb.cpp b/lib/gdi/fb.cpp index e792204d..fb0cc03b 100644 --- a/lib/gdi/fb.cpp +++ b/lib/gdi/fb.cpp @@ -59,7 +59,7 @@ fbClass::fbClass(const char *fb) goto nolfb; } - showConsole(0); +// showConsole(0); return; nolfb: lfb=0; diff --git a/lib/gui/ewidgetdesktop.cpp b/lib/gui/ewidgetdesktop.cpp index ff913680..bb6c7c39 100644 --- a/lib/gui/ewidgetdesktop.cpp +++ b/lib/gui/ewidgetdesktop.cpp @@ -1,5 +1,6 @@ #include <lib/gui/ewidgetdesktop.h> #include <lib/gui/ewidget.h> +#include <lib/base/ebase.h> void eWidgetDesktop::addRootWidget(eWidget *root, int top) { @@ -50,6 +51,8 @@ void eWidgetDesktop::recalcClipRegions() void eWidgetDesktop::invalidate(const gRegion ®ion) { + if (m_timer && m_dirty_region.empty()) + m_timer->start(0, 1); // start singleshot redraw timer m_dirty_region |= region; } @@ -67,7 +70,23 @@ void eWidgetDesktop::setDC(gDC *dc) m_dc = dc; } -eWidgetDesktop::eWidgetDesktop(eSize size): m_screen_size(size) +void eWidgetDesktop::setRedrawTask(eMainloop &ml) +{ + if (m_mainloop) + { + delete m_timer; + m_timer = 0; + m_mainloop = 0; + } + m_mainloop = &ml; + m_timer = new eTimer(m_mainloop); + CONNECT(m_timer->timeout, eWidgetDesktop::paint); + + if (!m_dirty_region.empty()) + m_timer->start(0, 1); +} + +eWidgetDesktop::eWidgetDesktop(eSize size): m_screen_size(size), m_mainloop(0), m_timer(0) { } diff --git a/lib/gui/ewidgetdesktop.h b/lib/gui/ewidgetdesktop.h index 42e6b61e..1354a86b 100644 --- a/lib/gui/ewidgetdesktop.h +++ b/lib/gui/ewidgetdesktop.h @@ -5,8 +5,10 @@ #include <lib/base/eptrlist.h> class eWidget; +class eMainloop; +class eTimer; -class eWidgetDesktop +class eWidgetDesktop: public Object { public: // weil debug eSize m_screen_size; @@ -22,9 +24,14 @@ public: void invalidate(const gRegion ®ion); void paint(); void setDC(gDC *dc); + + void setRedrawTask(eMainloop &ml); private: ePtrList<eWidget> m_root; void calcWidgetClipRegion(eWidget *widget, gRegion &parent_visible); + + eMainloop *m_mainloop; + eTimer *m_timer; }; #endif diff --git a/lib/gui/ewindowstyle.cpp b/lib/gui/ewindowstyle.cpp index 778291c7..8599cfd7 100644 --- a/lib/gui/ewindowstyle.cpp +++ b/lib/gui/ewindowstyle.cpp @@ -53,7 +53,6 @@ void eWindowStyleSimple::paintWindowDecoration(eWindow *wnd, gPainter &painter, void eWindowStyleSimple::paintBackground(gPainter &painter, const ePoint &offset, const eSize &size) { - eDebug("eWindowStyleSimple::paintBackground"); painter.setBackgroundColor(m_background_color); painter.clear(); } diff --git a/lib/python/Makefile.am b/lib/python/Makefile.am index c3d98c0b..e82cb650 100644 --- a/lib/python/Makefile.am +++ b/lib/python/Makefile.am @@ -1,12 +1,11 @@ INCLUDES = \ -I$(top_srcdir)/include \ - -I$(top_srcdir)/src \ - -I/usr/include/python2.3 + -I$(top_srcdir)/src noinst_LIBRARIES = libenigma_python.a libenigma_python_a_SOURCES = \ - python.cpp enigma_python_wrap.cxx + python.cpp enigma_python_wrap.cxx connections.cpp enigma_python_wrap.cxx: enigma_python.i swig -I$(top_srcdir)/ -c++ -python enigma_python.i diff --git a/lib/python/enigma_python.i b/lib/python/enigma_python.i index 15bc16e2..c621bb62 100644 --- a/lib/python/enigma_python.i +++ b/lib/python/enigma_python.i @@ -1,6 +1,43 @@ +/* + NOTE: you have two options when adding classes so that + they are callable *from* python. + + - either you %include the header file + - or you re-declare it + + In both cases, you must #include the required + header file (i.e. the header file itself), otherwise + enigma_python_wrap.cxx won't build. + + In case you import the whole header file, + please make sure that no unimportant stuff + is wrapped, as this makes the wrapper stuff + much more complex and it can probably break + very easily because of missing typemaps etc. + + you could make use of dizzy macros to ensure + that some stuff is left out when parsed as SWIG + definitions, but be sure to not modify the binary + representation. DON'T USE #ifdef SWIG_COMPILE + for leaving out stuff (unless you *really* know + what you are doing,of course!). you WILL break it. + + The better way (with more work) is to re-declare + the class. It won't be compiled, so you can + leave out stuff as you like. + + + +Oh, things like "operator= is private in this context" etc. +is usually caused by not marking PSignals as immutable. + +*/ + + %module enigma %{ #define SWIG_COMPILE +#include <lib/base/ebase.h> #include <lib/base/smartptr.h> #include <lib/base/eerror.h> #include <lib/base/econfig.h> @@ -14,6 +51,8 @@ #include <lib/gui/ewidgetdesktop.h> #include <lib/gui/eslider.h> #include <lib/python/connections.h> + +extern void runMainloop(); %} #define DEBUG @@ -69,3 +108,22 @@ public: $1 = $input->get(); } + +/************** base **************/ + +%immutable eTimer::timeout; + +class eTimer +{ +public: + eTimer(eMainloop *context = eApp); + PSignal0<void> timeout; + + void start(long msec, bool singleShot=false); + void stop(); + void changeInterval(long msek); +}; + +/************** debug **************/ + +void runMainloop(); diff --git a/lib/python/python.cpp b/lib/python/python.cpp index 9e7e5c21..14e32af6 100644 --- a/lib/python/python.cpp +++ b/lib/python/python.cpp @@ -103,7 +103,7 @@ void ePython::call(PyObject *pFunc, PyObject *pArgs) pValue = PyObject_CallObject(pFunc, pArgs); if (pValue != NULL) { - printf("Result of call: %ld\n", PyInt_AsLong(pValue)); +// printf("Result of call: %ld\n", PyInt_AsLong(pValue)); Py_DECREF(pValue); } else { |
