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 //( ^^^^^^^^^^^^^eh?^^^^^^^^^^^^^)
250 config.init(configFileName);
252 // Send the login reply
254 time_t timeNow = time(NULL);
255 struct tm* timeStruct = localtime(&timeNow);
256 int timeOffset = timeStruct->tm_gmtoff;
258 UCHAR sendBuffer[12];
259 *(ULONG*)&sendBuffer[0] = htonl(8);
260 *(ULONG*)&sendBuffer[4] = htonl(timeNow);
261 *(signed int*)&sendBuffer[8] = htonl(timeOffset);
263 tcp.sendPacket(sendBuffer, 12);
264 log->log("Client", Log::DEBUG, "written login reply");
270 int MVPClient::processGetRecordingsList(UCHAR* data, int length)
272 UCHAR* sendBuffer = new UCHAR[50000]; // hope this is enough
273 int count = 4; // leave space for the packet length
278 int Percent = VideoDiskSpace(&FreeMB);
279 int Total = (FreeMB / (100 - Percent)) * 100;
281 *(ULONG*)&sendBuffer[count] = htonl(Total);
282 count += sizeof(ULONG);
283 *(ULONG*)&sendBuffer[count] = htonl(FreeMB);
284 count += sizeof(ULONG);
285 *(ULONG*)&sendBuffer[count] = htonl(Percent);
286 count += sizeof(ULONG);
289 cRecordings Recordings;
292 for (cRecording *recording = Recordings.First(); recording; recording = Recordings.Next(recording))
294 if (count > 49000) break; // just how big is that hard disk?!
295 *(ULONG*)&sendBuffer[count] = htonl(recording->start);// + timeOffset);
298 point = (char*)recording->Name();
299 strcpy((char*)&sendBuffer[count], point);
300 count += strlen(point) + 1;
302 point = (char*)recording->FileName();
303 strcpy((char*)&sendBuffer[count], point);
304 count += strlen(point) + 1;
307 *(ULONG*)&sendBuffer[0] = htonl(count - 4); // -4 : take off the size field
309 log->log("Client", Log::DEBUG, "recorded size as %u", ntohl(*(ULONG*)&sendBuffer[0]));
311 tcp.sendPacket(sendBuffer, count);
313 log->log("Client", Log::DEBUG, "Written list");
318 int MVPClient::processDeleteRecording(UCHAR* data, int length)
320 // data is a pointer to the fileName string
322 cRecordings Recordings;
323 Recordings.Load(); // probably have to do this
325 cRecording* recording = Recordings.GetByName((char*)data);
327 log->log("Client", Log::DEBUG, "recording pointer %p", recording);
331 log->log("Client", Log::DEBUG, "deleting recording: %s", recording->Name());
343 int MVPClient::processGetSummary(UCHAR* data, int length)
345 // data is a pointer to the fileName string
347 cRecordings Recordings;
348 Recordings.Load(); // probably have to do this
350 cRecording *recording = Recordings.GetByName((char*)data);
352 log->log("Client", Log::DEBUG, "recording pointer %p", recording);
356 UCHAR* sendBuffer = new UCHAR[50000]; // hope this is enough
357 int count = 4; // leave space for the packet length
360 #if VDRVERSNUM < 10300
361 point = (char*)recording->Summary();
363 const cRecordingInfo *Info = recording->Info();
364 point = (char*)Info->ShortText();
365 log->log("Client", Log::DEBUG, "info pointer %p summary pointer %p", Info, point);
368 point = (char*)Info->Description();
369 log->log("Client", Log::DEBUG, "description pointer %p", point);
372 strcpy((char*)&sendBuffer[count], point);
373 count += strlen(point) + 1;
374 *(ULONG*)&sendBuffer[0] = htonl(count - 4); // -4 : take off the size field
376 log->log("Client", Log::DEBUG, "recorded size as %u", ntohl(*(ULONG*)&sendBuffer[0]));
378 tcp.sendPacket(sendBuffer, count);
380 log->log("Client", Log::DEBUG, "Written summary");
392 int MVPClient::processGetChannelsList(UCHAR* data, int length)
394 UCHAR* sendBuffer = new UCHAR[50000]; // FIXME hope this is enough
395 int count = 4; // leave space for the packet length
399 char* chanConfig = config.getValueString("General", "Channels");
401 if (chanConfig) allChans = strcasecmp(chanConfig, "FTA only");
403 for (cChannel *channel = Channels.First(); channel; channel = Channels.Next(channel))
405 #if VDRVERSNUM < 10300
406 if (!channel->GroupSep() && (!channel->Ca() || allChans))
408 if (!channel->GroupSep() && (!channel->Ca(0) || allChans))
411 log->log("Client", Log::DEBUG, "name: '%s'", channel->Name());
413 if (channel->Vpid()) type = 1;
414 #if VDRVERSNUM < 10300
417 else if (channel->Apid(0)) type = 2;
421 if (count > 49000) break;
422 *(ULONG*)&sendBuffer[count] = htonl(channel->Number());
425 *(ULONG*)&sendBuffer[count] = htonl(type);
428 point = (char*)channel->Name();
429 strcpy((char*)&sendBuffer[count], point);
430 count += strlen(point) + 1;
434 *(ULONG*)&sendBuffer[0] = htonl(count - 4); // -4 : take off the size field
436 log->log("Client", Log::DEBUG, "recorded size as %u", ntohl(*(ULONG*)&sendBuffer[0]));
438 tcp.sendPacket(sendBuffer, count);
440 log->log("Client", Log::DEBUG, "Written channels list");
445 int MVPClient::processStartStreamingChannel(UCHAR* data, int length)
447 log->log("Client", Log::DEBUG, "length = %i", length);
448 ULONG channelNumber = ntohl(*(ULONG*)data);
450 cChannel* channel = channelFromNumber(channelNumber);
457 // get the priority we should use
459 int priority = config.getValueLong("General", "Live priority", &fail);
462 log->log("Client", Log::DEBUG, "Config: Live TV priority: %i", priority);
466 log->log("Client", Log::DEBUG, "Config: Live TV priority config fail");
471 if (priority < 0) priority = 0;
472 if (priority > 99) priority = 99;
474 log->log("Client", Log::DEBUG, "Using live TV priority %i", priority);
475 lp = MVPReceiver::create(channel, priority);
495 int MVPClient::processStopStreaming(UCHAR* data, int length)
497 log->log("Client", Log::DEBUG, "STOP STREAMING RECEIVED");
508 delete recordingManager;
510 recordingManager = NULL;
517 int MVPClient::processGetBlock(UCHAR* data, int length)
521 log->log("Client", Log::DEBUG, "Get block called when no streaming happening!");
525 ULLONG position = ntohll(*(ULLONG*)data);
526 data += sizeof(ULLONG);
527 ULONG amount = ntohl(*(ULONG*)data);
529 log->log("Client", Log::DEBUG, "getblock pos = %llu length = %lu", position, amount);
531 UCHAR sendBuffer[amount + 4];
532 ULONG amountReceived = 0; // compiler moan.
535 log->log("Client", Log::DEBUG, "getting from live");
536 amountReceived = lp->getBlock(&sendBuffer[4], amount);
540 // vdr has possibly disconnected the receiver
541 log->log("Client", Log::DEBUG, "VDR has disconnected the live receiver");
548 log->log("Client", Log::DEBUG, "getting from recording");
549 amountReceived = rp->getBlock(&sendBuffer[4], position, amount);
552 *(ULONG*)&sendBuffer[0] = htonl(amountReceived);
553 tcp.sendPacket(sendBuffer, amountReceived + 4);
554 log->log("Client", Log::DEBUG, "written ok %lu", amountReceived);
559 int MVPClient::processStartStreamingRecording(UCHAR* data, int length)
561 // data is a pointer to the fileName string
563 recordingManager = new cRecordings;
564 recordingManager->Load();
566 cRecording* recording = recordingManager->GetByName((char*)data);
568 log->log("Client", Log::DEBUG, "recording pointer %p", recording);
572 rp = new RecPlayer(recording);
574 UCHAR sendBuffer[12];
575 *(ULONG*)&sendBuffer[0] = htonl(8);
576 *(ULLONG*)&sendBuffer[4] = htonll(rp->getTotalLength());
578 tcp.sendPacket(sendBuffer, 12);
579 log->log("Client", Log::DEBUG, "written totalLength");
583 delete recordingManager;
584 recordingManager = NULL;
589 int MVPClient::processReScanRecording(UCHAR* data, int length)
595 log->log("Client", Log::DEBUG, "Rescan recording called when no recording being played!");
600 retval = rp->getTotalLength();
603 UCHAR sendBuffer[12];
604 *(ULONG*)&sendBuffer[0] = htonl(8);
605 *(ULLONG*)&sendBuffer[4] = htonll(retval);
607 tcp.sendPacket(sendBuffer, 12);
608 log->log("Client", Log::DEBUG, "Rescan recording, wrote new length to client");
612 int MVPClient::processGetChannelSchedule(UCHAR* data, int length)
614 ULONG channelNumber = ntohl(*(ULLONG*)data);
616 ULONG startTime = ntohl(*(ULLONG*)data);
618 ULONG duration = ntohl(*(ULLONG*)data);
620 log->log("Client", Log::DEBUG, "get schedule called for channel %lu", channelNumber);
622 cChannel* channel = channelFromNumber(channelNumber);
626 *(ULONG*)&sendBuffer[0] = htonl(4);
627 *(ULONG*)&sendBuffer[4] = htonl(0);
628 tcp.sendPacket(sendBuffer, 8);
629 log->log("Client", Log::DEBUG, "written 0 because channel = NULL");
633 log->log("Client", Log::DEBUG, "Got channel");
635 #if VDRVERSNUM < 10300
636 cMutexLock MutexLock;
637 const cSchedules *Schedules = cSIProcessor::Schedules(MutexLock);
639 cSchedulesLock MutexLock;
640 const cSchedules *Schedules = cSchedules::Schedules(MutexLock);
645 *(ULONG*)&sendBuffer[0] = htonl(4);
646 *(ULONG*)&sendBuffer[4] = htonl(0);
647 tcp.sendPacket(sendBuffer, 8);
648 log->log("Client", Log::DEBUG, "written 0 because Schedule!s! = NULL");
652 log->log("Client", Log::DEBUG, "Got schedule!s! object");
654 const cSchedule *Schedule = Schedules->GetSchedule(channel->GetChannelID());
658 *(ULONG*)&sendBuffer[0] = htonl(4);
659 *(ULONG*)&sendBuffer[4] = htonl(0);
660 tcp.sendPacket(sendBuffer, 8);
661 log->log("Client", Log::DEBUG, "written 0 because Schedule = NULL");
665 log->log("Client", Log::DEBUG, "Got schedule object");
667 UCHAR* sendBuffer = (UCHAR*)malloc(100000);
668 ULONG sendBufferLength = 100000;
669 ULONG sendBufferUsed = sizeof(ULONG); // leave a hole for the entire packet length
673 // assign all the event info to temp vars then we know exactly what size they are
676 ULONG thisEventDuration;
677 const char* thisEventTitle;
678 const char* thisEventSubTitle;
679 const char* thisEventDescription;
681 ULONG constEventLength = sizeof(thisEventID) + sizeof(thisEventTime) + sizeof(thisEventDuration);
682 ULONG thisEventLength;
684 #if VDRVERSNUM < 10300
686 const cEventInfo *event;
687 for (int eventNumber = 0; eventNumber < Schedule->NumEvents(); eventNumber++)
689 event = Schedule->GetEventNumber(eventNumber);
691 thisEventID = event->GetEventID();
692 thisEventTime = event->GetTime();
693 thisEventDuration = event->GetDuration();
694 thisEventTitle = event->GetTitle();
695 thisEventSubTitle = event->GetSubtitle();
696 thisEventDescription = event->GetExtendedDescription();
700 for (const cEvent* event = Schedule->Events()->First(); event; event = Schedule->Events()->Next(event))
702 thisEventID = event->EventID();
703 thisEventTime = event->StartTime();
704 thisEventDuration = event->Duration();
705 thisEventTitle = event->Title();
706 thisEventSubTitle = NULL;
707 thisEventDescription = event->Description();
711 log->log("Client", Log::DEBUG, "Got an event object %p", event);
714 if ((thisEventTime + thisEventDuration) < (ULONG)time(NULL)) continue;
717 if ((thisEventTime + thisEventDuration) <= startTime) continue;
720 if (thisEventTime >= (startTime + duration)) continue;
722 if (!thisEventTitle) thisEventTitle = empty;
723 if (!thisEventSubTitle) thisEventSubTitle = empty;
724 if (!thisEventDescription) thisEventDescription = empty;
726 thisEventLength = constEventLength + strlen(thisEventTitle) + 1 + strlen(thisEventSubTitle) + 1 + strlen(thisEventDescription) + 1;
728 log->log("Client", Log::DEBUG, "Done s1");
730 // now extend the buffer if necessary
731 if ((sendBufferUsed + thisEventLength) > sendBufferLength)
733 log->log("Client", Log::DEBUG, "Extending buffer");
734 sendBufferLength += 100000;
735 UCHAR* temp = (UCHAR*)realloc(sendBuffer, sendBufferLength);
739 UCHAR sendBuffer2[8];
740 *(ULONG*)&sendBuffer2[0] = htonl(4);
741 *(ULONG*)&sendBuffer2[4] = htonl(0);
742 tcp.sendPacket(sendBuffer2, 8);
743 log->log("Client", Log::DEBUG, "written 0 because failed to realloc packet");
749 log->log("Client", Log::DEBUG, "Done s2");
751 *(ULONG*)&sendBuffer[sendBufferUsed] = htonl(thisEventID); sendBufferUsed += sizeof(ULONG);
752 *(ULONG*)&sendBuffer[sendBufferUsed] = htonl(thisEventTime); sendBufferUsed += sizeof(ULONG);
753 *(ULONG*)&sendBuffer[sendBufferUsed] = htonl(thisEventDuration); sendBufferUsed += sizeof(ULONG);
755 strcpy((char*)&sendBuffer[sendBufferUsed], thisEventTitle); sendBufferUsed += strlen(thisEventTitle) + 1;
756 strcpy((char*)&sendBuffer[sendBufferUsed], thisEventSubTitle); sendBufferUsed += strlen(thisEventSubTitle) + 1;
757 strcpy((char*)&sendBuffer[sendBufferUsed], thisEventDescription); sendBufferUsed += strlen(thisEventDescription) + 1;
759 log->log("Client", Log::DEBUG, "Done s3 %lu", sendBufferUsed);
762 log->log("Client", Log::DEBUG, "Got all event data");
764 // Write the length into the first 4 bytes. It's sendBufferUsed - 4 because of the hole!
765 *(ULONG*)&sendBuffer[0] = htonl(sendBufferUsed - sizeof(ULONG));
767 tcp.sendPacket(sendBuffer, sendBufferUsed);
768 log->log("Client", Log::DEBUG, "written %lu schedules packet", sendBufferUsed);
775 int MVPClient::processConfigSave(UCHAR* buffer, int length)
777 char* section = (char*)buffer;
781 for (int k = 0; k < length; k++)
783 if (buffer[k] == '\0')
787 key = (char*)&buffer[k+1];
791 value = (char*)&buffer[k+1];
797 // if the last string (value) doesnt have null terminator, give up
798 if (buffer[length - 1] != '\0') return 0;
800 log->log("Client", Log::DEBUG, "Config save: %s %s %s", section, key, value);
801 if (config.setValueString(section, key, value))
813 int MVPClient::processConfigLoad(UCHAR* buffer, int length)
815 char* section = (char*)buffer;
818 for (int k = 0; k < length; k++)
820 if (buffer[k] == '\0')
822 key = (char*)&buffer[k+1];
827 char* value = config.getValueString(section, key);
831 UCHAR sendBuffer[4 + strlen(value) + 1];
832 *(ULONG*)&sendBuffer[0] = htonl(strlen(value) + 1);
833 strcpy((char*)&sendBuffer[4], value);
834 tcp.sendPacket(sendBuffer, 4 + strlen(value) + 1);
836 log->log("Client", Log::DEBUG, "Written config load packet");
842 *(ULONG*)&sendBuffer[0] = htonl(4);
843 *(ULONG*)&sendBuffer[4] = htonl(0);
844 tcp.sendPacket(sendBuffer, 8);
846 log->log("Client", Log::DEBUG, "Written config load failed packet");
852 void MVPClient::cleanConfig()
854 log->log("Client", Log::DEBUG, "Clean config");
856 cRecordings Recordings;
861 char* resumes = config.getSectionKeyNames("ResumeData", numReturns, length);
862 char* position = resumes;
863 for(int k = 0; k < numReturns; k++)
865 log->log("Client", Log::DEBUG, "EXAMINING: %i %i %p %s", k, numReturns, position, position);
867 cRecording* recording = Recordings.GetByName(position);
870 // doesn't exist anymore
871 log->log("Client", Log::DEBUG, "Found a recording that doesn't exist anymore");
872 config.deleteValue("ResumeData", position);
876 log->log("Client", Log::DEBUG, "This recording still exists");
879 position += strlen(position) + 1;
891 event = Schedule->GetPresentEvent();
893 fprintf(f, "\n\nCurrent event\n\n");
895 fprintf(f, "Event %i eventid = %u time = %lu duration = %li\n", 0, event->GetEventID(), event->GetTime(), event->GetDuration());
896 fprintf(f, "Event %i title = %s subtitle = %s\n", 0, event->GetTitle(), event->GetSubtitle());
897 fprintf(f, "Event %i extendeddescription = %s\n", 0, event->GetExtendedDescription());
898 fprintf(f, "Event %i isFollowing = %i, isPresent = %i\n", 0, event->IsFollowing(), event->IsPresent());
900 event = Schedule->GetFollowingEvent();
902 fprintf(f, "\n\nFollowing event\n\n");
904 fprintf(f, "Event %i eventid = %u time = %lu duration = %li\n", 0, event->GetEventID(), event->GetTime(), event->GetDuration());
905 fprintf(f, "Event %i title = %s subtitle = %s\n", 0, event->GetTitle(), event->GetSubtitle());
906 fprintf(f, "Event %i extendeddescription = %s\n", 0, event->GetExtendedDescription());
907 fprintf(f, "Event %i isFollowing = %i, isPresent = %i\n", 0, event->IsFollowing(), event->IsPresent());
913 fprintf(f, "Event %i eventid = %u time = %lu duration = %li\n", eventNumber, event->GetEventID(), event->GetTime(), event->GetDuration());
914 fprintf(f, "Event %i title = %s subtitle = %s\n", eventNumber, event->GetTitle(), event->GetSubtitle());
915 fprintf(f, "Event %i extendeddescription = %s\n", eventNumber, event->GetExtendedDescription());
916 fprintf(f, "Event %i isFollowing = %i, isPresent = %i\n", eventNumber, event->IsFollowing(), event->IsPresent());
924 void MVPClient::test2()
926 FILE* f = fopen("/tmp/s.txt", "w");
928 #if VDRVERSNUM < 10300
929 cMutexLock MutexLock;
930 const cSchedules *Schedules = cSIProcessor::Schedules(MutexLock);
932 cSchedulesLock MutexLock;
933 const cSchedules *Schedules = cSchedules::Schedules(MutexLock);
938 fprintf(f, "Schedules = NULL\n");
943 fprintf(f, "Schedules dump:\n");
947 const cSchedule *Schedule;
948 int scheduleNumber = 0;
951 cChannel *thisChannel;
953 #if VDRVERSNUM < 10300
954 const cEventInfo *event;
960 // Schedule = Schedules->GetSchedule(channel->GetChannelID());
961 // Schedule = Schedules->GetSchedule();
962 Schedule = Schedules->First();
965 fprintf(f, "First Schedule = NULL\n");
972 fprintf(f, "Schedule #%i\n", scheduleNumber);
973 fprintf(f, "-------------\n\n");
975 #if VDRVERSNUM < 10300
976 tchid = Schedule->GetChannelID();
978 tchid = Schedule->ChannelID();
981 #if VDRVERSNUM < 10300
982 fprintf(f, "ChannelID.ToString() = %s\n", tchid.ToString());
983 fprintf(f, "NumEvents() = %i\n", Schedule->NumEvents());
985 // put the count at the end.
988 thisChannel = Channels.GetByChannelID(tchid, true);
991 fprintf(f, "Channel Number: %p %i\n", thisChannel, thisChannel->Number());
995 fprintf(f, "thisChannel = NULL for tchid\n");
998 #if VDRVERSNUM < 10300
999 for (eventNumber = 0; eventNumber < Schedule->NumEvents(); eventNumber++)
1001 event = Schedule->GetEventNumber(eventNumber);
1002 fprintf(f, "Event %i tableid = %i timestring = %s endtimestring = %s\n", eventNumber, event->GetTableID(), event->GetTimeString(), event->GetEndTimeString());
1003 fprintf(f, "Event %i date = %s isfollowing = %i ispresent = %i\n", eventNumber, event->GetDate(), event->IsFollowing(), event->IsPresent());
1004 fprintf(f, "Event %i extendeddescription = %s\n", eventNumber, event->GetExtendedDescription());
1005 fprintf(f, "Event %i subtitle = %s title = %s\n", eventNumber, event->GetSubtitle(), event->GetTitle());
1006 fprintf(f, "Event %i eventid = %u duration = %li time = %lu channelnumber = %i\n", eventNumber, event->GetEventID(), event->GetDuration(), event->GetTime(), event->GetChannelNumber());
1007 fprintf(f, "Event %u dump:\n", eventNumber);
1012 // This whole section needs rewriting to walk the list.
1013 event = Schedule->Events()->First();
1015 event = Schedule->Events()->Next(event);
1020 fprintf(f, "\nDump from object:\n");
1022 fprintf(f, "\nEND\n");
1032 fprintf(f, "End of current Schedule\n\n\n");
1034 Schedule = (const cSchedule *)Schedules->Next(Schedule);
1048 const cEventInfo *GetPresentEvent(void) const;
1049 const cEventInfo *GetFollowingEvent(void) const;
1050 const cEventInfo *GetEvent(unsigned short uEventID, time_t tTime = 0) const;
1051 const cEventInfo *GetEventAround(time_t tTime) const;
1052 const cEventInfo *GetEventNumber(int n) const { return Events.Get(n); }
1055 const unsigned char GetTableID(void) const;
1056 const char *GetTimeString(void) const;
1057 const char *GetEndTimeString(void) const;
1058 const char *GetDate(void) const;
1059 bool IsFollowing(void) const;
1060 bool IsPresent(void) const;
1061 const char *GetExtendedDescription(void) const;
1062 const char *GetSubtitle(void) const;
1063 const char *GetTitle(void) const;
1064 unsigned short GetEventID(void) const;
1065 long GetDuration(void) const;
1066 time_t GetTime(void) const;
1067 tChannelID GetChannelID(void) const;
1068 int GetChannelNumber(void) const { return nChannelNumber; }
1069 void SetChannelNumber(int ChannelNumber) const { ((cEventInfo *)this)->nChannelNumber = ChannelNumber; } // doesn't modify the EIT data, so it's ok to make it 'const'
1070 void Dump(FILE *f, const char *Prefix = "") const;
1076 void MVPClient::test(int channelNumber)
1078 FILE* f = fopen("/tmp/test.txt", "w");
1080 cMutexLock MutexLock;
1081 const cSchedules *Schedules = cSIProcessor::Schedules(MutexLock);
1085 fprintf(f, "Schedules = NULL\n");
1090 fprintf(f, "Schedules dump:\n");
1091 // Schedules->Dump(f);
1093 const cSchedule *Schedule;
1094 cChannel *thisChannel;
1095 const cEventInfo *event;
1097 thisChannel = channelFromNumber(channelNumber);
1100 fprintf(f, "thisChannel = NULL\n");
1105 Schedule = Schedules->GetSchedule(thisChannel->GetChannelID());
1106 // Schedule = Schedules->GetSchedule();
1107 // Schedule = Schedules->First();
1110 fprintf(f, "First Schedule = NULL\n");
1115 fprintf(f, "NumEvents() = %i\n\n", Schedule->NumEvents());
1117 // For some channels VDR seems to pick a random point in time to
1118 // start dishing out events, but they are in order
1119 // at some point in the list the time snaps to the current event
1124 for (int eventNumber = 0; eventNumber < Schedule->NumEvents(); eventNumber++)
1126 event = Schedule->GetEventNumber(eventNumber);
1127 fprintf(f, "Event %i eventid = %u time = %lu duration = %li\n", eventNumber, event->GetEventID(), event->GetTime(), event->GetDuration());
1128 fprintf(f, "Event %i title = %s subtitle = %s\n", eventNumber, event->GetTitle(), event->GetSubtitle());
1129 fprintf(f, "Event %i extendeddescription = %s\n", eventNumber, event->GetExtendedDescription());
1133 fprintf(f, "\nEND\n");
1147 Schedules = the collection of all the Schedule objects
1148 Schedule = One schedule, contants all the events for a channel
1149 Event = One programme
1158 Subtitle (used for "Programmes resume at ...")
1161 IsPresent ? easy to work out tho. Oh it doesn't always work
1166 void MVPClient::test2()
1168 log->log("-", Log::DEBUG, "Timers List");
1170 for (int i = 0; i < Timers.Count(); i++)
1172 cTimer *timer = Timers.Get(i);
1173 //Reply(i < Timers.Count() - 1 ? -250 : 250, "%d %s", timer->Index() + 1, timer->ToText());
1174 log->log("-", Log::DEBUG, "i=%i count=%i index=%d", i, Timers.Count(), timer->Index() + 1);
1175 #if VDRVERSNUM < 10300
1176 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());
1178 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());
1180 log->log("-", Log::DEBUG, "channel=%i file=%s summary=%s", timer->Channel()->Number(), timer->File(), timer->Summary());
1181 log->log("-", Log::DEBUG, "");
1184 // asprintf(&buffer, "%d:%s:%s :%04d:%04d:%d:%d:%s:%s\n",
1185 // active, (UseChannelID ? Channel()->GetChannelID().ToString() : itoa(Channel()->Number())),
1186 // PrintDay(day, firstday), start, stop, priority, lifetime, file, summary ? summary : "");
1191 Active seems to be a bool - whether the timer should be done or not. If set to inactive it stays around after its time
1192 recording is a bool, 0 for not currently recording, 1 for currently recording
1193 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
1197 int MVPClient::processGetTimers(UCHAR* buffer, int length)
1199 UCHAR* sendBuffer = new UCHAR[50000]; // FIXME hope this is enough
1200 int count = 4; // leave space for the packet length
1204 int numTimers = Timers.Count();
1206 // *(ULONG*)&sendBuffer[count] = htonl(numTimers); count += 4;
1208 for (int i = 0; i < numTimers; i++)
1210 if (count > 49000) break;
1212 timer = Timers.Get(i);
1214 #if VDRVERSNUM < 10300
1215 *(ULONG*)&sendBuffer[count] = htonl(timer->Active()); count += 4;
1217 *(ULONG*)&sendBuffer[count] = htonl(timer->HasFlags(tfActive)); count += 4;
1219 *(ULONG*)&sendBuffer[count] = htonl(timer->Recording()); count += 4;
1220 *(ULONG*)&sendBuffer[count] = htonl(timer->Pending()); count += 4;
1221 *(ULONG*)&sendBuffer[count] = htonl(timer->Priority()); count += 4;
1222 *(ULONG*)&sendBuffer[count] = htonl(timer->Lifetime()); count += 4;
1223 *(ULONG*)&sendBuffer[count] = htonl(timer->Channel()->Number()); count += 4;
1224 *(ULONG*)&sendBuffer[count] = htonl(timer->StartTime()); count += 4;
1225 *(ULONG*)&sendBuffer[count] = htonl(timer->StopTime()); count += 4;
1227 string = timer->File();
1228 strcpy((char*)&sendBuffer[count], string);
1229 count += strlen(string) + 1;
1231 string = timer->Summary();
1234 strcpy((char*)&sendBuffer[count], string);
1235 count += strlen(string) + 1;
1239 sendBuffer[count++] = 0;
1243 *(ULONG*)&sendBuffer[0] = htonl(count - 4); // -4 : take off the size field
1245 log->log("Client", Log::DEBUG, "recorded size as %u", ntohl(*(ULONG*)&sendBuffer[0]));
1247 tcp.sendPacket(sendBuffer, count);
1248 delete[] sendBuffer;
1249 log->log("Client", Log::DEBUG, "Written timers list");