From 27e5b202769009918f241a0677dcbfd744d81efd Mon Sep 17 00:00:00 2001 From: Chris Tallon Date: Sun, 12 Mar 2006 17:31:45 +0000 Subject: [PATCH] Connection failed detection --- command.cc | 54 ++++++++++++++++++++++++++++++++++++++++++++++- command.h | 3 +++ message.h | 1 + tcp.cc | 2 +- vdr.cc | 25 +++++++++++++++++++++- vdr.h | 21 ++++++++++++++++-- vinfo.cc | 16 ++++++++++++++ vinfo.h | 5 +++++ vrecordinglist.cc | 8 ++++++- vrecordinglist.h | 1 + vrecordingmenu.cc | 6 +++++- vrecordingmenu.h | 1 + vvideorec.cc | 8 +++++++ vwelcome.cc | 6 ++++-- 14 files changed, 148 insertions(+), 9 deletions(-) diff --git a/command.cc b/command.cc index 7409b30..a65538d 100644 --- a/command.cc +++ b/command.cc @@ -29,6 +29,7 @@ Command::Command() initted = 0; isStandby = 0; firstBoot = 1; + connLost = NULL; } Command::~Command() @@ -230,6 +231,12 @@ void Command::processMessage(Message* m) case Message::SCREENSHOT: { Osd::getInstance()->screenShot("/out.jpg"); + break; + } + case Message::CONNECTION_LOST: + { + doFromTheTop(true); + break; } } } @@ -238,7 +245,7 @@ void Command::handleCommand(int button) { if (isStandby && (button != Remote::POWER)) return; - if (viewman->handleCommand(button)) return; + if (!connLost && viewman->handleCommand(button)) return; // don't send to viewman if connLost // command was not handled @@ -267,6 +274,12 @@ void Command::handleCommand(int button) doStandby(); return; } + case Remote::OK: + { + if (!connLost) return; // if connLost, handle Remote::OK + doFromTheTop(false); + return; + } } } @@ -306,6 +319,37 @@ void Command::doStandby() } } +void Command::doFromTheTop(bool which) +{ + if (which) + { + connLost = new VInfo(); + connLost->create(360, 200); + if (Video::getInstance()->getFormat() == Video::PAL) + connLost->setScreenPos(190, 170); + else + connLost->setScreenPos(180, 120); + connLost->setOneLiner(tr("Connection lost")); + connLost->setDropThrough(); + connLost->setBorderOn(1); + connLost->setTitleBarColour(Colour::DANGER); + connLost->okButton(); + connLost->draw(); + viewman->add(connLost); + viewman->updateView(connLost); + } + else + { + VDR::getInstance()->disconnect(); + viewman->removeAll(); + viewman->updateView(wallpaper); + connLost = NULL; + VConnect* vconnect = new VConnect(); + viewman->add(vconnect); + vconnect->run(); + } +} + void Command::doReboot() { VDR::getInstance()->disconnect(); @@ -314,6 +358,14 @@ void Command::doReboot() reboot(LINUX_REBOOT_CMD_RESTART); } +void Command::connectionLost() +{ + Message* m = new Message(); // break into master mutex + m->message = Message::CONNECTION_LOST; + m->to = this; + postMessageNoLock(m); +} + void Command::doJustConnected(VConnect* vconnect) { I18n::initialize(); diff --git a/command.h b/command.h index 13db4e2..2760f74 100644 --- a/command.h +++ b/command.h @@ -71,12 +71,14 @@ class Command : public MessageQueue void postMessageNoLock(Message* m); // override of MessageQueue::postMessage bool postMessageIfNotBusy(Message* m); // for timers, when masterMutex might be locked void sig1(); + void connectionLost(); private: void handleCommand(int); void doStandby(); void doJustConnected(VConnect* vconnect); void doWallpaper(); + void doFromTheTop(bool which); // true - show vinfo,wait. false - del vinfo,restart static Command* instance; pid_t mainPid; @@ -90,6 +92,7 @@ class Command : public MessageQueue ViewMan* viewman; Remote* remote; VWallpaper* wallpaper; + VInfo* connLost; void processMessage(Message* m); }; diff --git a/message.h b/message.h index 3508883..f16262e 100644 --- a/message.h +++ b/message.h @@ -61,6 +61,7 @@ class Message const static ULONG EPG = 16; const static ULONG EPG_CLOSE = 17; const static ULONG CHANGED_OPTIONS = 18; + const static ULONG CONNECTION_LOST = 19; }; #endif diff --git a/tcp.cc b/tcp.cc index 61a079a..07276ab 100644 --- 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 = 10; + timeout.tv_sec = 30; timeout.tv_usec = 0; success = select(sock + 1, &readSet, NULL, NULL, passToSelect); if (success < 1) diff --git a/vdr.cc b/vdr.cc index 92d5055..0eee6ea 100644 --- a/vdr.cc +++ b/vdr.cc @@ -162,7 +162,11 @@ void VDR::setReceiveWindow(size_t size) int VDR::getPacket() { packet = (UCHAR*)tcp->receivePacket(); - if (!packet) return 0; + if (!packet) + { + disconnect(); + return 0; + } packetLength = tcp->getDataLength(); return 1; } @@ -236,6 +240,7 @@ int VDR::doLogin() int a = tcp->sendPacket(buffer, 14); if (a != 14) { + disconnect(); pthread_mutex_unlock(&mutex); return 0; } @@ -304,6 +309,7 @@ Directory* VDR::getRecordingsList() int a = tcp->sendPacket(buffer, 8); if (a != 8) { + disconnect(); pthread_mutex_unlock(&mutex); return NULL; } @@ -398,6 +404,7 @@ int VDR::deleteRecording(char* fileName) unsigned int a = tcp->sendPacket(buffer, totalLength); if (a != totalLength) { + disconnect(); pthread_mutex_unlock(&mutex); return 0; } @@ -430,6 +437,7 @@ char* VDR::getRecordingSummary(char* fileName) unsigned int a = tcp->sendPacket(buffer, totalLength); if (a != totalLength) { + disconnect(); pthread_mutex_unlock(&mutex); return NULL; } @@ -459,6 +467,7 @@ ChannelList* VDR::getChannelsList(ULONG type) int a = tcp->sendPacket(buffer, 8); if (a != 8) { + disconnect(); pthread_mutex_unlock(&mutex); return NULL; } @@ -512,6 +521,7 @@ int VDR::streamChannel(ULONG number) if (a != 12) { + disconnect(); pthread_mutex_unlock(&mutex); return 0; } @@ -543,6 +553,7 @@ int VDR::stopStreaming() if (a != 8) { + disconnect(); pthread_mutex_unlock(&mutex); return 0; } @@ -575,6 +586,7 @@ UCHAR* VDR::getBlock(ULLONG position, UINT maxAmount, UINT* amountReceived) int a = tcp->sendPacket(buffer, 20); if (a != 20) { + disconnect(); pthread_mutex_unlock(&mutex); return NULL; } @@ -611,6 +623,7 @@ ULLONG VDR::streamRecording(Recording* rec) unsigned int a = tcp->sendPacket(buffer, totalLength); if (a != totalLength) { + disconnect(); pthread_mutex_unlock(&mutex); return 0; } @@ -644,6 +657,7 @@ ULLONG VDR::rescanRecording() unsigned int a = tcp->sendPacket(buffer, totalLength); if (a != totalLength) { + disconnect(); pthread_mutex_unlock(&mutex); return 0; } @@ -678,6 +692,7 @@ ULLONG VDR::positionFromFrameNumber(ULONG frameNumber) unsigned int a = tcp->sendPacket(buffer, totalLength); if (a != totalLength) { + disconnect(); pthread_mutex_unlock(&mutex); return 0; } @@ -722,6 +737,7 @@ EventList* VDR::getChannelSchedule(ULONG number, time_t start, ULONG duration) if (a != 20) { + disconnect(); pthread_mutex_unlock(&mutex); return NULL; } @@ -735,6 +751,7 @@ EventList* VDR::getChannelSchedule(ULONG number, time_t start, ULONG duration) if (serverError()) { freePacket(); + disconnect(); pthread_mutex_unlock(&mutex); return NULL; } @@ -812,6 +829,7 @@ int VDR::configSave(char* section, char* key, const char* value) unsigned int a = tcp->sendPacket(buffer, totalLength); if (a != totalLength) { + disconnect(); pthread_mutex_unlock(&mutex); return 0; } @@ -848,6 +866,7 @@ char* VDR::configLoad(char* section, char* key) unsigned int a = tcp->sendPacket(buffer, totalLength); if (a != totalLength) { + disconnect(); pthread_mutex_unlock(&mutex); return NULL; } @@ -861,6 +880,8 @@ char* VDR::configLoad(char* section, char* key) freePacket(); pthread_mutex_unlock(&mutex); + printf("%p %s\n", toReturn, toReturn); + return toReturn; } @@ -877,6 +898,7 @@ RecTimerList* VDR::getRecTimersList() int a = tcp->sendPacket(buffer, 8); if (a != 8) { + disconnect(); pthread_mutex_unlock(&mutex); return NULL; } @@ -945,6 +967,7 @@ ULONG VDR::setEventTimer(char* timerString) unsigned int a = tcp->sendPacket(buffer, totalLength); if (a != totalLength) { + disconnect(); pthread_mutex_unlock(&mutex); return 0; } diff --git a/vdr.h b/vdr.h index 0c4dd7f..616c308 100644 --- a/vdr.h +++ b/vdr.h @@ -39,8 +39,6 @@ using namespace std; - // FIXME do some tcp connection error checking and kill it! - typedef vector EventList; typedef vector ChannelList; typedef vector RecTimerList; @@ -106,11 +104,30 @@ class VDR void setServerIP(char*); int connect(); void disconnect(); + bool isConnected() { return connected; } ULLONG getResumePoint(char* fileName); // uses configLoad void setReceiveWindow(size_t size); // protocol functions + // for the following, if result == false then the connection has died + // doLogin + // getRecordingList + // getChannelsList + // getChannelSchedule + // getRecTimersList + // isConnected can be called after the following to determine if still ok + // getRecordingSummary + // deleteRecording + // streamRecording + // rescanRecording + // positionFromFrameNumber + // streamChannel + // getBlock + // stopStreaming + // configLoad + // configSave + // setEventTimer int doLogin(); diff --git a/vinfo.cc b/vinfo.cc index 3760da7..1febf92 100644 --- a/vinfo.cc +++ b/vinfo.cc @@ -25,6 +25,7 @@ VInfo::VInfo() mainText = NULL; exitable = 0; dropThrough = 0; + okbutton = false; setBackgroundColour(Colour::VIEWBACKGROUND); setTitleBarOn(1); @@ -79,6 +80,16 @@ void VInfo::draw() else drawTextCentre(mainText, area.w / 2, 55, Colour::LIGHTTEXT); } } + + if (okbutton) + { + WButton button; + button.setSurface(surface); + button.setSurfaceOffset((area.w / 2) - 30, area.h - 50); + button.setText(tr("OK")); + button.setActive(1); + button.draw(); + } } int VInfo::handleCommand(int command) @@ -96,3 +107,8 @@ int VInfo::handleCommand(int command) return 1; } + +void VInfo::okButton() +{ + okbutton = true; +} diff --git a/vinfo.h b/vinfo.h index 5a8b286..d8e7783 100644 --- a/vinfo.h +++ b/vinfo.h @@ -28,6 +28,8 @@ #include "view.h" #include "remote.h" #include "colour.h" +#include "wbutton.h" +#include "i18n.h" class VInfo : public View { @@ -39,6 +41,7 @@ class VInfo : public View void setOneLiner(char* text); void setExitable(); void setDropThrough(); + void okButton(); virtual int handleCommand(int command); void draw(); @@ -48,6 +51,8 @@ class VInfo : public View UCHAR exitable; UCHAR dropThrough; UCHAR mainTextType; + bool okbutton; + const static UCHAR NORMAL = 1; const static UCHAR ONELINER = 2; }; diff --git a/vrecordinglist.cc b/vrecordinglist.cc index bd1575e..8fc3948 100644 --- a/vrecordinglist.cc +++ b/vrecordinglist.cc @@ -219,7 +219,13 @@ void VRecordingList::doDeleteSelected() Log::getInstance()->log("VRecordingList", Log::DEBUG, "FOUND: %i %s %s", toDelete->index, toDelete->getProgName(), toDelete->fileName); VDR* vdr = VDR::getInstance(); - vdr->deleteRecording(toDelete->fileName); + int success = vdr->deleteRecording(toDelete->fileName); + if (!success && !vdr->isConnected()) + { + Command::getInstance()->connectionLost(); + } + + // FIXME add notify of fail to delete delete toDelete; diff --git a/vrecordinglist.h b/vrecordinglist.h index ac7c823..48ff61f 100644 --- a/vrecordinglist.h +++ b/vrecordinglist.h @@ -39,6 +39,7 @@ #include "colour.h" #include "video.h" #include "i18n.h" +#include "command.h" class VRecordingList : public View { diff --git a/vrecordingmenu.cc b/vrecordingmenu.cc index eaa8879..87ee0c3 100644 --- a/vrecordingmenu.cc +++ b/vrecordingmenu.cc @@ -34,7 +34,6 @@ VRecordingMenu::VRecordingMenu() setScreenPos(250, 160); } - setBackgroundColour(Colour::VIEWBACKGROUND); setTitleBarOn(1); setBorderOn(1); @@ -115,6 +114,11 @@ int VRecordingMenu::handleCommand(int command) if (sl.getCurrentOption() == 2) { char* summary = VDR::getInstance()->getRecordingSummary(rec->fileName); + if (!summary && !VDR::getInstance()->isConnected()) + { + Command::getInstance()->connectionLost(); + return 2; + } VInfo* vi = new VInfo(); vi->setTitleText(tr("Programme summary")); diff --git a/vrecordingmenu.h b/vrecordingmenu.h index 3fae830..a72e2b0 100644 --- a/vrecordingmenu.h +++ b/vrecordingmenu.h @@ -36,6 +36,7 @@ #include "colour.h" #include "video.h" #include "i18n.h" +#include "command.h" class VRecordingList; diff --git a/vvideorec.cc b/vvideorec.cc index d4d921e..63cb0bc 100644 --- a/vvideorec.cc +++ b/vvideorec.cc @@ -106,6 +106,14 @@ void VVideoRec::go(ULLONG startPosition) } else { + stopPlay(); // clean up + + if (!vdr->isConnected()) + { + Command::getInstance()->connectionLost(); + return; + } + ViewMan* viewman = ViewMan::getInstance(); Message* m = new Message(); diff --git a/vwelcome.cc b/vwelcome.cc index b495bae..7f20431 100644 --- a/vwelcome.cc +++ b/vwelcome.cc @@ -268,10 +268,12 @@ void VWelcome::doRecordingsList() viewman->add(vrec); viewman->updateView(vrec); } + else + { + Command::getInstance()->connectionLost(); + } - Log::getInstance()->log("VWelcome", Log::DEBUG, "possible delay start"); viewman->removeView(viewWait); - Log::getInstance()->log("VWelcome", Log::DEBUG, "possible delay end"); } void VWelcome::doTimersList() -- 2.39.2