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))
190 result = processLogin(data, packetLength);
193 result = processGetRecordingsList(data, packetLength);
196 result = processDeleteRecording(data, packetLength);
199 result = processGetSummary(data, packetLength);
202 result = processGetChannelsList(data, packetLength);
205 result = processStartStreamingChannel(data, packetLength);
208 result = processGetBlock(data, packetLength);
211 result = processStopStreaming(data, packetLength);
214 result = processStartStreamingRecording(data, packetLength);
217 result = processGetChannelSchedule(data, packetLength);
220 result = processConfigSave(data, packetLength);
223 result = processConfigLoad(data, packetLength);
226 result = processReScanRecording(data, packetLength);
229 result = processGetTimers(data, packetLength);
232 result = processSetTimer(data, packetLength);
235 result = processPositionFromFrameNumber(data, packetLength);
244 int MVPClient::processLogin(UCHAR* buffer, int length)
246 if (length != 6) return 0;
250 const char* configDir = cPlugin::ConfigDirectory(configDirExtra);
253 log->log("Client", Log::DEBUG, "No config dir!");
257 char configFileName[PATH_MAX];
258 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]);
259 config.init(configFileName);
261 // Send the login reply
263 time_t timeNow = time(NULL);
264 struct tm* timeStruct = localtime(&timeNow);
265 int timeOffset = timeStruct->tm_gmtoff;
267 UCHAR sendBuffer[12];
268 *(ULONG*)&sendBuffer[0] = htonl(8);
269 *(ULONG*)&sendBuffer[4] = htonl(timeNow);
270 *(signed int*)&sendBuffer[8] = htonl(timeOffset);
272 tcp.sendPacket(sendBuffer, 12);
273 log->log("Client", Log::DEBUG, "written login reply");
279 int MVPClient::processGetRecordingsList(UCHAR* data, int length)
281 UCHAR* sendBuffer = new UCHAR[50000]; // hope this is enough
282 int count = 4; // leave space for the packet length
287 int Percent = VideoDiskSpace(&FreeMB);
288 int Total = (FreeMB / (100 - Percent)) * 100;
290 *(ULONG*)&sendBuffer[count] = htonl(Total);
291 count += sizeof(ULONG);
292 *(ULONG*)&sendBuffer[count] = htonl(FreeMB);
293 count += sizeof(ULONG);
294 *(ULONG*)&sendBuffer[count] = htonl(Percent);
295 count += sizeof(ULONG);
298 cRecordings Recordings;
301 for (cRecording *recording = Recordings.First(); recording; recording = Recordings.Next(recording))
303 if (count > 49000) break; // just how big is that hard disk?!
304 *(ULONG*)&sendBuffer[count] = htonl(recording->start);// + timeOffset);
307 point = (char*)recording->Name();
308 strcpy((char*)&sendBuffer[count], point);
309 count += strlen(point) + 1;
311 point = (char*)recording->FileName();
312 strcpy((char*)&sendBuffer[count], point);
313 count += strlen(point) + 1;
316 *(ULONG*)&sendBuffer[0] = htonl(count - 4); // -4 : take off the size field
318 log->log("Client", Log::DEBUG, "recorded size as %u", ntohl(*(ULONG*)&sendBuffer[0]));
320 tcp.sendPacket(sendBuffer, count);
322 log->log("Client", Log::DEBUG, "Written list");
327 int MVPClient::processDeleteRecording(UCHAR* data, int length)
329 // data is a pointer to the fileName string
331 cRecordings Recordings;
332 Recordings.Load(); // probably have to do this
334 cRecording* recording = Recordings.GetByName((char*)data);
336 log->log("Client", Log::DEBUG, "recording pointer %p", recording);
340 log->log("Client", Log::DEBUG, "deleting recording: %s", recording->Name());
342 cRecordControl *rc = cRecordControls::GetRecordControl(recording->FileName());
345 if (recording->Delete())
347 // Copy svdrp's way of doing this, see if it works
348 ::Recordings.DelByName(recording->FileName());
369 int MVPClient::processGetSummary(UCHAR* data, int length)
371 // data is a pointer to the fileName string
373 cRecordings Recordings;
374 Recordings.Load(); // probably have to do this
376 cRecording *recording = Recordings.GetByName((char*)data);
378 log->log("Client", Log::DEBUG, "recording pointer %p", recording);
382 UCHAR* sendBuffer = new UCHAR[50000]; // hope this is enough
383 int count = 4; // leave space for the packet length
386 #if VDRVERSNUM < 10300
387 point = (char*)recording->Summary();
389 const cRecordingInfo *Info = recording->Info();
390 point = (char*)Info->ShortText();
391 log->log("Client", Log::DEBUG, "info pointer %p summary pointer %p", Info, point);
394 point = (char*)Info->Description();
395 log->log("Client", Log::DEBUG, "description pointer %p", point);
401 strcpy((char*)&sendBuffer[count], point);
402 count += strlen(point) + 1;
406 strcpy((char*)&sendBuffer[count], "");
410 *(ULONG*)&sendBuffer[0] = htonl(count - 4); // -4 : take off the size field
412 log->log("Client", Log::DEBUG, "recorded size as %u", ntohl(*(ULONG*)&sendBuffer[0]));
414 tcp.sendPacket(sendBuffer, count);
416 log->log("Client", Log::DEBUG, "Written summary");
428 int MVPClient::processGetChannelsList(UCHAR* data, int length)
430 UCHAR* sendBuffer = new UCHAR[50000]; // FIXME hope this is enough
431 int count = 4; // leave space for the packet length
435 char* chanConfig = config.getValueString("General", "Channels");
437 if (chanConfig) allChans = strcasecmp(chanConfig, "FTA only");
439 for (cChannel *channel = Channels.First(); channel; channel = Channels.Next(channel))
441 #if VDRVERSNUM < 10300
442 if (!channel->GroupSep() && (!channel->Ca() || allChans))
444 if (!channel->GroupSep() && (!channel->Ca(0) || allChans))
447 log->log("Client", Log::DEBUG, "name: '%s'", channel->Name());
449 if (channel->Vpid()) type = 1;
450 #if VDRVERSNUM < 10300
453 else if (channel->Apid(0)) type = 2;
457 if (count > 49000) break;
458 *(ULONG*)&sendBuffer[count] = htonl(channel->Number());
461 *(ULONG*)&sendBuffer[count] = htonl(type);
464 point = (char*)channel->Name();
465 strcpy((char*)&sendBuffer[count], point);
466 count += strlen(point) + 1;
470 *(ULONG*)&sendBuffer[0] = htonl(count - 4); // -4 : take off the size field
472 log->log("Client", Log::DEBUG, "recorded size as %u", ntohl(*(ULONG*)&sendBuffer[0]));
474 tcp.sendPacket(sendBuffer, count);
476 log->log("Client", Log::DEBUG, "Written channels list");
481 int MVPClient::processStartStreamingChannel(UCHAR* data, int length)
483 log->log("Client", Log::DEBUG, "length = %i", length);
484 ULONG channelNumber = ntohl(*(ULONG*)data);
486 cChannel* channel = channelFromNumber(channelNumber);
493 // get the priority we should use
495 int priority = config.getValueLong("General", "Live priority", &fail);
498 log->log("Client", Log::DEBUG, "Config: Live TV priority: %i", priority);
502 log->log("Client", Log::DEBUG, "Config: Live TV priority config fail");
507 if (priority < 0) priority = 0;
508 if (priority > 99) priority = 99;
510 log->log("Client", Log::DEBUG, "Using live TV priority %i", priority);
511 lp = MVPReceiver::create(channel, priority);
531 int MVPClient::processStopStreaming(UCHAR* data, int length)
533 log->log("Client", Log::DEBUG, "STOP STREAMING RECEIVED");
544 delete recordingManager;
546 recordingManager = NULL;
553 int MVPClient::processGetBlock(UCHAR* data, int length)
557 log->log("Client", Log::DEBUG, "Get block called when no streaming happening!");
561 ULLONG position = ntohll(*(ULLONG*)data);
562 data += sizeof(ULLONG);
563 ULONG amount = ntohl(*(ULONG*)data);
565 log->log("Client", Log::DEBUG, "getblock pos = %llu length = %lu", position, amount);
567 UCHAR sendBuffer[amount + 4];
568 ULONG amountReceived = 0; // compiler moan.
571 log->log("Client", Log::DEBUG, "getting from live");
572 amountReceived = lp->getBlock(&sendBuffer[4], amount);
576 // vdr has possibly disconnected the receiver
577 log->log("Client", Log::DEBUG, "VDR has disconnected the live receiver");
584 log->log("Client", Log::DEBUG, "getting from recording");
585 amountReceived = rp->getBlock(&sendBuffer[4], position, amount);
591 log->log("Client", Log::DEBUG, "written 4(0) as getblock got 0");
595 *(ULONG*)&sendBuffer[0] = htonl(amountReceived);
596 tcp.sendPacket(sendBuffer, amountReceived + 4);
597 log->log("Client", Log::DEBUG, "written ok %lu", amountReceived);
603 int MVPClient::processStartStreamingRecording(UCHAR* data, int length)
605 // data is a pointer to the fileName string
607 recordingManager = new cRecordings;
608 recordingManager->Load();
610 cRecording* recording = recordingManager->GetByName((char*)data);
612 log->log("Client", Log::DEBUG, "recording pointer %p", recording);
616 rp = new RecPlayer(recording);
618 UCHAR sendBuffer[12];
619 *(ULONG*)&sendBuffer[0] = htonl(8);
620 *(ULLONG*)&sendBuffer[4] = htonll(rp->getTotalLength());
622 tcp.sendPacket(sendBuffer, 12);
623 log->log("Client", Log::DEBUG, "written totalLength");
627 delete recordingManager;
628 recordingManager = NULL;
633 int MVPClient::processReScanRecording(UCHAR* data, int length)
639 log->log("Client", Log::DEBUG, "Rescan recording called when no recording being played!");
644 retval = rp->getTotalLength();
647 UCHAR sendBuffer[12];
648 *(ULONG*)&sendBuffer[0] = htonl(8);
649 *(ULLONG*)&sendBuffer[4] = htonll(retval);
651 tcp.sendPacket(sendBuffer, 12);
652 log->log("Client", Log::DEBUG, "Rescan recording, wrote new length to client");
656 int MVPClient::processPositionFromFrameNumber(UCHAR* data, int length)
660 ULONG frameNumber = ntohl(*(ULONG*)data);
665 log->log("Client", Log::DEBUG, "Rescan recording called when no recording being played!");
669 retval = rp->positionFromFrameNumber(frameNumber);
672 UCHAR sendBuffer[12];
673 *(ULONG*)&sendBuffer[0] = htonl(8);
674 *(ULLONG*)&sendBuffer[4] = htonll(retval);
676 tcp.sendPacket(sendBuffer, 12);
677 log->log("Client", Log::DEBUG, "Wrote posFromFrameNum reply to client");
681 int MVPClient::processGetChannelSchedule(UCHAR* data, int length)
683 ULONG channelNumber = ntohl(*(ULONG*)data);
685 ULONG startTime = ntohl(*(ULONG*)data);
687 ULONG duration = ntohl(*(ULONG*)data);
689 log->log("Client", Log::DEBUG, "get schedule called for channel %lu", channelNumber);
691 cChannel* channel = channelFromNumber(channelNumber);
695 log->log("Client", Log::DEBUG, "written 0 because channel = NULL");
699 log->log("Client", Log::DEBUG, "Got channel");
701 #if VDRVERSNUM < 10300
702 cMutexLock MutexLock;
703 const cSchedules *Schedules = cSIProcessor::Schedules(MutexLock);
705 cSchedulesLock MutexLock;
706 const cSchedules *Schedules = cSchedules::Schedules(MutexLock);
711 log->log("Client", Log::DEBUG, "written 0 because Schedule!s! = NULL");
715 log->log("Client", Log::DEBUG, "Got schedule!s! object");
717 const cSchedule *Schedule = Schedules->GetSchedule(channel->GetChannelID());
721 log->log("Client", Log::DEBUG, "written 0 because Schedule = NULL");
725 log->log("Client", Log::DEBUG, "Got schedule object");
727 UCHAR* sendBuffer = (UCHAR*)malloc(100000);
728 ULONG sendBufferLength = 100000;
729 ULONG sendBufferUsed = sizeof(ULONG); // leave a hole for the entire packet length
733 // assign all the event info to temp vars then we know exactly what size they are
736 ULONG thisEventDuration;
737 const char* thisEventTitle;
738 const char* thisEventSubTitle;
739 const char* thisEventDescription;
741 ULONG constEventLength = sizeof(thisEventID) + sizeof(thisEventTime) + sizeof(thisEventDuration);
742 ULONG thisEventLength;
744 #if VDRVERSNUM < 10300
746 const cEventInfo *event;
747 for (int eventNumber = 0; eventNumber < Schedule->NumEvents(); eventNumber++)
749 event = Schedule->GetEventNumber(eventNumber);
751 thisEventID = event->GetEventID();
752 thisEventTime = event->GetTime();
753 thisEventDuration = event->GetDuration();
754 thisEventTitle = event->GetTitle();
755 thisEventSubTitle = event->GetSubtitle();
756 thisEventDescription = event->GetExtendedDescription();
760 for (const cEvent* event = Schedule->Events()->First(); event; event = Schedule->Events()->Next(event))
762 thisEventID = event->EventID();
763 thisEventTime = event->StartTime();
764 thisEventDuration = event->Duration();
765 thisEventTitle = event->Title();
766 thisEventSubTitle = NULL;
767 thisEventDescription = event->Description();
771 log->log("Client", Log::DEBUG, "Got an event object %p", event);
774 if ((thisEventTime + thisEventDuration) < (ULONG)time(NULL)) continue;
777 if ((thisEventTime + thisEventDuration) <= startTime) continue;
780 if (thisEventTime >= (startTime + duration)) continue;
782 if (!thisEventTitle) thisEventTitle = empty;
783 if (!thisEventSubTitle) thisEventSubTitle = empty;
784 if (!thisEventDescription) thisEventDescription = empty;
786 thisEventLength = constEventLength + strlen(thisEventTitle) + 1 + strlen(thisEventSubTitle) + 1 + strlen(thisEventDescription) + 1;
788 log->log("Client", Log::DEBUG, "Done s1");
790 // now extend the buffer if necessary
791 if ((sendBufferUsed + thisEventLength) > sendBufferLength)
793 log->log("Client", Log::DEBUG, "Extending buffer");
794 sendBufferLength += 100000;
795 UCHAR* temp = (UCHAR*)realloc(sendBuffer, sendBufferLength);
799 UCHAR sendBuffer2[8];
800 *(ULONG*)&sendBuffer2[0] = htonl(4);
801 *(ULONG*)&sendBuffer2[4] = htonl(0);
802 tcp.sendPacket(sendBuffer2, 8);
803 log->log("Client", Log::DEBUG, "written 0 because failed to realloc packet");
809 log->log("Client", Log::DEBUG, "Done s2");
811 *(ULONG*)&sendBuffer[sendBufferUsed] = htonl(thisEventID); sendBufferUsed += sizeof(ULONG);
812 *(ULONG*)&sendBuffer[sendBufferUsed] = htonl(thisEventTime); sendBufferUsed += sizeof(ULONG);
813 *(ULONG*)&sendBuffer[sendBufferUsed] = htonl(thisEventDuration); sendBufferUsed += sizeof(ULONG);
815 strcpy((char*)&sendBuffer[sendBufferUsed], thisEventTitle); sendBufferUsed += strlen(thisEventTitle) + 1;
816 strcpy((char*)&sendBuffer[sendBufferUsed], thisEventSubTitle); sendBufferUsed += strlen(thisEventSubTitle) + 1;
817 strcpy((char*)&sendBuffer[sendBufferUsed], thisEventDescription); sendBufferUsed += strlen(thisEventDescription) + 1;
819 log->log("Client", Log::DEBUG, "Done s3 %lu", sendBufferUsed);
822 log->log("Client", Log::DEBUG, "Got all event data");
824 if (sendBufferUsed == sizeof(ULONG))
828 log->log("Client", Log::DEBUG, "Written 0 because no data");
832 // Write the length into the first 4 bytes. It's sendBufferUsed - 4 because of the hole!
833 *(ULONG*)&sendBuffer[0] = htonl(sendBufferUsed - sizeof(ULONG));
834 tcp.sendPacket(sendBuffer, sendBufferUsed);
835 log->log("Client", Log::DEBUG, "written %lu schedules packet", sendBufferUsed);
843 int MVPClient::processConfigSave(UCHAR* buffer, int length)
845 char* section = (char*)buffer;
849 for (int k = 0; k < length; k++)
851 if (buffer[k] == '\0')
855 key = (char*)&buffer[k+1];
859 value = (char*)&buffer[k+1];
865 // if the last string (value) doesnt have null terminator, give up
866 if (buffer[length - 1] != '\0') return 0;
868 log->log("Client", Log::DEBUG, "Config save: %s %s %s", section, key, value);
869 if (config.setValueString(section, key, value))
881 int MVPClient::processConfigLoad(UCHAR* buffer, int length)
883 char* section = (char*)buffer;
886 for (int k = 0; k < length; k++)
888 if (buffer[k] == '\0')
890 key = (char*)&buffer[k+1];
895 char* value = config.getValueString(section, key);
899 UCHAR sendBuffer[4 + strlen(value) + 1];
900 *(ULONG*)&sendBuffer[0] = htonl(strlen(value) + 1);
901 strcpy((char*)&sendBuffer[4], value);
902 tcp.sendPacket(sendBuffer, 4 + strlen(value) + 1);
904 log->log("Client", Log::DEBUG, "Written config load packet");
910 *(ULONG*)&sendBuffer[0] = htonl(4);
911 *(ULONG*)&sendBuffer[4] = htonl(0);
912 tcp.sendPacket(sendBuffer, 8);
914 log->log("Client", Log::DEBUG, "Written config load failed packet");
920 void MVPClient::cleanConfig()
922 log->log("Client", Log::DEBUG, "Clean config");
924 cRecordings Recordings;
929 char* resumes = config.getSectionKeyNames("ResumeData", numReturns, length);
930 char* position = resumes;
931 for(int k = 0; k < numReturns; k++)
933 log->log("Client", Log::DEBUG, "EXAMINING: %i %i %p %s", k, numReturns, position, position);
935 cRecording* recording = Recordings.GetByName(position);
938 // doesn't exist anymore
939 log->log("Client", Log::DEBUG, "Found a recording that doesn't exist anymore");
940 config.deleteValue("ResumeData", position);
944 log->log("Client", Log::DEBUG, "This recording still exists");
947 position += strlen(position) + 1;
959 event = Schedule->GetPresentEvent();
961 fprintf(f, "\n\nCurrent event\n\n");
963 fprintf(f, "Event %i eventid = %u time = %lu duration = %li\n", 0, event->GetEventID(), event->GetTime(), event->GetDuration());
964 fprintf(f, "Event %i title = %s subtitle = %s\n", 0, event->GetTitle(), event->GetSubtitle());
965 fprintf(f, "Event %i extendeddescription = %s\n", 0, event->GetExtendedDescription());
966 fprintf(f, "Event %i isFollowing = %i, isPresent = %i\n", 0, event->IsFollowing(), event->IsPresent());
968 event = Schedule->GetFollowingEvent();
970 fprintf(f, "\n\nFollowing event\n\n");
972 fprintf(f, "Event %i eventid = %u time = %lu duration = %li\n", 0, event->GetEventID(), event->GetTime(), event->GetDuration());
973 fprintf(f, "Event %i title = %s subtitle = %s\n", 0, event->GetTitle(), event->GetSubtitle());
974 fprintf(f, "Event %i extendeddescription = %s\n", 0, event->GetExtendedDescription());
975 fprintf(f, "Event %i isFollowing = %i, isPresent = %i\n", 0, event->IsFollowing(), event->IsPresent());
981 fprintf(f, "Event %i eventid = %u time = %lu duration = %li\n", eventNumber, event->GetEventID(), event->GetTime(), event->GetDuration());
982 fprintf(f, "Event %i title = %s subtitle = %s\n", eventNumber, event->GetTitle(), event->GetSubtitle());
983 fprintf(f, "Event %i extendeddescription = %s\n", eventNumber, event->GetExtendedDescription());
984 fprintf(f, "Event %i isFollowing = %i, isPresent = %i\n", eventNumber, event->IsFollowing(), event->IsPresent());
992 void MVPClient::test2()
994 FILE* f = fopen("/tmp/s.txt", "w");
996 #if VDRVERSNUM < 10300
997 cMutexLock MutexLock;
998 const cSchedules *Schedules = cSIProcessor::Schedules(MutexLock);
1000 cSchedulesLock MutexLock;
1001 const cSchedules *Schedules = cSchedules::Schedules(MutexLock);
1006 fprintf(f, "Schedules = NULL\n");
1011 fprintf(f, "Schedules dump:\n");
1015 const cSchedule *Schedule;
1016 int scheduleNumber = 0;
1019 cChannel *thisChannel;
1021 #if VDRVERSNUM < 10300
1022 const cEventInfo *event;
1023 int eventNumber = 0;
1025 const cEvent *event;
1028 // Schedule = Schedules->GetSchedule(channel->GetChannelID());
1029 // Schedule = Schedules->GetSchedule();
1030 Schedule = Schedules->First();
1033 fprintf(f, "First Schedule = NULL\n");
1040 fprintf(f, "Schedule #%i\n", scheduleNumber);
1041 fprintf(f, "-------------\n\n");
1043 #if VDRVERSNUM < 10300
1044 tchid = Schedule->GetChannelID();
1046 tchid = Schedule->ChannelID();
1049 #if VDRVERSNUM < 10300
1050 fprintf(f, "ChannelID.ToString() = %s\n", tchid.ToString());
1051 fprintf(f, "NumEvents() = %i\n", Schedule->NumEvents());
1053 // put the count at the end.
1056 thisChannel = Channels.GetByChannelID(tchid, true);
1059 fprintf(f, "Channel Number: %p %i\n", thisChannel, thisChannel->Number());
1063 fprintf(f, "thisChannel = NULL for tchid\n");
1066 #if VDRVERSNUM < 10300
1067 for (eventNumber = 0; eventNumber < Schedule->NumEvents(); eventNumber++)
1069 event = Schedule->GetEventNumber(eventNumber);
1070 fprintf(f, "Event %i tableid = %i timestring = %s endtimestring = %s\n", eventNumber, event->GetTableID(), event->GetTimeString(), event->GetEndTimeString());
1071 fprintf(f, "Event %i date = %s isfollowing = %i ispresent = %i\n", eventNumber, event->GetDate(), event->IsFollowing(), event->IsPresent());
1072 fprintf(f, "Event %i extendeddescription = %s\n", eventNumber, event->GetExtendedDescription());
1073 fprintf(f, "Event %i subtitle = %s title = %s\n", eventNumber, event->GetSubtitle(), event->GetTitle());
1074 fprintf(f, "Event %i eventid = %u duration = %li time = %lu channelnumber = %i\n", eventNumber, event->GetEventID(), event->GetDuration(), event->GetTime(), event->GetChannelNumber());
1075 fprintf(f, "Event %u dump:\n", eventNumber);
1080 // This whole section needs rewriting to walk the list.
1081 event = Schedule->Events()->First();
1083 event = Schedule->Events()->Next(event);
1088 fprintf(f, "\nDump from object:\n");
1090 fprintf(f, "\nEND\n");
1100 fprintf(f, "End of current Schedule\n\n\n");
1102 Schedule = (const cSchedule *)Schedules->Next(Schedule);
1116 const cEventInfo *GetPresentEvent(void) const;
1117 const cEventInfo *GetFollowingEvent(void) const;
1118 const cEventInfo *GetEvent(unsigned short uEventID, time_t tTime = 0) const;
1119 const cEventInfo *GetEventAround(time_t tTime) const;
1120 const cEventInfo *GetEventNumber(int n) const { return Events.Get(n); }
1123 const unsigned char GetTableID(void) const;
1124 const char *GetTimeString(void) const;
1125 const char *GetEndTimeString(void) const;
1126 const char *GetDate(void) const;
1127 bool IsFollowing(void) const;
1128 bool IsPresent(void) const;
1129 const char *GetExtendedDescription(void) const;
1130 const char *GetSubtitle(void) const;
1131 const char *GetTitle(void) const;
1132 unsigned short GetEventID(void) const;
1133 long GetDuration(void) const;
1134 time_t GetTime(void) const;
1135 tChannelID GetChannelID(void) const;
1136 int GetChannelNumber(void) const { return nChannelNumber; }
1137 void SetChannelNumber(int ChannelNumber) const { ((cEventInfo *)this)->nChannelNumber = ChannelNumber; } // doesn't modify the EIT data, so it's ok to make it 'const'
1138 void Dump(FILE *f, const char *Prefix = "") const;
1144 void MVPClient::test(int channelNumber)
1146 FILE* f = fopen("/tmp/test.txt", "w");
1148 cMutexLock MutexLock;
1149 const cSchedules *Schedules = cSIProcessor::Schedules(MutexLock);
1153 fprintf(f, "Schedules = NULL\n");
1158 fprintf(f, "Schedules dump:\n");
1159 // Schedules->Dump(f);
1161 const cSchedule *Schedule;
1162 cChannel *thisChannel;
1163 const cEventInfo *event;
1165 thisChannel = channelFromNumber(channelNumber);
1168 fprintf(f, "thisChannel = NULL\n");
1173 Schedule = Schedules->GetSchedule(thisChannel->GetChannelID());
1174 // Schedule = Schedules->GetSchedule();
1175 // Schedule = Schedules->First();
1178 fprintf(f, "First Schedule = NULL\n");
1183 fprintf(f, "NumEvents() = %i\n\n", Schedule->NumEvents());
1185 // For some channels VDR seems to pick a random point in time to
1186 // start dishing out events, but they are in order
1187 // at some point in the list the time snaps to the current event
1192 for (int eventNumber = 0; eventNumber < Schedule->NumEvents(); eventNumber++)
1194 event = Schedule->GetEventNumber(eventNumber);
1195 fprintf(f, "Event %i eventid = %u time = %lu duration = %li\n", eventNumber, event->GetEventID(), event->GetTime(), event->GetDuration());
1196 fprintf(f, "Event %i title = %s subtitle = %s\n", eventNumber, event->GetTitle(), event->GetSubtitle());
1197 fprintf(f, "Event %i extendeddescription = %s\n", eventNumber, event->GetExtendedDescription());
1201 fprintf(f, "\nEND\n");
1215 Schedules = the collection of all the Schedule objects
1216 Schedule = One schedule, contants all the events for a channel
1217 Event = One programme
1226 Subtitle (used for "Programmes resume at ...")
1229 IsPresent ? easy to work out tho. Oh it doesn't always work
1234 void MVPClient::test2()
1236 log->log("-", Log::DEBUG, "Timers List");
1238 for (int i = 0; i < Timers.Count(); i++)
1240 cTimer *timer = Timers.Get(i);
1241 //Reply(i < Timers.Count() - 1 ? -250 : 250, "%d %s", timer->Index() + 1, timer->ToText());
1242 log->log("-", Log::DEBUG, "i=%i count=%i index=%d", i, Timers.Count(), timer->Index() + 1);
1243 #if VDRVERSNUM < 10300
1244 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());
1246 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());
1248 log->log("-", Log::DEBUG, "channel=%i file=%s summary=%s", timer->Channel()->Number(), timer->File(), timer->Summary());
1249 log->log("-", Log::DEBUG, "");
1252 // asprintf(&buffer, "%d:%s:%s :%04d:%04d:%d:%d:%s:%s\n",
1253 // active, (UseChannelID ? Channel()->GetChannelID().ToString() : itoa(Channel()->Number())),
1254 // PrintDay(day, firstday), start, stop, priority, lifetime, file, summary ? summary : "");
1259 Active seems to be a bool - whether the timer should be done or not. If set to inactive it stays around after its time
1260 recording is a bool, 0 for not currently recording, 1 for currently recording
1261 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
1265 int MVPClient::processGetTimers(UCHAR* buffer, int length)
1267 UCHAR* sendBuffer = new UCHAR[50000]; // FIXME hope this is enough
1268 int count = 4; // leave space for the packet length
1270 const char* fileName;
1272 int numTimers = Timers.Count();
1274 *(ULONG*)&sendBuffer[count] = htonl(numTimers); count += 4;
1276 for (int i = 0; i < numTimers; i++)
1278 if (count > 49000) break;
1280 timer = Timers.Get(i);
1282 #if VDRVERSNUM < 10300
1283 *(ULONG*)&sendBuffer[count] = htonl(timer->Active()); count += 4;
1285 *(ULONG*)&sendBuffer[count] = htonl(timer->HasFlags(tfActive)); count += 4;
1287 *(ULONG*)&sendBuffer[count] = htonl(timer->Recording()); count += 4;
1288 *(ULONG*)&sendBuffer[count] = htonl(timer->Pending()); count += 4;
1289 *(ULONG*)&sendBuffer[count] = htonl(timer->Priority()); count += 4;
1290 *(ULONG*)&sendBuffer[count] = htonl(timer->Lifetime()); count += 4;
1291 *(ULONG*)&sendBuffer[count] = htonl(timer->Channel()->Number()); count += 4;
1292 *(ULONG*)&sendBuffer[count] = htonl(timer->StartTime()); count += 4;
1293 *(ULONG*)&sendBuffer[count] = htonl(timer->StopTime()); count += 4;
1295 fileName = timer->File();
1296 strcpy((char*)&sendBuffer[count], fileName);
1297 count += strlen(fileName) + 1;
1300 *(ULONG*)&sendBuffer[0] = htonl(count - 4); // -4 : take off the size field
1302 log->log("Client", Log::DEBUG, "recorded size as %u", ntohl(*(ULONG*)&sendBuffer[0]));
1304 tcp.sendPacket(sendBuffer, count);
1305 delete[] sendBuffer;
1306 log->log("Client", Log::DEBUG, "Written timers list");
1311 int MVPClient::processSetTimer(UCHAR* buffer, int length)
1313 char* timerString = new char[strlen((char*)buffer) + 1];
1314 strcpy(timerString, (char*)buffer);
1316 #if VDRVERSNUM < 10300
1318 // If this is VDR 1.2 the date part of the timer string must be reduced
1319 // to just DD rather than YYYY-MM-DD
1321 int s = 0; // source
1322 int d = 0; // destination
1324 while(c != 2) // copy up to date section, including the second ':'
1326 timerString[d] = buffer[s];
1327 if (buffer[s] == ':') c++;
1331 // now it has copied up to the date section
1333 while(c != 2) // waste YYYY-MM-
1335 if (buffer[s] == '-') c++;
1338 // now source is at the DD
1339 memcpy(&timerString[d], &buffer[s], length - s);
1341 timerString[d] = '\0';
1343 log->log("Client", Log::DEBUG, "Timer string after 1.2 conversion:");
1344 log->log("Client", Log::DEBUG, "%s", timerString);
1348 cTimer *timer = new cTimer;
1349 if (timer->Parse((char*)timerString))
1351 cTimer *t = Timers.GetTimer(timer);
1355 #if VDRVERSNUM < 10300
1358 Timers.SetModified();