initted = 0;
isStandby = 0;
firstBoot = 1;
+ connLost = NULL;
}
Command::~Command()
case Message::SCREENSHOT:
{
Osd::getInstance()->screenShot("/out.jpg");
+ break;
+ }
+ case Message::CONNECTION_LOST:
+ {
+ doFromTheTop(true);
+ break;
}
}
}
{
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
doStandby();
return;
}
+ case Remote::OK:
+ {
+ if (!connLost) return; // if connLost, handle Remote::OK
+ doFromTheTop(false);
+ return;
+ }
}
}
}
}
+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();
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();
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;
ViewMan* viewman;
Remote* remote;
VWallpaper* wallpaper;
+ VInfo* connLost;
void processMessage(Message* m);
};
const static ULONG EPG = 16;
const static ULONG EPG_CLOSE = 17;
const static ULONG CHANGED_OPTIONS = 18;
+ const static ULONG CONNECTION_LOST = 19;
};
#endif
{
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)
int VDR::getPacket()
{
packet = (UCHAR*)tcp->receivePacket();
- if (!packet) return 0;
+ if (!packet)
+ {
+ disconnect();
+ return 0;
+ }
packetLength = tcp->getDataLength();
return 1;
}
int a = tcp->sendPacket(buffer, 14);
if (a != 14)
{
+ disconnect();
pthread_mutex_unlock(&mutex);
return 0;
}
int a = tcp->sendPacket(buffer, 8);
if (a != 8)
{
+ disconnect();
pthread_mutex_unlock(&mutex);
return NULL;
}
unsigned int a = tcp->sendPacket(buffer, totalLength);
if (a != totalLength)
{
+ disconnect();
pthread_mutex_unlock(&mutex);
return 0;
}
unsigned int a = tcp->sendPacket(buffer, totalLength);
if (a != totalLength)
{
+ disconnect();
pthread_mutex_unlock(&mutex);
return NULL;
}
int a = tcp->sendPacket(buffer, 8);
if (a != 8)
{
+ disconnect();
pthread_mutex_unlock(&mutex);
return NULL;
}
if (a != 12)
{
+ disconnect();
pthread_mutex_unlock(&mutex);
return 0;
}
if (a != 8)
{
+ disconnect();
pthread_mutex_unlock(&mutex);
return 0;
}
int a = tcp->sendPacket(buffer, 20);
if (a != 20)
{
+ disconnect();
pthread_mutex_unlock(&mutex);
return NULL;
}
unsigned int a = tcp->sendPacket(buffer, totalLength);
if (a != totalLength)
{
+ disconnect();
pthread_mutex_unlock(&mutex);
return 0;
}
unsigned int a = tcp->sendPacket(buffer, totalLength);
if (a != totalLength)
{
+ disconnect();
pthread_mutex_unlock(&mutex);
return 0;
}
unsigned int a = tcp->sendPacket(buffer, totalLength);
if (a != totalLength)
{
+ disconnect();
pthread_mutex_unlock(&mutex);
return 0;
}
if (a != 20)
{
+ disconnect();
pthread_mutex_unlock(&mutex);
return NULL;
}
if (serverError())
{
freePacket();
+ disconnect();
pthread_mutex_unlock(&mutex);
return NULL;
}
unsigned int a = tcp->sendPacket(buffer, totalLength);
if (a != totalLength)
{
+ disconnect();
pthread_mutex_unlock(&mutex);
return 0;
}
unsigned int a = tcp->sendPacket(buffer, totalLength);
if (a != totalLength)
{
+ disconnect();
pthread_mutex_unlock(&mutex);
return NULL;
}
freePacket();
pthread_mutex_unlock(&mutex);
+ printf("%p %s\n", toReturn, toReturn);
+
return toReturn;
}
int a = tcp->sendPacket(buffer, 8);
if (a != 8)
{
+ disconnect();
pthread_mutex_unlock(&mutex);
return NULL;
}
unsigned int a = tcp->sendPacket(buffer, totalLength);
if (a != totalLength)
{
+ disconnect();
pthread_mutex_unlock(&mutex);
return 0;
}
using namespace std;
- // FIXME do some tcp connection error checking and kill it!
-
typedef vector<Event*> EventList;
typedef vector<Channel*> ChannelList;
typedef vector<RecTimer*> RecTimerList;
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();
mainText = NULL;
exitable = 0;
dropThrough = 0;
+ okbutton = false;
setBackgroundColour(Colour::VIEWBACKGROUND);
setTitleBarOn(1);
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)
return 1;
}
+
+void VInfo::okButton()
+{
+ okbutton = true;
+}
#include "view.h"
#include "remote.h"
#include "colour.h"
+#include "wbutton.h"
+#include "i18n.h"
class VInfo : public View
{
void setOneLiner(char* text);
void setExitable();
void setDropThrough();
+ void okButton();
virtual int handleCommand(int command);
void draw();
UCHAR exitable;
UCHAR dropThrough;
UCHAR mainTextType;
+ bool okbutton;
+
const static UCHAR NORMAL = 1;
const static UCHAR ONELINER = 2;
};
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;
#include "colour.h"
#include "video.h"
#include "i18n.h"
+#include "command.h"
class VRecordingList : public View
{
setScreenPos(250, 160);
}
-
setBackgroundColour(Colour::VIEWBACKGROUND);
setTitleBarOn(1);
setBorderOn(1);
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"));
#include "colour.h"
#include "video.h"
#include "i18n.h"
+#include "command.h"
class VRecordingList;
}
else
{
+ stopPlay(); // clean up
+
+ if (!vdr->isConnected())
+ {
+ Command::getInstance()->connectionLost();
+ return;
+ }
+
ViewMan* viewman = ViewMan::getInstance();
Message* m = new Message();
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()