better solution to add possibility to delete eSocketNotifiers,
authorAndreas Monzner <andreas.monzner@multimedia-labs.de>
Wed, 29 Oct 2008 19:46:57 +0000 (19:46 +0000)
committerAndreas Monzner <andreas.monzner@multimedia-labs.de>
Wed, 29 Oct 2008 19:46:57 +0000 (19:46 +0000)
eConsoleAppContainers in callback funktions without crash

29 files changed:
lib/base/console.cpp
lib/base/console.h
lib/base/ebase.cpp
lib/base/ebase.h
lib/base/message.h
lib/driver/avswitch.cpp
lib/driver/avswitch.h
lib/driver/rc.cpp
lib/driver/rc.h
lib/driver/rcconsole.cpp
lib/driver/rcconsole.h
lib/dvb/decoder.cpp
lib/dvb/decoder.h
lib/dvb/demux.cpp
lib/dvb/demux.h
lib/dvb/frontend.cpp
lib/dvb/frontend.h
lib/dvb/pmt.cpp
lib/dvb/pmt.h
lib/dvb_ci/dvbci.cpp
lib/dvb_ci/dvbci.h
lib/network/socket.cpp
lib/network/socket.h
lib/python/Plugins/Extensions/DVDPlayer/src/servicedvd.cpp
lib/python/Plugins/Extensions/DVDPlayer/src/servicedvd.h
lib/python/Plugins/Extensions/SocketMMI/src/socket_mmi.cpp
lib/python/Plugins/Extensions/SocketMMI/src/socket_mmi.h
lib/python/connections.cpp
lib/python/connections.h

index 830855fc9433df0f3604becebea4e1a1f5661493..a12cb5e29bc7f408442e79c2cc303a97c1d2182d 100644 (file)
@@ -55,8 +55,10 @@ int bidirpipe(int pfd[], const char *cmd , const char * const argv[], const char
        return(pid);
 }
 
+DEFINE_REF(eConsoleAppContainer);
+
 eConsoleAppContainer::eConsoleAppContainer()
-:pid(-1), killstate(0), in(0), out(0), err(0)
+:pid(-1), killstate(0)
 {
        for (int i=0; i < 3; ++i)
        {
@@ -109,12 +111,15 @@ int eConsoleAppContainer::execute(const char *cmdline, const char * const argv[]
 
        ::fcntl(fd[1], F_SETFL, O_NONBLOCK);
        ::fcntl(fd[2], F_SETFL, O_NONBLOCK);
-       in = new eSocketNotifier(eApp, fd[0], eSocketNotifier::Read|eSocketNotifier::Priority|eSocketNotifier::Hungup );
-       out = new eSocketNotifier(eApp, fd[1], eSocketNotifier::Write, false);  
-       err = new eSocketNotifier(eApp, fd[2], eSocketNotifier::Read|eSocketNotifier::Priority );
+       in = eSocketNotifier::create(eApp, fd[0], eSocketNotifier::Read|eSocketNotifier::Priority|eSocketNotifier::Hungup );
+       out = eSocketNotifier::create(eApp, fd[1], eSocketNotifier::Write, false);  
+       err = eSocketNotifier::create(eApp, fd[2], eSocketNotifier::Read|eSocketNotifier::Priority );
        CONNECT(in->activated, eConsoleAppContainer::readyRead);
        CONNECT(out->activated, eConsoleAppContainer::readyWrite);
        CONNECT(err->activated, eConsoleAppContainer::readyErrRead);
+       in->m_clients.push_back(this);
+       out->m_clients.push_back(this);
+       err->m_clients.push_back(this);
 
        return 0;
 }
@@ -143,10 +148,9 @@ void eConsoleAppContainer::kill()
                outbuf.pop();
                delete [] d.data;
        }
-       delete in;
-       delete out;
-       delete err;
-       in=out=err=0;
+       in = 0;
+       out = 0;
+       err = 0;
 
        for (int i=0; i < 3; ++i)
        {
@@ -209,6 +213,7 @@ void eConsoleAppContainer::closePipes()
                outbuf.pop();
                delete [] d.data;
        }
+       in = 0; out = 0; err = 0;
        pid = -1;
 }
 
@@ -390,23 +395,23 @@ static PyGetSetDef eConsolePy_getseters[] = {
 static int
 eConsolePy_traverse(eConsolePy *self, visitproc visit, void *arg)
 {
-       PyObject *obj = self->cont->dataAvail.get(true);
+       PyObject *obj = self->cont->dataAvail.getSteal();
        if (obj) {
                Py_VISIT(obj);
        }
-       obj = self->cont->stdoutAvail.get(true);
+       obj = self->cont->stdoutAvail.getSteal();
        if (obj) {
                Py_VISIT(obj);
        }
-       obj = self->cont->stderrAvail.get(true);
+       obj = self->cont->stderrAvail.getSteal();
        if (obj) {
                Py_VISIT(obj);
        }
-       obj = self->cont->dataSent.get(true);
+       obj = self->cont->dataSent.getSteal();
        if (obj) {
                Py_VISIT(obj);
        }
-       obj = self->cont->appClosed.get(true);
+       obj = self->cont->appClosed.getSteal();
        if (obj) {
                Py_VISIT(obj);
        }
@@ -416,23 +421,23 @@ eConsolePy_traverse(eConsolePy *self, visitproc visit, void *arg)
 static int
 eConsolePy_clear(eConsolePy *self)
 {
-       PyObject *obj = self->cont->dataAvail.get(true);
+       PyObject *obj = self->cont->dataAvail.getSteal(true);
        if (obj) {
                Py_CLEAR(obj);
        }
-       obj = self->cont->stdoutAvail.get(true);
+       obj = self->cont->stdoutAvail.getSteal(true);
        if (obj) {
                Py_CLEAR(obj);
        }
-       obj = self->cont->stderrAvail.get(true);
+       obj = self->cont->stderrAvail.getSteal(true);
        if (obj) {
                Py_CLEAR(obj);
        }
-       obj = self->cont->dataSent.get(true);
+       obj = self->cont->dataSent.getSteal(true);
        if (obj) {
                Py_CLEAR(obj);
        }
-       obj = self->cont->appClosed.get(true);
+       obj = self->cont->appClosed.getSteal(true);
        if (obj) {
                Py_CLEAR(obj);
        }
@@ -445,7 +450,7 @@ eConsolePy_dealloc(eConsolePy* self)
        if (self->in_weakreflist != NULL)
                PyObject_ClearWeakRefs((PyObject *) self);
        eConsolePy_clear(self);
-       delete self->cont;
+       self->cont->Release();
        self->ob_type->tp_free((PyObject*)self);
 }
 
@@ -454,6 +459,7 @@ eConsolePy_new(PyTypeObject *type, PyObject *args, PyObject *kwds)
 {
        eConsolePy *self = (eConsolePy *)type->tp_alloc(type, 0);
        self->cont = new eConsoleAppContainer();
+       self->cont->AddRef();
        self->in_weakreflist = NULL;
        return (PyObject *)self;
 }
index a5712bb7ec8082aada04c4214797465144deb745..e730b40ee97a5dd4c023ad6176fe22b85bcb2e22 100644 (file)
@@ -18,15 +18,16 @@ struct queue_data
        int dataSent;
 };
 
-class eConsoleAppContainer: public Object
+class eConsoleAppContainer: public Object, public iObject
 {
+       DECLARE_REF(eConsoleAppContainer);
        int fd[3];
        int filefd[3];
        int pid;
        int killstate;
        std::string m_cwd;
        std::queue<struct queue_data> outbuf;
-       eSocketNotifier *in, *out, *err;
+       ePtr<eSocketNotifier> in, out, err;
        void readyRead(int what);
        void readyErrRead(int what);
        void readyWrite(int what);
index e7708633da3544a0655a475cae8dc0fe03c91b35..a66d1958e9806c85bf087747ce8b3d29e254e4fb 100644 (file)
@@ -8,9 +8,11 @@
 #include <lib/base/elock.h>
 #include <lib/gdi/grc.h>
 
+DEFINE_REF(eSocketNotifier);
+
 eSocketNotifier::eSocketNotifier(eMainloop *context, int fd, int requested, bool startnow): context(*context), fd(fd), state(0), requested(requested)
 {
-       if (startnow)   
+       if (startnow)
                start();
 }
 
@@ -31,9 +33,10 @@ void eSocketNotifier::start()
 void eSocketNotifier::stop()
 {
        if (state)
+       {
+               state=0;
                context.removeSocketNotifier(this);
-
-       state=0;
+       }
 }
 
                                        // timer
@@ -131,8 +134,13 @@ void eMainloop::removeSocketNotifier(eSocketNotifier *sn)
        int fd = sn->getFD();
        std::map<int,eSocketNotifier*>::iterator i(notifiers.find(fd));
        if (i != notifiers.end())
-               return notifiers.erase(i);
-       eFatal("removed socket notifier which is not present");
+       {
+               notifiers.erase(i);
+               return;
+       }
+       for (i = notifiers.begin(); i != notifiers.end(); ++i)
+               eDebug("fd=%d, sn=%d", i->second->getFD(), (void*)i->second);
+       eFatal("removed socket notifier which is not present, fd=%d", fd);
 }
 
 int eMainloop::processOneEvent(unsigned int twisted_timeout, PyObject **res, ePyObject additional)
@@ -175,6 +183,7 @@ int eMainloop::processOneEvent(unsigned int twisted_timeout, PyObject **res, ePy
                // build the poll aray
        pollfd pfd[fdcount];  // make new pollfd array
        std::map<int,eSocketNotifier*>::iterator it = notifiers.begin();
+
        int i=0;
        for (; i < nativecount; ++i, ++it)
        {
@@ -228,9 +237,13 @@ int eMainloop::processOneEvent(unsigned int twisted_timeout, PyObject **res, ePy
                                if (it != notifiers.end()
                                        && it->second->state == 1) // added and in poll
                                {
-                                       int req = it->second->getRequested();
-                                       if (pfd[i].revents & req)
-                                               it->second->activate(pfd[i].revents & req);
+                                       eSocketNotifier *sn = it->second;
+                                       int req = sn->getRequested();
+                                       if (pfd[i].revents & req) {
+                                               sn->AddRef();
+                                               sn->activate(pfd[i].revents & req);
+                                               sn->Release();
+                                       }
                                        pfd[i].revents &= ~req;
                                }
                                if (pfd[i].revents & (POLLERR|POLLHUP|POLLNVAL))
@@ -368,7 +381,7 @@ struct eTimerPy
 static int
 eTimerPy_traverse(eTimerPy *self, visitproc visit, void *arg)
 {
-       PyObject *obj = self->tm->timeout.get(true);
+       PyObject *obj = self->tm->timeout.getSteal();
        if (obj) {
                Py_VISIT(obj);
        }
@@ -378,7 +391,7 @@ eTimerPy_traverse(eTimerPy *self, visitproc visit, void *arg)
 static int
 eTimerPy_clear(eTimerPy *self)
 {
-       PyObject *obj = self->tm->timeout.get(true);
+       PyObject *obj = self->tm->timeout.getSteal(true);
        if (obj)
                Py_CLEAR(obj);
        return 0;
@@ -575,7 +588,7 @@ struct eSocketNotifierPy
 static int
 eSocketNotifierPy_traverse(eSocketNotifierPy *self, visitproc visit, void *arg)
 {
-       PyObject *obj = self->sn->activated.get(true);
+       PyObject *obj = self->sn->activated.getSteal();
        if (obj)
                Py_VISIT(obj);
        return 0;
@@ -584,7 +597,7 @@ eSocketNotifierPy_traverse(eSocketNotifierPy *self, visitproc visit, void *arg)
 static int
 eSocketNotifierPy_clear(eSocketNotifierPy *self)
 {
-       PyObject *obj = self->sn->activated.get(true);
+       PyObject *obj = self->sn->activated.getSteal(true);
        if (obj)
                Py_CLEAR(obj);
        return 0;
@@ -596,7 +609,7 @@ eSocketNotifierPy_dealloc(eSocketNotifierPy* self)
        if (self->in_weakreflist != NULL)
                PyObject_ClearWeakRefs((PyObject *) self);
        eSocketNotifierPy_clear(self);
-       delete self->sn;
+       self->sn->Release();
        self->ob_type->tp_free((PyObject*)self);
 }
 
@@ -620,7 +633,8 @@ eSocketNotifierPy_new(PyTypeObject *type, PyObject *args, PyObject *kwds)
        }
        else if (size < 2 || !PyArg_ParseTuple(args, "ii", &fd, &req))
                return NULL;
-       self->sn = new eSocketNotifier(eApp, fd, req, immediate_start);
+       self->sn = eSocketNotifier::create(eApp, fd, req, immediate_start);
+       self->sn->AddRef();
        self->in_weakreflist = NULL;
        return (PyObject *)self;
 }
index 10b46120a3e7737033f2756d468e36c8eb597e8f..cb676d0be915236e2dfc579f042880c68f238647 100644 (file)
@@ -142,8 +142,9 @@ class eMainloop;
  * This class emits the signal \c eSocketNotifier::activate whenever the
  * event specified by \c req is available.
  */
-class eSocketNotifier
+class eSocketNotifier: iObject
 {
+       DECLARE_REF(eSocketNotifier);
        friend class eMainloop;
 public:
        enum { Read=POLLIN, Write=POLLOUT, Priority=POLLPRI, Error=POLLERR, Hungup=POLLHUP };
@@ -153,6 +154,7 @@ private:
        int state;
        int requested;          // requested events (POLLIN, ...)
        void activate(int what) { /*emit*/ activated(what); }
+       eSocketNotifier(eMainloop *context, int fd, int req, bool startnow);
 public:
        /**
         * \brief Constructs a eSocketNotifier.
@@ -161,7 +163,7 @@ public:
         * \param req The events to watch to, normally either \c Read or \c Write. You can specify any events that \c poll supports.
         * \param startnow Specifies if the socketnotifier should start immediately.
         */
-       eSocketNotifier(eMainloop *context, int fd, int req, bool startnow=true);
+       static eSocketNotifier* create(eMainloop *context, int fd, int req, bool startnow=true) { return new eSocketNotifier(context, fd, req, startnow); }
        ~eSocketNotifier();
 
        PSignal1<void, int> activated;
@@ -173,6 +175,8 @@ public:
        int getFD() { return fd; }
        int getRequested() { return requested; }
        void setRequested(int req) { requested=req; }
+
+       eSmartPtrList<iObject> m_clients;
 };
 
 #endif
index 038fd55dba642a3d5b168ab1abf43f32c3b577d5..6e9eb07c3629c48b024da8539267a7882ade7bd0 100644 (file)
@@ -39,7 +39,7 @@ protected:
 template<class T>
 class eFixedMessagePump: private eMessagePump, public Object
 {
-       eSocketNotifier *sn;
+       ePtr<eSocketNotifier> sn;
        void do_recv(int)
        {
                T msg;
@@ -54,15 +54,10 @@ public:
        }
        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()
-       {
-               delete sn;
-               sn=0;
-       }
        void start() { if (sn) sn->start(); }
        void stop() { if (sn) sn->stop(); }
 };
@@ -70,7 +65,7 @@ public:
 
 class ePythonMessagePump: public eMessagePump, public Object
 {
-       eSocketNotifier *sn;
+       ePtr<eSocketNotifier> sn;
        void do_recv(int)
        {
                int msg;
@@ -86,17 +81,10 @@ public:
        ePythonMessagePump()
                :eMessagePump(1)
        {
-               eDebug("add python messagepump %p", this);
-               sn=new eSocketNotifier(eApp, getOutputFD(), eSocketNotifier::Read);
+               sn=eSocketNotifier::create(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(); }
 };
index 1f2765ec1fdd75918720198a8e3026794459d45a..dbfebf5f2e15ee0d45a9ffe506bd4478ff338a6c 100644 (file)
@@ -24,7 +24,7 @@ eAVSwitch::eAVSwitch()
        }
        else
        {
-               m_fp_notifier = new eSocketNotifier(eApp, m_fp_fd, eSocketNotifier::Read|POLLERR);
+               m_fp_notifier = eSocketNotifier::create(eApp, m_fp_fd, eSocketNotifier::Read|POLLERR);
                CONNECT(m_fp_notifier->activated, eAVSwitch::fp_event);
        }
 }
@@ -93,8 +93,6 @@ eAVSwitch::~eAVSwitch()
 {
        if ( m_fp_fd >= 0 )
                close(m_fp_fd);
-       if (m_fp_notifier)
-               delete m_fp_notifier;
 }
 
 eAVSwitch *eAVSwitch::getInstance()
index cc92e20e42be80a1580956e6da3c14b066746395..8fdafdd1b4faab33f14999fccdf172dd185bf68d 100644 (file)
@@ -10,7 +10,7 @@ class eAVSwitch: public Object
 {
        static eAVSwitch *instance;
        int m_video_mode;
-       eSocketNotifier *m_fp_notifier;
+       ePtr<eSocketNotifier> m_fp_notifier;
        void fp_event(int what);
        int m_fp_fd;
 #ifdef SWIG
index d943352a1588bb1e2d5117ff50e1efbb42ff5231..c7acd1138a1b35bc10c937e72df8e0d53453ff7d 100644 (file)
@@ -79,7 +79,7 @@ eRCShortDriver::eRCShortDriver(const char *filename): eRCDriver(eRCInput::getIns
                sn=0;
        } else
        {
-               sn=new eSocketNotifier(eApp, handle, eSocketNotifier::Read);
+               sn=eSocketNotifier::create(eApp, handle, eSocketNotifier::Read);
                CONNECT(sn->activated, eRCShortDriver::keyPressed);
                eRCInput::getInstance()->setFile(handle);
        }
@@ -89,8 +89,6 @@ eRCShortDriver::~eRCShortDriver()
 {
        if (handle>=0)
                close(handle);
-       if (sn)
-               delete sn;
 }
 
 void eRCInputEventDriver::keyPressed(int)
@@ -115,7 +113,7 @@ eRCInputEventDriver::eRCInputEventDriver(const char *filename): eRCDriver(eRCInp
                sn=0;
        } else
        {
-               sn=new eSocketNotifier(eApp, handle, eSocketNotifier::Read);
+               sn=eSocketNotifier::create(eApp, handle, eSocketNotifier::Read);
                CONNECT(sn->activated, eRCInputEventDriver::keyPressed);
                eRCInput::getInstance()->setFile(handle);
        }
@@ -133,8 +131,6 @@ eRCInputEventDriver::~eRCInputEventDriver()
 {
        if (handle>=0)
                close(handle);
-       if (sn)
-               delete sn;
 }
 
 eRCConfig::eRCConfig()
index 2a776ee4d5e0ec35bf1fc9789a4a4e1c7ae62581..9708ea7b73d81907c37a98a2f1faca139f4d5679 100644 (file)
@@ -95,7 +95,7 @@ class eRCShortDriver: public eRCDriver
 {
 protected:
        int handle;
-       eSocketNotifier *sn;
+       ePtr<eSocketNotifier> sn;
        void keyPressed(int);
 public:
        eRCShortDriver(const char *filename);
@@ -106,7 +106,7 @@ class eRCInputEventDriver: public eRCDriver
 {
 protected:
        int handle;
-       eSocketNotifier *sn;
+       ePtr<eSocketNotifier> sn;
        void keyPressed(int);
 public:
        std::string getDeviceName();
index 53630ca96502c7dcc3335935870e76ab3264da13..05fbec1dde6aaecdb715a2b80b50cf0a2a7c474e 100644 (file)
@@ -14,7 +14,7 @@ eRCConsoleDriver::eRCConsoleDriver(const char *filename): eRCDriver(eRCInput::ge
                sn=0;
        } else
        {
-               sn=new eSocketNotifier(eApp, handle, eSocketNotifier::Read);
+               sn=eSocketNotifier::create(eApp, handle, eSocketNotifier::Read);
                CONNECT(sn->activated, eRCConsoleDriver::keyPressed);
                eRCInput::getInstance()->setFile(handle);
        }
@@ -32,8 +32,6 @@ eRCConsoleDriver::~eRCConsoleDriver()
        tcsetattr(handle,TCSANOW, &ot);
        if (handle>=0)
                close(handle);
-       if (sn)
-               delete sn;
 }
 
 void eRCConsoleDriver::keyPressed(int)
index 4af2a4c2134d80442f057163d0538800524290b4..85234d5b1ea75537599858ef193b73e739d9d3c8 100644 (file)
@@ -9,7 +9,7 @@ class eRCConsoleDriver: public eRCDriver
        struct termios ot;
 protected:
        int handle;
-       eSocketNotifier *sn;
+       ePtr<eSocketNotifier> sn;
        void keyPressed(int);
 public:
        eRCConsoleDriver(const char *filename);
index 57f48ee3a7e6cb1ad382b4f03df97f5ab32d4f1a..c550163e5e984c9e0cd04176c6456a631ea61b52 100644 (file)
@@ -315,7 +315,7 @@ eDVBVideo::eDVBVideo(eDVBDemux *demux, int dev)
                eWarning("%s: %m", filename);
        else
        {
-               m_sn = new eSocketNotifier(eApp, m_fd, eSocketNotifier::Priority);
+               m_sn = eSocketNotifier::create(eApp, m_fd, eSocketNotifier::Priority);
                CONNECT(m_sn->activated, eDVBVideo::video_event);
        }
        eDebug("Video Device: %s", filename);
@@ -527,8 +527,6 @@ int eDVBVideo::getPTS(pts_t &now)
 
 eDVBVideo::~eDVBVideo()
 {
-       if (m_sn)
-               delete m_sn;
        if (m_is_slow_motion)
                setSlowMotion(0);
        if (m_is_fast_forward)
index 7dfe38343a5868e605f0f5afaf1b1cf5dbeb111f..a652e094d359ff0d7c18547079f4ba3fedd8dfd9 100644 (file)
@@ -44,7 +44,7 @@ private:
        m_fd_video;
 #endif
        int m_is_slow_motion, m_is_fast_forward, m_is_freezed;
-       eSocketNotifier *m_sn;
+       ePtr<eSocketNotifier> m_sn;
        void video_event(int what);
        Signal1<void, struct iTSMPEGDecoder::videoEvent> m_event;
 public:
index 29bbf264c7f6fa71dea0ae40e6a43af7a7db486e..a0f1c326a9522f768afa375a2a92dbb37194ba5b 100644 (file)
@@ -206,7 +206,7 @@ eDVBSectionReader::eDVBSectionReader(eDVBDemux *demux, eMainloop *context, RESUL
        
        if (fd >= 0)
        {
-               notifier=new eSocketNotifier(context, fd, eSocketNotifier::Read, false);
+               notifier=eSocketNotifier::create(context, fd, eSocketNotifier::Read, false);
                CONNECT(notifier->activated, eDVBSectionReader::data);
                res = 0;
        } else
@@ -220,8 +220,6 @@ DEFINE_REF(eDVBSectionReader)
 
 eDVBSectionReader::~eDVBSectionReader()
 {
-       if (notifier)
-               delete notifier;
        if (fd >= 0)
                ::close(fd);
 }
@@ -331,7 +329,7 @@ eDVBPESReader::eDVBPESReader(eDVBDemux *demux, eMainloop *context, RESULT &res):
        {
                ::ioctl(m_fd, DMX_SET_BUFFER_SIZE, 64*1024);
                ::fcntl(m_fd, F_SETFL, O_NONBLOCK);
-               m_notifier = new eSocketNotifier(context, m_fd, eSocketNotifier::Read, false);
+               m_notifier = eSocketNotifier::create(context, m_fd, eSocketNotifier::Read, false);
                CONNECT(m_notifier->activated, eDVBPESReader::data);
                res = 0;
        } else
@@ -345,8 +343,6 @@ DEFINE_REF(eDVBPESReader)
 
 eDVBPESReader::~eDVBPESReader()
 {
-       if (m_notifier)
-               delete m_notifier;
        if (m_fd >= 0)
                ::close(m_fd);
 }
index 1c0da47c6f6b27f188b5a5f615f3a66b9a623740..1a7db9791296190350adbb6f1caf9c580eb1e19b 100644 (file)
@@ -54,7 +54,7 @@ class eDVBSectionReader: public iDVBSectionReader, public Object
        int active;
        int checkcrc;
        void data(int);
-       eSocketNotifier *notifier;
+       ePtr<eSocketNotifier> notifier;
 public:
        
        eDVBSectionReader(eDVBDemux *demux, eMainloop *context, RESULT &res);
@@ -72,7 +72,7 @@ class eDVBPESReader: public iDVBPESReader, public Object
        ePtr<eDVBDemux> m_demux;
        int m_active;
        void data(int);
-       eSocketNotifier *m_notifier;
+       ePtr<eSocketNotifier> m_notifier;
 public:
        eDVBPESReader(eDVBDemux *demux, eMainloop *context, RESULT &res);
        virtual ~eDVBPESReader();
index bfbd9b57934ee89dc89c9febcf5ab079b05c5449..01eb27ae731e5b1821728b396a1dabcf574941d7 100644 (file)
@@ -443,7 +443,7 @@ int eDVBFrontend::PriorityOrder=0;
 eDVBFrontend::eDVBFrontend(int adap, int fe, int &ok, bool simulate)
        :m_simulate(simulate), m_enabled(false), m_type(-1), m_dvbid(fe), m_slotid(fe)
        ,m_fd(-1), m_need_rotor_workaround(false), m_can_handle_dvbs2(false)
-       ,m_sn(0), m_timeout(0), m_tuneTimer(0)
+       , m_timeout(0), m_tuneTimer(0)
 #if HAVE_DVB_API_VERSION < 3
        ,m_secfd(-1)
 #endif
@@ -555,7 +555,7 @@ int eDVBFrontend::openFrontend()
 
        if (!m_simulate)
        {
-               m_sn = new eSocketNotifier(eApp, m_fd, eSocketNotifier::Read, false);
+               m_sn = eSocketNotifier::create(eApp, m_fd, eSocketNotifier::Read, false);
                CONNECT(m_sn->activated, eDVBFrontend::feEvent);
        }
 
@@ -607,7 +607,6 @@ int eDVBFrontend::closeFrontend(bool force)
                        eWarning("couldnt close sec %d", m_dvbid);
        }
 #endif
-       delete m_sn;
        m_sn=0;
        m_state = stateClosed;
 
index 0ab2387ed1b0816300de6c7a05128d22ed75d89b..61ea3bcfe7ee248aef8fb3b403b077c68de0ed7e 100644 (file)
@@ -85,7 +85,7 @@ private:
        FRONTENDPARAMETERS parm;
        int m_state;
        ePtr<iDVBSatelliteEquipmentControl> m_sec;
-       eSocketNotifier *m_sn;
+       ePtr<eSocketNotifier> m_sn;
        int m_tuning;
        eTimer *m_timeout;
        eTimer *m_tuneTimer;
index c0447b47f8f0aa527fbfb2afea24497d118222c3..8364be5303b81b7616e720bd0ae37ba36c144b0b 100644 (file)
@@ -671,7 +671,7 @@ ChannelMap eDVBCAService::exist_channels;
 ePtr<eConnection> eDVBCAService::m_chanAddedConn;
 
 eDVBCAService::eDVBCAService()
-       :m_sn(0), m_prev_build_hash(0), m_sendstate(0), m_retryTimer(eApp)
+       : m_prev_build_hash(0), m_sendstate(0), m_retryTimer(eApp)
 {
        memset(m_used_demux, 0xFF, sizeof(m_used_demux));
        CONNECT(m_retryTimer.timeout, eDVBCAService::sendCAPMT);
@@ -682,7 +682,6 @@ eDVBCAService::~eDVBCAService()
 {
        eDebug("[eDVBCAService] free service %s", m_service.toString().c_str());
        ::close(m_sock);
-       delete m_sn;
 }
 
 // begin static methods
@@ -876,10 +875,7 @@ void eDVBCAService::socketCB(int what)
 
 void eDVBCAService::Connect()
 {
-       if (m_sn) {
-               delete m_sn;
-               m_sn=0;
-       }
+       m_sn=0;
        memset(&m_servaddr, 0, sizeof(struct sockaddr_un));
        m_servaddr.sun_family = AF_UNIX;
        strcpy(m_servaddr.sun_path, "/tmp/camd.socket");
@@ -892,7 +888,7 @@ void eDVBCAService::Connect()
                        int val=1;
                        fcntl(m_sock, F_SETFL, O_NONBLOCK);
                        setsockopt(m_sock, SOL_SOCKET, SO_REUSEADDR, &val, 4);
-                       m_sn = new eSocketNotifier(eApp, m_sock,
+                       m_sn = eSocketNotifier::create(eApp, m_sock,
                                eSocketNotifier::Read|eSocketNotifier::Priority|eSocketNotifier::Error|eSocketNotifier::Hungup);
                        CONNECT(m_sn->activated, eDVBCAService::socketCB);
                        
index 9b33d30b9bacf984f1b99dff214c86d56aa17400..bd6c4f166f20f3c1082be2c2474f1fb1407c2112 100644 (file)
@@ -35,7 +35,7 @@ typedef std::map<iDVBChannel*, channel_data*> ChannelMap;
 
 class eDVBCAService: public Object
 {
-       eSocketNotifier *m_sn;
+       ePtr<eSocketNotifier> m_sn;
        eServiceReferenceDVB m_service;
        uint8_t m_used_demux[32];
        unsigned int m_prev_build_hash;
index 9a3739a09dc5841e64af2e7e205b19ba7940f000..7525040452c8794f5fadea6c44beadc25ed31a70 100644 (file)
@@ -898,7 +898,7 @@ eDVBCISlot::eDVBCISlot(eMainloop *context, int nr)
 
        if (fd >= 0)
        {
-               notifier = new eSocketNotifier(context, fd, eSocketNotifier::Read | eSocketNotifier::Priority | eSocketNotifier::Write);
+               notifier = eSocketNotifier::create(context, fd, eSocketNotifier::Read | eSocketNotifier::Priority | eSocketNotifier::Write);
                CONNECT(notifier->activated, eDVBCISlot::data);
        } else
        {
@@ -908,7 +908,6 @@ eDVBCISlot::eDVBCISlot(eMainloop *context, int nr)
 
 eDVBCISlot::~eDVBCISlot()
 {
-       delete notifier;
 }
 
 void eDVBCISlot::setAppManager( eDVBCIApplicationManagerSession *session )
index 8fa313e2709c8cfaa4d2e153a8b603e60c12fd62..4e3fcce276bc5345526f8a765f0327e6c72107b4 100644 (file)
@@ -44,7 +44,7 @@ class eDVBCISlot: public iObject, public Object
        DECLARE_REF(eDVBCISlot);
        int slotid;
        int fd;
-       eSocketNotifier *notifier;
+       ePtr<eSocketNotifier> notifier;
        int state;
        std::map<uint16_t, uint8_t> running_services;
        eDVBCIApplicationManagerSession *application_manager;
index b2ab7437642568a520391f7ae0846cd766471d97..162ead81a62b4aabed1f22e2be66a202a34bb25d 100644 (file)
@@ -10,7 +10,6 @@ void eSocket::close()
        if (writebuffer.empty())
        {
                int wasconnected=(mystate==Connection) || (mystate==Closing);
-               delete rsn;
                rsn=0;
                ::close(socketdesc);
                socketdesc=-1;
@@ -87,9 +86,8 @@ int eSocket::setSocket(int s, int iss, eMainloop *ml)
        fcntl(socketdesc, F_SETFL, O_NONBLOCK);
        last_break = 0xFFFFFFFF;
 
-       if (rsn)
-               delete rsn;
-       rsn=new eSocketNotifier(ml, getDescriptor(), 
+       rsn = 0;
+       rsn=eSocketNotifier::create(ml, getDescriptor(), 
                eSocketNotifier::Read|eSocketNotifier::Hungup);
        CONNECT(rsn->activated, eSocket::notifier);
        return 0;
@@ -278,7 +276,7 @@ eSocket::eSocket(eMainloop *ml): readbuffer(32768), writebuffer(32768), rsn(0)
        setSocket(s, 1, ml);
 }
 
-eSocket::eSocket(int socket, int issocket, eMainloop *ml): readbuffer(32768), writebuffer(32768), rsn(0)
+eSocket::eSocket(int socket, int issocket, eMainloop *ml): readbuffer(32768), writebuffer(32768)
 {
        setSocket(socket, issocket, ml);
        mystate=Connection;
@@ -286,8 +284,6 @@ eSocket::eSocket(int socket, int issocket, eMainloop *ml): readbuffer(32768), wr
 
 eSocket::~eSocket()
 {
-       if (rsn)
-               delete rsn;
        if(socketdesc>=0)
        {
                ::close(socketdesc);
index 08a191f6f1edd3553ace2eb290278876c4778813..9ffc7a782d9ef8b7b8fe30dbeacdd9cdc54dedfb 100644 (file)
@@ -26,7 +26,7 @@ private:
        int writebusy;
        sockaddr_in  serv_addr;
 protected:
-       eSocketNotifier *rsn;
+       ePtr<eSocketNotifier> rsn;
        virtual void notifier(int);
 public:
        eSocket(eMainloop *ml);
index da7bc5f22e852abc90a4dd25cde484ed7de2119a..1add04ab47661bd55c460d364baf94406c96eb7e 100644 (file)
@@ -91,9 +91,9 @@ eServiceDVD::eServiceDVD(const char *filename):
        m_subtitle_widget(0),
        m_state(stIdle),
        m_current_trick(0),
-       m_sn(eApp, ddvd_get_messagepipe_fd(m_ddvdconfig), eSocketNotifier::Read|eSocketNotifier::Priority|eSocketNotifier::Error|eSocketNotifier::Hungup),
        m_pump(eApp, 1)
 {
+       m_sn = eSocketNotifier::create(eApp, ddvd_get_messagepipe_fd(m_ddvdconfig), eSocketNotifier::Read|eSocketNotifier::Priority|eSocketNotifier::Error|eSocketNotifier::Hungup);
        std::string aspect;
        eDebug("SERVICEDVD construct!");
        // create handle
@@ -111,7 +111,7 @@ eServiceDVD::eServiceDVD(const char *filename):
                ddvd_set_video(m_ddvdconfig, DDVD_16_9, DDVD_PAL);
 
        ddvd_set_lfb(m_ddvdconfig, (unsigned char *)m_pixmap->surface->data, 720, 576, 4, 720*4);
-       CONNECT(m_sn.activated, eServiceDVD::gotMessage);
+       CONNECT(m_sn->activated, eServiceDVD::gotMessage);
        CONNECT(m_pump.recv_msg, eServiceDVD::gotThreadMessage);
        strcpy(m_ddvd_titlestring,"");
        m_cue_pts = 0;
index bdec483650c30dad80cecc1c6c763b68612ba9cb..12e21d2f63c7ae439846a812ef8012373d772b9b 100644 (file)
@@ -118,7 +118,7 @@ private:
 
        char m_ddvd_titlestring[96];
 
-       eSocketNotifier m_sn;
+       ePtr<eSocketNotifier> m_sn;
        eFixedMessagePump<int> m_pump;
 
        pts_t m_cue_pts;
index 36ce9f4093b25c0ac694e912f459196144a06049..673b525c22e82477d2d562fac8c8a19970342a24 100644 (file)
@@ -129,7 +129,7 @@ int eSocketMMIHandler::send_to_mmisock( void* buf, size_t len)
 }
 
 eSocketMMIHandler::eSocketMMIHandler()
-       :buffer(512), connfd(-1), connsn(0), sockname("/tmp/mmi.socket"), name(0)
+       :buffer(512), connfd(-1), sockname("/tmp/mmi.socket"), name(0)
 {
        memset(&servaddr, 0, sizeof(struct sockaddr_un));
        servaddr.sun_family = AF_UNIX;
@@ -154,7 +154,7 @@ eSocketMMIHandler::eSocketMMIHandler()
        else if (listen(listenfd, 0) == -1)
                eDebug("[eSocketMMIHandler] listen (%m)");
        else {
-               listensn = new eSocketNotifier( eApp, listenfd, POLLIN );
+               listensn = eSocketNotifier::create( eApp, listenfd, POLLIN );
                listensn->start();
                CONNECT( listensn->activated, eSocketMMIHandler::listenDataAvail );
                eDebug("[eSocketMMIHandler] created successfully");
@@ -186,7 +186,7 @@ void eSocketMMIHandler::listenDataAvail(int what)
                else if (fcntl(connfd, F_SETFL, val | O_NONBLOCK) == -1)
                        eDebug("[eSocketMMIHandler] F_SETFL (%m)");
                else {
-                       connsn = new eSocketNotifier( eApp, connfd, POLLIN|POLLHUP|POLLERR );
+                       connsn = eSocketNotifier::create( eApp, connfd, POLLIN|POLLHUP|POLLERR );
                        CONNECT( connsn->activated, eSocketMMIHandler::connDataAvail );
                        return;
                }
@@ -294,11 +294,7 @@ void eSocketMMIHandler::closeConn()
                close(connfd);
                connfd=-1;
        }
-       if ( connsn )
-       {
-               delete connsn;
-               connsn=0;
-       }
+       connsn=0;
        if ( name )
        {
                delete [] name;
@@ -309,7 +305,6 @@ void eSocketMMIHandler::closeConn()
 eSocketMMIHandler::~eSocketMMIHandler()
 {
        closeConn();
-       delete listensn;
        unlink(sockname);
 }
 
index ebba9a6277306c814ca56e156e1338a64e8d76cd..063e1d54f2d07501014bfb04d86312b66fc8cd1e 100644 (file)
@@ -16,7 +16,7 @@ class eSocketMMIHandler: public Object
        eIOBuffer buffer;
        int listenfd, connfd, clilen;
        struct sockaddr_un servaddr;
-       eSocketNotifier *listensn, *connsn;
+       ePtr<eSocketNotifier> listensn, connsn;
        void listenDataAvail(int what);
        void connDataAvail(int what);
        void closeConn();
index b54c07b16620287b40684b98592a936b6b5c7e50..c0d38f8931a38c8a3fc1786ec9a60f6087f2d3ef 100644 (file)
@@ -1,14 +1,11 @@
 #include <lib/python/connections.h>
 
 PSignal::PSignal()
-       :m_destroyed(0)
 {
 }
 
 PSignal::~PSignal()
 {
-       if (m_destroyed)
-               *m_destroyed = true;
        Py_XDECREF(m_list);
 }
 
@@ -23,12 +20,21 @@ void PSignal::callPython(ePyObject tuple)
        }
 }
 
-PyObject *PSignal::get(bool steal)
+PyObject *PSignal::get()
 {
-       if (!steal) {
-               if (!m_list)
-                       m_list = PyList_New(0);
-               Py_INCREF(m_list);
+       if (!m_list)
+               m_list = PyList_New(0);
+       Py_INCREF(m_list);
+       return m_list;
+}
+
+PyObject *PSignal::getSteal(bool clear)
+{
+       if (clear)
+       {
+               ePyObject ret = m_list;
+               m_list = (PyObject*)0;
+               return ret;
        }
        return m_list;
 }
index ab123137db9a2ec6fc6d5538946e47fe210cd35c..ad76198a7ca1d35e29826a2f98a434288fb333ff 100644 (file)
@@ -14,12 +14,14 @@ class PSignal
 {
 protected:
        ePyObject m_list;
-       bool *m_destroyed;
 public:
        PSignal();
        ~PSignal();
        void callPython(SWIG_PYOBJECT(ePyObject) tuple);
-       PyObject *get(bool steal=false);
+#ifndef SWIG
+       PyObject *getSteal(bool clear=false);
+#endif
+       PyObject *get();
 };
 
 inline PyObject *PyFrom(int v)
@@ -38,18 +40,13 @@ class PSignal0: public PSignal, public Signal0<R>
 public:
        R operator()()
        {
-               bool destroyed=false;
-               m_destroyed = &destroyed;
                if (m_list)
                {
                        PyObject *pArgs = PyTuple_New(0);
                        callPython(pArgs);
                        Org_Py_DECREF(pArgs);
                }
-               if (!destroyed) {
-                       m_destroyed = 0;
-                       return Signal0<R>::operator()();
-               }
+               return Signal0<R>::operator()();
        }
 };
 
@@ -59,8 +56,6 @@ class PSignal1: public PSignal, public Signal1<R,V0>
 public:
        R operator()(V0 a0)
        {
-               bool destroyed=false;
-               m_destroyed = &destroyed;
                if (m_list)
                {
                        PyObject *pArgs = PyTuple_New(1);
@@ -68,10 +63,7 @@ public:
                        callPython(pArgs);
                        Org_Py_DECREF(pArgs);
                }
-               if (!destroyed) {
-                       m_destroyed = 0;
-                       return Signal1<R,V0>::operator()(a0);
-               }
+               return Signal1<R,V0>::operator()(a0);
        }
 };
 
@@ -81,8 +73,6 @@ class PSignal2: public PSignal, public Signal2<R,V0,V1>
 public:
        R operator()(V0 a0, V1 a1)
        {
-               bool destroyed=false;
-               m_destroyed = &destroyed;
                if (m_list)
                {
                        PyObject *pArgs = PyTuple_New(2);
@@ -91,10 +81,7 @@ public:
                        callPython(pArgs);
                        Org_Py_DECREF(pArgs);
                }
-               if (!destroyed) {
-                       m_destroyed = 0;
-                       return Signal2<R,V0,V1>::operator()(a0, a1);
-               }
+               return Signal2<R,V0,V1>::operator()(a0, a1);
        }
 };