lib/base/ebase.h/cpp: dont crash when try to start eTimers, eSocketNotifiers with...
authorghost <andreas.monzner@multimedia-labs.de>
Mon, 17 May 2010 19:58:45 +0000 (21:58 +0200)
committerghost <andreas.monzner@multimedia-labs.de>
Mon, 17 May 2010 19:59:34 +0000 (21:59 +0200)
lib/base/ebase.cpp
lib/base/ebase.h

index 5bafe7323e86781527239265408f27de56323d16..caccb3918b31ccb1b8905aa4f2ff46323856a25f 100644 (file)
@@ -26,8 +26,11 @@ void eSocketNotifier::start()
        if (state)
                stop();
 
-       context.addSocketNotifier(this);
-       state=2;  // running but not in poll yet
+       if (eMainloop::isValid(&context))
+       {
+               context.addSocketNotifier(this);
+               state=2;  // running but not in poll yet
+       }
 }
 
 void eSocketNotifier::stop()
@@ -46,29 +49,35 @@ void eTimer::start(long msek, bool singleShot)
        if (bActive)
                stop();
 
-       bActive = true;
-       bSingleShot = singleShot;
-       interval = msek;
-       clock_gettime(CLOCK_MONOTONIC, &nextActivation);
-//     eDebug("this = %p\nnow sec = %d, nsec = %d\nadd %d msec", this, nextActivation.tv_sec, nextActivation.tv_nsec, msek);
-       nextActivation += (msek<0 ? 0 : msek);
-//     eDebug("next Activation sec = %d, nsec = %d", nextActivation.tv_sec, nextActivation.tv_nsec );
-       context.addTimer(this);
+       if (eMainloop::isValid(&context))
+       {
+               bActive = true;
+               bSingleShot = singleShot;
+               interval = msek;
+               clock_gettime(CLOCK_MONOTONIC, &nextActivation);
+//             eDebug("this = %p\nnow sec = %d, nsec = %d\nadd %d msec", this, nextActivation.tv_sec, nextActivation.tv_nsec, msek);
+               nextActivation += (msek<0 ? 0 : msek);
+//             eDebug("next Activation sec = %d, nsec = %d", nextActivation.tv_sec, nextActivation.tv_nsec );
+               context.addTimer(this);
+       }
 }
 
-void eTimer::startLongTimer( int seconds )
+void eTimer::startLongTimer(int seconds)
 {
        if (bActive)
                stop();
 
-       bActive = bSingleShot = true;
-       interval = 0;
-       clock_gettime(CLOCK_MONOTONIC, &nextActivation);
-//     eDebug("this = %p\nnow sec = %d, nsec = %d\nadd %d sec", this, nextActivation.tv_sec, nextActivation.tv_nsec, seconds);
-       if ( seconds > 0 )
-               nextActivation.tv_sec += seconds;
-//     eDebug("next Activation sec = %d, nsec = %d", nextActivation.tv_sec, nextActivation.tv_nsec );
-       context.addTimer(this);
+       if (eMainloop::isValid(&context))
+       {
+               bActive = bSingleShot = true;
+               interval = 0;
+               clock_gettime(CLOCK_MONOTONIC, &nextActivation);
+//             eDebug("this = %p\nnow sec = %d, nsec = %d\nadd %d sec", this, nextActivation.tv_sec, nextActivation.tv_nsec, seconds);
+               if ( seconds > 0 )
+                       nextActivation.tv_sec += seconds;
+//             eDebug("next Activation sec = %d, nsec = %d", nextActivation.tv_sec, nextActivation.tv_nsec );
+               context.addTimer(this);
+       }
 }
 
 void eTimer::stop()
@@ -114,6 +123,11 @@ void eTimer::activate()   // Internal Funktion... called from eApplication
 // mainloop
 ePtrList<eMainloop> eMainloop::existing_loops;
 
+bool eMainloop::isValid(eMainloop *ml)
+{
+       return std::find(existing_loops.begin(), existing_loops.end(), ml) != existing_loops.end();
+}
+
 eMainloop::~eMainloop()
 {
        existing_loops.remove(this);
index c69133f621239a431b1bc74254df93979044f5cf..f6fc07d3c423f6166c91e0e69a369e69ab156386 100644 (file)
@@ -205,11 +205,9 @@ class eMainloop
        void removeSocketNotifier(eSocketNotifier *sn);
        void addTimer(eTimer* e);
        void removeTimer(eTimer* e);
-public:
-#ifndef SWIG
        static ePtrList<eMainloop> existing_loops;
-#endif
-
+       static bool isValid(eMainloop *);
+public:
        eMainloop()
                :app_quit_now(0),loop_level(0),retval(0), m_is_idle(0), m_idle_count(0), m_inActivate(0), m_interrupt_requested(0)
        {