From 081d04da2e6eba18ecb3bd5a756797fcd38198a3 Mon Sep 17 00:00:00 2001 From: Chris Tallon Date: Sat, 1 Oct 2005 14:53:55 +0000 Subject: [PATCH] Dongle 13, fix for 2 segfaults --- command.cc | 12 +++++++++++- message.h | 1 + vconnect.cc | 14 ++++++++------ vdr.cc | 40 ++++++++++++++++++++++++++++++++++++++- vdr.h | 1 + view.h | 2 +- vrecordinglist.cc | 48 ++++++++++++++++++++++++++++++++++------------- 7 files changed, 96 insertions(+), 22 deletions(-) diff --git a/command.cc b/command.cc index 16cb7b1..18633ba 100644 --- a/command.cc +++ b/command.cc @@ -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); + */ + } diff --git a/message.h b/message.h index e68c83e..fafb3c4 100644 --- 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 diff --git a/vconnect.cc b/vconnect.cc index 9c3affc..562d57a 100644 --- a/vconnect.cc +++ b/vconnect.cc @@ -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 1e22100..7cc6fc2 100644 --- 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 2767b43..9f971c4 100644 --- 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 0cc12b2..c53a17f 100644 --- 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; }; diff --git a/vrecordinglist.cc b/vrecordinglist.cc index 4a072b3..cf3e736 100644 --- a/vrecordinglist.cc +++ b/vrecordinglist.cc @@ -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; -- 2.39.5