]> git.vomp.tv Git - vompclient.git/commitdiff
Connection failure detection
authorChris Tallon <chris@vomp.tv>
Sun, 12 Mar 2006 20:33:04 +0000 (20:33 +0000)
committerChris Tallon <chris@vomp.tv>
Sun, 12 Mar 2006 20:33:04 +0000 (20:33 +0000)
13 files changed:
command.cc
i18n.cc
player.cc
remote.cc
remote.h
tcp.cc
timers.cc
vdr.cc
vepgsettimer.cc
vepgsettimer.h
vlivebanner.cc
vvideolive.cc
vwelcome.cc

index a65538d5339dfe175ae308cd8e739c018076f8ab..286e1bd63896bb0b43633f609aa0d85f11f285cb 100644 (file)
@@ -337,6 +337,7 @@ void Command::doFromTheTop(bool which)
     connLost->draw();
     viewman->add(connLost);
     viewman->updateView(connLost);
+    remote->clearBuffer();
   }
   else
   {
@@ -618,18 +619,24 @@ void Command::doJustConnected(VConnect* vconnect)
 
   vdr->configSave("General", "Last Power State", "On");
 
+  // Make sure connection didn't die
+  if (!vdr->isConnected())
+  {
+    Command::getInstance()->connectionLost();
+  }
+  else
+  {
+    viewman->removeView(vi);
 
-  viewman->removeView(vi);
-
-  VWelcome* vw = new VWelcome();
-  vw->draw();
-  viewman->add(vw);
-  viewman->updateView(vw);
+    VWelcome* vw = new VWelcome();
+    vw->draw();
+    viewman->add(vw);
+    viewman->updateView(vw);
 
   // Enter pre-keys here
 //  handleCommand(Remote::THREE);
 //  handleCommand(Remote::DOWN);
 //  handleCommand(Remote::OK);
 //  handleCommand(Remote::PLAY);
-
+  }
 }
diff --git a/i18n.cc b/i18n.cc
index 4c04d83cda5b653334132861fe7b028288fd5e69..28904a0c65180035ef64001a27cd7ed66e8dcffe 100644 (file)
--- a/i18n.cc
+++ b/i18n.cc
@@ -38,6 +38,7 @@ int I18n::initialize(void)
     {
       LanguageID = 0;
     }
+    delete[] lang;
   }
   else
   {
index d8dc92e7403d1e971ba8179fbba1e50962049358..a48f557d84ed7ad553d95714cc0d321af0c965c2 100644 (file)
--- a/player.cc
+++ b/player.cc
@@ -211,6 +211,8 @@ void Player::stop()
   if (!initted) return;
   if (!playing) return;
 
+  logger->log("Player", Log::DEBUG, "Stop called", streamLength);
+
   if (ffwd || fbwd)
   {
     ffwd = false;
@@ -526,6 +528,14 @@ void Player::threadMethod()
     if (isRecording && ((lastRescan + 60) < time(NULL)))
     {
       streamLength = vdr->rescanRecording();
+      if (!vdr->isConnected())
+      {
+        Message* m = new Message();
+        m->message = Message::CONNECTION_LOST;
+        m->to = this;
+        commandMessageQueue->postMessage(m);
+        return;
+      }
       logger->log("Player", Log::DEBUG, "Rescanned and reset length: %llu", streamLength);
       lastRescan = time(NULL);
       setEndTS();
@@ -559,6 +569,15 @@ void Player::threadMethod()
     }
 
     threadBuffer = vdr->getBlock(feedPosition, askFor, &thisRead);
+    if (!vdr->isConnected())
+    {
+      Message* m = new Message();
+      m->message = Message::CONNECTION_LOST;
+      m->to = this;
+      commandMessageQueue->postMessage(m);
+      return;
+    }
+
     if (!threadBuffer) break;
 
     if (startup)
@@ -619,6 +638,9 @@ void Player::threadMethod()
 
   // end of recording
   logger->log("Player", Log::DEBUG, "Recording playback ends");
+
+  threadCheckExit();
+
   Message* m = new Message(); // Must be done after this thread finishes, and must break into master mutex
   if (streamLength) m->message = Message::STOP_PLAYBACK;  // recording
   else m->message = Message::STREAM_END;                  // live
index a0ed018aef5d658a4de9a70a5800644cc0f03da6..ce04e10f2ed16e8b571763c81b915542fe830579 100644 (file)
--- a/remote.cc
+++ b/remote.cc
@@ -145,3 +145,8 @@ UCHAR Remote::getButtonPress(int waitType)
   }
   return NA_UNKNOWN;
 }
+
+void Remote::clearBuffer()
+{
+  while(getButtonPress(3) != NA_NONE);
+}
index 799f62fbb364ea334ebd402aa9a2260a417ad67f..edba87a966e92d5fd8e0695c74f68546398cc10b 100644 (file)
--- a/remote.h
+++ b/remote.h
@@ -40,6 +40,7 @@ class Remote
     int getDevice();
     void setRemoteType(UCHAR type);
     UCHAR getButtonPress(int how);
+    void clearBuffer();
 
     // Not buttons
     const static UCHAR NA_NONE     = 98;
diff --git a/tcp.cc b/tcp.cc
index 07276abeb00a9370c5853bb4bbf214d43df7879a..6f68d4f16e92d6b5d8fdca9d403bc05d35c83725 100644 (file)
--- a/tcp.cc
+++ b/tcp.cc
@@ -249,7 +249,7 @@ int TCP::readData(UCHAR* buffer, int totalBytes)
   {
     FD_ZERO(&readSet);
     FD_SET(sock, &readSet);
-    timeout.tv_sec = 30;
+    timeout.tv_sec = 20;
     timeout.tv_usec = 0;
     success = select(sock + 1, &readSet, NULL, NULL, passToSelect);
     if (success < 1)
index e5307599756724390bf524267e24a95a66dbe8ef..26624b07fc2cfdc10941b3ff9dd4f45afa038e25 100755 (executable)
--- a/timers.cc
+++ b/timers.cc
@@ -271,7 +271,7 @@ void Timers::threadMethod()
 \r
     // timer ran out\r
 \r
-//##    Log::getInstance()->log("Timers", Log::DEBUG, "Timer firing for client %p ref %i", nextTimer->client, nextTimer->clientReference);\r
+    Log::getInstance()->log("Timers", Log::DEBUG, "Timer firing for client %p ref %i", nextTimer->client, nextTimer->clientReference);\r
 \r
     // send this timer to the timer receiver, via the command message queue\r
     // so that the gui mutex is locked when it happens\r
diff --git a/vdr.cc b/vdr.cc
index 0eee6eac660aa3208a696d0e75c6d5da0b555ad8..10e6d67faa89e48fe1cc2bc56fc346bb5d5ce770 100644 (file)
--- a/vdr.cc
+++ b/vdr.cc
@@ -154,7 +154,7 @@ void VDR::disconnect()
 
 void VDR::setReceiveWindow(size_t size)
 {
-  tcp->setReceiveWindow(size);
+  if (connected) tcp->setReceiveWindow(size);
 }
 
 ///////////////////////////////////////////////////////
@@ -226,8 +226,6 @@ long VDR::extractLONG()
 
 int VDR::doLogin()
 {
-  if (!connected) return 0;
-
   UCHAR buffer[14];
 
   *(unsigned long*)&buffer[0] = htonl(10);
@@ -235,8 +233,9 @@ int VDR::doLogin()
 
   tcp->getMAC((char*)&buffer[8]);
 
-
   pthread_mutex_lock(&mutex);
+  if (!connected) { pthread_mutex_unlock(&mutex); return 0; }
+
   int a = tcp->sendPacket(buffer, 14);
   if (a != 14)
   {
@@ -298,14 +297,14 @@ int VDR::doLogin()
 
 Directory* VDR::getRecordingsList()
 {
-  if (!connected) return 0;
-
   UCHAR buffer[8];
 
   *(unsigned long*)&buffer[0] = htonl(4);
   *(unsigned long*)&buffer[4] = htonl(VDR_GETRECORDINGLIST);
 
   pthread_mutex_lock(&mutex);
+  if (!connected) { pthread_mutex_unlock(&mutex); return 0; }
+
   int a = tcp->sendPacket(buffer, 8);
   if (a != 8)
   {
@@ -391,8 +390,6 @@ Directory* VDR::getRecordingsList()
 
 int VDR::deleteRecording(char* fileName)
 {
-  if (!connected) return 0;
-
   unsigned long totalLength = 8 + strlen(fileName) + 1;
   UCHAR buffer[totalLength];
 
@@ -401,6 +398,8 @@ int VDR::deleteRecording(char* fileName)
   strcpy((char*)&buffer[8], fileName);
 
   pthread_mutex_lock(&mutex);
+  if (!connected) { pthread_mutex_unlock(&mutex); return 0; }
+
   unsigned int a = tcp->sendPacket(buffer, totalLength);
   if (a != totalLength)
   {
@@ -424,8 +423,6 @@ int VDR::deleteRecording(char* fileName)
 
 char* VDR::getRecordingSummary(char* fileName)
 {
-  if (!connected) return 0;
-
   unsigned long totalLength = 8 + strlen(fileName) + 1;
   UCHAR buffer[totalLength];
 
@@ -434,6 +431,8 @@ char* VDR::getRecordingSummary(char* fileName)
   strcpy((char*)&buffer[8], fileName);
 
   pthread_mutex_lock(&mutex);
+  if (!connected) { pthread_mutex_unlock(&mutex); return 0; }
+
   unsigned int a = tcp->sendPacket(buffer, totalLength);
   if (a != totalLength)
   {
@@ -456,14 +455,14 @@ char* VDR::getRecordingSummary(char* fileName)
 
 ChannelList* VDR::getChannelsList(ULONG type)
 {
-  if (!connected) return 0;
-
   UCHAR buffer[8];
 
   *(unsigned long*)&buffer[0] = htonl(4);
   *(unsigned long*)&buffer[4] = htonl(VDR_GETCHANNELLIST);
 
   pthread_mutex_lock(&mutex);
+  if (!connected) { pthread_mutex_unlock(&mutex); return 0; }
+
   int a = tcp->sendPacket(buffer, 8);
   if (a != 8)
   {
@@ -508,8 +507,6 @@ ChannelList* VDR::getChannelsList(ULONG type)
 
 int VDR::streamChannel(ULONG number)
 {
-  if (!connected) return 0;
-
   UCHAR buffer[12];
 
   *(unsigned long*)&buffer[0] = htonl(8);
@@ -517,6 +514,8 @@ int VDR::streamChannel(ULONG number)
   *(unsigned long*)&buffer[8] = htonl(number);
 
   pthread_mutex_lock(&mutex);
+  if (!connected) { pthread_mutex_unlock(&mutex); return 0; }
+
   int a = tcp->sendPacket(buffer, 12);
 
   if (a != 12)
@@ -541,14 +540,14 @@ int VDR::streamChannel(ULONG number)
 
 int VDR::stopStreaming()
 {
-  if (!connected) return 0;
-
   UCHAR buffer[8];
 
   *(unsigned long*)&buffer[0] = htonl(4);
   *(unsigned long*)&buffer[4] = htonl(VDR_STOPSTREAMING);
 
   pthread_mutex_lock(&mutex);
+  if (!connected) { pthread_mutex_unlock(&mutex); return 0; }
+
   int a = tcp->sendPacket(buffer, 8);
 
   if (a != 8)
@@ -573,8 +572,6 @@ int VDR::stopStreaming()
 
 UCHAR* VDR::getBlock(ULLONG position, UINT maxAmount, UINT* amountReceived)
 {
-  if (!connected) return 0;
-
   UCHAR buffer[20];
 
   *(unsigned long*)&buffer[0] = htonl(16);
@@ -583,6 +580,8 @@ UCHAR* VDR::getBlock(ULLONG position, UINT maxAmount, UINT* amountReceived)
   *(unsigned long*)&buffer[16] = htonl(maxAmount);
 
   pthread_mutex_lock(&mutex);
+  if (!connected) { pthread_mutex_unlock(&mutex); return 0; }
+
   int a = tcp->sendPacket(buffer, 20);
   if (a != 20)
   {
@@ -597,6 +596,14 @@ UCHAR* VDR::getBlock(ULLONG position, UINT maxAmount, UINT* amountReceived)
     return NULL;
   }
 
+  if (serverError())
+  {
+    Log::getInstance()->log("VDR", Log::DEBUG, "Detected getblock 0");
+    freePacket();
+    pthread_mutex_unlock(&mutex);
+    return NULL;
+  }
+
   UCHAR* toReturn = packet;
   *amountReceived = packetLength;
   // Manually clean up instead of running freePacket to keep the block
@@ -610,8 +617,6 @@ UCHAR* VDR::getBlock(ULLONG position, UINT maxAmount, UINT* amountReceived)
 
 ULLONG VDR::streamRecording(Recording* rec)
 {
-  if (!connected) return 0;
-
   unsigned long totalLength = 8 + strlen(rec->fileName) + 1;
   UCHAR buffer[totalLength];
 
@@ -620,6 +625,8 @@ ULLONG VDR::streamRecording(Recording* rec)
   strcpy((char*)&buffer[8], rec->fileName);
 
   pthread_mutex_lock(&mutex);
+  if (!connected) { pthread_mutex_unlock(&mutex); return 0; }
+
   unsigned int a = tcp->sendPacket(buffer, totalLength);
   if (a != totalLength)
   {
@@ -645,8 +652,6 @@ ULLONG VDR::streamRecording(Recording* rec)
 
 ULLONG VDR::rescanRecording()
 {
-  if (!connected) return 0;
-
   unsigned long totalLength = 8;
   UCHAR buffer[totalLength];
 
@@ -654,6 +659,8 @@ ULLONG VDR::rescanRecording()
   *(unsigned long*)&buffer[4] = htonl(VDR_RESCANRECORDING);
 
   pthread_mutex_lock(&mutex);
+  if (!connected) { pthread_mutex_unlock(&mutex); return 0; }
+
   unsigned int a = tcp->sendPacket(buffer, totalLength);
   if (a != totalLength)
   {
@@ -679,8 +686,6 @@ ULLONG VDR::rescanRecording()
 
 ULLONG VDR::positionFromFrameNumber(ULONG frameNumber)
 {
-  if (!connected) return 0;
-
   unsigned long totalLength = 12;
   UCHAR buffer[totalLength];
 
@@ -689,6 +694,8 @@ ULLONG VDR::positionFromFrameNumber(ULONG frameNumber)
   *(unsigned long*)&buffer[8] = htonl(frameNumber);
 
   pthread_mutex_lock(&mutex);
+  if (!connected) { pthread_mutex_unlock(&mutex); return 0; }
+
   unsigned int a = tcp->sendPacket(buffer, totalLength);
   if (a != totalLength)
   {
@@ -722,8 +729,6 @@ EventList* VDR::getChannelSchedule(ULONG number)
 EventList* VDR::getChannelSchedule(ULONG number, time_t start, ULONG duration)
 {
 // retrieve event list (vector of events) from vdr within filter window. duration is in seconds
-  if (!connected) return 0;
-
   UCHAR buffer[20];
 
   *(unsigned long*)&buffer[0] = htonl(16);
@@ -733,6 +738,8 @@ EventList* VDR::getChannelSchedule(ULONG number, time_t start, ULONG duration)
   *(unsigned long*)&buffer[16] = htonl(duration);
 
   pthread_mutex_lock(&mutex);
+  if (!connected) { pthread_mutex_unlock(&mutex); return 0; }
+
   int a = tcp->sendPacket(buffer, 20);
 
   if (a != 20)
@@ -748,10 +755,10 @@ EventList* VDR::getChannelSchedule(ULONG number, time_t start, ULONG duration)
     return NULL;
   }
 
+  // received a ulong(0) - schedules error in the plugin
   if (serverError())
   {
     freePacket();
-    disconnect();
     pthread_mutex_unlock(&mutex);
     return NULL;
   }
@@ -810,8 +817,6 @@ ULLONG VDR::getResumePoint(char* fileName)
 
 int VDR::configSave(char* section, char* key, const char* value)
 {
-  if (!connected) return 0;
-
   ULONG totalLength = 8 + strlen(section) + strlen(key) + strlen(value) + 3; // 8 for headers, 3 for nulls
   UCHAR buffer[totalLength];
 
@@ -826,6 +831,8 @@ int VDR::configSave(char* section, char* key, const char* value)
   strcpy((char*)&buffer[position], value);
 
   pthread_mutex_lock(&mutex);
+  if (!connected) { pthread_mutex_unlock(&mutex); return 0; }
+
   unsigned int a = tcp->sendPacket(buffer, totalLength);
   if (a != totalLength)
   {
@@ -849,8 +856,6 @@ int VDR::configSave(char* section, char* key, const char* value)
 
 char* VDR::configLoad(char* section, char* key)
 {
-  if (!connected) return 0;
-
   ULONG totalLength = 8 + strlen(section) + strlen(key) + 2; // 8 for headers, 2 for nulls
   UCHAR buffer[totalLength];
 
@@ -863,6 +868,8 @@ char* VDR::configLoad(char* section, char* key)
   strcpy((char*)&buffer[position], key);
 
   pthread_mutex_lock(&mutex);
+  if (!connected) { pthread_mutex_unlock(&mutex); return 0; }
+
   unsigned int a = tcp->sendPacket(buffer, totalLength);
   if (a != totalLength)
   {
@@ -880,21 +887,19 @@ char* VDR::configLoad(char* section, char* key)
   freePacket();
   pthread_mutex_unlock(&mutex);
 
-  printf("%p %s\n", toReturn, toReturn);
-
   return toReturn;
 }
 
 RecTimerList* VDR::getRecTimersList()
 {
-  if (!connected) return NULL;
-
   UCHAR buffer[8];
 
   *(unsigned long*)&buffer[0] = htonl(4);
   *(unsigned long*)&buffer[4] = htonl(VDR_GETTIMERS);
 
   pthread_mutex_lock(&mutex);
+  if (!connected) { pthread_mutex_unlock(&mutex); return 0; }
+
   int a = tcp->sendPacket(buffer, 8);
   if (a != 8)
   {
@@ -954,8 +959,6 @@ RecTimerList* VDR::getRecTimersList()
 
 ULONG VDR::setEventTimer(char* timerString)
 {
-  if (!connected) return false;
-
   unsigned long totalLength = 8 + strlen(timerString) + 1;
   UCHAR buffer[totalLength];
 
@@ -964,6 +967,8 @@ ULONG VDR::setEventTimer(char* timerString)
   strcpy((char*)&buffer[8], timerString);
 
   pthread_mutex_lock(&mutex);
+  if (!connected) { pthread_mutex_unlock(&mutex); return 0; }
+
   unsigned int a = tcp->sendPacket(buffer, totalLength);
   if (a != totalLength)
   {
index 7fdf590ff16c14a449e03f1f51aed43171066bd1..a185e6ece4258535eedbaa22a360f0eb0e0c0b27 100644 (file)
@@ -228,6 +228,11 @@ void VEpgSetTimer::doit()
   ULONG ret = vdr->setEventTimer(timerString);
   delete[] timerString;
 
+  if (!vdr->isConnected())
+  {
+    Command::getInstance()->connectionLost();
+  }
+
   if (ret == 0) logger->log("VEPGST", Log::DEBUG, "Success");
   else if (ret == 1) logger->log("VEPGST", Log::DEBUG, "Fail: Timer already set for this event");
   else if (ret == 2) logger->log("VEPGST", Log::DEBUG, "Fail: General failure setting timer");
index 01f05d4f47c74c381cf2066c73ceb729b638ed44..bd13583939a9ffec7315eaec50ce34d5b58c3f0f 100644 (file)
@@ -33,6 +33,7 @@
 #include "wbutton.h"
 #include "vinfo.h"
 #include "message.h"
+#include "command.h"
 
 class VEpgSetTimer : public View
 {
index 1ca5a9fb0eb852aff8f13cd729598fb1187b3705..6e53cf9f693cc7f0e229389a4e6698f02343f961 100644 (file)
@@ -96,7 +96,9 @@ void VLiveBanner::setChannel(Channel* tChannel)
   snprintf(ttitleText, 99, "%03lu - %s", currentChannel->number, currentChannel->name);
 
   setTitleText(ttitleText);
+    Log::getInstance()->log("Banner", Log::DEBUG, "Start get ch");
   eventList = VDR::getInstance()->getChannelSchedule(currentChannel->number);
+    Log::getInstance()->log("Banner", Log::DEBUG, "End get ch");
 
   if (!eventList)
   {
@@ -104,10 +106,7 @@ void VLiveBanner::setChannel(Channel* tChannel)
   }
   else
   {
-    // sort the list
-    Log::getInstance()->log("Banner", Log::DEBUG, "Start sort");
     sort(eventList->begin(), eventList->end(), EventSorter());
-    Log::getInstance()->log("Banner", Log::DEBUG, "End sort");
 
     char tempString[300];
     char tempString2[300];
index b66959895e52b60f70b03ec320d706b5e7ab970b..0b233765613afd1f82ead90f710873cdc83c4651 100644 (file)
@@ -213,7 +213,7 @@ void VVideoLive::channelChange(UCHAR changeType, UINT newData)
 void VVideoLive::streamEnd()
 {
   Log::getInstance()->log("VVideoLive", Log::DEBUG, "streamEnd");
-  stop();
+  stop(1);
   showUnavailable(1);
 }
 
index 7f20431df774bfc20ba44a1fdc16d304e6a7ce40..fb3f84910467439edf1a1c606127aa3678cad0e0 100644 (file)
@@ -223,6 +223,10 @@ void VWelcome::doChannelsList()
     viewman->add(vchan);
     viewman->updateView(vchan);
   }
+  else
+  {
+    Command::getInstance()->connectionLost();
+  }
 }
 
 void VWelcome::doRadioList()
@@ -238,6 +242,10 @@ void VWelcome::doRadioList()
     viewman->add(vchan);
     viewman->updateView(vchan);
   }
+  else
+  {
+    Command::getInstance()->connectionLost();
+  }
 }
 
 void VWelcome::doRecordingsList()
@@ -287,6 +295,10 @@ void VWelcome::doTimersList()
     viewman->add(vtl);
     viewman->updateView(vtl);
   }
+  else
+  {
+    Command::getInstance()->connectionLost();
+  }
 }
 
 void VWelcome::doOptions()