]> git.vomp.tv Git - vompclient-marten.git/commitdiff
Dongle 13, fix for 2 segfaults
authorChris Tallon <chris@vomp.tv>
Sat, 1 Oct 2005 14:53:55 +0000 (14:53 +0000)
committerChris Tallon <chris@vomp.tv>
Sat, 1 Oct 2005 14:53:55 +0000 (14:53 +0000)
command.cc
message.h
vconnect.cc
vdr.cc
vdr.h
view.h
vrecordinglist.cc

index 16cb7b100464cd48d177af7ade5bba598f56b2f1..18633ba8e284ec311a7e5270207a463130e3c2a4 100644 (file)
@@ -436,9 +436,19 @@ void Command::doJustConnected(VConnect* vconnect)
 //  viewman->redrawAll();
 
 /*
+  handleCommand(Remote::DOWN);
+  handleCommand(Remote::DOWN);
+  handleCommand(Remote::OK);
   handleCommand(Remote::DOWN);
   handleCommand(Remote::DOWN);
   handleCommand(Remote::DOWN);
   handleCommand(Remote::OK);
-*/
+  handleCommand(Remote::OK);
+  handleCommand(Remote::UP);
+  handleCommand(Remote::OK);
+  handleCommand(Remote::DF_LEFT);
+  handleCommand(Remote::OK);
+  handleCommand(Remote::BACK);
+  */
+
 }
index e68c83ec43a541538389a19ffdbce277d79915a8..fafb3c4d72fa6efc01445074eed5ef989e6b6f8c 100644 (file)
--- a/message.h
+++ b/message.h
@@ -54,6 +54,7 @@ class Message
     const static ULONG CHANNEL_UP = 15;
     const static ULONG CHANNEL_DOWN = 16;
     const static ULONG STREAM_END = 17;
+    const static ULONG CHILD_CLOSE = 18;
 };
 
 #endif
index 9c3affca0835fd252e120d0b5e5225591a449986..562d57a6cc03c3e3014cc65c1bca6e26863ee551 100644 (file)
@@ -43,7 +43,7 @@ VConnect::~VConnect()
 {
   irun = 0;
   vdr->cancelFindingServer();
-  threadCancel();
+  threadStop();
 }
 
 void VConnect::draw()
@@ -77,7 +77,12 @@ void VConnect::threadMethod()
     show();
 
     vdr->findServers(serverIPs);
-    if (!irun) return;
+    if (!irun)
+    {
+      for(UINT k = 0; k < serverIPs.size(); k++) delete[] serverIPs[k];
+      serverIPs.clear();
+      return;
+    }
 
     if (serverIPs.size() == 1)
     {
@@ -98,10 +103,7 @@ void VConnect::threadMethod()
     vdr->setServerIP(serverIPs[selectedServer]);
 
     // Clear the serverIPs vector
-    for(UINT k = 0; k < serverIPs.size(); k++)
-    {
-      delete[] serverIPs[k];
-    }
+    for(UINT k = 0; k < serverIPs.size(); k++) delete[] serverIPs[k];
     serverIPs.clear();
 
     setMainText("\n                     Connecting to VDR");
diff --git a/vdr.cc b/vdr.cc
index 1e221001a8271ca6216771159f2963681b3f2dc8..7cc6fc252ceeabb0fbf387bb26a18fd26e0d6116 100644 (file)
--- a/vdr.cc
+++ b/vdr.cc
@@ -33,6 +33,7 @@ VDR::VDR()
   packetLength = 0;
   packetPos = 0;
   packet = NULL;
+  connected = false;
 }
 
 VDR::~VDR()
@@ -119,13 +120,22 @@ int VDR::connect()
 {
   if (tcp) delete tcp;
   tcp = new TCP();
-  return tcp->connectTo(serverIP, 3024);
+  if (tcp->connectTo(serverIP, 3024))
+  {
+    connected = true;
+    return 1;
+  }
+  else
+  {
+    return 0;
+  }
 }
 
 void VDR::disconnect()
 {
   if (tcp) delete tcp;
   tcp = NULL;
+  connected = false;
   Log::getInstance()->log("VDR", Log::DEBUG, "Disconnect");
 }
 
@@ -194,6 +204,8 @@ long VDR::extractLONG()
 
 int VDR::doLogin()
 {
+  if (!connected) return 0;
+
   UCHAR buffer[8];
 
   *(unsigned long*)&buffer[0] = htonl(4);
@@ -260,6 +272,8 @@ int VDR::doLogin()
 
 Directory* VDR::getRecordingsList()
 {
+  if (!connected) return 0;
+
   UCHAR buffer[8];
 
   *(unsigned long*)&buffer[0] = htonl(4);
@@ -334,6 +348,8 @@ Directory* VDR::getRecordingsList()
 
 int VDR::deleteRecording(char* fileName)
 {
+  if (!connected) return 0;
+
   unsigned long totalLength = 8 + strlen(fileName) + 1;
   UCHAR buffer[totalLength];
 
@@ -364,6 +380,8 @@ int VDR::deleteRecording(char* fileName)
 
 char* VDR::getRecordingSummary(char* fileName)
 {
+  if (!connected) return 0;
+
   unsigned long totalLength = 8 + strlen(fileName) + 1;
   UCHAR buffer[totalLength];
 
@@ -393,6 +411,8 @@ char* VDR::getRecordingSummary(char* fileName)
 
 ChannelList* VDR::getChannelsList(ULONG type)
 {
+  if (!connected) return 0;
+
   UCHAR buffer[8];
 
   *(unsigned long*)&buffer[0] = htonl(4);
@@ -442,6 +462,8 @@ ChannelList* VDR::getChannelsList(ULONG type)
 
 int VDR::streamChannel(ULONG number)
 {
+  if (!connected) return 0;
+
   UCHAR buffer[12];
 
   *(unsigned long*)&buffer[0] = htonl(8);
@@ -472,6 +494,8 @@ int VDR::streamChannel(ULONG number)
 
 int VDR::stopStreaming()
 {
+  if (!connected) return 0;
+
   UCHAR buffer[8];
 
   *(unsigned long*)&buffer[0] = htonl(4);
@@ -501,6 +525,8 @@ 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);
@@ -535,6 +561,8 @@ 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];
 
@@ -567,6 +595,8 @@ ULLONG VDR::streamRecording(Recording* rec)
 
 ULLONG VDR::rescanRecording()
 {
+  if (!connected) return 0;
+
   unsigned long totalLength = 8;
   UCHAR buffer[totalLength];
 
@@ -598,6 +628,8 @@ ULLONG VDR::rescanRecording()
 
 EventList* VDR::getChannelSchedule(ULONG number)
 {
+  if (!connected) return 0;
+
   UCHAR buffer[12];
 
   *(unsigned long*)&buffer[0] = htonl(8);
@@ -668,6 +700,8 @@ EventList* VDR::getChannelSchedule(ULONG number)
 
 ULLONG VDR::getResumePoint(char* fileName)
 {
+  if (!connected) return 0;
+
   char* resumeString = configLoad("ResumeData", fileName);
   if (!resumeString) return 0;
 
@@ -678,6 +712,8 @@ ULLONG VDR::getResumePoint(char* fileName)
 
 int VDR::configSave(char* section, char* key, 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];
 
@@ -714,6 +750,8 @@ int VDR::configSave(char* section, char* key, 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];
 
diff --git a/vdr.h b/vdr.h
index 2767b43bef8cc2ecec21588c000374bd2f180768..9f971c48ba1602cbebebe41e9d033cea41e7b3da 100644 (file)
--- a/vdr.h
+++ b/vdr.h
@@ -92,6 +92,7 @@ class VDR
     TCP* tcp;
     int port;
     char serverIP[16];
+    bool connected;
     pthread_mutex_t mutex;
 
     UCHAR* packet;
diff --git a/view.h b/view.h
index 0cc12b2d6f5ed90aded2619251102e7964bcb565..c53a17fcad113acae0be81a2dffa8ab2eeffb332 100644 (file)
--- a/view.h
+++ b/view.h
@@ -62,9 +62,9 @@ class View : public Box
     UCHAR titleBarOn;
     UCHAR borderOn;
 
-    char* titleText;
 
   protected:
+    char* titleText;//FIXME move this back to private
     Colour titleBarColour;
     View* parent;
 };
index 4a072b3a387ce158253d3f94eb49b50ae9c9d185..cf3e73628343bc87e97da968dee193cd689cdb0b 100644 (file)
@@ -42,14 +42,24 @@ VRecordingList::VRecordingList(VRecordingList* tparent)
   sl.setSurface(surface);
   sl.setSurfaceOffset(10, 30 + 5);
   sl.setDimensions(width - 20, height - 30 - 15 - 30);
-
-  Log::getInstance()->log("VRecordingList", Log::DEBUG, "this=%p parent=%p\n", this, myParent);
 }
 
 VRecordingList::~VRecordingList()
 {
+  // if this is a child window, inform the parent of our destruct
+  if (myParent)
+  {
+    Message* m = new Message();
+    m->to = myParent;
+    m->message = Message::CHILD_CLOSE;
+    ViewMan::getInstance()->postMessage(m);
+  }
+
   // only delete the list if this is not a sub dir window
-  if (recDir->isRoot) delete recDir;
+  if (recDir->isRoot)
+  {
+    delete recDir;
+  }
 }
 
 void VRecordingList::setDir(Directory* tdir)
@@ -85,16 +95,20 @@ void VRecordingList::drawData()
   Directory* dir;
   DirectoryList::iterator i;
 
-  // First go through to delete 1 empty dir if necessary
-
-  for (i = recDir->dirList.begin(); i != recDir->dirList.end(); i++)
+  if (dataInvalid == 2) // special case, a child list has closed, check for 0 dir entries
   {
-    dir = *i;
-    if (dir->getNumRecordings() == 0)
+
+    // First go through to delete 1 empty dir if necessary
+
+    for (i = recDir->dirList.begin(); i != recDir->dirList.end(); i++)
     {
-      delete dir;
-      recDir->dirList.erase(i);
-      break;
+      dir = *i;
+      if (dir->getNumRecordings() == 0)
+      {
+        delete dir;
+        recDir->dirList.erase(i);
+        break;
+      }
     }
   }
 
@@ -217,6 +231,14 @@ void VRecordingList::processMessage(Message* m)
     draw();
     return;
   }
+
+  if (m->message == Message::CHILD_CLOSE)
+  {
+    dataInvalid = 2;
+    draw();
+    show();
+    return;
+  }
 }
 
 void VRecordingList::doDeleteSelected()
@@ -254,15 +276,15 @@ void VRecordingList::doDeleteSelected()
   }
 
   if (myParent) // if this is not root send a message to parent to say redraw data
-  {
+  { // FIXME not really necessary any more ?
     Message* m1 = new Message();
     m1->to = myParent;
     m1->message = Message::REDRAW_DATA;
     ViewMan::getInstance()->postMessage(m1);
   }
 
-
   show();
+
 /*
   Message* m2 = new Message();
   m2->from = this;