From 54f8b4f0a6d3296d0a058ed12ad592dce552bc01 Mon Sep 17 00:00:00 2001 From: Rolf Ahrenberg Date: Mon, 17 Nov 2014 22:33:38 +0200 Subject: [PATCH] Get rid of pointers. --- discover.c | 42 ++++++++++++++++++------------------------ discover.h | 2 +- 2 files changed, 19 insertions(+), 25 deletions(-) diff --git a/discover.c b/discover.c index 4433243..f8fbd82 100644 --- a/discover.c +++ b/discover.c @@ -124,7 +124,7 @@ cSatipDiscover::cSatipDiscover() handleM(curl_easy_init()), sleepM(), probeIntervalM(0), - serversM(new cSatipServers()) + serversM() { debug("cSatipDiscover::%s()", __FUNCTION__); } @@ -135,7 +135,6 @@ cSatipDiscover::~cSatipDiscover() Deactivate(); cMutexLock MutexLock(&mutexM); // Free allocated memory - DELETENULL(serversM); if (handleM) curl_easy_cleanup(handleM); handleM = NULL; @@ -170,8 +169,7 @@ void cSatipDiscover::Action(void) probeIntervalM.Set(eProbeIntervalMs); msearchM.Probe(); mutexM.Lock(); - if (serversM) - serversM->Cleanup(eProbeIntervalMs * 2); + serversM.Cleanup(eProbeIntervalMs * 2); mutexM.Unlock(); } mutexM.Lock(); @@ -242,79 +240,75 @@ void cSatipDiscover::AddServer(const char *addrP, const char *modelP, const char { debug("cSatipDiscover::%s(%s, %s, %s)", __FUNCTION__, addrP, modelP, descP); cMutexLock MutexLock(&mutexM); - if (serversM) { - cSatipServer *tmp = new cSatipServer(addrP, modelP, descP); - // Validate against existing servers - if (!serversM->Update(tmp)) { - info("Adding device '%s|%s|%s'", tmp->Address(), tmp->Model(), tmp->Description()); - serversM->Add(tmp); - } - else - DELETENULL(tmp); + cSatipServer *tmp = new cSatipServer(addrP, modelP, descP); + // Validate against existing servers + if (!serversM.Update(tmp)) { + info("Adding device '%s|%s|%s'", tmp->Address(), tmp->Model(), tmp->Description()); + serversM.Add(tmp); } + else + DELETENULL(tmp); } int cSatipDiscover::GetServerCount(void) { //debug("cSatipDiscover::%s()", __FUNCTION__); cMutexLock MutexLock(&mutexM); - return serversM ? serversM->Count() : -1; + return serversM.Count(); } cSatipServer *cSatipDiscover::GetServer(int sourceP, int transponderP, int systemP) { //debug("cSatipDiscover::%s(%d, %d, %d)", __FUNCTION__, sourceP, transponderP, systemP); cMutexLock MutexLock(&mutexM); - return serversM ? serversM->Find(sourceP, transponderP, systemP) : NULL; + return serversM.Find(sourceP, transponderP, systemP); } cSatipServer *cSatipDiscover::GetServer(cSatipServer *serverP) { //debug("cSatipDiscover::%s()", __FUNCTION__); cMutexLock MutexLock(&mutexM); - return serversM ? serversM->Find(serverP) : NULL; + return serversM.Find(serverP); } cSatipServers *cSatipDiscover::GetServers(void) { //debug("cSatipDiscover::%s()", __FUNCTION__); cMutexLock MutexLock(&mutexM); - return serversM; + return &serversM; } cString cSatipDiscover::GetServerString(cSatipServer *serverP) { //debug("cSatipDiscover::%s()", __FUNCTION__); cMutexLock MutexLock(&mutexM); - return serversM ? serversM->GetString(serverP) : ""; + return serversM.GetString(serverP); } cString cSatipDiscover::GetServerList(void) { //debug("cSatipDiscover::%s()", __FUNCTION__); cMutexLock MutexLock(&mutexM); - return serversM ? serversM->List() : ""; + return serversM.List(); } void cSatipDiscover::SetTransponder(cSatipServer *serverP, int transponderP) { //debug("cSatipDiscover::%s(%d)", __FUNCTION__, transponderP); cMutexLock MutexLock(&mutexM); - if (serversM) - serversM->SetTransponder(serverP, transponderP); + serversM.SetTransponder(serverP, transponderP); } void cSatipDiscover::UseServer(cSatipServer *serverP, bool onOffP) { //debug("cSatipDiscover::%s(%d)", __FUNCTION__, onOffP); cMutexLock MutexLock(&mutexM); - if (serversM) - serversM->Use(serverP, onOffP); + serversM.Use(serverP, onOffP); } int cSatipDiscover::NumProvidedSystems(void) { //debug("cSatipDiscover::%s()", __FUNCTION__); cMutexLock MutexLock(&mutexM); - return serversM ? serversM->NumProvidedSystems() : 0; + return serversM.NumProvidedSystems(); } diff --git a/discover.h b/discover.h index 6cb04a9..601676f 100644 --- a/discover.h +++ b/discover.h @@ -52,7 +52,7 @@ private: CURL *handleM; cCondWait sleepM; cTimeMs probeIntervalM; - cSatipServers *serversM; + cSatipServers serversM; void Activate(void); void Deactivate(void); void AddServer(const char *addrP, const char *modelP, const char *descP);