log->log("Client", Log::DEBUG, "Config file name: %s", configFileName);
-// processGetChannelSchedule(NULL, 0);
-//test();
+//test(14);
}
cleanConfig();
}
-cChannel* MVPClient::channelFromNumber(unsigned long channelNumber)
+cChannel* MVPClient::channelFromNumber(ULONG channelNumber)
{
cChannel* channel = NULL;
void MVPClient::sendULONG(ULONG ul)
{
- unsigned char sendBuffer[8];
- *(unsigned long*)&sendBuffer[0] = htonl(4);
- *(unsigned long*)&sendBuffer[4] = htonl(ul);
+ UCHAR sendBuffer[8];
+ *(ULONG*)&sendBuffer[0] = htonl(4);
+ *(ULONG*)&sendBuffer[4] = htonl(ul);
tcp.sendPacket(sendBuffer, 8);
log->log("Client", Log::DEBUG, "written ULONG %lu", ul);
tcp.setSoKeepTime(3);
tcp.setNonBlocking();
- unsigned char* buffer;
- unsigned char* data;
+ UCHAR* buffer;
+ UCHAR* data;
int packetLength;
- unsigned long opcode;
+ ULONG opcode;
while(1)
{
log->log("Client", Log::DEBUG, "Waiting");
- buffer = (unsigned char*)tcp.receivePacket();
+ buffer = (UCHAR*)tcp.receivePacket();
log->log("Client", Log::DEBUG, "Received packet, length = %u", tcp.getDataLength());
if (buffer == NULL)
{
}
packetLength = tcp.getDataLength() - 4;
- opcode = ntohl(*(unsigned long*)buffer);
+ opcode = ntohl(*(ULONG*)buffer);
data = buffer + 4;
}
}
-void MVPClient::processLogin(unsigned char* buffer, int length)
+void MVPClient::processLogin(UCHAR* buffer, int length)
{
time_t timeNow = time(NULL);
struct tm* timeStruct = localtime(&timeNow);
int timeOffset = timeStruct->tm_gmtoff;
- unsigned char sendBuffer[12];
- *(unsigned long*)&sendBuffer[0] = htonl(8);
- *(unsigned long*)&sendBuffer[4] = htonl(timeNow);
+ UCHAR sendBuffer[12];
+ *(ULONG*)&sendBuffer[0] = htonl(8);
+ *(ULONG*)&sendBuffer[4] = htonl(timeNow);
*(signed int*)&sendBuffer[8] = htonl(timeOffset);
tcp.sendPacket(sendBuffer, 12);
log->log("Client", Log::DEBUG, "written login reply");
}
-void MVPClient::processGetRecordingsList(unsigned char* data, int length)
+void MVPClient::processGetRecordingsList(UCHAR* data, int length)
{
- unsigned char* sendBuffer = new unsigned char[50000]; // hope this is enough
+ UCHAR* sendBuffer = new UCHAR[50000]; // hope this is enough
int count = 4; // leave space for the packet length
char* point;
int Percent = VideoDiskSpace(&FreeMB);
int Total = (FreeMB / (100 - Percent)) * 100;
- *(unsigned long*)&sendBuffer[count] = htonl(Total);
- count += sizeof(unsigned long);
- *(unsigned long*)&sendBuffer[count] = htonl(FreeMB);
- count += sizeof(unsigned long);
- *(unsigned long*)&sendBuffer[count] = htonl(Percent);
- count += sizeof(unsigned long);
+ *(ULONG*)&sendBuffer[count] = htonl(Total);
+ count += sizeof(ULONG);
+ *(ULONG*)&sendBuffer[count] = htonl(FreeMB);
+ count += sizeof(ULONG);
+ *(ULONG*)&sendBuffer[count] = htonl(Percent);
+ count += sizeof(ULONG);
cRecordings Recordings;
for (cRecording *recording = Recordings.First(); recording; recording = Recordings.Next(recording))
{
if (count > 49000) break; // just how big is that hard disk?!
- *(unsigned long*)&sendBuffer[count] = htonl(recording->start);// + timeOffset);
+ *(ULONG*)&sendBuffer[count] = htonl(recording->start);// + timeOffset);
count += 4;
point = (char*)recording->Name();
count += strlen(point) + 1;
}
- *(unsigned long*)&sendBuffer[0] = htonl(count - 4); // -4 : take off the size field
+ *(ULONG*)&sendBuffer[0] = htonl(count - 4); // -4 : take off the size field
- log->log("Client", Log::DEBUG, "recorded size as %u", ntohl(*(unsigned long*)&sendBuffer[0]));
+ log->log("Client", Log::DEBUG, "recorded size as %u", ntohl(*(ULONG*)&sendBuffer[0]));
tcp.sendPacket(sendBuffer, count);
delete[] sendBuffer;
log->log("Client", Log::DEBUG, "Written list");
}
-void MVPClient::processDeleteRecording(unsigned char* data, int length)
+void MVPClient::processDeleteRecording(UCHAR* data, int length)
{
// data is a pointer to the fileName string
}
}
-void MVPClient::processGetSummary(unsigned char* data, int length)
+void MVPClient::processGetSummary(UCHAR* data, int length)
{
// data is a pointer to the fileName string
if (recording)
{
- unsigned char* sendBuffer = new unsigned char[50000]; // hope this is enough
+ UCHAR* sendBuffer = new UCHAR[50000]; // hope this is enough
int count = 4; // leave space for the packet length
char* point;
#endif
strcpy((char*)&sendBuffer[count], point);
count += strlen(point) + 1;
- *(unsigned long*)&sendBuffer[0] = htonl(count - 4); // -4 : take off the size field
+ *(ULONG*)&sendBuffer[0] = htonl(count - 4); // -4 : take off the size field
- log->log("Client", Log::DEBUG, "recorded size as %u", ntohl(*(unsigned long*)&sendBuffer[0]));
+ log->log("Client", Log::DEBUG, "recorded size as %u", ntohl(*(ULONG*)&sendBuffer[0]));
tcp.sendPacket(sendBuffer, count);
delete[] sendBuffer;
}
}
-void MVPClient::processGetChannelsList(unsigned char* data, int length)
+void MVPClient::processGetChannelsList(UCHAR* data, int length)
{
- unsigned char* sendBuffer = new unsigned char[50000]; // FIXME hope this is enough
+ UCHAR* sendBuffer = new UCHAR[50000]; // FIXME hope this is enough
int count = 4; // leave space for the packet length
char* point;
- unsigned long type;
+ ULONG type;
for (cChannel *channel = Channels.First(); channel; channel = Channels.Next(channel))
{
#endif
if (count > 49000) break;
- *(unsigned long*)&sendBuffer[count] = htonl(channel->Number());
+ *(ULONG*)&sendBuffer[count] = htonl(channel->Number());
count += 4;
- *(unsigned long*)&sendBuffer[count] = htonl(type);
+ *(ULONG*)&sendBuffer[count] = htonl(type);
count += 4;
point = (char*)channel->Name();
}
}
- *(unsigned long*)&sendBuffer[0] = htonl(count - 4); // -4 : take off the size field
+ *(ULONG*)&sendBuffer[0] = htonl(count - 4); // -4 : take off the size field
- log->log("Client", Log::DEBUG, "recorded size as %u", ntohl(*(unsigned long*)&sendBuffer[0]));
+ log->log("Client", Log::DEBUG, "recorded size as %u", ntohl(*(ULONG*)&sendBuffer[0]));
tcp.sendPacket(sendBuffer, count);
delete[] sendBuffer;
log->log("Client", Log::DEBUG, "Written channels list");
}
-void MVPClient::processStartStreamingChannel(unsigned char* data, int length)
+void MVPClient::processStartStreamingChannel(UCHAR* data, int length)
{
log->log("Client", Log::DEBUG, "length = %i", length);
- unsigned long channelNumber = ntohl(*(unsigned long*)data);
+ ULONG channelNumber = ntohl(*(ULONG*)data);
cChannel* channel = channelFromNumber(channelNumber);
if (!channel)
sendULONG(1);
}
-void MVPClient::processStopStreaming(unsigned char* data, int length)
+void MVPClient::processStopStreaming(UCHAR* data, int length)
{
log->log("Client", Log::DEBUG, "STOP STREAMING RECEIVED");
if (lp)
sendULONG(1);
}
-void MVPClient::processGetBlock(unsigned char* data, int length)
+void MVPClient::processGetBlock(UCHAR* data, int length)
{
if (!lp && !rp)
{
ULLONG position = ntohll(*(ULLONG*)data);
data += sizeof(ULLONG);
- unsigned long amount = ntohl(*(unsigned long*)data);
+ ULONG amount = ntohl(*(ULONG*)data);
log->log("Client", Log::DEBUG, "getblock pos = %llu length = %lu", position, amount);
- unsigned char sendBuffer[amount + 4];
- unsigned long amountReceived = 0; // compiler moan.
+ UCHAR sendBuffer[amount + 4];
+ ULONG amountReceived = 0; // compiler moan.
if (lp)
{
log->log("Client", Log::DEBUG, "getting from live");
amountReceived = rp->getBlock(&sendBuffer[4], position, amount);
}
- *(unsigned long*)&sendBuffer[0] = htonl(amountReceived);
+ *(ULONG*)&sendBuffer[0] = htonl(amountReceived);
tcp.sendPacket(sendBuffer, amountReceived + 4);
log->log("Client", Log::DEBUG, "written ok %lu", amountReceived);
}
-void MVPClient::processStartStreamingRecording(unsigned char* data, int length)
+void MVPClient::processStartStreamingRecording(UCHAR* data, int length)
{
// data is a pointer to the fileName string
{
rp = new RecPlayer(recording);
- unsigned char sendBuffer[12];
- *(unsigned long*)&sendBuffer[0] = htonl(8);
+ UCHAR sendBuffer[12];
+ *(ULONG*)&sendBuffer[0] = htonl(8);
*(ULLONG*)&sendBuffer[4] = htonll(rp->getTotalLength());
tcp.sendPacket(sendBuffer, 12);
}
}
-void MVPClient::processReScanRecording(unsigned char* data, int length)
+void MVPClient::processReScanRecording(UCHAR* data, int length)
{
ULLONG retval = 0;
retval = rp->getTotalLength();
}
- unsigned char sendBuffer[12];
- *(unsigned long*)&sendBuffer[0] = htonl(8);
+ UCHAR sendBuffer[12];
+ *(ULONG*)&sendBuffer[0] = htonl(8);
*(ULLONG*)&sendBuffer[4] = htonll(retval);
tcp.sendPacket(sendBuffer, 12);
log->log("Client", Log::DEBUG, "Rescan recording, wrote new length to client");
}
-void MVPClient::processGetChannelSchedule(unsigned char* data, int length)
+void MVPClient::processGetChannelSchedule(UCHAR* data, int length)
{
ULONG channelNumber = ntohl(*(ULLONG*)data);
log->log("Client", Log::DEBUG, "get schedule called for channel %lu", channelNumber);
cChannel* channel = channelFromNumber(channelNumber);
if (!channel)
{
- unsigned char sendBuffer[4];
- *(unsigned long*)&sendBuffer[0] = htonl(0);
- tcp.sendPacket(sendBuffer, 4);
- log->log("Client", Log::DEBUG, "written null");
+ UCHAR sendBuffer[4];
+ *(ULONG*)&sendBuffer[0] = htonl(4);
+ *(ULONG*)&sendBuffer[4] = htonl(0);
+ tcp.sendPacket(sendBuffer, 8);
+ log->log("Client", Log::DEBUG, "written 0 because channel = NULL");
return;
}
+ log->log("Client", Log::DEBUG, "Got channel");
+
#if VDRVERSNUM < 10300
cMutexLock MutexLock;
const cSchedules *Schedules = cSIProcessor::Schedules(MutexLock);
#endif
if (!Schedules)
{
- unsigned char sendBuffer[8];
- *(unsigned long*)&sendBuffer[0] = htonl(4);
- *(unsigned long*)&sendBuffer[4] = htonl(0);
+ UCHAR sendBuffer[8];
+ *(ULONG*)&sendBuffer[0] = htonl(4);
+ *(ULONG*)&sendBuffer[4] = htonl(0);
tcp.sendPacket(sendBuffer, 8);
- log->log("Client", Log::DEBUG, "written 0");
+ log->log("Client", Log::DEBUG, "written 0 because Schedule!s! = NULL");
return;
}
- unsigned char sendBuffer[8];
- *(unsigned long*)&sendBuffer[0] = htonl(4);
- *(unsigned long*)&sendBuffer[4] = htonl(1);
- tcp.sendPacket(sendBuffer, 8);
- log->log("Client", Log::DEBUG, "written 1");
+ log->log("Client", Log::DEBUG, "Got schedule!s! object");
+
+ const cSchedule *Schedule = Schedules->GetSchedule(channel->GetChannelID());
+ if (!Schedule)
+ {
+ UCHAR sendBuffer[8];
+ *(ULONG*)&sendBuffer[0] = htonl(4);
+ *(ULONG*)&sendBuffer[4] = htonl(0);
+ tcp.sendPacket(sendBuffer, 8);
+ log->log("Client", Log::DEBUG, "written 0 because Schedule = NULL");
+ return;
+ }
+
+ log->log("Client", Log::DEBUG, "Got schedule object");
+
+ UCHAR* sendBuffer = (UCHAR*)malloc(100000);
+ ULONG sendBufferLength = 100000;
+ ULONG sendBufferUsed = sizeof(ULONG); // leave a hole for the entire packet length
+
+ char* empty = "";
+
+ // assign all the event info to temp vars then we know exactly what size they are
+ ULONG thisEventID;
+ ULONG thisEventTime;
+ ULONG thisEventDuration;
+ const char* thisEventTitle;
+ const char* thisEventSubTitle;
+ const char* thisEventDescription;
+
+ ULONG constEventLength = sizeof(thisEventID) + sizeof(thisEventTime) + sizeof(thisEventDuration);
+ ULONG thisEventLength;
+
+#if VDRVERSNUM < 10300
+
+ const cEventInfo *event;
+ for (int eventNumber = 0; eventNumber < Schedule->NumEvents(); eventNumber++)
+ {
+ event = Schedule->GetEventNumber(eventNumber);
+
+ thisEventID = event->GetEventID();
+ thisEventTime = event->GetTime();
+ thisEventDuration = event->GetDuration();
+ thisEventTitle = event->GetTitle();
+ thisEventSubTitle = event->GetSubtitle();
+ thisEventDescription = event->GetExtendedDescription();
+
+#else
+
+ for (const cEvent* event = Schedule->Events()->First(); event; event = Schedule->Events()->Next(event))
+ {
+ thisEventID = event->EventID();
+ thisEventTime = event->StartTime();
+ thisEventDuration = event->Duration();
+ thisEventTitle = event->Title();
+ thisEventSubTitle = NULL;
+ thisEventDescription = event->Description();
+
+#endif
+
+ log->log("Client", Log::DEBUG, "Got an event object %p", event);
+
+ //in the past filter
+ if ((thisEventTime + thisEventDuration) < (ULONG)time(NULL)) continue;
+
+ //24 hour filter
+ if (thisEventTime > ((ULONG)time(NULL) + 86400)) continue;
+
+ if (!thisEventTitle) thisEventTitle = empty;
+ if (!thisEventSubTitle) thisEventSubTitle = empty;
+ if (!thisEventDescription) thisEventDescription = empty;
+
+ thisEventLength = constEventLength + strlen(thisEventTitle) + 1 + strlen(thisEventSubTitle) + 1 + strlen(thisEventDescription) + 1;
+
+ log->log("Client", Log::DEBUG, "Done s1");
+
+ // now extend the buffer if necessary
+ if ((sendBufferUsed + thisEventLength) > sendBufferLength)
+ {
+ log->log("Client", Log::DEBUG, "Extending buffer");
+ sendBufferLength += 100000;
+ UCHAR* temp = (UCHAR*)realloc(sendBuffer, sendBufferLength);
+ if (temp == NULL)
+ {
+ free(sendBuffer);
+ UCHAR sendBuffer2[8];
+ *(ULONG*)&sendBuffer2[0] = htonl(4);
+ *(ULONG*)&sendBuffer2[4] = htonl(0);
+ tcp.sendPacket(sendBuffer2, 8);
+ log->log("Client", Log::DEBUG, "written 0 because failed to realloc packet");
+ return;
+ }
+ sendBuffer = temp;
+ }
+
+ log->log("Client", Log::DEBUG, "Done s2");
+
+ *(ULONG*)&sendBuffer[sendBufferUsed] = htonl(thisEventID); sendBufferUsed += sizeof(ULONG);
+ *(ULONG*)&sendBuffer[sendBufferUsed] = htonl(thisEventTime); sendBufferUsed += sizeof(ULONG);
+ *(ULONG*)&sendBuffer[sendBufferUsed] = htonl(thisEventDuration); sendBufferUsed += sizeof(ULONG);
+
+ strcpy((char*)&sendBuffer[sendBufferUsed], thisEventTitle); sendBufferUsed += strlen(thisEventTitle) + 1;
+ strcpy((char*)&sendBuffer[sendBufferUsed], thisEventSubTitle); sendBufferUsed += strlen(thisEventSubTitle) + 1;
+ strcpy((char*)&sendBuffer[sendBufferUsed], thisEventDescription); sendBufferUsed += strlen(thisEventDescription) + 1;
+
+ log->log("Client", Log::DEBUG, "Done s3 %lu", sendBufferUsed);
+ }
+
+ log->log("Client", Log::DEBUG, "Got all event data");
+
+ // Write the length into the first 4 bytes. It's sendBufferUsed - 4 because of the hole!
+ *(ULONG*)&sendBuffer[0] = htonl(sendBufferUsed - sizeof(ULONG));
+
+ tcp.sendPacket(sendBuffer, sendBufferUsed);
+ log->log("Client", Log::DEBUG, "written %lu schedules packet", sendBufferUsed);
+
+ free(sendBuffer);
+
+ return;
+}
+
+void MVPClient::processConfigSave(UCHAR* buffer, int length)
+{
+ char* section = (char*)buffer;
+ char* key = NULL;
+ char* value = NULL;
+
+ for (int k = 0; k < length; k++)
+ {
+ if (buffer[k] == '\0')
+ {
+ if (!key)
+ {
+ key = (char*)&buffer[k+1];
+ }
+ else
+ {
+ value = (char*)&buffer[k+1];
+ break;
+ }
+ }
+ }
+
+ // if the last string (value) doesnt have null terminator, give up
+ if (buffer[length - 1] != '\0') return;
+
+ log->log("Client", Log::DEBUG, "Config save: %s %s %s", section, key, value);
+ if (config.setValueString(section, key, value))
+ {
+ sendULONG(1);
+ }
+ else
+ {
+ sendULONG(0);
+ }
+}
+
+void MVPClient::processConfigLoad(UCHAR* buffer, int length)
+{
+ char* section = (char*)buffer;
+ char* key = NULL;
+
+ for (int k = 0; k < length; k++)
+ {
+ if (buffer[k] == '\0')
+ {
+ key = (char*)&buffer[k+1];
+ break;
+ }
+ }
+
+ char* value = config.getValueString(section, key);
+
+ if (value)
+ {
+ UCHAR sendBuffer[4 + strlen(value) + 1];
+ *(ULONG*)&sendBuffer[0] = htonl(strlen(value) + 1);
+ strcpy((char*)&sendBuffer[4], value);
+ tcp.sendPacket(sendBuffer, 4 + strlen(value) + 1);
+
+ log->log("Client", Log::DEBUG, "Written config load packet");
+ delete[] value;
+ }
+ else
+ {
+ UCHAR sendBuffer[8];
+ *(ULONG*)&sendBuffer[0] = htonl(4);
+ *(ULONG*)&sendBuffer[4] = htonl(0);
+ tcp.sendPacket(sendBuffer, 8);
+
+ log->log("Client", Log::DEBUG, "Written config load failed packet");
+ }
+}
+void MVPClient::cleanConfig()
+{
+ log->log("Client", Log::DEBUG, "Clean config");
+
+ cRecordings Recordings;
+ Recordings.Load();
+
+ int numReturns;
+ int length;
+ char* resumes = config.getSectionKeyNames("ResumeData", numReturns, length);
+ char* position = resumes;
+ for(int k = 0; k < numReturns; k++)
+ {
+ log->log("Client", Log::DEBUG, "EXAMINING: %i %i %p %s", k, numReturns, position, position);
+
+ cRecording* recording = Recordings.GetByName(position);
+ if (!recording)
+ {
+ // doesn't exist anymore
+ log->log("Client", Log::DEBUG, "Found a recording that doesn't exist anymore");
+ config.deleteValue("ResumeData", position);
+ }
+ else
+ {
+ log->log("Client", Log::DEBUG, "This recording still exists");
+ }
+
+ position += strlen(position) + 1;
+ }
+ delete[] resumes;
}
-void MVPClient::testChannelSchedule(unsigned char* data, int length)
+
+
+
+
+
+/*
+ event = Schedule->GetPresentEvent();
+
+ fprintf(f, "\n\nCurrent event\n\n");
+
+ fprintf(f, "Event %i eventid = %u time = %lu duration = %li\n", 0, event->GetEventID(), event->GetTime(), event->GetDuration());
+ fprintf(f, "Event %i title = %s subtitle = %s\n", 0, event->GetTitle(), event->GetSubtitle());
+ fprintf(f, "Event %i extendeddescription = %s\n", 0, event->GetExtendedDescription());
+ fprintf(f, "Event %i isFollowing = %i, isPresent = %i\n", 0, event->IsFollowing(), event->IsPresent());
+
+ event = Schedule->GetFollowingEvent();
+
+ fprintf(f, "\n\nFollowing event\n\n");
+
+ fprintf(f, "Event %i eventid = %u time = %lu duration = %li\n", 0, event->GetEventID(), event->GetTime(), event->GetDuration());
+ fprintf(f, "Event %i title = %s subtitle = %s\n", 0, event->GetTitle(), event->GetSubtitle());
+ fprintf(f, "Event %i extendeddescription = %s\n", 0, event->GetExtendedDescription());
+ fprintf(f, "Event %i isFollowing = %i, isPresent = %i\n", 0, event->IsFollowing(), event->IsPresent());
+
+ fprintf(f, "\n\n");
+*/
+
+/*
+ fprintf(f, "Event %i eventid = %u time = %lu duration = %li\n", eventNumber, event->GetEventID(), event->GetTime(), event->GetDuration());
+ fprintf(f, "Event %i title = %s subtitle = %s\n", eventNumber, event->GetTitle(), event->GetSubtitle());
+ fprintf(f, "Event %i extendeddescription = %s\n", eventNumber, event->GetExtendedDescription());
+ fprintf(f, "Event %i isFollowing = %i, isPresent = %i\n", eventNumber, event->IsFollowing(), event->IsPresent());
+
+ fprintf(f, "\n\n");
+*/
+
+/*
+
+
+void MVPClient::test2()
{
FILE* f = fopen("/tmp/s.txt", "w");
cSchedulesLock MutexLock;
const cSchedules *Schedules = cSchedules::Schedules(MutexLock);
#endif
+
if (!Schedules)
{
fprintf(f, "Schedules = NULL\n");
#else
tchid = Schedule->ChannelID();
#endif
+
#if VDRVERSNUM < 10300
fprintf(f, "ChannelID.ToString() = %s\n", tchid.ToString());
fprintf(f, "NumEvents() = %i\n", Schedule->NumEvents());
#else
// put the count at the end.
#endif
+
thisChannel = Channels.GetByChannelID(tchid, true);
if (thisChannel)
{
+
+
+
+
+
+ fprintf(f, "End of current Schedule\n\n\n");
+
+ Schedule = (const cSchedule *)Schedules->Next(Schedule);
+ scheduleNumber++;
+ }
+
+ fclose(f);
+}
+
+
+
+*/
+
+
+
/*
const cEventInfo *GetPresentEvent(void) const;
const cEventInfo *GetFollowingEvent(void) const;
*/
+/*
+void MVPClient::test(int channelNumber)
+{
+ FILE* f = fopen("/tmp/test.txt", "w");
+ cMutexLock MutexLock;
+ const cSchedules *Schedules = cSIProcessor::Schedules(MutexLock);
-
- fprintf(f, "End of current Schedule\n\n\n");
-
- Schedule = (const cSchedule *)Schedules->Next(Schedule);
- scheduleNumber++;
+ if (!Schedules)
+ {
+ fprintf(f, "Schedules = NULL\n");
+ fclose(f);
+ return;
}
- fclose(f);
-}
+ fprintf(f, "Schedules dump:\n");
+// Schedules->Dump(f);
-void MVPClient::processConfigSave(unsigned char* buffer, int length)
-{
- char* section = (char*)buffer;
- char* key = NULL;
- char* value = NULL;
+ const cSchedule *Schedule;
+ cChannel *thisChannel;
+ const cEventInfo *event;
- for (int k = 0; k < length; k++)
+ thisChannel = channelFromNumber(channelNumber);
+ if (!thisChannel)
{
- if (buffer[k] == '\0')
- {
- if (!key)
- {
- key = (char*)&buffer[k+1];
- }
- else
- {
- value = (char*)&buffer[k+1];
- break;
- }
- }
+ fprintf(f, "thisChannel = NULL\n");
+ fclose(f);
+ return;
}
- // if the last string (value) doesnt have null terminator, give up
- if (buffer[length - 1] != '\0') return;
-
- log->log("Client", Log::DEBUG, "Config save: %s %s %s", section, key, value);
- if (config.setValueString(section, key, value))
- {
- sendULONG(1);
- }
- else
+ Schedule = Schedules->GetSchedule(thisChannel->GetChannelID());
+// Schedule = Schedules->GetSchedule();
+// Schedule = Schedules->First();
+ if (!Schedule)
{
- sendULONG(0);
+ fprintf(f, "First Schedule = NULL\n");
+ fclose(f);
+ return;
}
-}
-void MVPClient::processConfigLoad(unsigned char* buffer, int length)
-{
- char* section = (char*)buffer;
- char* key = NULL;
+ fprintf(f, "NumEvents() = %i\n\n", Schedule->NumEvents());
- for (int k = 0; k < length; k++)
- {
- if (buffer[k] == '\0')
- {
- key = (char*)&buffer[k+1];
- break;
- }
- }
+ // For some channels VDR seems to pick a random point in time to
+ // start dishing out events, but they are in order
+ // at some point in the list the time snaps to the current event
- char* value = config.getValueString(section, key);
- if (value)
- {
- unsigned char sendBuffer[4 + strlen(value) + 1];
- *(unsigned long*)&sendBuffer[0] = htonl(strlen(value) + 1);
- strcpy((char*)&sendBuffer[4], value);
- tcp.sendPacket(sendBuffer, 4 + strlen(value) + 1);
- log->log("Client", Log::DEBUG, "Written config load packet");
- delete[] value;
- }
- else
- {
- unsigned char sendBuffer[8];
- *(unsigned long*)&sendBuffer[0] = htonl(4);
- *(unsigned long*)&sendBuffer[4] = htonl(0);
- tcp.sendPacket(sendBuffer, 8);
- log->log("Client", Log::DEBUG, "Written config load failed packet");
+ for (int eventNumber = 0; eventNumber < Schedule->NumEvents(); eventNumber++)
+ {
+ event = Schedule->GetEventNumber(eventNumber);
+ fprintf(f, "Event %i eventid = %u time = %lu duration = %li\n", eventNumber, event->GetEventID(), event->GetTime(), event->GetDuration());
+ fprintf(f, "Event %i title = %s subtitle = %s\n", eventNumber, event->GetTitle(), event->GetSubtitle());
+ fprintf(f, "Event %i extendeddescription = %s\n", eventNumber, event->GetExtendedDescription());
+ fprintf(f, "\n\n");
}
+
+ fprintf(f, "\nEND\n");
+
+ fclose(f);
}
-void MVPClient::cleanConfig()
-{
- log->log("Client", Log::DEBUG, "Clean config");
+*/
- cRecordings Recordings;
- Recordings.Load();
- int numReturns;
- int length;
- char* resumes = config.getSectionKeyNames("ResumeData", numReturns, length);
- char* position = resumes;
- for(int k = 0; k < numReturns; k++)
- {
- log->log("Client", Log::DEBUG, "EXAMINING: %i %i %p %s", k, numReturns, position, position);
- cRecording* recording = Recordings.GetByName(position);
- if (!recording)
- {
- // doesn't exist anymore
- log->log("Client", Log::DEBUG, "Found a recording that doesn't exist anymore");
- config.deleteValue("ResumeData", position);
- }
- else
- {
- log->log("Client", Log::DEBUG, "This recording still exists");
- }
+/*
- position += strlen(position) + 1;
- }
- delete[] resumes;
-}
+Right, so
+
+Schedules = the collection of all the Schedule objects
+Schedule = One schedule, contants all the events for a channel
+Event = One programme
+Want:
+
+Event ID
+Time
+Duration
+Title
+Subtitle (used for "Programmes resume at ...")
+Description
+
+IsPresent ? easy to work out tho. Oh it doesn't always work
+
+*/