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();
31 // Get IP address of client for config module
34 struct sockaddr_in peer;
35 socklen_t salen = sizeof(struct sockaddr);
36 if(getpeername(tsocket, (struct sockaddr*)&peer, &salen) == 0)
38 strcpy(ipa, inet_ntoa(peer.sin_addr));
43 log->log("Client", Log::DEBUG, "Cannot get peer name!");
46 const char* configDir = cPlugin::ConfigDirectory();
49 log->log("Client", Log::DEBUG, "No config dir!");
53 char configFileName[PATH_MAX];
54 snprintf(configFileName, PATH_MAX - strlen(configDir) - strlen(ipa) - 20, "%s/vomp-%s.conf", configDir, ipa);
55 config.init(configFileName);
57 log->log("Client", Log::DEBUG, "Config file name: %s", configFileName);
64 MVPClient::~MVPClient()
66 log->log("Client", Log::DEBUG, "MVP client destructor");
77 delete recordingManager;
79 recordingManager = NULL;
85 cChannel* MVPClient::channelFromNumber(ULONG channelNumber)
87 cChannel* channel = NULL;
89 for (channel = Channels.First(); channel; channel = Channels.Next(channel))
91 if (!channel->GroupSep())
93 log->log("Client", Log::DEBUG, "Looking for channel %lu::: number: %i name: '%s'", channelNumber, channel->Number(), channel->Name());
95 if (channel->Number() == (int)channelNumber)
97 int vpid = channel->Vpid();
98 #if VDRVERSNUM < 10300
99 int apid1 = channel->Apid1();
101 int apid1 = channel->Apid(0);
103 log->log("Client", Log::DEBUG, "Found channel number %lu, vpid = %i, apid1 = %i", channelNumber, vpid, apid1);
111 log->log("Client", Log::DEBUG, "Channel not found");
118 void MVPClient::writeResumeData()
120 config.setValueLongLong("ResumeData", (char*)rp->getCurrentRecording()->FileName(), rp->getLastPosition());
123 void MVPClient::sendULONG(ULONG ul)
126 *(ULONG*)&sendBuffer[0] = htonl(4);
127 *(ULONG*)&sendBuffer[4] = htonl(ul);
129 tcp.sendPacket(sendBuffer, 8);
130 log->log("Client", Log::DEBUG, "written ULONG %lu", ul);
133 void MVPClientStartThread(void* arg)
135 MVPClient* m = (MVPClient*)arg;
137 // Nothing external to this class has a reference to it
138 // This is the end of the thread.. so delete m
145 if (pthread_create(&runThread, NULL, (void*(*)(void*))MVPClientStartThread, (void *)this) == -1) return 0;
146 log->log("Client", Log::DEBUG, "MVPClient run success");
150 void MVPClient::run2()
155 pthread_sigmask(SIG_BLOCK, &sigset, NULL);
156 pthread_detach(runThread); // Detach
158 tcp.disableReadTimeout();
160 tcp.setSoKeepTime(3);
161 tcp.setNonBlocking();
170 log->log("Client", Log::DEBUG, "Waiting");
171 buffer = (UCHAR*)tcp.receivePacket();
172 log->log("Client", Log::DEBUG, "Received packet, length = %u", tcp.getDataLength());
175 log->log("Client", Log::DEBUG, "Detected connection closed");
179 packetLength = tcp.getDataLength() - 4;
180 opcode = ntohl(*(ULONG*)buffer);
187 processLogin(data, packetLength);
190 processGetRecordingsList(data, packetLength);
193 processDeleteRecording(data, packetLength);
196 processGetSummary(data, packetLength);
199 processGetChannelsList(data, packetLength);
202 processStartStreamingChannel(data, packetLength);
205 processGetBlock(data, packetLength);
208 processStopStreaming(data, packetLength);
211 processStartStreamingRecording(data, packetLength);
214 processGetChannelSchedule(data, packetLength);
217 processConfigSave(data, packetLength);
220 processConfigLoad(data, packetLength);
223 processReScanRecording(data, packetLength);
231 void MVPClient::processLogin(UCHAR* buffer, int length)
233 time_t timeNow = time(NULL);
234 struct tm* timeStruct = localtime(&timeNow);
235 int timeOffset = timeStruct->tm_gmtoff;
237 UCHAR sendBuffer[12];
238 *(ULONG*)&sendBuffer[0] = htonl(8);
239 *(ULONG*)&sendBuffer[4] = htonl(timeNow);
240 *(signed int*)&sendBuffer[8] = htonl(timeOffset);
242 tcp.sendPacket(sendBuffer, 12);
243 log->log("Client", Log::DEBUG, "written login reply");
246 void MVPClient::processGetRecordingsList(UCHAR* data, int length)
248 UCHAR* sendBuffer = new UCHAR[50000]; // hope this is enough
249 int count = 4; // leave space for the packet length
254 int Percent = VideoDiskSpace(&FreeMB);
255 int Total = (FreeMB / (100 - Percent)) * 100;
257 *(ULONG*)&sendBuffer[count] = htonl(Total);
258 count += sizeof(ULONG);
259 *(ULONG*)&sendBuffer[count] = htonl(FreeMB);
260 count += sizeof(ULONG);
261 *(ULONG*)&sendBuffer[count] = htonl(Percent);
262 count += sizeof(ULONG);
265 cRecordings Recordings;
268 for (cRecording *recording = Recordings.First(); recording; recording = Recordings.Next(recording))
270 if (count > 49000) break; // just how big is that hard disk?!
271 *(ULONG*)&sendBuffer[count] = htonl(recording->start);// + timeOffset);
274 point = (char*)recording->Name();
275 strcpy((char*)&sendBuffer[count], point);
276 count += strlen(point) + 1;
278 point = (char*)recording->FileName();
279 strcpy((char*)&sendBuffer[count], point);
280 count += strlen(point) + 1;
283 *(ULONG*)&sendBuffer[0] = htonl(count - 4); // -4 : take off the size field
285 log->log("Client", Log::DEBUG, "recorded size as %u", ntohl(*(ULONG*)&sendBuffer[0]));
287 tcp.sendPacket(sendBuffer, count);
289 log->log("Client", Log::DEBUG, "Written list");
292 void MVPClient::processDeleteRecording(UCHAR* data, int length)
294 // data is a pointer to the fileName string
296 cRecordings Recordings;
297 Recordings.Load(); // probably have to do this
299 cRecording* recording = Recordings.GetByName((char*)data);
301 log->log("Client", Log::DEBUG, "recording pointer %p", recording);
305 log->log("Client", Log::DEBUG, "deleting recording: %s", recording->Name());
315 void MVPClient::processGetSummary(UCHAR* data, int length)
317 // data is a pointer to the fileName string
319 cRecordings Recordings;
320 Recordings.Load(); // probably have to do this
322 cRecording *recording = Recordings.GetByName((char*)data);
324 log->log("Client", Log::DEBUG, "recording pointer %p", recording);
328 UCHAR* sendBuffer = new UCHAR[50000]; // hope this is enough
329 int count = 4; // leave space for the packet length
332 #if VDRVERSNUM < 10300
333 point = (char*)recording->Summary();
335 const cRecordingInfo *Info = recording->Info();
336 point = (char*)Info->ShortText();
337 log->log("Client", Log::DEBUG, "info pointer %p summary pointer %p", Info, point);
340 point = (char*)Info->Description();
341 log->log("Client", Log::DEBUG, "description pointer %p", point);
344 strcpy((char*)&sendBuffer[count], point);
345 count += strlen(point) + 1;
346 *(ULONG*)&sendBuffer[0] = htonl(count - 4); // -4 : take off the size field
348 log->log("Client", Log::DEBUG, "recorded size as %u", ntohl(*(ULONG*)&sendBuffer[0]));
350 tcp.sendPacket(sendBuffer, count);
352 log->log("Client", Log::DEBUG, "Written summary");
362 void MVPClient::processGetChannelsList(UCHAR* data, int length)
364 UCHAR* sendBuffer = new UCHAR[50000]; // FIXME hope this is enough
365 int count = 4; // leave space for the packet length
369 for (cChannel *channel = Channels.First(); channel; channel = Channels.Next(channel))
372 // Re-enable later with some client side option
373 //#if VDRVERSNUM < 10300
374 // if (!channel->GroupSep() && !channel->Ca())
376 // if (!channel->GroupSep() && !channel->Ca(0))
380 if (!channel->GroupSep())
382 log->log("Client", Log::DEBUG, "name: '%s'", channel->Name());
384 if (channel->Vpid()) type = 1;
385 #if VDRVERSNUM < 10300
388 else if (channel->Apid(0)) type = 2;
392 if (count > 49000) break;
393 *(ULONG*)&sendBuffer[count] = htonl(channel->Number());
396 *(ULONG*)&sendBuffer[count] = htonl(type);
399 point = (char*)channel->Name();
400 strcpy((char*)&sendBuffer[count], point);
401 count += strlen(point) + 1;
405 *(ULONG*)&sendBuffer[0] = htonl(count - 4); // -4 : take off the size field
407 log->log("Client", Log::DEBUG, "recorded size as %u", ntohl(*(ULONG*)&sendBuffer[0]));
409 tcp.sendPacket(sendBuffer, count);
411 log->log("Client", Log::DEBUG, "Written channels list");
414 void MVPClient::processStartStreamingChannel(UCHAR* data, int length)
416 log->log("Client", Log::DEBUG, "length = %i", length);
417 ULONG channelNumber = ntohl(*(ULONG*)data);
419 cChannel* channel = channelFromNumber(channelNumber);
426 lp = MVPReceiver::create(channel);
445 void MVPClient::processStopStreaming(UCHAR* data, int length)
447 log->log("Client", Log::DEBUG, "STOP STREAMING RECEIVED");
458 delete recordingManager;
460 recordingManager = NULL;
466 void MVPClient::processGetBlock(UCHAR* data, int length)
470 log->log("Client", Log::DEBUG, "Get block called when no streaming happening!");
474 ULLONG position = ntohll(*(ULLONG*)data);
475 data += sizeof(ULLONG);
476 ULONG amount = ntohl(*(ULONG*)data);
478 log->log("Client", Log::DEBUG, "getblock pos = %llu length = %lu", position, amount);
480 UCHAR sendBuffer[amount + 4];
481 ULONG amountReceived = 0; // compiler moan.
484 log->log("Client", Log::DEBUG, "getting from live");
485 amountReceived = lp->getBlock(&sendBuffer[4], amount);
489 // vdr has possibly disconnected the receiver
490 log->log("Client", Log::DEBUG, "VDR has disconnected the live receiver");
497 log->log("Client", Log::DEBUG, "getting from recording");
498 amountReceived = rp->getBlock(&sendBuffer[4], position, amount);
501 *(ULONG*)&sendBuffer[0] = htonl(amountReceived);
502 tcp.sendPacket(sendBuffer, amountReceived + 4);
503 log->log("Client", Log::DEBUG, "written ok %lu", amountReceived);
506 void MVPClient::processStartStreamingRecording(UCHAR* data, int length)
508 // data is a pointer to the fileName string
510 recordingManager = new cRecordings;
511 recordingManager->Load();
513 cRecording* recording = recordingManager->GetByName((char*)data);
515 log->log("Client", Log::DEBUG, "recording pointer %p", recording);
519 rp = new RecPlayer(recording);
521 UCHAR sendBuffer[12];
522 *(ULONG*)&sendBuffer[0] = htonl(8);
523 *(ULLONG*)&sendBuffer[4] = htonll(rp->getTotalLength());
525 tcp.sendPacket(sendBuffer, 12);
526 log->log("Client", Log::DEBUG, "written totalLength");
530 delete recordingManager;
531 recordingManager = NULL;
535 void MVPClient::processReScanRecording(UCHAR* data, int length)
541 log->log("Client", Log::DEBUG, "Rescan recording called when no recording being played!");
546 retval = rp->getTotalLength();
549 UCHAR sendBuffer[12];
550 *(ULONG*)&sendBuffer[0] = htonl(8);
551 *(ULLONG*)&sendBuffer[4] = htonll(retval);
553 tcp.sendPacket(sendBuffer, 12);
554 log->log("Client", Log::DEBUG, "Rescan recording, wrote new length to client");
557 void MVPClient::processGetChannelSchedule(UCHAR* data, int length)
559 ULONG channelNumber = ntohl(*(ULLONG*)data);
560 log->log("Client", Log::DEBUG, "get schedule called for channel %lu", channelNumber);
562 cChannel* channel = channelFromNumber(channelNumber);
566 *(ULONG*)&sendBuffer[0] = htonl(4);
567 *(ULONG*)&sendBuffer[4] = htonl(0);
568 tcp.sendPacket(sendBuffer, 8);
569 log->log("Client", Log::DEBUG, "written 0 because channel = NULL");
573 log->log("Client", Log::DEBUG, "Got channel");
575 #if VDRVERSNUM < 10300
576 cMutexLock MutexLock;
577 const cSchedules *Schedules = cSIProcessor::Schedules(MutexLock);
579 cSchedulesLock MutexLock;
580 const cSchedules *Schedules = cSchedules::Schedules(MutexLock);
585 *(ULONG*)&sendBuffer[0] = htonl(4);
586 *(ULONG*)&sendBuffer[4] = htonl(0);
587 tcp.sendPacket(sendBuffer, 8);
588 log->log("Client", Log::DEBUG, "written 0 because Schedule!s! = NULL");
592 log->log("Client", Log::DEBUG, "Got schedule!s! object");
594 const cSchedule *Schedule = Schedules->GetSchedule(channel->GetChannelID());
598 *(ULONG*)&sendBuffer[0] = htonl(4);
599 *(ULONG*)&sendBuffer[4] = htonl(0);
600 tcp.sendPacket(sendBuffer, 8);
601 log->log("Client", Log::DEBUG, "written 0 because Schedule = NULL");
605 log->log("Client", Log::DEBUG, "Got schedule object");
607 UCHAR* sendBuffer = (UCHAR*)malloc(100000);
608 ULONG sendBufferLength = 100000;
609 ULONG sendBufferUsed = sizeof(ULONG); // leave a hole for the entire packet length
613 // assign all the event info to temp vars then we know exactly what size they are
616 ULONG thisEventDuration;
617 const char* thisEventTitle;
618 const char* thisEventSubTitle;
619 const char* thisEventDescription;
621 ULONG constEventLength = sizeof(thisEventID) + sizeof(thisEventTime) + sizeof(thisEventDuration);
622 ULONG thisEventLength;
624 #if VDRVERSNUM < 10300
626 const cEventInfo *event;
627 for (int eventNumber = 0; eventNumber < Schedule->NumEvents(); eventNumber++)
629 event = Schedule->GetEventNumber(eventNumber);
631 thisEventID = event->GetEventID();
632 thisEventTime = event->GetTime();
633 thisEventDuration = event->GetDuration();
634 thisEventTitle = event->GetTitle();
635 thisEventSubTitle = event->GetSubtitle();
636 thisEventDescription = event->GetExtendedDescription();
640 for (const cEvent* event = Schedule->Events()->First(); event; event = Schedule->Events()->Next(event))
642 thisEventID = event->EventID();
643 thisEventTime = event->StartTime();
644 thisEventDuration = event->Duration();
645 thisEventTitle = event->Title();
646 thisEventSubTitle = NULL;
647 thisEventDescription = event->Description();
651 log->log("Client", Log::DEBUG, "Got an event object %p", event);
654 if ((thisEventTime + thisEventDuration) < (ULONG)time(NULL)) continue;
657 if (thisEventTime > ((ULONG)time(NULL) + 86400)) continue;
659 if (!thisEventTitle) thisEventTitle = empty;
660 if (!thisEventSubTitle) thisEventSubTitle = empty;
661 if (!thisEventDescription) thisEventDescription = empty;
663 thisEventLength = constEventLength + strlen(thisEventTitle) + 1 + strlen(thisEventSubTitle) + 1 + strlen(thisEventDescription) + 1;
665 log->log("Client", Log::DEBUG, "Done s1");
667 // now extend the buffer if necessary
668 if ((sendBufferUsed + thisEventLength) > sendBufferLength)
670 log->log("Client", Log::DEBUG, "Extending buffer");
671 sendBufferLength += 100000;
672 UCHAR* temp = (UCHAR*)realloc(sendBuffer, sendBufferLength);
676 UCHAR sendBuffer2[8];
677 *(ULONG*)&sendBuffer2[0] = htonl(4);
678 *(ULONG*)&sendBuffer2[4] = htonl(0);
679 tcp.sendPacket(sendBuffer2, 8);
680 log->log("Client", Log::DEBUG, "written 0 because failed to realloc packet");
686 log->log("Client", Log::DEBUG, "Done s2");
688 *(ULONG*)&sendBuffer[sendBufferUsed] = htonl(thisEventID); sendBufferUsed += sizeof(ULONG);
689 *(ULONG*)&sendBuffer[sendBufferUsed] = htonl(thisEventTime); sendBufferUsed += sizeof(ULONG);
690 *(ULONG*)&sendBuffer[sendBufferUsed] = htonl(thisEventDuration); sendBufferUsed += sizeof(ULONG);
692 strcpy((char*)&sendBuffer[sendBufferUsed], thisEventTitle); sendBufferUsed += strlen(thisEventTitle) + 1;
693 strcpy((char*)&sendBuffer[sendBufferUsed], thisEventSubTitle); sendBufferUsed += strlen(thisEventSubTitle) + 1;
694 strcpy((char*)&sendBuffer[sendBufferUsed], thisEventDescription); sendBufferUsed += strlen(thisEventDescription) + 1;
696 log->log("Client", Log::DEBUG, "Done s3 %lu", sendBufferUsed);
699 log->log("Client", Log::DEBUG, "Got all event data");
701 // Write the length into the first 4 bytes. It's sendBufferUsed - 4 because of the hole!
702 *(ULONG*)&sendBuffer[0] = htonl(sendBufferUsed - sizeof(ULONG));
704 tcp.sendPacket(sendBuffer, sendBufferUsed);
705 log->log("Client", Log::DEBUG, "written %lu schedules packet", sendBufferUsed);
712 void MVPClient::processConfigSave(UCHAR* buffer, int length)
714 char* section = (char*)buffer;
718 for (int k = 0; k < length; k++)
720 if (buffer[k] == '\0')
724 key = (char*)&buffer[k+1];
728 value = (char*)&buffer[k+1];
734 // if the last string (value) doesnt have null terminator, give up
735 if (buffer[length - 1] != '\0') return;
737 log->log("Client", Log::DEBUG, "Config save: %s %s %s", section, key, value);
738 if (config.setValueString(section, key, value))
748 void MVPClient::processConfigLoad(UCHAR* buffer, int length)
750 char* section = (char*)buffer;
753 for (int k = 0; k < length; k++)
755 if (buffer[k] == '\0')
757 key = (char*)&buffer[k+1];
762 char* value = config.getValueString(section, key);
766 UCHAR sendBuffer[4 + strlen(value) + 1];
767 *(ULONG*)&sendBuffer[0] = htonl(strlen(value) + 1);
768 strcpy((char*)&sendBuffer[4], value);
769 tcp.sendPacket(sendBuffer, 4 + strlen(value) + 1);
771 log->log("Client", Log::DEBUG, "Written config load packet");
777 *(ULONG*)&sendBuffer[0] = htonl(4);
778 *(ULONG*)&sendBuffer[4] = htonl(0);
779 tcp.sendPacket(sendBuffer, 8);
781 log->log("Client", Log::DEBUG, "Written config load failed packet");
785 void MVPClient::cleanConfig()
787 log->log("Client", Log::DEBUG, "Clean config");
789 cRecordings Recordings;
794 char* resumes = config.getSectionKeyNames("ResumeData", numReturns, length);
795 char* position = resumes;
796 for(int k = 0; k < numReturns; k++)
798 log->log("Client", Log::DEBUG, "EXAMINING: %i %i %p %s", k, numReturns, position, position);
800 cRecording* recording = Recordings.GetByName(position);
803 // doesn't exist anymore
804 log->log("Client", Log::DEBUG, "Found a recording that doesn't exist anymore");
805 config.deleteValue("ResumeData", position);
809 log->log("Client", Log::DEBUG, "This recording still exists");
812 position += strlen(position) + 1;
824 event = Schedule->GetPresentEvent();
826 fprintf(f, "\n\nCurrent event\n\n");
828 fprintf(f, "Event %i eventid = %u time = %lu duration = %li\n", 0, event->GetEventID(), event->GetTime(), event->GetDuration());
829 fprintf(f, "Event %i title = %s subtitle = %s\n", 0, event->GetTitle(), event->GetSubtitle());
830 fprintf(f, "Event %i extendeddescription = %s\n", 0, event->GetExtendedDescription());
831 fprintf(f, "Event %i isFollowing = %i, isPresent = %i\n", 0, event->IsFollowing(), event->IsPresent());
833 event = Schedule->GetFollowingEvent();
835 fprintf(f, "\n\nFollowing event\n\n");
837 fprintf(f, "Event %i eventid = %u time = %lu duration = %li\n", 0, event->GetEventID(), event->GetTime(), event->GetDuration());
838 fprintf(f, "Event %i title = %s subtitle = %s\n", 0, event->GetTitle(), event->GetSubtitle());
839 fprintf(f, "Event %i extendeddescription = %s\n", 0, event->GetExtendedDescription());
840 fprintf(f, "Event %i isFollowing = %i, isPresent = %i\n", 0, event->IsFollowing(), event->IsPresent());
846 fprintf(f, "Event %i eventid = %u time = %lu duration = %li\n", eventNumber, event->GetEventID(), event->GetTime(), event->GetDuration());
847 fprintf(f, "Event %i title = %s subtitle = %s\n", eventNumber, event->GetTitle(), event->GetSubtitle());
848 fprintf(f, "Event %i extendeddescription = %s\n", eventNumber, event->GetExtendedDescription());
849 fprintf(f, "Event %i isFollowing = %i, isPresent = %i\n", eventNumber, event->IsFollowing(), event->IsPresent());
857 void MVPClient::test2()
859 FILE* f = fopen("/tmp/s.txt", "w");
861 #if VDRVERSNUM < 10300
862 cMutexLock MutexLock;
863 const cSchedules *Schedules = cSIProcessor::Schedules(MutexLock);
865 cSchedulesLock MutexLock;
866 const cSchedules *Schedules = cSchedules::Schedules(MutexLock);
871 fprintf(f, "Schedules = NULL\n");
876 fprintf(f, "Schedules dump:\n");
880 const cSchedule *Schedule;
881 int scheduleNumber = 0;
884 cChannel *thisChannel;
886 #if VDRVERSNUM < 10300
887 const cEventInfo *event;
893 // Schedule = Schedules->GetSchedule(channel->GetChannelID());
894 // Schedule = Schedules->GetSchedule();
895 Schedule = Schedules->First();
898 fprintf(f, "First Schedule = NULL\n");
905 fprintf(f, "Schedule #%i\n", scheduleNumber);
906 fprintf(f, "-------------\n\n");
908 #if VDRVERSNUM < 10300
909 tchid = Schedule->GetChannelID();
911 tchid = Schedule->ChannelID();
914 #if VDRVERSNUM < 10300
915 fprintf(f, "ChannelID.ToString() = %s\n", tchid.ToString());
916 fprintf(f, "NumEvents() = %i\n", Schedule->NumEvents());
918 // put the count at the end.
921 thisChannel = Channels.GetByChannelID(tchid, true);
924 fprintf(f, "Channel Number: %p %i\n", thisChannel, thisChannel->Number());
928 fprintf(f, "thisChannel = NULL for tchid\n");
931 #if VDRVERSNUM < 10300
932 for (eventNumber = 0; eventNumber < Schedule->NumEvents(); eventNumber++)
934 event = Schedule->GetEventNumber(eventNumber);
935 fprintf(f, "Event %i tableid = %i timestring = %s endtimestring = %s\n", eventNumber, event->GetTableID(), event->GetTimeString(), event->GetEndTimeString());
936 fprintf(f, "Event %i date = %s isfollowing = %i ispresent = %i\n", eventNumber, event->GetDate(), event->IsFollowing(), event->IsPresent());
937 fprintf(f, "Event %i extendeddescription = %s\n", eventNumber, event->GetExtendedDescription());
938 fprintf(f, "Event %i subtitle = %s title = %s\n", eventNumber, event->GetSubtitle(), event->GetTitle());
939 fprintf(f, "Event %i eventid = %u duration = %li time = %lu channelnumber = %i\n", eventNumber, event->GetEventID(), event->GetDuration(), event->GetTime(), event->GetChannelNumber());
940 fprintf(f, "Event %u dump:\n", eventNumber);
945 // This whole section needs rewriting to walk the list.
946 event = Schedule->Events()->First();
948 event = Schedule->Events()->Next(event);
953 fprintf(f, "\nDump from object:\n");
955 fprintf(f, "\nEND\n");
965 fprintf(f, "End of current Schedule\n\n\n");
967 Schedule = (const cSchedule *)Schedules->Next(Schedule);
981 const cEventInfo *GetPresentEvent(void) const;
982 const cEventInfo *GetFollowingEvent(void) const;
983 const cEventInfo *GetEvent(unsigned short uEventID, time_t tTime = 0) const;
984 const cEventInfo *GetEventAround(time_t tTime) const;
985 const cEventInfo *GetEventNumber(int n) const { return Events.Get(n); }
988 const unsigned char GetTableID(void) const;
989 const char *GetTimeString(void) const;
990 const char *GetEndTimeString(void) const;
991 const char *GetDate(void) const;
992 bool IsFollowing(void) const;
993 bool IsPresent(void) const;
994 const char *GetExtendedDescription(void) const;
995 const char *GetSubtitle(void) const;
996 const char *GetTitle(void) const;
997 unsigned short GetEventID(void) const;
998 long GetDuration(void) const;
999 time_t GetTime(void) const;
1000 tChannelID GetChannelID(void) const;
1001 int GetChannelNumber(void) const { return nChannelNumber; }
1002 void SetChannelNumber(int ChannelNumber) const { ((cEventInfo *)this)->nChannelNumber = ChannelNumber; } // doesn't modify the EIT data, so it's ok to make it 'const'
1003 void Dump(FILE *f, const char *Prefix = "") const;
1009 void MVPClient::test(int channelNumber)
1011 FILE* f = fopen("/tmp/test.txt", "w");
1013 cMutexLock MutexLock;
1014 const cSchedules *Schedules = cSIProcessor::Schedules(MutexLock);
1018 fprintf(f, "Schedules = NULL\n");
1023 fprintf(f, "Schedules dump:\n");
1024 // Schedules->Dump(f);
1026 const cSchedule *Schedule;
1027 cChannel *thisChannel;
1028 const cEventInfo *event;
1030 thisChannel = channelFromNumber(channelNumber);
1033 fprintf(f, "thisChannel = NULL\n");
1038 Schedule = Schedules->GetSchedule(thisChannel->GetChannelID());
1039 // Schedule = Schedules->GetSchedule();
1040 // Schedule = Schedules->First();
1043 fprintf(f, "First Schedule = NULL\n");
1048 fprintf(f, "NumEvents() = %i\n\n", Schedule->NumEvents());
1050 // For some channels VDR seems to pick a random point in time to
1051 // start dishing out events, but they are in order
1052 // at some point in the list the time snaps to the current event
1057 for (int eventNumber = 0; eventNumber < Schedule->NumEvents(); eventNumber++)
1059 event = Schedule->GetEventNumber(eventNumber);
1060 fprintf(f, "Event %i eventid = %u time = %lu duration = %li\n", eventNumber, event->GetEventID(), event->GetTime(), event->GetDuration());
1061 fprintf(f, "Event %i title = %s subtitle = %s\n", eventNumber, event->GetTitle(), event->GetSubtitle());
1062 fprintf(f, "Event %i extendeddescription = %s\n", eventNumber, event->GetExtendedDescription());
1066 fprintf(f, "\nEND\n");
1080 Schedules = the collection of all the Schedule objects
1081 Schedule = One schedule, contants all the events for a channel
1082 Event = One programme
1091 Subtitle (used for "Programmes resume at ...")
1094 IsPresent ? easy to work out tho. Oh it doesn't always work