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 char* chanConfig = config.getValueString("General", "Channels");
371 if (chanConfig) allChans = strcasecmp(chanConfig, "FTA only");
373 for (cChannel *channel = Channels.First(); channel; channel = Channels.Next(channel))
375 #if VDRVERSNUM < 10300
376 if (!channel->GroupSep() && (!channel->Ca() || allChans))
378 if (!channel->GroupSep() && (!channel->Ca(0) || allChans))
381 log->log("Client", Log::DEBUG, "name: '%s'", channel->Name());
383 if (channel->Vpid()) type = 1;
384 #if VDRVERSNUM < 10300
387 else if (channel->Apid(0)) type = 2;
391 if (count > 49000) break;
392 *(ULONG*)&sendBuffer[count] = htonl(channel->Number());
395 *(ULONG*)&sendBuffer[count] = htonl(type);
398 point = (char*)channel->Name();
399 strcpy((char*)&sendBuffer[count], point);
400 count += strlen(point) + 1;
404 *(ULONG*)&sendBuffer[0] = htonl(count - 4); // -4 : take off the size field
406 log->log("Client", Log::DEBUG, "recorded size as %u", ntohl(*(ULONG*)&sendBuffer[0]));
408 tcp.sendPacket(sendBuffer, count);
410 log->log("Client", Log::DEBUG, "Written channels list");
413 void MVPClient::processStartStreamingChannel(UCHAR* data, int length)
415 log->log("Client", Log::DEBUG, "length = %i", length);
416 ULONG channelNumber = ntohl(*(ULONG*)data);
418 cChannel* channel = channelFromNumber(channelNumber);
425 lp = MVPReceiver::create(channel);
444 void MVPClient::processStopStreaming(UCHAR* data, int length)
446 log->log("Client", Log::DEBUG, "STOP STREAMING RECEIVED");
457 delete recordingManager;
459 recordingManager = NULL;
465 void MVPClient::processGetBlock(UCHAR* data, int length)
469 log->log("Client", Log::DEBUG, "Get block called when no streaming happening!");
473 ULLONG position = ntohll(*(ULLONG*)data);
474 data += sizeof(ULLONG);
475 ULONG amount = ntohl(*(ULONG*)data);
477 log->log("Client", Log::DEBUG, "getblock pos = %llu length = %lu", position, amount);
479 UCHAR sendBuffer[amount + 4];
480 ULONG amountReceived = 0; // compiler moan.
483 log->log("Client", Log::DEBUG, "getting from live");
484 amountReceived = lp->getBlock(&sendBuffer[4], amount);
488 // vdr has possibly disconnected the receiver
489 log->log("Client", Log::DEBUG, "VDR has disconnected the live receiver");
496 log->log("Client", Log::DEBUG, "getting from recording");
497 amountReceived = rp->getBlock(&sendBuffer[4], position, amount);
500 *(ULONG*)&sendBuffer[0] = htonl(amountReceived);
501 tcp.sendPacket(sendBuffer, amountReceived + 4);
502 log->log("Client", Log::DEBUG, "written ok %lu", amountReceived);
505 void MVPClient::processStartStreamingRecording(UCHAR* data, int length)
507 // data is a pointer to the fileName string
509 recordingManager = new cRecordings;
510 recordingManager->Load();
512 cRecording* recording = recordingManager->GetByName((char*)data);
514 log->log("Client", Log::DEBUG, "recording pointer %p", recording);
518 rp = new RecPlayer(recording);
520 UCHAR sendBuffer[12];
521 *(ULONG*)&sendBuffer[0] = htonl(8);
522 *(ULLONG*)&sendBuffer[4] = htonll(rp->getTotalLength());
524 tcp.sendPacket(sendBuffer, 12);
525 log->log("Client", Log::DEBUG, "written totalLength");
529 delete recordingManager;
530 recordingManager = NULL;
534 void MVPClient::processReScanRecording(UCHAR* data, int length)
540 log->log("Client", Log::DEBUG, "Rescan recording called when no recording being played!");
545 retval = rp->getTotalLength();
548 UCHAR sendBuffer[12];
549 *(ULONG*)&sendBuffer[0] = htonl(8);
550 *(ULLONG*)&sendBuffer[4] = htonll(retval);
552 tcp.sendPacket(sendBuffer, 12);
553 log->log("Client", Log::DEBUG, "Rescan recording, wrote new length to client");
556 void MVPClient::processGetChannelSchedule(UCHAR* data, int length)
558 ULONG channelNumber = ntohl(*(ULLONG*)data);
559 log->log("Client", Log::DEBUG, "get schedule called for channel %lu", channelNumber);
561 cChannel* channel = channelFromNumber(channelNumber);
565 *(ULONG*)&sendBuffer[0] = htonl(4);
566 *(ULONG*)&sendBuffer[4] = htonl(0);
567 tcp.sendPacket(sendBuffer, 8);
568 log->log("Client", Log::DEBUG, "written 0 because channel = NULL");
572 log->log("Client", Log::DEBUG, "Got channel");
574 #if VDRVERSNUM < 10300
575 cMutexLock MutexLock;
576 const cSchedules *Schedules = cSIProcessor::Schedules(MutexLock);
578 cSchedulesLock MutexLock;
579 const cSchedules *Schedules = cSchedules::Schedules(MutexLock);
584 *(ULONG*)&sendBuffer[0] = htonl(4);
585 *(ULONG*)&sendBuffer[4] = htonl(0);
586 tcp.sendPacket(sendBuffer, 8);
587 log->log("Client", Log::DEBUG, "written 0 because Schedule!s! = NULL");
591 log->log("Client", Log::DEBUG, "Got schedule!s! object");
593 const cSchedule *Schedule = Schedules->GetSchedule(channel->GetChannelID());
597 *(ULONG*)&sendBuffer[0] = htonl(4);
598 *(ULONG*)&sendBuffer[4] = htonl(0);
599 tcp.sendPacket(sendBuffer, 8);
600 log->log("Client", Log::DEBUG, "written 0 because Schedule = NULL");
604 log->log("Client", Log::DEBUG, "Got schedule object");
606 UCHAR* sendBuffer = (UCHAR*)malloc(100000);
607 ULONG sendBufferLength = 100000;
608 ULONG sendBufferUsed = sizeof(ULONG); // leave a hole for the entire packet length
612 // assign all the event info to temp vars then we know exactly what size they are
615 ULONG thisEventDuration;
616 const char* thisEventTitle;
617 const char* thisEventSubTitle;
618 const char* thisEventDescription;
620 ULONG constEventLength = sizeof(thisEventID) + sizeof(thisEventTime) + sizeof(thisEventDuration);
621 ULONG thisEventLength;
623 #if VDRVERSNUM < 10300
625 const cEventInfo *event;
626 for (int eventNumber = 0; eventNumber < Schedule->NumEvents(); eventNumber++)
628 event = Schedule->GetEventNumber(eventNumber);
630 thisEventID = event->GetEventID();
631 thisEventTime = event->GetTime();
632 thisEventDuration = event->GetDuration();
633 thisEventTitle = event->GetTitle();
634 thisEventSubTitle = event->GetSubtitle();
635 thisEventDescription = event->GetExtendedDescription();
639 for (const cEvent* event = Schedule->Events()->First(); event; event = Schedule->Events()->Next(event))
641 thisEventID = event->EventID();
642 thisEventTime = event->StartTime();
643 thisEventDuration = event->Duration();
644 thisEventTitle = event->Title();
645 thisEventSubTitle = NULL;
646 thisEventDescription = event->Description();
650 log->log("Client", Log::DEBUG, "Got an event object %p", event);
653 if ((thisEventTime + thisEventDuration) < (ULONG)time(NULL)) continue;
656 if (thisEventTime > ((ULONG)time(NULL) + 86400)) continue;
658 if (!thisEventTitle) thisEventTitle = empty;
659 if (!thisEventSubTitle) thisEventSubTitle = empty;
660 if (!thisEventDescription) thisEventDescription = empty;
662 thisEventLength = constEventLength + strlen(thisEventTitle) + 1 + strlen(thisEventSubTitle) + 1 + strlen(thisEventDescription) + 1;
664 log->log("Client", Log::DEBUG, "Done s1");
666 // now extend the buffer if necessary
667 if ((sendBufferUsed + thisEventLength) > sendBufferLength)
669 log->log("Client", Log::DEBUG, "Extending buffer");
670 sendBufferLength += 100000;
671 UCHAR* temp = (UCHAR*)realloc(sendBuffer, sendBufferLength);
675 UCHAR sendBuffer2[8];
676 *(ULONG*)&sendBuffer2[0] = htonl(4);
677 *(ULONG*)&sendBuffer2[4] = htonl(0);
678 tcp.sendPacket(sendBuffer2, 8);
679 log->log("Client", Log::DEBUG, "written 0 because failed to realloc packet");
685 log->log("Client", Log::DEBUG, "Done s2");
687 *(ULONG*)&sendBuffer[sendBufferUsed] = htonl(thisEventID); sendBufferUsed += sizeof(ULONG);
688 *(ULONG*)&sendBuffer[sendBufferUsed] = htonl(thisEventTime); sendBufferUsed += sizeof(ULONG);
689 *(ULONG*)&sendBuffer[sendBufferUsed] = htonl(thisEventDuration); sendBufferUsed += sizeof(ULONG);
691 strcpy((char*)&sendBuffer[sendBufferUsed], thisEventTitle); sendBufferUsed += strlen(thisEventTitle) + 1;
692 strcpy((char*)&sendBuffer[sendBufferUsed], thisEventSubTitle); sendBufferUsed += strlen(thisEventSubTitle) + 1;
693 strcpy((char*)&sendBuffer[sendBufferUsed], thisEventDescription); sendBufferUsed += strlen(thisEventDescription) + 1;
695 log->log("Client", Log::DEBUG, "Done s3 %lu", sendBufferUsed);
698 log->log("Client", Log::DEBUG, "Got all event data");
700 // Write the length into the first 4 bytes. It's sendBufferUsed - 4 because of the hole!
701 *(ULONG*)&sendBuffer[0] = htonl(sendBufferUsed - sizeof(ULONG));
703 tcp.sendPacket(sendBuffer, sendBufferUsed);
704 log->log("Client", Log::DEBUG, "written %lu schedules packet", sendBufferUsed);
711 void MVPClient::processConfigSave(UCHAR* buffer, int length)
713 char* section = (char*)buffer;
717 for (int k = 0; k < length; k++)
719 if (buffer[k] == '\0')
723 key = (char*)&buffer[k+1];
727 value = (char*)&buffer[k+1];
733 // if the last string (value) doesnt have null terminator, give up
734 if (buffer[length - 1] != '\0') return;
736 log->log("Client", Log::DEBUG, "Config save: %s %s %s", section, key, value);
737 if (config.setValueString(section, key, value))
747 void MVPClient::processConfigLoad(UCHAR* buffer, int length)
749 char* section = (char*)buffer;
752 for (int k = 0; k < length; k++)
754 if (buffer[k] == '\0')
756 key = (char*)&buffer[k+1];
761 char* value = config.getValueString(section, key);
765 UCHAR sendBuffer[4 + strlen(value) + 1];
766 *(ULONG*)&sendBuffer[0] = htonl(strlen(value) + 1);
767 strcpy((char*)&sendBuffer[4], value);
768 tcp.sendPacket(sendBuffer, 4 + strlen(value) + 1);
770 log->log("Client", Log::DEBUG, "Written config load packet");
776 *(ULONG*)&sendBuffer[0] = htonl(4);
777 *(ULONG*)&sendBuffer[4] = htonl(0);
778 tcp.sendPacket(sendBuffer, 8);
780 log->log("Client", Log::DEBUG, "Written config load failed packet");
784 void MVPClient::cleanConfig()
786 log->log("Client", Log::DEBUG, "Clean config");
788 cRecordings Recordings;
793 char* resumes = config.getSectionKeyNames("ResumeData", numReturns, length);
794 char* position = resumes;
795 for(int k = 0; k < numReturns; k++)
797 log->log("Client", Log::DEBUG, "EXAMINING: %i %i %p %s", k, numReturns, position, position);
799 cRecording* recording = Recordings.GetByName(position);
802 // doesn't exist anymore
803 log->log("Client", Log::DEBUG, "Found a recording that doesn't exist anymore");
804 config.deleteValue("ResumeData", position);
808 log->log("Client", Log::DEBUG, "This recording still exists");
811 position += strlen(position) + 1;
823 event = Schedule->GetPresentEvent();
825 fprintf(f, "\n\nCurrent event\n\n");
827 fprintf(f, "Event %i eventid = %u time = %lu duration = %li\n", 0, event->GetEventID(), event->GetTime(), event->GetDuration());
828 fprintf(f, "Event %i title = %s subtitle = %s\n", 0, event->GetTitle(), event->GetSubtitle());
829 fprintf(f, "Event %i extendeddescription = %s\n", 0, event->GetExtendedDescription());
830 fprintf(f, "Event %i isFollowing = %i, isPresent = %i\n", 0, event->IsFollowing(), event->IsPresent());
832 event = Schedule->GetFollowingEvent();
834 fprintf(f, "\n\nFollowing event\n\n");
836 fprintf(f, "Event %i eventid = %u time = %lu duration = %li\n", 0, event->GetEventID(), event->GetTime(), event->GetDuration());
837 fprintf(f, "Event %i title = %s subtitle = %s\n", 0, event->GetTitle(), event->GetSubtitle());
838 fprintf(f, "Event %i extendeddescription = %s\n", 0, event->GetExtendedDescription());
839 fprintf(f, "Event %i isFollowing = %i, isPresent = %i\n", 0, event->IsFollowing(), event->IsPresent());
845 fprintf(f, "Event %i eventid = %u time = %lu duration = %li\n", eventNumber, event->GetEventID(), event->GetTime(), event->GetDuration());
846 fprintf(f, "Event %i title = %s subtitle = %s\n", eventNumber, event->GetTitle(), event->GetSubtitle());
847 fprintf(f, "Event %i extendeddescription = %s\n", eventNumber, event->GetExtendedDescription());
848 fprintf(f, "Event %i isFollowing = %i, isPresent = %i\n", eventNumber, event->IsFollowing(), event->IsPresent());
856 void MVPClient::test2()
858 FILE* f = fopen("/tmp/s.txt", "w");
860 #if VDRVERSNUM < 10300
861 cMutexLock MutexLock;
862 const cSchedules *Schedules = cSIProcessor::Schedules(MutexLock);
864 cSchedulesLock MutexLock;
865 const cSchedules *Schedules = cSchedules::Schedules(MutexLock);
870 fprintf(f, "Schedules = NULL\n");
875 fprintf(f, "Schedules dump:\n");
879 const cSchedule *Schedule;
880 int scheduleNumber = 0;
883 cChannel *thisChannel;
885 #if VDRVERSNUM < 10300
886 const cEventInfo *event;
892 // Schedule = Schedules->GetSchedule(channel->GetChannelID());
893 // Schedule = Schedules->GetSchedule();
894 Schedule = Schedules->First();
897 fprintf(f, "First Schedule = NULL\n");
904 fprintf(f, "Schedule #%i\n", scheduleNumber);
905 fprintf(f, "-------------\n\n");
907 #if VDRVERSNUM < 10300
908 tchid = Schedule->GetChannelID();
910 tchid = Schedule->ChannelID();
913 #if VDRVERSNUM < 10300
914 fprintf(f, "ChannelID.ToString() = %s\n", tchid.ToString());
915 fprintf(f, "NumEvents() = %i\n", Schedule->NumEvents());
917 // put the count at the end.
920 thisChannel = Channels.GetByChannelID(tchid, true);
923 fprintf(f, "Channel Number: %p %i\n", thisChannel, thisChannel->Number());
927 fprintf(f, "thisChannel = NULL for tchid\n");
930 #if VDRVERSNUM < 10300
931 for (eventNumber = 0; eventNumber < Schedule->NumEvents(); eventNumber++)
933 event = Schedule->GetEventNumber(eventNumber);
934 fprintf(f, "Event %i tableid = %i timestring = %s endtimestring = %s\n", eventNumber, event->GetTableID(), event->GetTimeString(), event->GetEndTimeString());
935 fprintf(f, "Event %i date = %s isfollowing = %i ispresent = %i\n", eventNumber, event->GetDate(), event->IsFollowing(), event->IsPresent());
936 fprintf(f, "Event %i extendeddescription = %s\n", eventNumber, event->GetExtendedDescription());
937 fprintf(f, "Event %i subtitle = %s title = %s\n", eventNumber, event->GetSubtitle(), event->GetTitle());
938 fprintf(f, "Event %i eventid = %u duration = %li time = %lu channelnumber = %i\n", eventNumber, event->GetEventID(), event->GetDuration(), event->GetTime(), event->GetChannelNumber());
939 fprintf(f, "Event %u dump:\n", eventNumber);
944 // This whole section needs rewriting to walk the list.
945 event = Schedule->Events()->First();
947 event = Schedule->Events()->Next(event);
952 fprintf(f, "\nDump from object:\n");
954 fprintf(f, "\nEND\n");
964 fprintf(f, "End of current Schedule\n\n\n");
966 Schedule = (const cSchedule *)Schedules->Next(Schedule);
980 const cEventInfo *GetPresentEvent(void) const;
981 const cEventInfo *GetFollowingEvent(void) const;
982 const cEventInfo *GetEvent(unsigned short uEventID, time_t tTime = 0) const;
983 const cEventInfo *GetEventAround(time_t tTime) const;
984 const cEventInfo *GetEventNumber(int n) const { return Events.Get(n); }
987 const unsigned char GetTableID(void) const;
988 const char *GetTimeString(void) const;
989 const char *GetEndTimeString(void) const;
990 const char *GetDate(void) const;
991 bool IsFollowing(void) const;
992 bool IsPresent(void) const;
993 const char *GetExtendedDescription(void) const;
994 const char *GetSubtitle(void) const;
995 const char *GetTitle(void) const;
996 unsigned short GetEventID(void) const;
997 long GetDuration(void) const;
998 time_t GetTime(void) const;
999 tChannelID GetChannelID(void) const;
1000 int GetChannelNumber(void) const { return nChannelNumber; }
1001 void SetChannelNumber(int ChannelNumber) const { ((cEventInfo *)this)->nChannelNumber = ChannelNumber; } // doesn't modify the EIT data, so it's ok to make it 'const'
1002 void Dump(FILE *f, const char *Prefix = "") const;
1008 void MVPClient::test(int channelNumber)
1010 FILE* f = fopen("/tmp/test.txt", "w");
1012 cMutexLock MutexLock;
1013 const cSchedules *Schedules = cSIProcessor::Schedules(MutexLock);
1017 fprintf(f, "Schedules = NULL\n");
1022 fprintf(f, "Schedules dump:\n");
1023 // Schedules->Dump(f);
1025 const cSchedule *Schedule;
1026 cChannel *thisChannel;
1027 const cEventInfo *event;
1029 thisChannel = channelFromNumber(channelNumber);
1032 fprintf(f, "thisChannel = NULL\n");
1037 Schedule = Schedules->GetSchedule(thisChannel->GetChannelID());
1038 // Schedule = Schedules->GetSchedule();
1039 // Schedule = Schedules->First();
1042 fprintf(f, "First Schedule = NULL\n");
1047 fprintf(f, "NumEvents() = %i\n\n", Schedule->NumEvents());
1049 // For some channels VDR seems to pick a random point in time to
1050 // start dishing out events, but they are in order
1051 // at some point in the list the time snaps to the current event
1056 for (int eventNumber = 0; eventNumber < Schedule->NumEvents(); eventNumber++)
1058 event = Schedule->GetEventNumber(eventNumber);
1059 fprintf(f, "Event %i eventid = %u time = %lu duration = %li\n", eventNumber, event->GetEventID(), event->GetTime(), event->GetDuration());
1060 fprintf(f, "Event %i title = %s subtitle = %s\n", eventNumber, event->GetTitle(), event->GetSubtitle());
1061 fprintf(f, "Event %i extendeddescription = %s\n", eventNumber, event->GetExtendedDescription());
1065 fprintf(f, "\nEND\n");
1079 Schedules = the collection of all the Schedule objects
1080 Schedule = One schedule, contants all the events for a channel
1081 Event = One programme
1090 Subtitle (used for "Programmes resume at ...")
1093 IsPresent ? easy to work out tho. Oh it doesn't always work