2 Copyright 2004-2005 Chris Tallon
4 This file is part of VOMP.
6 VOMP is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 2 of the License, or
9 (at your option) any later version.
11 VOMP is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
16 You should have received a copy of the GNU General Public License
17 along with VOMP; if not, write to the Free Software
18 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
21 #include "mvpclient.h"
23 // This is here else it causes compile errors with something in libdvbmpeg
26 MVPClient::MVPClient(char* tconfigDirExtra, int tsocket)
31 recordingManager = NULL;
32 log = Log::getInstance();
34 configDirExtra = tconfigDirExtra;
37 MVPClient::~MVPClient()
39 log->log("Client", Log::DEBUG, "MVP client destructor");
50 delete recordingManager;
52 recordingManager = NULL;
55 if (loggedIn) cleanConfig();
58 ULLONG MVPClient::ntohll(ULLONG a)
63 ULLONG MVPClient::htonll(ULLONG a)
65 #if BYTE_ORDER == BIG_ENDIAN
70 b = ((a << 56) & 0xFF00000000000000ULL)
71 | ((a << 40) & 0x00FF000000000000ULL)
72 | ((a << 24) & 0x0000FF0000000000ULL)
73 | ((a << 8) & 0x000000FF00000000ULL)
74 | ((a >> 8) & 0x00000000FF000000ULL)
75 | ((a >> 24) & 0x0000000000FF0000ULL)
76 | ((a >> 40) & 0x000000000000FF00ULL)
77 | ((a >> 56) & 0x00000000000000FFULL) ;
83 cChannel* MVPClient::channelFromNumber(ULONG channelNumber)
85 cChannel* channel = NULL;
87 for (channel = Channels.First(); channel; channel = Channels.Next(channel))
89 if (!channel->GroupSep())
91 log->log("Client", Log::DEBUG, "Looking for channel %lu::: number: %i name: '%s'", channelNumber, channel->Number(), channel->Name());
93 if (channel->Number() == (int)channelNumber)
95 int vpid = channel->Vpid();
96 #if VDRVERSNUM < 10300
97 int apid1 = channel->Apid1();
99 int apid1 = channel->Apid(0);
101 log->log("Client", Log::DEBUG, "Found channel number %lu, vpid = %i, apid1 = %i", channelNumber, vpid, apid1);
109 log->log("Client", Log::DEBUG, "Channel not found");
115 void MVPClient::writeResumeData()
117 config.setValueLongLong("ResumeData", (char*)rp->getCurrentRecording()->FileName(), rp->getLastPosition());
120 void MVPClient::sendULONG(ULONG ul)
123 *(ULONG*)&sendBuffer[0] = htonl(4);
124 *(ULONG*)&sendBuffer[4] = htonl(ul);
126 tcp.sendPacket(sendBuffer, 8);
127 log->log("Client", Log::DEBUG, "written ULONG %lu", ul);
130 void MVPClientStartThread(void* arg)
132 MVPClient* m = (MVPClient*)arg;
134 // Nothing external to this class has a reference to it
135 // This is the end of the thread.. so delete m
142 if (pthread_create(&runThread, NULL, (void*(*)(void*))MVPClientStartThread, (void *)this) == -1) return 0;
143 log->log("Client", Log::DEBUG, "MVPClient run success");
147 void MVPClient::run2()
152 pthread_sigmask(SIG_BLOCK, &sigset, NULL);
153 pthread_detach(runThread); // Detach
155 tcp.disableReadTimeout();
157 tcp.setSoKeepTime(3);
158 tcp.setNonBlocking();
168 log->log("Client", Log::DEBUG, "Waiting");
169 buffer = (UCHAR*)tcp.receivePacket();
170 log->log("Client", Log::DEBUG, "Received packet, length = %u", tcp.getDataLength());
173 log->log("Client", Log::DEBUG, "Detected connection closed");
177 packetLength = tcp.getDataLength() - 4;
178 opcode = ntohl(*(ULONG*)buffer);
181 if (!loggedIn && (opcode != 1))
187 log->log("Client", Log::DEBUG, "SwitchOp");
191 result = processLogin(data, packetLength);
194 result = processGetRecordingsList(data, packetLength);
197 result = processDeleteRecording(data, packetLength);
200 result = processGetSummary(data, packetLength);
203 result = processGetChannelsList(data, packetLength);
206 result = processStartStreamingChannel(data, packetLength);
209 result = processGetBlock(data, packetLength);
212 result = processStopStreaming(data, packetLength);
215 result = processStartStreamingRecording(data, packetLength);
218 result = processGetChannelSchedule(data, packetLength);
221 result = processConfigSave(data, packetLength);
224 result = processConfigLoad(data, packetLength);
227 result = processReScanRecording(data, packetLength);
230 result = processGetTimers(data, packetLength);
233 result = processSetTimer(data, packetLength);
236 result = processPositionFromFrameNumber(data, packetLength);
239 result = processFrameNumberFromPosition(data, packetLength);
242 result = processMoveRecording(data, packetLength);
251 int MVPClient::processLogin(UCHAR* buffer, int length)
253 if (length != 6) return 0;
257 const char* configDir = cPlugin::ConfigDirectory(configDirExtra);
260 log->log("Client", Log::DEBUG, "No config dir!");
264 char configFileName[PATH_MAX];
265 snprintf(configFileName, PATH_MAX, "%s/vomp-%02X-%02X-%02X-%02X-%02X-%02X.conf", configDir, buffer[0], buffer[1], buffer[2], buffer[3], buffer[4], buffer[5]);
266 config.init(configFileName);
268 // Send the login reply
270 time_t timeNow = time(NULL);
271 struct tm* timeStruct = localtime(&timeNow);
272 int timeOffset = timeStruct->tm_gmtoff;
274 UCHAR sendBuffer[12];
275 *(ULONG*)&sendBuffer[0] = htonl(8);
276 *(ULONG*)&sendBuffer[4] = htonl(timeNow);
277 *(signed int*)&sendBuffer[8] = htonl(timeOffset);
279 tcp.sendPacket(sendBuffer, 12);
280 log->log("Client", Log::DEBUG, "written login reply");
286 int MVPClient::processGetRecordingsList(UCHAR* data, int length)
288 UCHAR* sendBuffer = new UCHAR[50000]; // hope this is enough
289 int count = 4; // leave space for the packet length
294 int Percent = VideoDiskSpace(&FreeMB);
295 int Total = (FreeMB / (100 - Percent)) * 100;
297 *(ULONG*)&sendBuffer[count] = htonl(Total);
298 count += sizeof(ULONG);
299 *(ULONG*)&sendBuffer[count] = htonl(FreeMB);
300 count += sizeof(ULONG);
301 *(ULONG*)&sendBuffer[count] = htonl(Percent);
302 count += sizeof(ULONG);
305 cRecordings Recordings;
308 for (cRecording *recording = Recordings.First(); recording; recording = Recordings.Next(recording))
310 if (count > 49000) break; // just how big is that hard disk?!
311 *(ULONG*)&sendBuffer[count] = htonl(recording->start);// + timeOffset);
314 point = (char*)recording->Name();
315 strcpy((char*)&sendBuffer[count], point);
316 count += strlen(point) + 1;
318 point = (char*)recording->FileName();
319 strcpy((char*)&sendBuffer[count], point);
320 count += strlen(point) + 1;
323 *(ULONG*)&sendBuffer[0] = htonl(count - 4); // -4 : take off the size field
325 log->log("Client", Log::DEBUG, "recorded size as %u", ntohl(*(ULONG*)&sendBuffer[0]));
327 tcp.sendPacket(sendBuffer, count);
329 log->log("Client", Log::DEBUG, "Written list");
334 int MVPClient::processDeleteRecording(UCHAR* data, int length)
336 // data is a pointer to the fileName string
338 cRecordings Recordings;
339 Recordings.Load(); // probably have to do this
341 cRecording* recording = Recordings.GetByName((char*)data);
343 log->log("Client", Log::DEBUG, "recording pointer %p", recording);
347 log->log("Client", Log::DEBUG, "deleting recording: %s", recording->Name());
349 cRecordControl *rc = cRecordControls::GetRecordControl(recording->FileName());
352 if (recording->Delete())
354 // Copy svdrp's way of doing this, see if it works
355 #if VDRVERSNUM > 10300
356 ::Recordings.DelByName(recording->FileName());
378 int MVPClient::processMoveRecording(UCHAR* data, int length)
380 log->log("Client", Log::DEBUG, "Process move recording");
381 char* fileName = (char*)data;
382 char* newPath = NULL;
384 for (int k = 0; k < length; k++)
388 newPath = (char*)&data[k+1];
392 log->log("Client", Log::DEBUG, "newPath=%s", newPath);
393 if (!newPath) return 0;
395 cRecordings Recordings;
396 Recordings.Load(); // probably have to do this
398 cRecording* recording = Recordings.GetByName((char*)fileName);
400 log->log("Client", Log::DEBUG, "recording pointer %p", recording);
404 log->log("Client", Log::DEBUG, "moving recording: %s", recording->Name());
406 cRecordControl *rc = cRecordControls::GetRecordControl(recording->FileName());
432 int MVPClient::processGetSummary(UCHAR* data, int length)
434 // data is a pointer to the fileName string
436 cRecordings Recordings;
437 Recordings.Load(); // probably have to do this
439 cRecording *recording = Recordings.GetByName((char*)data);
441 log->log("Client", Log::DEBUG, "recording pointer %p", recording);
445 UCHAR* sendBuffer = new UCHAR[50000]; // hope this is enough
446 int count = 4; // leave space for the packet length
449 #if VDRVERSNUM < 10300
450 point = (char*)recording->Summary();
452 const cRecordingInfo *Info = recording->Info();
453 point = (char*)Info->ShortText();
454 log->log("Client", Log::DEBUG, "info pointer %p summary pointer %p", Info, point);
457 point = (char*)Info->Description();
458 log->log("Client", Log::DEBUG, "description pointer %p", point);
464 strcpy((char*)&sendBuffer[count], point);
465 count += strlen(point) + 1;
469 strcpy((char*)&sendBuffer[count], "");
473 *(ULONG*)&sendBuffer[0] = htonl(count - 4); // -4 : take off the size field
475 log->log("Client", Log::DEBUG, "recorded size as %u", ntohl(*(ULONG*)&sendBuffer[0]));
477 tcp.sendPacket(sendBuffer, count);
479 log->log("Client", Log::DEBUG, "Written summary");
491 int MVPClient::processGetChannelsList(UCHAR* data, int length)
493 UCHAR* sendBuffer = new UCHAR[50000]; // FIXME hope this is enough
494 int count = 4; // leave space for the packet length
498 char* chanConfig = config.getValueString("General", "Channels");
500 if (chanConfig) allChans = strcasecmp(chanConfig, "FTA only");
502 for (cChannel *channel = Channels.First(); channel; channel = Channels.Next(channel))
504 #if VDRVERSNUM < 10300
505 if (!channel->GroupSep() && (!channel->Ca() || allChans))
507 if (!channel->GroupSep() && (!channel->Ca(0) || allChans))
510 log->log("Client", Log::DEBUG, "name: '%s'", channel->Name());
512 if (channel->Vpid()) type = 1;
513 #if VDRVERSNUM < 10300
516 else if (channel->Apid(0)) type = 2;
520 if (count > 49000) break;
521 *(ULONG*)&sendBuffer[count] = htonl(channel->Number());
524 *(ULONG*)&sendBuffer[count] = htonl(type);
527 point = (char*)channel->Name();
528 strcpy((char*)&sendBuffer[count], point);
529 count += strlen(point) + 1;
533 *(ULONG*)&sendBuffer[0] = htonl(count - 4); // -4 : take off the size field
535 log->log("Client", Log::DEBUG, "recorded size as %u", ntohl(*(ULONG*)&sendBuffer[0]));
537 tcp.sendPacket(sendBuffer, count);
539 log->log("Client", Log::DEBUG, "Written channels list");
544 int MVPClient::processStartStreamingChannel(UCHAR* data, int length)
546 log->log("Client", Log::DEBUG, "length = %i", length);
547 ULONG channelNumber = ntohl(*(ULONG*)data);
549 cChannel* channel = channelFromNumber(channelNumber);
556 // get the priority we should use
558 int priority = config.getValueLong("General", "Live priority", &fail);
561 log->log("Client", Log::DEBUG, "Config: Live TV priority: %i", priority);
565 log->log("Client", Log::DEBUG, "Config: Live TV priority config fail");
570 if (priority < 0) priority = 0;
571 if (priority > 99) priority = 99;
573 log->log("Client", Log::DEBUG, "Using live TV priority %i", priority);
574 lp = MVPReceiver::create(channel, priority);
594 int MVPClient::processStopStreaming(UCHAR* data, int length)
596 log->log("Client", Log::DEBUG, "STOP STREAMING RECEIVED");
607 delete recordingManager;
609 recordingManager = NULL;
616 int MVPClient::processGetBlock(UCHAR* data, int length)
620 log->log("Client", Log::DEBUG, "Get block called when no streaming happening!");
624 ULLONG position = ntohll(*(ULLONG*)data);
625 data += sizeof(ULLONG);
626 ULONG amount = ntohl(*(ULONG*)data);
628 log->log("Client", Log::DEBUG, "getblock pos = %llu length = %lu", position, amount);
630 UCHAR sendBuffer[amount + 4];
631 ULONG amountReceived = 0; // compiler moan.
634 log->log("Client", Log::DEBUG, "getting from live");
635 amountReceived = lp->getBlock(&sendBuffer[4], amount);
639 // vdr has possibly disconnected the receiver
640 log->log("Client", Log::DEBUG, "VDR has disconnected the live receiver");
647 log->log("Client", Log::DEBUG, "getting from recording");
648 amountReceived = rp->getBlock(&sendBuffer[4], position, amount);
654 log->log("Client", Log::DEBUG, "written 4(0) as getblock got 0");
658 *(ULONG*)&sendBuffer[0] = htonl(amountReceived);
659 tcp.sendPacket(sendBuffer, amountReceived + 4);
660 log->log("Client", Log::DEBUG, "written ok %lu", amountReceived);
666 int MVPClient::processStartStreamingRecording(UCHAR* data, int length)
668 // data is a pointer to the fileName string
670 recordingManager = new cRecordings;
671 recordingManager->Load();
673 cRecording* recording = recordingManager->GetByName((char*)data);
675 log->log("Client", Log::DEBUG, "recording pointer %p", recording);
679 rp = new RecPlayer(recording);
681 UCHAR sendBuffer[12];
682 *(ULONG*)&sendBuffer[0] = htonl(8);
683 *(ULLONG*)&sendBuffer[4] = htonll(rp->getTotalLength());
685 tcp.sendPacket(sendBuffer, 12);
686 log->log("Client", Log::DEBUG, "written totalLength");
690 delete recordingManager;
691 recordingManager = NULL;
696 int MVPClient::processReScanRecording(UCHAR* data, int length)
702 log->log("Client", Log::DEBUG, "Rescan recording called when no recording being played!");
707 retval = rp->getTotalLength();
710 UCHAR sendBuffer[12];
711 *(ULONG*)&sendBuffer[0] = htonl(8);
712 *(ULLONG*)&sendBuffer[4] = htonll(retval);
714 tcp.sendPacket(sendBuffer, 12);
715 log->log("Client", Log::DEBUG, "Rescan recording, wrote new length to client");
719 int MVPClient::processPositionFromFrameNumber(UCHAR* data, int length)
723 ULONG frameNumber = ntohl(*(ULONG*)data);
728 log->log("Client", Log::DEBUG, "Rescan recording called when no recording being played!");
732 retval = rp->positionFromFrameNumber(frameNumber);
735 UCHAR sendBuffer[12];
736 *(ULONG*)&sendBuffer[0] = htonl(8);
737 *(ULLONG*)&sendBuffer[4] = htonll(retval);
739 tcp.sendPacket(sendBuffer, 12);
740 log->log("Client", Log::DEBUG, "Wrote posFromFrameNum reply to client");
744 int MVPClient::processFrameNumberFromPosition(UCHAR* data, int length)
748 ULLONG position = ntohll(*(ULLONG*)data);
753 log->log("Client", Log::DEBUG, "Rescan recording called when no recording being played!");
757 retval = rp->frameNumberFromPosition(position);
761 *(ULONG*)&sendBuffer[0] = htonl(4);
762 *(ULONG*)&sendBuffer[4] = htonl(retval);
764 tcp.sendPacket(sendBuffer, 8);
765 log->log("Client", Log::DEBUG, "Wrote frameNumFromPos reply to client");
769 int MVPClient::processGetChannelSchedule(UCHAR* data, int length)
771 ULONG channelNumber = ntohl(*(ULONG*)data);
773 ULONG startTime = ntohl(*(ULONG*)data);
775 ULONG duration = ntohl(*(ULONG*)data);
777 log->log("Client", Log::DEBUG, "get schedule called for channel %lu", channelNumber);
779 cChannel* channel = channelFromNumber(channelNumber);
783 log->log("Client", Log::DEBUG, "written 0 because channel = NULL");
787 log->log("Client", Log::DEBUG, "Got channel");
789 #if VDRVERSNUM < 10300
790 cMutexLock MutexLock;
791 const cSchedules *Schedules = cSIProcessor::Schedules(MutexLock);
793 cSchedulesLock MutexLock;
794 const cSchedules *Schedules = cSchedules::Schedules(MutexLock);
799 log->log("Client", Log::DEBUG, "written 0 because Schedule!s! = NULL");
803 log->log("Client", Log::DEBUG, "Got schedule!s! object");
805 const cSchedule *Schedule = Schedules->GetSchedule(channel->GetChannelID());
809 log->log("Client", Log::DEBUG, "written 0 because Schedule = NULL");
813 log->log("Client", Log::DEBUG, "Got schedule object");
815 UCHAR* sendBuffer = (UCHAR*)malloc(100000);
816 ULONG sendBufferLength = 100000;
817 ULONG sendBufferUsed = sizeof(ULONG); // leave a hole for the entire packet length
821 // assign all the event info to temp vars then we know exactly what size they are
824 ULONG thisEventDuration;
825 const char* thisEventTitle;
826 const char* thisEventSubTitle;
827 const char* thisEventDescription;
829 ULONG constEventLength = sizeof(thisEventID) + sizeof(thisEventTime) + sizeof(thisEventDuration);
830 ULONG thisEventLength;
832 #if VDRVERSNUM < 10300
834 const cEventInfo *event;
835 for (int eventNumber = 0; eventNumber < Schedule->NumEvents(); eventNumber++)
837 event = Schedule->GetEventNumber(eventNumber);
839 thisEventID = event->GetEventID();
840 thisEventTime = event->GetTime();
841 thisEventDuration = event->GetDuration();
842 thisEventTitle = event->GetTitle();
843 thisEventSubTitle = event->GetSubtitle();
844 thisEventDescription = event->GetExtendedDescription();
848 for (const cEvent* event = Schedule->Events()->First(); event; event = Schedule->Events()->Next(event))
850 thisEventID = event->EventID();
851 thisEventTime = event->StartTime();
852 thisEventDuration = event->Duration();
853 thisEventTitle = event->Title();
854 thisEventSubTitle = NULL;
855 thisEventDescription = event->Description();
859 log->log("Client", Log::DEBUG, "Got an event object %p", event);
862 if ((thisEventTime + thisEventDuration) < (ULONG)time(NULL)) continue;
865 if ((thisEventTime + thisEventDuration) <= startTime) continue;
868 if (thisEventTime >= (startTime + duration)) continue;
870 if (!thisEventTitle) thisEventTitle = empty;
871 if (!thisEventSubTitle) thisEventSubTitle = empty;
872 if (!thisEventDescription) thisEventDescription = empty;
874 thisEventLength = constEventLength + strlen(thisEventTitle) + 1 + strlen(thisEventSubTitle) + 1 + strlen(thisEventDescription) + 1;
876 log->log("Client", Log::DEBUG, "Done s1");
878 // now extend the buffer if necessary
879 if ((sendBufferUsed + thisEventLength) > sendBufferLength)
881 log->log("Client", Log::DEBUG, "Extending buffer");
882 sendBufferLength += 100000;
883 UCHAR* temp = (UCHAR*)realloc(sendBuffer, sendBufferLength);
887 UCHAR sendBuffer2[8];
888 *(ULONG*)&sendBuffer2[0] = htonl(4);
889 *(ULONG*)&sendBuffer2[4] = htonl(0);
890 tcp.sendPacket(sendBuffer2, 8);
891 log->log("Client", Log::DEBUG, "written 0 because failed to realloc packet");
897 log->log("Client", Log::DEBUG, "Done s2");
899 *(ULONG*)&sendBuffer[sendBufferUsed] = htonl(thisEventID); sendBufferUsed += sizeof(ULONG);
900 *(ULONG*)&sendBuffer[sendBufferUsed] = htonl(thisEventTime); sendBufferUsed += sizeof(ULONG);
901 *(ULONG*)&sendBuffer[sendBufferUsed] = htonl(thisEventDuration); sendBufferUsed += sizeof(ULONG);
903 strcpy((char*)&sendBuffer[sendBufferUsed], thisEventTitle); sendBufferUsed += strlen(thisEventTitle) + 1;
904 strcpy((char*)&sendBuffer[sendBufferUsed], thisEventSubTitle); sendBufferUsed += strlen(thisEventSubTitle) + 1;
905 strcpy((char*)&sendBuffer[sendBufferUsed], thisEventDescription); sendBufferUsed += strlen(thisEventDescription) + 1;
907 log->log("Client", Log::DEBUG, "Done s3 %lu", sendBufferUsed);
910 log->log("Client", Log::DEBUG, "Got all event data");
912 if (sendBufferUsed == sizeof(ULONG))
916 log->log("Client", Log::DEBUG, "Written 0 because no data");
920 // Write the length into the first 4 bytes. It's sendBufferUsed - 4 because of the hole!
921 *(ULONG*)&sendBuffer[0] = htonl(sendBufferUsed - sizeof(ULONG));
922 tcp.sendPacket(sendBuffer, sendBufferUsed);
923 log->log("Client", Log::DEBUG, "written %lu schedules packet", sendBufferUsed);
931 int MVPClient::processConfigSave(UCHAR* buffer, int length)
933 char* section = (char*)buffer;
937 for (int k = 0; k < length; k++)
939 if (buffer[k] == '\0')
943 key = (char*)&buffer[k+1];
947 value = (char*)&buffer[k+1];
953 // if the last string (value) doesnt have null terminator, give up
954 if (buffer[length - 1] != '\0') return 0;
956 log->log("Client", Log::DEBUG, "Config save: %s %s %s", section, key, value);
957 if (config.setValueString(section, key, value))
969 int MVPClient::processConfigLoad(UCHAR* buffer, int length)
971 char* section = (char*)buffer;
974 for (int k = 0; k < length; k++)
976 if (buffer[k] == '\0')
978 key = (char*)&buffer[k+1];
983 char* value = config.getValueString(section, key);
987 UCHAR sendBuffer[4 + strlen(value) + 1];
988 *(ULONG*)&sendBuffer[0] = htonl(strlen(value) + 1);
989 strcpy((char*)&sendBuffer[4], value);
990 tcp.sendPacket(sendBuffer, 4 + strlen(value) + 1);
992 log->log("Client", Log::DEBUG, "Written config load packet");
998 *(ULONG*)&sendBuffer[0] = htonl(4);
999 *(ULONG*)&sendBuffer[4] = htonl(0);
1000 tcp.sendPacket(sendBuffer, 8);
1002 log->log("Client", Log::DEBUG, "Written config load failed packet");
1008 void MVPClient::cleanConfig()
1010 log->log("Client", Log::DEBUG, "Clean config");
1012 cRecordings Recordings;
1017 char* resumes = config.getSectionKeyNames("ResumeData", numReturns, length);
1018 char* position = resumes;
1019 for(int k = 0; k < numReturns; k++)
1021 log->log("Client", Log::DEBUG, "EXAMINING: %i %i %p %s", k, numReturns, position, position);
1023 cRecording* recording = Recordings.GetByName(position);
1026 // doesn't exist anymore
1027 log->log("Client", Log::DEBUG, "Found a recording that doesn't exist anymore");
1028 config.deleteValue("ResumeData", position);
1032 log->log("Client", Log::DEBUG, "This recording still exists");
1035 position += strlen(position) + 1;
1047 event = Schedule->GetPresentEvent();
1049 fprintf(f, "\n\nCurrent event\n\n");
1051 fprintf(f, "Event %i eventid = %u time = %lu duration = %li\n", 0, event->GetEventID(), event->GetTime(), event->GetDuration());
1052 fprintf(f, "Event %i title = %s subtitle = %s\n", 0, event->GetTitle(), event->GetSubtitle());
1053 fprintf(f, "Event %i extendeddescription = %s\n", 0, event->GetExtendedDescription());
1054 fprintf(f, "Event %i isFollowing = %i, isPresent = %i\n", 0, event->IsFollowing(), event->IsPresent());
1056 event = Schedule->GetFollowingEvent();
1058 fprintf(f, "\n\nFollowing event\n\n");
1060 fprintf(f, "Event %i eventid = %u time = %lu duration = %li\n", 0, event->GetEventID(), event->GetTime(), event->GetDuration());
1061 fprintf(f, "Event %i title = %s subtitle = %s\n", 0, event->GetTitle(), event->GetSubtitle());
1062 fprintf(f, "Event %i extendeddescription = %s\n", 0, event->GetExtendedDescription());
1063 fprintf(f, "Event %i isFollowing = %i, isPresent = %i\n", 0, event->IsFollowing(), event->IsPresent());
1069 fprintf(f, "Event %i eventid = %u time = %lu duration = %li\n", eventNumber, event->GetEventID(), event->GetTime(), event->GetDuration());
1070 fprintf(f, "Event %i title = %s subtitle = %s\n", eventNumber, event->GetTitle(), event->GetSubtitle());
1071 fprintf(f, "Event %i extendeddescription = %s\n", eventNumber, event->GetExtendedDescription());
1072 fprintf(f, "Event %i isFollowing = %i, isPresent = %i\n", eventNumber, event->IsFollowing(), event->IsPresent());
1080 void MVPClient::test2()
1082 FILE* f = fopen("/tmp/s.txt", "w");
1084 #if VDRVERSNUM < 10300
1085 cMutexLock MutexLock;
1086 const cSchedules *Schedules = cSIProcessor::Schedules(MutexLock);
1088 cSchedulesLock MutexLock;
1089 const cSchedules *Schedules = cSchedules::Schedules(MutexLock);
1094 fprintf(f, "Schedules = NULL\n");
1099 fprintf(f, "Schedules dump:\n");
1103 const cSchedule *Schedule;
1104 int scheduleNumber = 0;
1107 cChannel *thisChannel;
1109 #if VDRVERSNUM < 10300
1110 const cEventInfo *event;
1111 int eventNumber = 0;
1113 const cEvent *event;
1116 // Schedule = Schedules->GetSchedule(channel->GetChannelID());
1117 // Schedule = Schedules->GetSchedule();
1118 Schedule = Schedules->First();
1121 fprintf(f, "First Schedule = NULL\n");
1128 fprintf(f, "Schedule #%i\n", scheduleNumber);
1129 fprintf(f, "-------------\n\n");
1131 #if VDRVERSNUM < 10300
1132 tchid = Schedule->GetChannelID();
1134 tchid = Schedule->ChannelID();
1137 #if VDRVERSNUM < 10300
1138 fprintf(f, "ChannelID.ToString() = %s\n", tchid.ToString());
1139 fprintf(f, "NumEvents() = %i\n", Schedule->NumEvents());
1141 // put the count at the end.
1144 thisChannel = Channels.GetByChannelID(tchid, true);
1147 fprintf(f, "Channel Number: %p %i\n", thisChannel, thisChannel->Number());
1151 fprintf(f, "thisChannel = NULL for tchid\n");
1154 #if VDRVERSNUM < 10300
1155 for (eventNumber = 0; eventNumber < Schedule->NumEvents(); eventNumber++)
1157 event = Schedule->GetEventNumber(eventNumber);
1158 fprintf(f, "Event %i tableid = %i timestring = %s endtimestring = %s\n", eventNumber, event->GetTableID(), event->GetTimeString(), event->GetEndTimeString());
1159 fprintf(f, "Event %i date = %s isfollowing = %i ispresent = %i\n", eventNumber, event->GetDate(), event->IsFollowing(), event->IsPresent());
1160 fprintf(f, "Event %i extendeddescription = %s\n", eventNumber, event->GetExtendedDescription());
1161 fprintf(f, "Event %i subtitle = %s title = %s\n", eventNumber, event->GetSubtitle(), event->GetTitle());
1162 fprintf(f, "Event %i eventid = %u duration = %li time = %lu channelnumber = %i\n", eventNumber, event->GetEventID(), event->GetDuration(), event->GetTime(), event->GetChannelNumber());
1163 fprintf(f, "Event %u dump:\n", eventNumber);
1168 // This whole section needs rewriting to walk the list.
1169 event = Schedule->Events()->First();
1171 event = Schedule->Events()->Next(event);
1176 fprintf(f, "\nDump from object:\n");
1178 fprintf(f, "\nEND\n");
1188 fprintf(f, "End of current Schedule\n\n\n");
1190 Schedule = (const cSchedule *)Schedules->Next(Schedule);
1204 const cEventInfo *GetPresentEvent(void) const;
1205 const cEventInfo *GetFollowingEvent(void) const;
1206 const cEventInfo *GetEvent(unsigned short uEventID, time_t tTime = 0) const;
1207 const cEventInfo *GetEventAround(time_t tTime) const;
1208 const cEventInfo *GetEventNumber(int n) const { return Events.Get(n); }
1211 const unsigned char GetTableID(void) const;
1212 const char *GetTimeString(void) const;
1213 const char *GetEndTimeString(void) const;
1214 const char *GetDate(void) const;
1215 bool IsFollowing(void) const;
1216 bool IsPresent(void) const;
1217 const char *GetExtendedDescription(void) const;
1218 const char *GetSubtitle(void) const;
1219 const char *GetTitle(void) const;
1220 unsigned short GetEventID(void) const;
1221 long GetDuration(void) const;
1222 time_t GetTime(void) const;
1223 tChannelID GetChannelID(void) const;
1224 int GetChannelNumber(void) const { return nChannelNumber; }
1225 void SetChannelNumber(int ChannelNumber) const { ((cEventInfo *)this)->nChannelNumber = ChannelNumber; } // doesn't modify the EIT data, so it's ok to make it 'const'
1226 void Dump(FILE *f, const char *Prefix = "") const;
1232 void MVPClient::test(int channelNumber)
1234 FILE* f = fopen("/tmp/test.txt", "w");
1236 cMutexLock MutexLock;
1237 const cSchedules *Schedules = cSIProcessor::Schedules(MutexLock);
1241 fprintf(f, "Schedules = NULL\n");
1246 fprintf(f, "Schedules dump:\n");
1247 // Schedules->Dump(f);
1249 const cSchedule *Schedule;
1250 cChannel *thisChannel;
1251 const cEventInfo *event;
1253 thisChannel = channelFromNumber(channelNumber);
1256 fprintf(f, "thisChannel = NULL\n");
1261 Schedule = Schedules->GetSchedule(thisChannel->GetChannelID());
1262 // Schedule = Schedules->GetSchedule();
1263 // Schedule = Schedules->First();
1266 fprintf(f, "First Schedule = NULL\n");
1271 fprintf(f, "NumEvents() = %i\n\n", Schedule->NumEvents());
1273 // For some channels VDR seems to pick a random point in time to
1274 // start dishing out events, but they are in order
1275 // at some point in the list the time snaps to the current event
1280 for (int eventNumber = 0; eventNumber < Schedule->NumEvents(); eventNumber++)
1282 event = Schedule->GetEventNumber(eventNumber);
1283 fprintf(f, "Event %i eventid = %u time = %lu duration = %li\n", eventNumber, event->GetEventID(), event->GetTime(), event->GetDuration());
1284 fprintf(f, "Event %i title = %s subtitle = %s\n", eventNumber, event->GetTitle(), event->GetSubtitle());
1285 fprintf(f, "Event %i extendeddescription = %s\n", eventNumber, event->GetExtendedDescription());
1289 fprintf(f, "\nEND\n");
1303 Schedules = the collection of all the Schedule objects
1304 Schedule = One schedule, contants all the events for a channel
1305 Event = One programme
1314 Subtitle (used for "Programmes resume at ...")
1317 IsPresent ? easy to work out tho. Oh it doesn't always work
1322 void MVPClient::test2()
1324 log->log("-", Log::DEBUG, "Timers List");
1326 for (int i = 0; i < Timers.Count(); i++)
1328 cTimer *timer = Timers.Get(i);
1329 //Reply(i < Timers.Count() - 1 ? -250 : 250, "%d %s", timer->Index() + 1, timer->ToText());
1330 log->log("-", Log::DEBUG, "i=%i count=%i index=%d", i, Timers.Count(), timer->Index() + 1);
1331 #if VDRVERSNUM < 10300
1332 log->log("-", Log::DEBUG, "active=%i recording=%i pending=%i start=%li stop=%li priority=%i lifetime=%i", timer->Active(), timer->Recording(), timer->Pending(), timer->StartTime(), timer->StopTime(), timer->Priority(), timer->Lifetime());
1334 log->log("-", Log::DEBUG, "active=%i recording=%i pending=%i start=%li stop=%li priority=%i lifetime=%i", timer->HasFlags(tfActive), timer->Recording(), timer->Pending(), timer->StartTime(), timer->StopTime(), timer->Priority(), timer->Lifetime());
1336 log->log("-", Log::DEBUG, "channel=%i file=%s summary=%s", timer->Channel()->Number(), timer->File(), timer->Summary());
1337 log->log("-", Log::DEBUG, "");
1340 // asprintf(&buffer, "%d:%s:%s :%04d:%04d:%d:%d:%s:%s\n",
1341 // active, (UseChannelID ? Channel()->GetChannelID().ToString() : itoa(Channel()->Number())),
1342 // PrintDay(day, firstday), start, stop, priority, lifetime, file, summary ? summary : "");
1347 Active seems to be a bool - whether the timer should be done or not. If set to inactive it stays around after its time
1348 recording is a bool, 0 for not currently recording, 1 for currently recording
1349 pending is a bool, 0 for would not be trying to record this right now, 1 for would/is trying to record this right now
1353 int MVPClient::processGetTimers(UCHAR* buffer, int length)
1355 UCHAR* sendBuffer = new UCHAR[50000]; // FIXME hope this is enough
1356 int count = 4; // leave space for the packet length
1358 const char* fileName;
1360 int numTimers = Timers.Count();
1362 *(ULONG*)&sendBuffer[count] = htonl(numTimers); count += 4;
1364 for (int i = 0; i < numTimers; i++)
1366 if (count > 49000) break;
1368 timer = Timers.Get(i);
1370 #if VDRVERSNUM < 10300
1371 *(ULONG*)&sendBuffer[count] = htonl(timer->Active()); count += 4;
1373 *(ULONG*)&sendBuffer[count] = htonl(timer->HasFlags(tfActive)); count += 4;
1375 *(ULONG*)&sendBuffer[count] = htonl(timer->Recording()); count += 4;
1376 *(ULONG*)&sendBuffer[count] = htonl(timer->Pending()); count += 4;
1377 *(ULONG*)&sendBuffer[count] = htonl(timer->Priority()); count += 4;
1378 *(ULONG*)&sendBuffer[count] = htonl(timer->Lifetime()); count += 4;
1379 *(ULONG*)&sendBuffer[count] = htonl(timer->Channel()->Number()); count += 4;
1380 *(ULONG*)&sendBuffer[count] = htonl(timer->StartTime()); count += 4;
1381 *(ULONG*)&sendBuffer[count] = htonl(timer->StopTime()); count += 4;
1383 fileName = timer->File();
1384 strcpy((char*)&sendBuffer[count], fileName);
1385 count += strlen(fileName) + 1;
1388 *(ULONG*)&sendBuffer[0] = htonl(count - 4); // -4 : take off the size field
1390 log->log("Client", Log::DEBUG, "recorded size as %u", ntohl(*(ULONG*)&sendBuffer[0]));
1392 tcp.sendPacket(sendBuffer, count);
1393 delete[] sendBuffer;
1394 log->log("Client", Log::DEBUG, "Written timers list");
1399 int MVPClient::processSetTimer(UCHAR* buffer, int length)
1401 char* timerString = new char[strlen((char*)buffer) + 1];
1402 strcpy(timerString, (char*)buffer);
1404 #if VDRVERSNUM < 10300
1406 // If this is VDR 1.2 the date part of the timer string must be reduced
1407 // to just DD rather than YYYY-MM-DD
1409 int s = 0; // source
1410 int d = 0; // destination
1412 while(c != 2) // copy up to date section, including the second ':'
1414 timerString[d] = buffer[s];
1415 if (buffer[s] == ':') c++;
1419 // now it has copied up to the date section
1421 while(c != 2) // waste YYYY-MM-
1423 if (buffer[s] == '-') c++;
1426 // now source is at the DD
1427 memcpy(&timerString[d], &buffer[s], length - s);
1429 timerString[d] = '\0';
1431 log->log("Client", Log::DEBUG, "Timer string after 1.2 conversion:");
1432 log->log("Client", Log::DEBUG, "%s", timerString);
1436 cTimer *timer = new cTimer;
1437 if (timer->Parse((char*)timerString))
1439 cTimer *t = Timers.GetTimer(timer);
1443 #if VDRVERSNUM < 10300
1446 Timers.SetModified();