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 MVPClient::MVPClient(int tsocket)
28 recordingManager = NULL;
29 log = Log::getInstance();
33 MVPClient::~MVPClient()
35 log->log("Client", Log::DEBUG, "MVP client destructor");
46 delete recordingManager;
48 recordingManager = NULL;
51 if (loggedIn) cleanConfig();
54 ULLONG MVPClient::ntohll(ULLONG a)
59 ULLONG MVPClient::htonll(ULLONG a)
61 #if BYTE_ORDER == BIG_ENDIAN
66 b = ((a << 56) & 0xFF00000000000000ULL)
67 | ((a << 40) & 0x00FF000000000000ULL)
68 | ((a << 24) & 0x0000FF0000000000ULL)
69 | ((a << 8) & 0x000000FF00000000ULL)
70 | ((a >> 8) & 0x00000000FF000000ULL)
71 | ((a >> 24) & 0x0000000000FF0000ULL)
72 | ((a >> 40) & 0x000000000000FF00ULL)
73 | ((a >> 56) & 0x00000000000000FFULL) ;
79 cChannel* MVPClient::channelFromNumber(ULONG channelNumber)
81 cChannel* channel = NULL;
83 for (channel = Channels.First(); channel; channel = Channels.Next(channel))
85 if (!channel->GroupSep())
87 log->log("Client", Log::DEBUG, "Looking for channel %lu::: number: %i name: '%s'", channelNumber, channel->Number(), channel->Name());
89 if (channel->Number() == (int)channelNumber)
91 int vpid = channel->Vpid();
92 #if VDRVERSNUM < 10300
93 int apid1 = channel->Apid1();
95 int apid1 = channel->Apid(0);
97 log->log("Client", Log::DEBUG, "Found channel number %lu, vpid = %i, apid1 = %i", channelNumber, vpid, apid1);
105 log->log("Client", Log::DEBUG, "Channel not found");
111 void MVPClient::writeResumeData()
113 config.setValueLongLong("ResumeData", (char*)rp->getCurrentRecording()->FileName(), rp->getLastPosition());
116 void MVPClient::sendULONG(ULONG ul)
119 *(ULONG*)&sendBuffer[0] = htonl(4);
120 *(ULONG*)&sendBuffer[4] = htonl(ul);
122 tcp.sendPacket(sendBuffer, 8);
123 log->log("Client", Log::DEBUG, "written ULONG %lu", ul);
126 void MVPClientStartThread(void* arg)
128 MVPClient* m = (MVPClient*)arg;
130 // Nothing external to this class has a reference to it
131 // This is the end of the thread.. so delete m
138 if (pthread_create(&runThread, NULL, (void*(*)(void*))MVPClientStartThread, (void *)this) == -1) return 0;
139 log->log("Client", Log::DEBUG, "MVPClient run success");
143 void MVPClient::run2()
148 pthread_sigmask(SIG_BLOCK, &sigset, NULL);
149 pthread_detach(runThread); // Detach
151 tcp.disableReadTimeout();
153 tcp.setSoKeepTime(3);
154 tcp.setNonBlocking();
164 log->log("Client", Log::DEBUG, "Waiting");
165 buffer = (UCHAR*)tcp.receivePacket();
166 log->log("Client", Log::DEBUG, "Received packet, length = %u", tcp.getDataLength());
169 log->log("Client", Log::DEBUG, "Detected connection closed");
173 packetLength = tcp.getDataLength() - 4;
174 opcode = ntohl(*(ULONG*)buffer);
177 if (!loggedIn && (opcode != 1))
186 result = processLogin(data, packetLength);
189 result = processGetRecordingsList(data, packetLength);
192 result = processDeleteRecording(data, packetLength);
195 result = processGetSummary(data, packetLength);
198 result = processGetChannelsList(data, packetLength);
201 result = processStartStreamingChannel(data, packetLength);
204 result = processGetBlock(data, packetLength);
207 result = processStopStreaming(data, packetLength);
210 result = processStartStreamingRecording(data, packetLength);
213 result = processGetChannelSchedule(data, packetLength);
216 result = processConfigSave(data, packetLength);
219 result = processConfigLoad(data, packetLength);
222 result = processReScanRecording(data, packetLength);
225 result = processGetTimers(data, packetLength);
234 int MVPClient::processLogin(UCHAR* buffer, int length)
236 if (length != 6) return 0;
240 const char* configDir = cPlugin::ConfigDirectory();
243 log->log("Client", Log::DEBUG, "No config dir!");
247 char configFileName[PATH_MAX];
248 snprintf(configFileName, PATH_MAX - strlen(configDir) - 17 - 20, "%s/vomp-%02X-%02X-%02X-%02X-%02X-%02X.conf", configDir, buffer[0], buffer[1], buffer[2], buffer[3], buffer[4], buffer[5]);
249 config.init(configFileName);
251 // Send the login reply
253 time_t timeNow = time(NULL);
254 struct tm* timeStruct = localtime(&timeNow);
255 int timeOffset = timeStruct->tm_gmtoff;
257 UCHAR sendBuffer[12];
258 *(ULONG*)&sendBuffer[0] = htonl(8);
259 *(ULONG*)&sendBuffer[4] = htonl(timeNow);
260 *(signed int*)&sendBuffer[8] = htonl(timeOffset);
262 tcp.sendPacket(sendBuffer, 12);
263 log->log("Client", Log::DEBUG, "written login reply");
269 int MVPClient::processGetRecordingsList(UCHAR* data, int length)
271 UCHAR* sendBuffer = new UCHAR[50000]; // hope this is enough
272 int count = 4; // leave space for the packet length
277 int Percent = VideoDiskSpace(&FreeMB);
278 int Total = (FreeMB / (100 - Percent)) * 100;
280 *(ULONG*)&sendBuffer[count] = htonl(Total);
281 count += sizeof(ULONG);
282 *(ULONG*)&sendBuffer[count] = htonl(FreeMB);
283 count += sizeof(ULONG);
284 *(ULONG*)&sendBuffer[count] = htonl(Percent);
285 count += sizeof(ULONG);
288 cRecordings Recordings;
291 for (cRecording *recording = Recordings.First(); recording; recording = Recordings.Next(recording))
293 if (count > 49000) break; // just how big is that hard disk?!
294 *(ULONG*)&sendBuffer[count] = htonl(recording->start);// + timeOffset);
297 point = (char*)recording->Name();
298 strcpy((char*)&sendBuffer[count], point);
299 count += strlen(point) + 1;
301 point = (char*)recording->FileName();
302 strcpy((char*)&sendBuffer[count], point);
303 count += strlen(point) + 1;
306 *(ULONG*)&sendBuffer[0] = htonl(count - 4); // -4 : take off the size field
308 log->log("Client", Log::DEBUG, "recorded size as %u", ntohl(*(ULONG*)&sendBuffer[0]));
310 tcp.sendPacket(sendBuffer, count);
312 log->log("Client", Log::DEBUG, "Written list");
317 int MVPClient::processDeleteRecording(UCHAR* data, int length)
319 // data is a pointer to the fileName string
321 cRecordings Recordings;
322 Recordings.Load(); // probably have to do this
324 cRecording* recording = Recordings.GetByName((char*)data);
326 log->log("Client", Log::DEBUG, "recording pointer %p", recording);
330 log->log("Client", Log::DEBUG, "deleting recording: %s", recording->Name());
342 int MVPClient::processGetSummary(UCHAR* data, int length)
344 // data is a pointer to the fileName string
346 cRecordings Recordings;
347 Recordings.Load(); // probably have to do this
349 cRecording *recording = Recordings.GetByName((char*)data);
351 log->log("Client", Log::DEBUG, "recording pointer %p", recording);
355 UCHAR* sendBuffer = new UCHAR[50000]; // hope this is enough
356 int count = 4; // leave space for the packet length
359 #if VDRVERSNUM < 10300
360 point = (char*)recording->Summary();
362 const cRecordingInfo *Info = recording->Info();
363 point = (char*)Info->ShortText();
364 log->log("Client", Log::DEBUG, "info pointer %p summary pointer %p", Info, point);
367 point = (char*)Info->Description();
368 log->log("Client", Log::DEBUG, "description pointer %p", point);
371 strcpy((char*)&sendBuffer[count], point);
372 count += strlen(point) + 1;
373 *(ULONG*)&sendBuffer[0] = htonl(count - 4); // -4 : take off the size field
375 log->log("Client", Log::DEBUG, "recorded size as %u", ntohl(*(ULONG*)&sendBuffer[0]));
377 tcp.sendPacket(sendBuffer, count);
379 log->log("Client", Log::DEBUG, "Written summary");
391 int MVPClient::processGetChannelsList(UCHAR* data, int length)
393 UCHAR* sendBuffer = new UCHAR[50000]; // FIXME hope this is enough
394 int count = 4; // leave space for the packet length
398 char* chanConfig = config.getValueString("General", "Channels");
400 if (chanConfig) allChans = strcasecmp(chanConfig, "FTA only");
402 for (cChannel *channel = Channels.First(); channel; channel = Channels.Next(channel))
404 #if VDRVERSNUM < 10300
405 if (!channel->GroupSep() && (!channel->Ca() || allChans))
407 if (!channel->GroupSep() && (!channel->Ca(0) || allChans))
410 log->log("Client", Log::DEBUG, "name: '%s'", channel->Name());
412 if (channel->Vpid()) type = 1;
413 #if VDRVERSNUM < 10300
416 else if (channel->Apid(0)) type = 2;
420 if (count > 49000) break;
421 *(ULONG*)&sendBuffer[count] = htonl(channel->Number());
424 *(ULONG*)&sendBuffer[count] = htonl(type);
427 point = (char*)channel->Name();
428 strcpy((char*)&sendBuffer[count], point);
429 count += strlen(point) + 1;
433 *(ULONG*)&sendBuffer[0] = htonl(count - 4); // -4 : take off the size field
435 log->log("Client", Log::DEBUG, "recorded size as %u", ntohl(*(ULONG*)&sendBuffer[0]));
437 tcp.sendPacket(sendBuffer, count);
439 log->log("Client", Log::DEBUG, "Written channels list");
444 int MVPClient::processStartStreamingChannel(UCHAR* data, int length)
446 log->log("Client", Log::DEBUG, "length = %i", length);
447 ULONG channelNumber = ntohl(*(ULONG*)data);
449 cChannel* channel = channelFromNumber(channelNumber);
456 // get the priority we should use
458 int priority = config.getValueLong("General", "Live priority", &fail);
461 log->log("Client", Log::DEBUG, "Config: Live TV priority: %i", priority);
465 log->log("Client", Log::DEBUG, "Config: Live TV priority config fail");
470 if (priority < 0) priority = 0;
471 if (priority > 99) priority = 99;
473 log->log("Client", Log::DEBUG, "Using live TV priority %i", priority);
474 lp = MVPReceiver::create(channel, priority);
494 int MVPClient::processStopStreaming(UCHAR* data, int length)
496 log->log("Client", Log::DEBUG, "STOP STREAMING RECEIVED");
507 delete recordingManager;
509 recordingManager = NULL;
516 int MVPClient::processGetBlock(UCHAR* data, int length)
520 log->log("Client", Log::DEBUG, "Get block called when no streaming happening!");
524 ULLONG position = ntohll(*(ULLONG*)data);
525 data += sizeof(ULLONG);
526 ULONG amount = ntohl(*(ULONG*)data);
528 log->log("Client", Log::DEBUG, "getblock pos = %llu length = %lu", position, amount);
530 UCHAR sendBuffer[amount + 4];
531 ULONG amountReceived = 0; // compiler moan.
534 log->log("Client", Log::DEBUG, "getting from live");
535 amountReceived = lp->getBlock(&sendBuffer[4], amount);
539 // vdr has possibly disconnected the receiver
540 log->log("Client", Log::DEBUG, "VDR has disconnected the live receiver");
547 log->log("Client", Log::DEBUG, "getting from recording");
548 amountReceived = rp->getBlock(&sendBuffer[4], position, amount);
551 *(ULONG*)&sendBuffer[0] = htonl(amountReceived);
552 tcp.sendPacket(sendBuffer, amountReceived + 4);
553 log->log("Client", Log::DEBUG, "written ok %lu", amountReceived);
558 int MVPClient::processStartStreamingRecording(UCHAR* data, int length)
560 // data is a pointer to the fileName string
562 recordingManager = new cRecordings;
563 recordingManager->Load();
565 cRecording* recording = recordingManager->GetByName((char*)data);
567 log->log("Client", Log::DEBUG, "recording pointer %p", recording);
571 rp = new RecPlayer(recording);
573 UCHAR sendBuffer[12];
574 *(ULONG*)&sendBuffer[0] = htonl(8);
575 *(ULLONG*)&sendBuffer[4] = htonll(rp->getTotalLength());
577 tcp.sendPacket(sendBuffer, 12);
578 log->log("Client", Log::DEBUG, "written totalLength");
582 delete recordingManager;
583 recordingManager = NULL;
588 int MVPClient::processReScanRecording(UCHAR* data, int length)
594 log->log("Client", Log::DEBUG, "Rescan recording called when no recording being played!");
599 retval = rp->getTotalLength();
602 UCHAR sendBuffer[12];
603 *(ULONG*)&sendBuffer[0] = htonl(8);
604 *(ULLONG*)&sendBuffer[4] = htonll(retval);
606 tcp.sendPacket(sendBuffer, 12);
607 log->log("Client", Log::DEBUG, "Rescan recording, wrote new length to client");
611 int MVPClient::processGetChannelSchedule(UCHAR* data, int length)
613 ULONG channelNumber = ntohl(*(ULLONG*)data);
615 ULONG startTime = ntohl(*(ULLONG*)data);
617 ULONG duration = ntohl(*(ULLONG*)data);
619 log->log("Client", Log::DEBUG, "get schedule called for channel %lu", channelNumber);
621 cChannel* channel = channelFromNumber(channelNumber);
625 *(ULONG*)&sendBuffer[0] = htonl(4);
626 *(ULONG*)&sendBuffer[4] = htonl(0);
627 tcp.sendPacket(sendBuffer, 8);
628 log->log("Client", Log::DEBUG, "written 0 because channel = NULL");
632 log->log("Client", Log::DEBUG, "Got channel");
634 #if VDRVERSNUM < 10300
635 cMutexLock MutexLock;
636 const cSchedules *Schedules = cSIProcessor::Schedules(MutexLock);
638 cSchedulesLock MutexLock;
639 const cSchedules *Schedules = cSchedules::Schedules(MutexLock);
644 *(ULONG*)&sendBuffer[0] = htonl(4);
645 *(ULONG*)&sendBuffer[4] = htonl(0);
646 tcp.sendPacket(sendBuffer, 8);
647 log->log("Client", Log::DEBUG, "written 0 because Schedule!s! = NULL");
651 log->log("Client", Log::DEBUG, "Got schedule!s! object");
653 const cSchedule *Schedule = Schedules->GetSchedule(channel->GetChannelID());
657 *(ULONG*)&sendBuffer[0] = htonl(4);
658 *(ULONG*)&sendBuffer[4] = htonl(0);
659 tcp.sendPacket(sendBuffer, 8);
660 log->log("Client", Log::DEBUG, "written 0 because Schedule = NULL");
664 log->log("Client", Log::DEBUG, "Got schedule object");
666 UCHAR* sendBuffer = (UCHAR*)malloc(100000);
667 ULONG sendBufferLength = 100000;
668 ULONG sendBufferUsed = sizeof(ULONG); // leave a hole for the entire packet length
672 // assign all the event info to temp vars then we know exactly what size they are
675 ULONG thisEventDuration;
676 const char* thisEventTitle;
677 const char* thisEventSubTitle;
678 const char* thisEventDescription;
680 ULONG constEventLength = sizeof(thisEventID) + sizeof(thisEventTime) + sizeof(thisEventDuration);
681 ULONG thisEventLength;
683 #if VDRVERSNUM < 10300
685 const cEventInfo *event;
686 for (int eventNumber = 0; eventNumber < Schedule->NumEvents(); eventNumber++)
688 event = Schedule->GetEventNumber(eventNumber);
690 thisEventID = event->GetEventID();
691 thisEventTime = event->GetTime();
692 thisEventDuration = event->GetDuration();
693 thisEventTitle = event->GetTitle();
694 thisEventSubTitle = event->GetSubtitle();
695 thisEventDescription = event->GetExtendedDescription();
699 for (const cEvent* event = Schedule->Events()->First(); event; event = Schedule->Events()->Next(event))
701 thisEventID = event->EventID();
702 thisEventTime = event->StartTime();
703 thisEventDuration = event->Duration();
704 thisEventTitle = event->Title();
705 thisEventSubTitle = NULL;
706 thisEventDescription = event->Description();
710 log->log("Client", Log::DEBUG, "Got an event object %p", event);
713 if ((thisEventTime + thisEventDuration) < (ULONG)time(NULL)) continue;
716 if ((thisEventTime + thisEventDuration) <= startTime) continue;
719 if (thisEventTime >= (startTime + duration)) continue;
721 if (!thisEventTitle) thisEventTitle = empty;
722 if (!thisEventSubTitle) thisEventSubTitle = empty;
723 if (!thisEventDescription) thisEventDescription = empty;
725 thisEventLength = constEventLength + strlen(thisEventTitle) + 1 + strlen(thisEventSubTitle) + 1 + strlen(thisEventDescription) + 1;
727 log->log("Client", Log::DEBUG, "Done s1");
729 // now extend the buffer if necessary
730 if ((sendBufferUsed + thisEventLength) > sendBufferLength)
732 log->log("Client", Log::DEBUG, "Extending buffer");
733 sendBufferLength += 100000;
734 UCHAR* temp = (UCHAR*)realloc(sendBuffer, sendBufferLength);
738 UCHAR sendBuffer2[8];
739 *(ULONG*)&sendBuffer2[0] = htonl(4);
740 *(ULONG*)&sendBuffer2[4] = htonl(0);
741 tcp.sendPacket(sendBuffer2, 8);
742 log->log("Client", Log::DEBUG, "written 0 because failed to realloc packet");
748 log->log("Client", Log::DEBUG, "Done s2");
750 *(ULONG*)&sendBuffer[sendBufferUsed] = htonl(thisEventID); sendBufferUsed += sizeof(ULONG);
751 *(ULONG*)&sendBuffer[sendBufferUsed] = htonl(thisEventTime); sendBufferUsed += sizeof(ULONG);
752 *(ULONG*)&sendBuffer[sendBufferUsed] = htonl(thisEventDuration); sendBufferUsed += sizeof(ULONG);
754 strcpy((char*)&sendBuffer[sendBufferUsed], thisEventTitle); sendBufferUsed += strlen(thisEventTitle) + 1;
755 strcpy((char*)&sendBuffer[sendBufferUsed], thisEventSubTitle); sendBufferUsed += strlen(thisEventSubTitle) + 1;
756 strcpy((char*)&sendBuffer[sendBufferUsed], thisEventDescription); sendBufferUsed += strlen(thisEventDescription) + 1;
758 log->log("Client", Log::DEBUG, "Done s3 %lu", sendBufferUsed);
761 log->log("Client", Log::DEBUG, "Got all event data");
763 // Write the length into the first 4 bytes. It's sendBufferUsed - 4 because of the hole!
764 *(ULONG*)&sendBuffer[0] = htonl(sendBufferUsed - sizeof(ULONG));
766 tcp.sendPacket(sendBuffer, sendBufferUsed);
767 log->log("Client", Log::DEBUG, "written %lu schedules packet", sendBufferUsed);
774 int MVPClient::processConfigSave(UCHAR* buffer, int length)
776 char* section = (char*)buffer;
780 for (int k = 0; k < length; k++)
782 if (buffer[k] == '\0')
786 key = (char*)&buffer[k+1];
790 value = (char*)&buffer[k+1];
796 // if the last string (value) doesnt have null terminator, give up
797 if (buffer[length - 1] != '\0') return 0;
799 log->log("Client", Log::DEBUG, "Config save: %s %s %s", section, key, value);
800 if (config.setValueString(section, key, value))
812 int MVPClient::processConfigLoad(UCHAR* buffer, int length)
814 char* section = (char*)buffer;
817 for (int k = 0; k < length; k++)
819 if (buffer[k] == '\0')
821 key = (char*)&buffer[k+1];
826 char* value = config.getValueString(section, key);
830 UCHAR sendBuffer[4 + strlen(value) + 1];
831 *(ULONG*)&sendBuffer[0] = htonl(strlen(value) + 1);
832 strcpy((char*)&sendBuffer[4], value);
833 tcp.sendPacket(sendBuffer, 4 + strlen(value) + 1);
835 log->log("Client", Log::DEBUG, "Written config load packet");
841 *(ULONG*)&sendBuffer[0] = htonl(4);
842 *(ULONG*)&sendBuffer[4] = htonl(0);
843 tcp.sendPacket(sendBuffer, 8);
845 log->log("Client", Log::DEBUG, "Written config load failed packet");
851 void MVPClient::cleanConfig()
853 log->log("Client", Log::DEBUG, "Clean config");
855 cRecordings Recordings;
860 char* resumes = config.getSectionKeyNames("ResumeData", numReturns, length);
861 char* position = resumes;
862 for(int k = 0; k < numReturns; k++)
864 log->log("Client", Log::DEBUG, "EXAMINING: %i %i %p %s", k, numReturns, position, position);
866 cRecording* recording = Recordings.GetByName(position);
869 // doesn't exist anymore
870 log->log("Client", Log::DEBUG, "Found a recording that doesn't exist anymore");
871 config.deleteValue("ResumeData", position);
875 log->log("Client", Log::DEBUG, "This recording still exists");
878 position += strlen(position) + 1;
890 event = Schedule->GetPresentEvent();
892 fprintf(f, "\n\nCurrent event\n\n");
894 fprintf(f, "Event %i eventid = %u time = %lu duration = %li\n", 0, event->GetEventID(), event->GetTime(), event->GetDuration());
895 fprintf(f, "Event %i title = %s subtitle = %s\n", 0, event->GetTitle(), event->GetSubtitle());
896 fprintf(f, "Event %i extendeddescription = %s\n", 0, event->GetExtendedDescription());
897 fprintf(f, "Event %i isFollowing = %i, isPresent = %i\n", 0, event->IsFollowing(), event->IsPresent());
899 event = Schedule->GetFollowingEvent();
901 fprintf(f, "\n\nFollowing event\n\n");
903 fprintf(f, "Event %i eventid = %u time = %lu duration = %li\n", 0, event->GetEventID(), event->GetTime(), event->GetDuration());
904 fprintf(f, "Event %i title = %s subtitle = %s\n", 0, event->GetTitle(), event->GetSubtitle());
905 fprintf(f, "Event %i extendeddescription = %s\n", 0, event->GetExtendedDescription());
906 fprintf(f, "Event %i isFollowing = %i, isPresent = %i\n", 0, event->IsFollowing(), event->IsPresent());
912 fprintf(f, "Event %i eventid = %u time = %lu duration = %li\n", eventNumber, event->GetEventID(), event->GetTime(), event->GetDuration());
913 fprintf(f, "Event %i title = %s subtitle = %s\n", eventNumber, event->GetTitle(), event->GetSubtitle());
914 fprintf(f, "Event %i extendeddescription = %s\n", eventNumber, event->GetExtendedDescription());
915 fprintf(f, "Event %i isFollowing = %i, isPresent = %i\n", eventNumber, event->IsFollowing(), event->IsPresent());
923 void MVPClient::test2()
925 FILE* f = fopen("/tmp/s.txt", "w");
927 #if VDRVERSNUM < 10300
928 cMutexLock MutexLock;
929 const cSchedules *Schedules = cSIProcessor::Schedules(MutexLock);
931 cSchedulesLock MutexLock;
932 const cSchedules *Schedules = cSchedules::Schedules(MutexLock);
937 fprintf(f, "Schedules = NULL\n");
942 fprintf(f, "Schedules dump:\n");
946 const cSchedule *Schedule;
947 int scheduleNumber = 0;
950 cChannel *thisChannel;
952 #if VDRVERSNUM < 10300
953 const cEventInfo *event;
959 // Schedule = Schedules->GetSchedule(channel->GetChannelID());
960 // Schedule = Schedules->GetSchedule();
961 Schedule = Schedules->First();
964 fprintf(f, "First Schedule = NULL\n");
971 fprintf(f, "Schedule #%i\n", scheduleNumber);
972 fprintf(f, "-------------\n\n");
974 #if VDRVERSNUM < 10300
975 tchid = Schedule->GetChannelID();
977 tchid = Schedule->ChannelID();
980 #if VDRVERSNUM < 10300
981 fprintf(f, "ChannelID.ToString() = %s\n", tchid.ToString());
982 fprintf(f, "NumEvents() = %i\n", Schedule->NumEvents());
984 // put the count at the end.
987 thisChannel = Channels.GetByChannelID(tchid, true);
990 fprintf(f, "Channel Number: %p %i\n", thisChannel, thisChannel->Number());
994 fprintf(f, "thisChannel = NULL for tchid\n");
997 #if VDRVERSNUM < 10300
998 for (eventNumber = 0; eventNumber < Schedule->NumEvents(); eventNumber++)
1000 event = Schedule->GetEventNumber(eventNumber);
1001 fprintf(f, "Event %i tableid = %i timestring = %s endtimestring = %s\n", eventNumber, event->GetTableID(), event->GetTimeString(), event->GetEndTimeString());
1002 fprintf(f, "Event %i date = %s isfollowing = %i ispresent = %i\n", eventNumber, event->GetDate(), event->IsFollowing(), event->IsPresent());
1003 fprintf(f, "Event %i extendeddescription = %s\n", eventNumber, event->GetExtendedDescription());
1004 fprintf(f, "Event %i subtitle = %s title = %s\n", eventNumber, event->GetSubtitle(), event->GetTitle());
1005 fprintf(f, "Event %i eventid = %u duration = %li time = %lu channelnumber = %i\n", eventNumber, event->GetEventID(), event->GetDuration(), event->GetTime(), event->GetChannelNumber());
1006 fprintf(f, "Event %u dump:\n", eventNumber);
1011 // This whole section needs rewriting to walk the list.
1012 event = Schedule->Events()->First();
1014 event = Schedule->Events()->Next(event);
1019 fprintf(f, "\nDump from object:\n");
1021 fprintf(f, "\nEND\n");
1031 fprintf(f, "End of current Schedule\n\n\n");
1033 Schedule = (const cSchedule *)Schedules->Next(Schedule);
1047 const cEventInfo *GetPresentEvent(void) const;
1048 const cEventInfo *GetFollowingEvent(void) const;
1049 const cEventInfo *GetEvent(unsigned short uEventID, time_t tTime = 0) const;
1050 const cEventInfo *GetEventAround(time_t tTime) const;
1051 const cEventInfo *GetEventNumber(int n) const { return Events.Get(n); }
1054 const unsigned char GetTableID(void) const;
1055 const char *GetTimeString(void) const;
1056 const char *GetEndTimeString(void) const;
1057 const char *GetDate(void) const;
1058 bool IsFollowing(void) const;
1059 bool IsPresent(void) const;
1060 const char *GetExtendedDescription(void) const;
1061 const char *GetSubtitle(void) const;
1062 const char *GetTitle(void) const;
1063 unsigned short GetEventID(void) const;
1064 long GetDuration(void) const;
1065 time_t GetTime(void) const;
1066 tChannelID GetChannelID(void) const;
1067 int GetChannelNumber(void) const { return nChannelNumber; }
1068 void SetChannelNumber(int ChannelNumber) const { ((cEventInfo *)this)->nChannelNumber = ChannelNumber; } // doesn't modify the EIT data, so it's ok to make it 'const'
1069 void Dump(FILE *f, const char *Prefix = "") const;
1075 void MVPClient::test(int channelNumber)
1077 FILE* f = fopen("/tmp/test.txt", "w");
1079 cMutexLock MutexLock;
1080 const cSchedules *Schedules = cSIProcessor::Schedules(MutexLock);
1084 fprintf(f, "Schedules = NULL\n");
1089 fprintf(f, "Schedules dump:\n");
1090 // Schedules->Dump(f);
1092 const cSchedule *Schedule;
1093 cChannel *thisChannel;
1094 const cEventInfo *event;
1096 thisChannel = channelFromNumber(channelNumber);
1099 fprintf(f, "thisChannel = NULL\n");
1104 Schedule = Schedules->GetSchedule(thisChannel->GetChannelID());
1105 // Schedule = Schedules->GetSchedule();
1106 // Schedule = Schedules->First();
1109 fprintf(f, "First Schedule = NULL\n");
1114 fprintf(f, "NumEvents() = %i\n\n", Schedule->NumEvents());
1116 // For some channels VDR seems to pick a random point in time to
1117 // start dishing out events, but they are in order
1118 // at some point in the list the time snaps to the current event
1123 for (int eventNumber = 0; eventNumber < Schedule->NumEvents(); eventNumber++)
1125 event = Schedule->GetEventNumber(eventNumber);
1126 fprintf(f, "Event %i eventid = %u time = %lu duration = %li\n", eventNumber, event->GetEventID(), event->GetTime(), event->GetDuration());
1127 fprintf(f, "Event %i title = %s subtitle = %s\n", eventNumber, event->GetTitle(), event->GetSubtitle());
1128 fprintf(f, "Event %i extendeddescription = %s\n", eventNumber, event->GetExtendedDescription());
1132 fprintf(f, "\nEND\n");
1146 Schedules = the collection of all the Schedule objects
1147 Schedule = One schedule, contants all the events for a channel
1148 Event = One programme
1157 Subtitle (used for "Programmes resume at ...")
1160 IsPresent ? easy to work out tho. Oh it doesn't always work
1165 void MVPClient::test2()
1167 log->log("-", Log::DEBUG, "Timers List");
1169 for (int i = 0; i < Timers.Count(); i++)
1171 cTimer *timer = Timers.Get(i);
1172 //Reply(i < Timers.Count() - 1 ? -250 : 250, "%d %s", timer->Index() + 1, timer->ToText());
1173 log->log("-", Log::DEBUG, "i=%i count=%i index=%d", i, Timers.Count(), timer->Index() + 1);
1174 #if VDRVERSNUM < 10300
1175 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());
1177 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());
1179 log->log("-", Log::DEBUG, "channel=%i file=%s summary=%s", timer->Channel()->Number(), timer->File(), timer->Summary());
1180 log->log("-", Log::DEBUG, "");
1183 // asprintf(&buffer, "%d:%s:%s :%04d:%04d:%d:%d:%s:%s\n",
1184 // active, (UseChannelID ? Channel()->GetChannelID().ToString() : itoa(Channel()->Number())),
1185 // PrintDay(day, firstday), start, stop, priority, lifetime, file, summary ? summary : "");
1190 Active seems to be a bool - whether the timer should be done or not. If set to inactive it stays around after its time
1191 recording is a bool, 0 for not currently recording, 1 for currently recording
1192 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
1196 int MVPClient::processGetTimers(UCHAR* buffer, int length)
1198 UCHAR* sendBuffer = new UCHAR[50000]; // FIXME hope this is enough
1199 int count = 4; // leave space for the packet length
1203 int numTimers = Timers.Count();
1205 // *(ULONG*)&sendBuffer[count] = htonl(numTimers); count += 4;
1207 for (int i = 0; i < numTimers; i++)
1209 if (count > 49000) break;
1211 timer = Timers.Get(i);
1213 #if VDRVERSNUM < 10300
1214 *(ULONG*)&sendBuffer[count] = htonl(timer->Active()); count += 4;
1216 *(ULONG*)&sendBuffer[count] = htonl(timer->HasFlags(tfActive)); count += 4;
1218 *(ULONG*)&sendBuffer[count] = htonl(timer->Recording()); count += 4;
1219 *(ULONG*)&sendBuffer[count] = htonl(timer->Pending()); count += 4;
1220 *(ULONG*)&sendBuffer[count] = htonl(timer->Priority()); count += 4;
1221 *(ULONG*)&sendBuffer[count] = htonl(timer->Lifetime()); count += 4;
1222 *(ULONG*)&sendBuffer[count] = htonl(timer->Channel()->Number()); count += 4;
1223 *(ULONG*)&sendBuffer[count] = htonl(timer->StartTime()); count += 4;
1224 *(ULONG*)&sendBuffer[count] = htonl(timer->StopTime()); count += 4;
1226 string = timer->File();
1227 strcpy((char*)&sendBuffer[count], string);
1228 count += strlen(string) + 1;
1230 string = timer->Summary();
1233 strcpy((char*)&sendBuffer[count], string);
1234 count += strlen(string) + 1;
1238 sendBuffer[count++] = 0;
1242 *(ULONG*)&sendBuffer[0] = htonl(count - 4); // -4 : take off the size field
1244 log->log("Client", Log::DEBUG, "recorded size as %u", ntohl(*(ULONG*)&sendBuffer[0]));
1246 tcp.sendPacket(sendBuffer, count);
1247 delete[] sendBuffer;
1248 log->log("Client", Log::DEBUG, "Written timers list");