2 Copyright 2004-2005 Chris Tallon
4 This file is part of VOMP.
6 VOMP is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 2 of the License, or
9 (at your option) any later version.
11 VOMP is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
16 You should have received a copy of the GNU General Public License
17 along with VOMP; if not, write to the Free Software
18 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
21 #include "mvpclient.h"
23 // This is here else it causes compile errors with something in libdvbmpeg
26 MVPClient::MVPClient(char* tconfigDirExtra, int tsocket)
31 recordingManager = NULL;
32 log = Log::getInstance();
34 configDirExtra = tconfigDirExtra;
37 MVPClient::~MVPClient()
39 log->log("Client", Log::DEBUG, "MVP client destructor");
50 delete recordingManager;
52 recordingManager = NULL;
55 if (loggedIn) cleanConfig();
58 ULLONG MVPClient::ntohll(ULLONG a)
63 ULLONG MVPClient::htonll(ULLONG a)
65 #if BYTE_ORDER == BIG_ENDIAN
70 b = ((a << 56) & 0xFF00000000000000ULL)
71 | ((a << 40) & 0x00FF000000000000ULL)
72 | ((a << 24) & 0x0000FF0000000000ULL)
73 | ((a << 8) & 0x000000FF00000000ULL)
74 | ((a >> 8) & 0x00000000FF000000ULL)
75 | ((a >> 24) & 0x0000000000FF0000ULL)
76 | ((a >> 40) & 0x000000000000FF00ULL)
77 | ((a >> 56) & 0x00000000000000FFULL) ;
83 cChannel* MVPClient::channelFromNumber(ULONG channelNumber)
85 cChannel* channel = NULL;
87 for (channel = Channels.First(); channel; channel = Channels.Next(channel))
89 if (!channel->GroupSep())
91 log->log("Client", Log::DEBUG, "Looking for channel %lu::: number: %i name: '%s'", channelNumber, channel->Number(), channel->Name());
93 if (channel->Number() == (int)channelNumber)
95 int vpid = channel->Vpid();
96 #if VDRVERSNUM < 10300
97 int apid1 = channel->Apid1();
99 int apid1 = channel->Apid(0);
101 log->log("Client", Log::DEBUG, "Found channel number %lu, vpid = %i, apid1 = %i", channelNumber, vpid, apid1);
109 log->log("Client", Log::DEBUG, "Channel not found");
115 void MVPClient::writeResumeData()
117 config.setValueLongLong("ResumeData", (char*)rp->getCurrentRecording()->FileName(), rp->getLastPosition());
120 void MVPClient::sendULONG(ULONG ul)
123 *(ULONG*)&sendBuffer[0] = htonl(4);
124 *(ULONG*)&sendBuffer[4] = htonl(ul);
126 tcp.sendPacket(sendBuffer, 8);
127 log->log("Client", Log::DEBUG, "written ULONG %lu", ul);
130 void MVPClientStartThread(void* arg)
132 MVPClient* m = (MVPClient*)arg;
134 // Nothing external to this class has a reference to it
135 // This is the end of the thread.. so delete m
142 if (pthread_create(&runThread, NULL, (void*(*)(void*))MVPClientStartThread, (void *)this) == -1) return 0;
143 log->log("Client", Log::DEBUG, "MVPClient run success");
147 void MVPClient::run2()
152 pthread_sigmask(SIG_BLOCK, &sigset, NULL);
153 pthread_detach(runThread); // Detach
155 tcp.disableReadTimeout();
157 tcp.setSoKeepTime(3);
158 tcp.setNonBlocking();
168 log->log("Client", Log::DEBUG, "Waiting");
169 buffer = (UCHAR*)tcp.receivePacket();
170 log->log("Client", Log::DEBUG, "Received packet, length = %u", tcp.getDataLength());
173 log->log("Client", Log::DEBUG, "Detected connection closed");
177 packetLength = tcp.getDataLength() - 4;
178 opcode = ntohl(*(ULONG*)buffer);
181 if (!loggedIn && (opcode != 1))
190 result = processLogin(data, packetLength);
193 result = processGetRecordingsList(data, packetLength);
196 result = processDeleteRecording(data, packetLength);
199 result = processGetSummary(data, packetLength);
202 result = processGetChannelsList(data, packetLength);
205 result = processStartStreamingChannel(data, packetLength);
208 result = processGetBlock(data, packetLength);
211 result = processStopStreaming(data, packetLength);
214 result = processStartStreamingRecording(data, packetLength);
217 result = processGetChannelSchedule(data, packetLength);
220 result = processConfigSave(data, packetLength);
223 result = processConfigLoad(data, packetLength);
226 result = processReScanRecording(data, packetLength);
229 result = processGetTimers(data, packetLength);
232 result = processSetTimer(data, packetLength);
235 result = processPositionFromFrameNumber(data, packetLength);
244 int MVPClient::processLogin(UCHAR* buffer, int length)
246 if (length != 6) return 0;
250 const char* configDir = cPlugin::ConfigDirectory(configDirExtra);
253 log->log("Client", Log::DEBUG, "No config dir!");
257 char configFileName[PATH_MAX];
258 snprintf(configFileName, PATH_MAX, "%s/vomp-%02X-%02X-%02X-%02X-%02X-%02X.conf", configDir, buffer[0], buffer[1], buffer[2], buffer[3], buffer[4], buffer[5]);
259 config.init(configFileName);
261 // Send the login reply
263 time_t timeNow = time(NULL);
264 struct tm* timeStruct = localtime(&timeNow);
265 int timeOffset = timeStruct->tm_gmtoff;
267 UCHAR sendBuffer[12];
268 *(ULONG*)&sendBuffer[0] = htonl(8);
269 *(ULONG*)&sendBuffer[4] = htonl(timeNow);
270 *(signed int*)&sendBuffer[8] = htonl(timeOffset);
272 tcp.sendPacket(sendBuffer, 12);
273 log->log("Client", Log::DEBUG, "written login reply");
279 int MVPClient::processGetRecordingsList(UCHAR* data, int length)
281 UCHAR* sendBuffer = new UCHAR[50000]; // hope this is enough
282 int count = 4; // leave space for the packet length
287 int Percent = VideoDiskSpace(&FreeMB);
288 int Total = (FreeMB / (100 - Percent)) * 100;
290 *(ULONG*)&sendBuffer[count] = htonl(Total);
291 count += sizeof(ULONG);
292 *(ULONG*)&sendBuffer[count] = htonl(FreeMB);
293 count += sizeof(ULONG);
294 *(ULONG*)&sendBuffer[count] = htonl(Percent);
295 count += sizeof(ULONG);
298 cRecordings Recordings;
301 for (cRecording *recording = Recordings.First(); recording; recording = Recordings.Next(recording))
303 if (count > 49000) break; // just how big is that hard disk?!
304 *(ULONG*)&sendBuffer[count] = htonl(recording->start);// + timeOffset);
307 point = (char*)recording->Name();
308 strcpy((char*)&sendBuffer[count], point);
309 count += strlen(point) + 1;
311 point = (char*)recording->FileName();
312 strcpy((char*)&sendBuffer[count], point);
313 count += strlen(point) + 1;
316 *(ULONG*)&sendBuffer[0] = htonl(count - 4); // -4 : take off the size field
318 log->log("Client", Log::DEBUG, "recorded size as %u", ntohl(*(ULONG*)&sendBuffer[0]));
320 tcp.sendPacket(sendBuffer, count);
322 log->log("Client", Log::DEBUG, "Written list");
327 int MVPClient::processDeleteRecording(UCHAR* data, int length)
329 // data is a pointer to the fileName string
331 cRecordings Recordings;
332 Recordings.Load(); // probably have to do this
334 cRecording* recording = Recordings.GetByName((char*)data);
336 log->log("Client", Log::DEBUG, "recording pointer %p", recording);
340 log->log("Client", Log::DEBUG, "deleting recording: %s", recording->Name());
342 cRecordControl *rc = cRecordControls::GetRecordControl(recording->FileName());
345 if (recording->Delete())
347 // Copy svdrp's way of doing this, see if it works
348 #if VDRVERSNUM > 10300
349 ::Recordings.DelByName(recording->FileName());
371 int MVPClient::processGetSummary(UCHAR* data, int length)
373 // data is a pointer to the fileName string
375 cRecordings Recordings;
376 Recordings.Load(); // probably have to do this
378 cRecording *recording = Recordings.GetByName((char*)data);
380 log->log("Client", Log::DEBUG, "recording pointer %p", recording);
384 UCHAR* sendBuffer = new UCHAR[50000]; // hope this is enough
385 int count = 4; // leave space for the packet length
388 #if VDRVERSNUM < 10300
389 point = (char*)recording->Summary();
391 const cRecordingInfo *Info = recording->Info();
392 point = (char*)Info->ShortText();
393 log->log("Client", Log::DEBUG, "info pointer %p summary pointer %p", Info, point);
396 point = (char*)Info->Description();
397 log->log("Client", Log::DEBUG, "description pointer %p", point);
403 strcpy((char*)&sendBuffer[count], point);
404 count += strlen(point) + 1;
408 strcpy((char*)&sendBuffer[count], "");
412 *(ULONG*)&sendBuffer[0] = htonl(count - 4); // -4 : take off the size field
414 log->log("Client", Log::DEBUG, "recorded size as %u", ntohl(*(ULONG*)&sendBuffer[0]));
416 tcp.sendPacket(sendBuffer, count);
418 log->log("Client", Log::DEBUG, "Written summary");
430 int MVPClient::processGetChannelsList(UCHAR* data, int length)
432 UCHAR* sendBuffer = new UCHAR[50000]; // FIXME hope this is enough
433 int count = 4; // leave space for the packet length
437 char* chanConfig = config.getValueString("General", "Channels");
439 if (chanConfig) allChans = strcasecmp(chanConfig, "FTA only");
441 for (cChannel *channel = Channels.First(); channel; channel = Channels.Next(channel))
443 #if VDRVERSNUM < 10300
444 if (!channel->GroupSep() && (!channel->Ca() || allChans))
446 if (!channel->GroupSep() && (!channel->Ca(0) || allChans))
449 log->log("Client", Log::DEBUG, "name: '%s'", channel->Name());
451 if (channel->Vpid()) type = 1;
452 #if VDRVERSNUM < 10300
455 else if (channel->Apid(0)) type = 2;
459 if (count > 49000) break;
460 *(ULONG*)&sendBuffer[count] = htonl(channel->Number());
463 *(ULONG*)&sendBuffer[count] = htonl(type);
466 point = (char*)channel->Name();
467 strcpy((char*)&sendBuffer[count], point);
468 count += strlen(point) + 1;
472 *(ULONG*)&sendBuffer[0] = htonl(count - 4); // -4 : take off the size field
474 log->log("Client", Log::DEBUG, "recorded size as %u", ntohl(*(ULONG*)&sendBuffer[0]));
476 tcp.sendPacket(sendBuffer, count);
478 log->log("Client", Log::DEBUG, "Written channels list");
483 int MVPClient::processStartStreamingChannel(UCHAR* data, int length)
485 log->log("Client", Log::DEBUG, "length = %i", length);
486 ULONG channelNumber = ntohl(*(ULONG*)data);
488 cChannel* channel = channelFromNumber(channelNumber);
495 // get the priority we should use
497 int priority = config.getValueLong("General", "Live priority", &fail);
500 log->log("Client", Log::DEBUG, "Config: Live TV priority: %i", priority);
504 log->log("Client", Log::DEBUG, "Config: Live TV priority config fail");
509 if (priority < 0) priority = 0;
510 if (priority > 99) priority = 99;
512 log->log("Client", Log::DEBUG, "Using live TV priority %i", priority);
513 lp = MVPReceiver::create(channel, priority);
533 int MVPClient::processStopStreaming(UCHAR* data, int length)
535 log->log("Client", Log::DEBUG, "STOP STREAMING RECEIVED");
546 delete recordingManager;
548 recordingManager = NULL;
555 int MVPClient::processGetBlock(UCHAR* data, int length)
559 log->log("Client", Log::DEBUG, "Get block called when no streaming happening!");
563 ULLONG position = ntohll(*(ULLONG*)data);
564 data += sizeof(ULLONG);
565 ULONG amount = ntohl(*(ULONG*)data);
567 log->log("Client", Log::DEBUG, "getblock pos = %llu length = %lu", position, amount);
569 UCHAR sendBuffer[amount + 4];
570 ULONG amountReceived = 0; // compiler moan.
573 log->log("Client", Log::DEBUG, "getting from live");
574 amountReceived = lp->getBlock(&sendBuffer[4], amount);
578 // vdr has possibly disconnected the receiver
579 log->log("Client", Log::DEBUG, "VDR has disconnected the live receiver");
586 log->log("Client", Log::DEBUG, "getting from recording");
587 amountReceived = rp->getBlock(&sendBuffer[4], position, amount);
593 log->log("Client", Log::DEBUG, "written 4(0) as getblock got 0");
597 *(ULONG*)&sendBuffer[0] = htonl(amountReceived);
598 tcp.sendPacket(sendBuffer, amountReceived + 4);
599 log->log("Client", Log::DEBUG, "written ok %lu", amountReceived);
605 int MVPClient::processStartStreamingRecording(UCHAR* data, int length)
607 // data is a pointer to the fileName string
609 recordingManager = new cRecordings;
610 recordingManager->Load();
612 cRecording* recording = recordingManager->GetByName((char*)data);
614 log->log("Client", Log::DEBUG, "recording pointer %p", recording);
618 rp = new RecPlayer(recording);
620 UCHAR sendBuffer[12];
621 *(ULONG*)&sendBuffer[0] = htonl(8);
622 *(ULLONG*)&sendBuffer[4] = htonll(rp->getTotalLength());
624 tcp.sendPacket(sendBuffer, 12);
625 log->log("Client", Log::DEBUG, "written totalLength");
629 delete recordingManager;
630 recordingManager = NULL;
635 int MVPClient::processReScanRecording(UCHAR* data, int length)
641 log->log("Client", Log::DEBUG, "Rescan recording called when no recording being played!");
646 retval = rp->getTotalLength();
649 UCHAR sendBuffer[12];
650 *(ULONG*)&sendBuffer[0] = htonl(8);
651 *(ULLONG*)&sendBuffer[4] = htonll(retval);
653 tcp.sendPacket(sendBuffer, 12);
654 log->log("Client", Log::DEBUG, "Rescan recording, wrote new length to client");
658 int MVPClient::processPositionFromFrameNumber(UCHAR* data, int length)
662 ULONG frameNumber = ntohl(*(ULONG*)data);
667 log->log("Client", Log::DEBUG, "Rescan recording called when no recording being played!");
671 retval = rp->positionFromFrameNumber(frameNumber);
674 UCHAR sendBuffer[12];
675 *(ULONG*)&sendBuffer[0] = htonl(8);
676 *(ULLONG*)&sendBuffer[4] = htonll(retval);
678 tcp.sendPacket(sendBuffer, 12);
679 log->log("Client", Log::DEBUG, "Wrote posFromFrameNum reply to client");
683 int MVPClient::processGetChannelSchedule(UCHAR* data, int length)
685 ULONG channelNumber = ntohl(*(ULONG*)data);
687 ULONG startTime = ntohl(*(ULONG*)data);
689 ULONG duration = ntohl(*(ULONG*)data);
691 log->log("Client", Log::DEBUG, "get schedule called for channel %lu", channelNumber);
693 cChannel* channel = channelFromNumber(channelNumber);
697 log->log("Client", Log::DEBUG, "written 0 because channel = NULL");
701 log->log("Client", Log::DEBUG, "Got channel");
703 #if VDRVERSNUM < 10300
704 cMutexLock MutexLock;
705 const cSchedules *Schedules = cSIProcessor::Schedules(MutexLock);
707 cSchedulesLock MutexLock;
708 const cSchedules *Schedules = cSchedules::Schedules(MutexLock);
713 log->log("Client", Log::DEBUG, "written 0 because Schedule!s! = NULL");
717 log->log("Client", Log::DEBUG, "Got schedule!s! object");
719 const cSchedule *Schedule = Schedules->GetSchedule(channel->GetChannelID());
723 log->log("Client", Log::DEBUG, "written 0 because Schedule = NULL");
727 log->log("Client", Log::DEBUG, "Got schedule object");
729 UCHAR* sendBuffer = (UCHAR*)malloc(100000);
730 ULONG sendBufferLength = 100000;
731 ULONG sendBufferUsed = sizeof(ULONG); // leave a hole for the entire packet length
735 // assign all the event info to temp vars then we know exactly what size they are
738 ULONG thisEventDuration;
739 const char* thisEventTitle;
740 const char* thisEventSubTitle;
741 const char* thisEventDescription;
743 ULONG constEventLength = sizeof(thisEventID) + sizeof(thisEventTime) + sizeof(thisEventDuration);
744 ULONG thisEventLength;
746 #if VDRVERSNUM < 10300
748 const cEventInfo *event;
749 for (int eventNumber = 0; eventNumber < Schedule->NumEvents(); eventNumber++)
751 event = Schedule->GetEventNumber(eventNumber);
753 thisEventID = event->GetEventID();
754 thisEventTime = event->GetTime();
755 thisEventDuration = event->GetDuration();
756 thisEventTitle = event->GetTitle();
757 thisEventSubTitle = event->GetSubtitle();
758 thisEventDescription = event->GetExtendedDescription();
762 for (const cEvent* event = Schedule->Events()->First(); event; event = Schedule->Events()->Next(event))
764 thisEventID = event->EventID();
765 thisEventTime = event->StartTime();
766 thisEventDuration = event->Duration();
767 thisEventTitle = event->Title();
768 thisEventSubTitle = NULL;
769 thisEventDescription = event->Description();
773 log->log("Client", Log::DEBUG, "Got an event object %p", event);
776 if ((thisEventTime + thisEventDuration) < (ULONG)time(NULL)) continue;
779 if ((thisEventTime + thisEventDuration) <= startTime) continue;
782 if (thisEventTime >= (startTime + duration)) continue;
784 if (!thisEventTitle) thisEventTitle = empty;
785 if (!thisEventSubTitle) thisEventSubTitle = empty;
786 if (!thisEventDescription) thisEventDescription = empty;
788 thisEventLength = constEventLength + strlen(thisEventTitle) + 1 + strlen(thisEventSubTitle) + 1 + strlen(thisEventDescription) + 1;
790 log->log("Client", Log::DEBUG, "Done s1");
792 // now extend the buffer if necessary
793 if ((sendBufferUsed + thisEventLength) > sendBufferLength)
795 log->log("Client", Log::DEBUG, "Extending buffer");
796 sendBufferLength += 100000;
797 UCHAR* temp = (UCHAR*)realloc(sendBuffer, sendBufferLength);
801 UCHAR sendBuffer2[8];
802 *(ULONG*)&sendBuffer2[0] = htonl(4);
803 *(ULONG*)&sendBuffer2[4] = htonl(0);
804 tcp.sendPacket(sendBuffer2, 8);
805 log->log("Client", Log::DEBUG, "written 0 because failed to realloc packet");
811 log->log("Client", Log::DEBUG, "Done s2");
813 *(ULONG*)&sendBuffer[sendBufferUsed] = htonl(thisEventID); sendBufferUsed += sizeof(ULONG);
814 *(ULONG*)&sendBuffer[sendBufferUsed] = htonl(thisEventTime); sendBufferUsed += sizeof(ULONG);
815 *(ULONG*)&sendBuffer[sendBufferUsed] = htonl(thisEventDuration); sendBufferUsed += sizeof(ULONG);
817 strcpy((char*)&sendBuffer[sendBufferUsed], thisEventTitle); sendBufferUsed += strlen(thisEventTitle) + 1;
818 strcpy((char*)&sendBuffer[sendBufferUsed], thisEventSubTitle); sendBufferUsed += strlen(thisEventSubTitle) + 1;
819 strcpy((char*)&sendBuffer[sendBufferUsed], thisEventDescription); sendBufferUsed += strlen(thisEventDescription) + 1;
821 log->log("Client", Log::DEBUG, "Done s3 %lu", sendBufferUsed);
824 log->log("Client", Log::DEBUG, "Got all event data");
826 if (sendBufferUsed == sizeof(ULONG))
830 log->log("Client", Log::DEBUG, "Written 0 because no data");
834 // Write the length into the first 4 bytes. It's sendBufferUsed - 4 because of the hole!
835 *(ULONG*)&sendBuffer[0] = htonl(sendBufferUsed - sizeof(ULONG));
836 tcp.sendPacket(sendBuffer, sendBufferUsed);
837 log->log("Client", Log::DEBUG, "written %lu schedules packet", sendBufferUsed);
845 int MVPClient::processConfigSave(UCHAR* buffer, int length)
847 char* section = (char*)buffer;
851 for (int k = 0; k < length; k++)
853 if (buffer[k] == '\0')
857 key = (char*)&buffer[k+1];
861 value = (char*)&buffer[k+1];
867 // if the last string (value) doesnt have null terminator, give up
868 if (buffer[length - 1] != '\0') return 0;
870 log->log("Client", Log::DEBUG, "Config save: %s %s %s", section, key, value);
871 if (config.setValueString(section, key, value))
883 int MVPClient::processConfigLoad(UCHAR* buffer, int length)
885 char* section = (char*)buffer;
888 for (int k = 0; k < length; k++)
890 if (buffer[k] == '\0')
892 key = (char*)&buffer[k+1];
897 char* value = config.getValueString(section, key);
901 UCHAR sendBuffer[4 + strlen(value) + 1];
902 *(ULONG*)&sendBuffer[0] = htonl(strlen(value) + 1);
903 strcpy((char*)&sendBuffer[4], value);
904 tcp.sendPacket(sendBuffer, 4 + strlen(value) + 1);
906 log->log("Client", Log::DEBUG, "Written config load packet");
912 *(ULONG*)&sendBuffer[0] = htonl(4);
913 *(ULONG*)&sendBuffer[4] = htonl(0);
914 tcp.sendPacket(sendBuffer, 8);
916 log->log("Client", Log::DEBUG, "Written config load failed packet");
922 void MVPClient::cleanConfig()
924 log->log("Client", Log::DEBUG, "Clean config");
926 cRecordings Recordings;
931 char* resumes = config.getSectionKeyNames("ResumeData", numReturns, length);
932 char* position = resumes;
933 for(int k = 0; k < numReturns; k++)
935 log->log("Client", Log::DEBUG, "EXAMINING: %i %i %p %s", k, numReturns, position, position);
937 cRecording* recording = Recordings.GetByName(position);
940 // doesn't exist anymore
941 log->log("Client", Log::DEBUG, "Found a recording that doesn't exist anymore");
942 config.deleteValue("ResumeData", position);
946 log->log("Client", Log::DEBUG, "This recording still exists");
949 position += strlen(position) + 1;
961 event = Schedule->GetPresentEvent();
963 fprintf(f, "\n\nCurrent event\n\n");
965 fprintf(f, "Event %i eventid = %u time = %lu duration = %li\n", 0, event->GetEventID(), event->GetTime(), event->GetDuration());
966 fprintf(f, "Event %i title = %s subtitle = %s\n", 0, event->GetTitle(), event->GetSubtitle());
967 fprintf(f, "Event %i extendeddescription = %s\n", 0, event->GetExtendedDescription());
968 fprintf(f, "Event %i isFollowing = %i, isPresent = %i\n", 0, event->IsFollowing(), event->IsPresent());
970 event = Schedule->GetFollowingEvent();
972 fprintf(f, "\n\nFollowing event\n\n");
974 fprintf(f, "Event %i eventid = %u time = %lu duration = %li\n", 0, event->GetEventID(), event->GetTime(), event->GetDuration());
975 fprintf(f, "Event %i title = %s subtitle = %s\n", 0, event->GetTitle(), event->GetSubtitle());
976 fprintf(f, "Event %i extendeddescription = %s\n", 0, event->GetExtendedDescription());
977 fprintf(f, "Event %i isFollowing = %i, isPresent = %i\n", 0, event->IsFollowing(), event->IsPresent());
983 fprintf(f, "Event %i eventid = %u time = %lu duration = %li\n", eventNumber, event->GetEventID(), event->GetTime(), event->GetDuration());
984 fprintf(f, "Event %i title = %s subtitle = %s\n", eventNumber, event->GetTitle(), event->GetSubtitle());
985 fprintf(f, "Event %i extendeddescription = %s\n", eventNumber, event->GetExtendedDescription());
986 fprintf(f, "Event %i isFollowing = %i, isPresent = %i\n", eventNumber, event->IsFollowing(), event->IsPresent());
994 void MVPClient::test2()
996 FILE* f = fopen("/tmp/s.txt", "w");
998 #if VDRVERSNUM < 10300
999 cMutexLock MutexLock;
1000 const cSchedules *Schedules = cSIProcessor::Schedules(MutexLock);
1002 cSchedulesLock MutexLock;
1003 const cSchedules *Schedules = cSchedules::Schedules(MutexLock);
1008 fprintf(f, "Schedules = NULL\n");
1013 fprintf(f, "Schedules dump:\n");
1017 const cSchedule *Schedule;
1018 int scheduleNumber = 0;
1021 cChannel *thisChannel;
1023 #if VDRVERSNUM < 10300
1024 const cEventInfo *event;
1025 int eventNumber = 0;
1027 const cEvent *event;
1030 // Schedule = Schedules->GetSchedule(channel->GetChannelID());
1031 // Schedule = Schedules->GetSchedule();
1032 Schedule = Schedules->First();
1035 fprintf(f, "First Schedule = NULL\n");
1042 fprintf(f, "Schedule #%i\n", scheduleNumber);
1043 fprintf(f, "-------------\n\n");
1045 #if VDRVERSNUM < 10300
1046 tchid = Schedule->GetChannelID();
1048 tchid = Schedule->ChannelID();
1051 #if VDRVERSNUM < 10300
1052 fprintf(f, "ChannelID.ToString() = %s\n", tchid.ToString());
1053 fprintf(f, "NumEvents() = %i\n", Schedule->NumEvents());
1055 // put the count at the end.
1058 thisChannel = Channels.GetByChannelID(tchid, true);
1061 fprintf(f, "Channel Number: %p %i\n", thisChannel, thisChannel->Number());
1065 fprintf(f, "thisChannel = NULL for tchid\n");
1068 #if VDRVERSNUM < 10300
1069 for (eventNumber = 0; eventNumber < Schedule->NumEvents(); eventNumber++)
1071 event = Schedule->GetEventNumber(eventNumber);
1072 fprintf(f, "Event %i tableid = %i timestring = %s endtimestring = %s\n", eventNumber, event->GetTableID(), event->GetTimeString(), event->GetEndTimeString());
1073 fprintf(f, "Event %i date = %s isfollowing = %i ispresent = %i\n", eventNumber, event->GetDate(), event->IsFollowing(), event->IsPresent());
1074 fprintf(f, "Event %i extendeddescription = %s\n", eventNumber, event->GetExtendedDescription());
1075 fprintf(f, "Event %i subtitle = %s title = %s\n", eventNumber, event->GetSubtitle(), event->GetTitle());
1076 fprintf(f, "Event %i eventid = %u duration = %li time = %lu channelnumber = %i\n", eventNumber, event->GetEventID(), event->GetDuration(), event->GetTime(), event->GetChannelNumber());
1077 fprintf(f, "Event %u dump:\n", eventNumber);
1082 // This whole section needs rewriting to walk the list.
1083 event = Schedule->Events()->First();
1085 event = Schedule->Events()->Next(event);
1090 fprintf(f, "\nDump from object:\n");
1092 fprintf(f, "\nEND\n");
1102 fprintf(f, "End of current Schedule\n\n\n");
1104 Schedule = (const cSchedule *)Schedules->Next(Schedule);
1118 const cEventInfo *GetPresentEvent(void) const;
1119 const cEventInfo *GetFollowingEvent(void) const;
1120 const cEventInfo *GetEvent(unsigned short uEventID, time_t tTime = 0) const;
1121 const cEventInfo *GetEventAround(time_t tTime) const;
1122 const cEventInfo *GetEventNumber(int n) const { return Events.Get(n); }
1125 const unsigned char GetTableID(void) const;
1126 const char *GetTimeString(void) const;
1127 const char *GetEndTimeString(void) const;
1128 const char *GetDate(void) const;
1129 bool IsFollowing(void) const;
1130 bool IsPresent(void) const;
1131 const char *GetExtendedDescription(void) const;
1132 const char *GetSubtitle(void) const;
1133 const char *GetTitle(void) const;
1134 unsigned short GetEventID(void) const;
1135 long GetDuration(void) const;
1136 time_t GetTime(void) const;
1137 tChannelID GetChannelID(void) const;
1138 int GetChannelNumber(void) const { return nChannelNumber; }
1139 void SetChannelNumber(int ChannelNumber) const { ((cEventInfo *)this)->nChannelNumber = ChannelNumber; } // doesn't modify the EIT data, so it's ok to make it 'const'
1140 void Dump(FILE *f, const char *Prefix = "") const;
1146 void MVPClient::test(int channelNumber)
1148 FILE* f = fopen("/tmp/test.txt", "w");
1150 cMutexLock MutexLock;
1151 const cSchedules *Schedules = cSIProcessor::Schedules(MutexLock);
1155 fprintf(f, "Schedules = NULL\n");
1160 fprintf(f, "Schedules dump:\n");
1161 // Schedules->Dump(f);
1163 const cSchedule *Schedule;
1164 cChannel *thisChannel;
1165 const cEventInfo *event;
1167 thisChannel = channelFromNumber(channelNumber);
1170 fprintf(f, "thisChannel = NULL\n");
1175 Schedule = Schedules->GetSchedule(thisChannel->GetChannelID());
1176 // Schedule = Schedules->GetSchedule();
1177 // Schedule = Schedules->First();
1180 fprintf(f, "First Schedule = NULL\n");
1185 fprintf(f, "NumEvents() = %i\n\n", Schedule->NumEvents());
1187 // For some channels VDR seems to pick a random point in time to
1188 // start dishing out events, but they are in order
1189 // at some point in the list the time snaps to the current event
1194 for (int eventNumber = 0; eventNumber < Schedule->NumEvents(); eventNumber++)
1196 event = Schedule->GetEventNumber(eventNumber);
1197 fprintf(f, "Event %i eventid = %u time = %lu duration = %li\n", eventNumber, event->GetEventID(), event->GetTime(), event->GetDuration());
1198 fprintf(f, "Event %i title = %s subtitle = %s\n", eventNumber, event->GetTitle(), event->GetSubtitle());
1199 fprintf(f, "Event %i extendeddescription = %s\n", eventNumber, event->GetExtendedDescription());
1203 fprintf(f, "\nEND\n");
1217 Schedules = the collection of all the Schedule objects
1218 Schedule = One schedule, contants all the events for a channel
1219 Event = One programme
1228 Subtitle (used for "Programmes resume at ...")
1231 IsPresent ? easy to work out tho. Oh it doesn't always work
1236 void MVPClient::test2()
1238 log->log("-", Log::DEBUG, "Timers List");
1240 for (int i = 0; i < Timers.Count(); i++)
1242 cTimer *timer = Timers.Get(i);
1243 //Reply(i < Timers.Count() - 1 ? -250 : 250, "%d %s", timer->Index() + 1, timer->ToText());
1244 log->log("-", Log::DEBUG, "i=%i count=%i index=%d", i, Timers.Count(), timer->Index() + 1);
1245 #if VDRVERSNUM < 10300
1246 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());
1248 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());
1250 log->log("-", Log::DEBUG, "channel=%i file=%s summary=%s", timer->Channel()->Number(), timer->File(), timer->Summary());
1251 log->log("-", Log::DEBUG, "");
1254 // asprintf(&buffer, "%d:%s:%s :%04d:%04d:%d:%d:%s:%s\n",
1255 // active, (UseChannelID ? Channel()->GetChannelID().ToString() : itoa(Channel()->Number())),
1256 // PrintDay(day, firstday), start, stop, priority, lifetime, file, summary ? summary : "");
1261 Active seems to be a bool - whether the timer should be done or not. If set to inactive it stays around after its time
1262 recording is a bool, 0 for not currently recording, 1 for currently recording
1263 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
1267 int MVPClient::processGetTimers(UCHAR* buffer, int length)
1269 UCHAR* sendBuffer = new UCHAR[50000]; // FIXME hope this is enough
1270 int count = 4; // leave space for the packet length
1272 const char* fileName;
1274 int numTimers = Timers.Count();
1276 *(ULONG*)&sendBuffer[count] = htonl(numTimers); count += 4;
1278 for (int i = 0; i < numTimers; i++)
1280 if (count > 49000) break;
1282 timer = Timers.Get(i);
1284 #if VDRVERSNUM < 10300
1285 *(ULONG*)&sendBuffer[count] = htonl(timer->Active()); count += 4;
1287 *(ULONG*)&sendBuffer[count] = htonl(timer->HasFlags(tfActive)); count += 4;
1289 *(ULONG*)&sendBuffer[count] = htonl(timer->Recording()); count += 4;
1290 *(ULONG*)&sendBuffer[count] = htonl(timer->Pending()); count += 4;
1291 *(ULONG*)&sendBuffer[count] = htonl(timer->Priority()); count += 4;
1292 *(ULONG*)&sendBuffer[count] = htonl(timer->Lifetime()); count += 4;
1293 *(ULONG*)&sendBuffer[count] = htonl(timer->Channel()->Number()); count += 4;
1294 *(ULONG*)&sendBuffer[count] = htonl(timer->StartTime()); count += 4;
1295 *(ULONG*)&sendBuffer[count] = htonl(timer->StopTime()); count += 4;
1297 fileName = timer->File();
1298 strcpy((char*)&sendBuffer[count], fileName);
1299 count += strlen(fileName) + 1;
1302 *(ULONG*)&sendBuffer[0] = htonl(count - 4); // -4 : take off the size field
1304 log->log("Client", Log::DEBUG, "recorded size as %u", ntohl(*(ULONG*)&sendBuffer[0]));
1306 tcp.sendPacket(sendBuffer, count);
1307 delete[] sendBuffer;
1308 log->log("Client", Log::DEBUG, "Written timers list");
1313 int MVPClient::processSetTimer(UCHAR* buffer, int length)
1315 char* timerString = new char[strlen((char*)buffer) + 1];
1316 strcpy(timerString, (char*)buffer);
1318 #if VDRVERSNUM < 10300
1320 // If this is VDR 1.2 the date part of the timer string must be reduced
1321 // to just DD rather than YYYY-MM-DD
1323 int s = 0; // source
1324 int d = 0; // destination
1326 while(c != 2) // copy up to date section, including the second ':'
1328 timerString[d] = buffer[s];
1329 if (buffer[s] == ':') c++;
1333 // now it has copied up to the date section
1335 while(c != 2) // waste YYYY-MM-
1337 if (buffer[s] == '-') c++;
1340 // now source is at the DD
1341 memcpy(&timerString[d], &buffer[s], length - s);
1343 timerString[d] = '\0';
1345 log->log("Client", Log::DEBUG, "Timer string after 1.2 conversion:");
1346 log->log("Client", Log::DEBUG, "%s", timerString);
1350 cTimer *timer = new cTimer;
1351 if (timer->Parse((char*)timerString))
1353 cTimer *t = Timers.GetTimer(timer);
1357 #if VDRVERSNUM < 10300
1360 Timers.SetModified();