From: Andreas Monzner Date: Wed, 29 Oct 2008 19:46:57 +0000 (+0000) Subject: better solution to add possibility to delete eSocketNotifiers, X-Git-Url: http://code.vuplus.com/gitweb/?p=vuplus_dvbapp;a=commitdiff_plain;h=10e7e45ae92d4fe06f70126ed256b87896dbc432;hp=6bb94cd5b0d8fd3608afe84e8d76aef554a4b401 better solution to add possibility to delete eSocketNotifiers, eConsoleAppContainers in callback funktions without crash --- diff --git a/lib/base/console.cpp b/lib/base/console.cpp index 830855f..a12cb5e 100644 --- a/lib/base/console.cpp +++ b/lib/base/console.cpp @@ -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; } diff --git a/lib/base/console.h b/lib/base/console.h index a5712bb..e730b40 100644 --- a/lib/base/console.h +++ b/lib/base/console.h @@ -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 outbuf; - eSocketNotifier *in, *out, *err; + ePtr in, out, err; void readyRead(int what); void readyErrRead(int what); void readyWrite(int what); diff --git a/lib/base/ebase.cpp b/lib/base/ebase.cpp index e770863..a66d195 100644 --- a/lib/base/ebase.cpp +++ b/lib/base/ebase.cpp @@ -8,9 +8,11 @@ #include #include +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::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::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; } diff --git a/lib/base/ebase.h b/lib/base/ebase.h index 10b4612..cb676d0 100644 --- a/lib/base/ebase.h +++ b/lib/base/ebase.h @@ -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 activated; @@ -173,6 +175,8 @@ public: int getFD() { return fd; } int getRequested() { return requested; } void setRequested(int req) { requested=req; } + + eSmartPtrList m_clients; }; #endif diff --git a/lib/base/message.h b/lib/base/message.h index 038fd55..6e9eb07 100644 --- a/lib/base/message.h +++ b/lib/base/message.h @@ -39,7 +39,7 @@ protected: template class eFixedMessagePump: private eMessagePump, public Object { - eSocketNotifier *sn; + ePtr 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::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 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(); } }; diff --git a/lib/driver/avswitch.cpp b/lib/driver/avswitch.cpp index 1f2765e..dbfebf5 100644 --- a/lib/driver/avswitch.cpp +++ b/lib/driver/avswitch.cpp @@ -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() diff --git a/lib/driver/avswitch.h b/lib/driver/avswitch.h index cc92e20..8fdafdd 100644 --- a/lib/driver/avswitch.h +++ b/lib/driver/avswitch.h @@ -10,7 +10,7 @@ class eAVSwitch: public Object { static eAVSwitch *instance; int m_video_mode; - eSocketNotifier *m_fp_notifier; + ePtr m_fp_notifier; void fp_event(int what); int m_fp_fd; #ifdef SWIG diff --git a/lib/driver/rc.cpp b/lib/driver/rc.cpp index d943352..c7acd11 100644 --- a/lib/driver/rc.cpp +++ b/lib/driver/rc.cpp @@ -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() diff --git a/lib/driver/rc.h b/lib/driver/rc.h index 2a776ee..9708ea7 100644 --- a/lib/driver/rc.h +++ b/lib/driver/rc.h @@ -95,7 +95,7 @@ class eRCShortDriver: public eRCDriver { protected: int handle; - eSocketNotifier *sn; + ePtr sn; void keyPressed(int); public: eRCShortDriver(const char *filename); @@ -106,7 +106,7 @@ class eRCInputEventDriver: public eRCDriver { protected: int handle; - eSocketNotifier *sn; + ePtr sn; void keyPressed(int); public: std::string getDeviceName(); diff --git a/lib/driver/rcconsole.cpp b/lib/driver/rcconsole.cpp index 53630ca..05fbec1 100644 --- a/lib/driver/rcconsole.cpp +++ b/lib/driver/rcconsole.cpp @@ -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) diff --git a/lib/driver/rcconsole.h b/lib/driver/rcconsole.h index 4af2a4c..85234d5 100644 --- a/lib/driver/rcconsole.h +++ b/lib/driver/rcconsole.h @@ -9,7 +9,7 @@ class eRCConsoleDriver: public eRCDriver struct termios ot; protected: int handle; - eSocketNotifier *sn; + ePtr sn; void keyPressed(int); public: eRCConsoleDriver(const char *filename); diff --git a/lib/dvb/decoder.cpp b/lib/dvb/decoder.cpp index 57f48ee..c550163 100644 --- a/lib/dvb/decoder.cpp +++ b/lib/dvb/decoder.cpp @@ -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) diff --git a/lib/dvb/decoder.h b/lib/dvb/decoder.h index 7dfe383..a652e09 100644 --- a/lib/dvb/decoder.h +++ b/lib/dvb/decoder.h @@ -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 m_sn; void video_event(int what); Signal1 m_event; public: diff --git a/lib/dvb/demux.cpp b/lib/dvb/demux.cpp index 29bbf26..a0f1c32 100644 --- a/lib/dvb/demux.cpp +++ b/lib/dvb/demux.cpp @@ -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); } diff --git a/lib/dvb/demux.h b/lib/dvb/demux.h index 1c0da47..1a7db97 100644 --- a/lib/dvb/demux.h +++ b/lib/dvb/demux.h @@ -54,7 +54,7 @@ class eDVBSectionReader: public iDVBSectionReader, public Object int active; int checkcrc; void data(int); - eSocketNotifier *notifier; + ePtr notifier; public: eDVBSectionReader(eDVBDemux *demux, eMainloop *context, RESULT &res); @@ -72,7 +72,7 @@ class eDVBPESReader: public iDVBPESReader, public Object ePtr m_demux; int m_active; void data(int); - eSocketNotifier *m_notifier; + ePtr m_notifier; public: eDVBPESReader(eDVBDemux *demux, eMainloop *context, RESULT &res); virtual ~eDVBPESReader(); diff --git a/lib/dvb/frontend.cpp b/lib/dvb/frontend.cpp index bfbd9b5..01eb27a 100644 --- a/lib/dvb/frontend.cpp +++ b/lib/dvb/frontend.cpp @@ -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; diff --git a/lib/dvb/frontend.h b/lib/dvb/frontend.h index 0ab2387..61ea3bc 100644 --- a/lib/dvb/frontend.h +++ b/lib/dvb/frontend.h @@ -85,7 +85,7 @@ private: FRONTENDPARAMETERS parm; int m_state; ePtr m_sec; - eSocketNotifier *m_sn; + ePtr m_sn; int m_tuning; eTimer *m_timeout; eTimer *m_tuneTimer; diff --git a/lib/dvb/pmt.cpp b/lib/dvb/pmt.cpp index c0447b4..8364be5 100644 --- a/lib/dvb/pmt.cpp +++ b/lib/dvb/pmt.cpp @@ -671,7 +671,7 @@ ChannelMap eDVBCAService::exist_channels; ePtr 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); diff --git a/lib/dvb/pmt.h b/lib/dvb/pmt.h index 9b33d30..bd6c4f1 100644 --- a/lib/dvb/pmt.h +++ b/lib/dvb/pmt.h @@ -35,7 +35,7 @@ typedef std::map ChannelMap; class eDVBCAService: public Object { - eSocketNotifier *m_sn; + ePtr m_sn; eServiceReferenceDVB m_service; uint8_t m_used_demux[32]; unsigned int m_prev_build_hash; diff --git a/lib/dvb_ci/dvbci.cpp b/lib/dvb_ci/dvbci.cpp index 9a3739a..7525040 100644 --- a/lib/dvb_ci/dvbci.cpp +++ b/lib/dvb_ci/dvbci.cpp @@ -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 ) diff --git a/lib/dvb_ci/dvbci.h b/lib/dvb_ci/dvbci.h index 8fa313e..4e3fcce 100644 --- a/lib/dvb_ci/dvbci.h +++ b/lib/dvb_ci/dvbci.h @@ -44,7 +44,7 @@ class eDVBCISlot: public iObject, public Object DECLARE_REF(eDVBCISlot); int slotid; int fd; - eSocketNotifier *notifier; + ePtr notifier; int state; std::map running_services; eDVBCIApplicationManagerSession *application_manager; diff --git a/lib/network/socket.cpp b/lib/network/socket.cpp index b2ab743..162ead8 100644 --- a/lib/network/socket.cpp +++ b/lib/network/socket.cpp @@ -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); diff --git a/lib/network/socket.h b/lib/network/socket.h index 08a191f..9ffc7a7 100644 --- a/lib/network/socket.h +++ b/lib/network/socket.h @@ -26,7 +26,7 @@ private: int writebusy; sockaddr_in serv_addr; protected: - eSocketNotifier *rsn; + ePtr rsn; virtual void notifier(int); public: eSocket(eMainloop *ml); diff --git a/lib/python/Plugins/Extensions/DVDPlayer/src/servicedvd.cpp b/lib/python/Plugins/Extensions/DVDPlayer/src/servicedvd.cpp index da7bc5f..1add04a 100644 --- a/lib/python/Plugins/Extensions/DVDPlayer/src/servicedvd.cpp +++ b/lib/python/Plugins/Extensions/DVDPlayer/src/servicedvd.cpp @@ -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; diff --git a/lib/python/Plugins/Extensions/DVDPlayer/src/servicedvd.h b/lib/python/Plugins/Extensions/DVDPlayer/src/servicedvd.h index bdec483..12e21d2 100644 --- a/lib/python/Plugins/Extensions/DVDPlayer/src/servicedvd.h +++ b/lib/python/Plugins/Extensions/DVDPlayer/src/servicedvd.h @@ -118,7 +118,7 @@ private: char m_ddvd_titlestring[96]; - eSocketNotifier m_sn; + ePtr m_sn; eFixedMessagePump m_pump; pts_t m_cue_pts; diff --git a/lib/python/Plugins/Extensions/SocketMMI/src/socket_mmi.cpp b/lib/python/Plugins/Extensions/SocketMMI/src/socket_mmi.cpp index 36ce9f4..673b525 100644 --- a/lib/python/Plugins/Extensions/SocketMMI/src/socket_mmi.cpp +++ b/lib/python/Plugins/Extensions/SocketMMI/src/socket_mmi.cpp @@ -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); } diff --git a/lib/python/Plugins/Extensions/SocketMMI/src/socket_mmi.h b/lib/python/Plugins/Extensions/SocketMMI/src/socket_mmi.h index ebba9a6..063e1d5 100644 --- a/lib/python/Plugins/Extensions/SocketMMI/src/socket_mmi.h +++ b/lib/python/Plugins/Extensions/SocketMMI/src/socket_mmi.h @@ -16,7 +16,7 @@ class eSocketMMIHandler: public Object eIOBuffer buffer; int listenfd, connfd, clilen; struct sockaddr_un servaddr; - eSocketNotifier *listensn, *connsn; + ePtr listensn, connsn; void listenDataAvail(int what); void connDataAvail(int what); void closeConn(); diff --git a/lib/python/connections.cpp b/lib/python/connections.cpp index b54c07b..c0d38f8 100644 --- a/lib/python/connections.cpp +++ b/lib/python/connections.cpp @@ -1,14 +1,11 @@ #include 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; } diff --git a/lib/python/connections.h b/lib/python/connections.h index ab12313..ad76198 100644 --- a/lib/python/connections.h +++ b/lib/python/connections.h @@ -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 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::operator()(); - } + return Signal0::operator()(); } }; @@ -59,8 +56,6 @@ class PSignal1: public PSignal, public Signal1 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::operator()(a0); - } + return Signal1::operator()(a0); } }; @@ -81,8 +73,6 @@ class PSignal2: public PSignal, public Signal2 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::operator()(a0, a1); - } + return Signal2::operator()(a0, a1); } };