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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
31 #include "vdrrequestpacket.h"
32 #include "vdrresponsepacket.h"
34 VDR* VDR::instance = NULL;
45 channelNumberWidth = 1;
51 if (initted) shutdown();
54 VDR* VDR::getInstance()
59 int VDR::init(int tport)
61 if (initted) return 0;
64 logger = Log::getInstance();
70 if (!initted) return 0;
76 void VDR::findServers(vector<VDRServer>& servers)
78 Wol* wol = Wol::getInstance();
80 char* message = "VOMP";
82 DatagramSocket ds(port);
83 int haveAtLeastOne = 0;
86 bool firstloop = true;
93 logger->log("VDR", Log::NOTICE, "Broadcasting for server");
94 ds.send("255.255.255.255", 3024, message, strlen(message));
95 if(!firstloop) wol->doWakeUp();
97 retval = ds.waitforMessage(waitType);
99 if (retval == 2) // we got a reply
101 if (!strcmp(ds.getData(), "VOMP")) // echo.....
108 newServer.ip = new char[16];
109 strcpy(newServer.ip, ds.getFromIPA());
111 if (ds.getDataLength() == 0)
113 newServer.name = new char[1];
114 newServer.name[0] = '\0';
118 newServer.name = new char[strlen(ds.getData())+1];
119 strcpy(newServer.name, ds.getData());
122 servers.push_back(newServer);
129 if (haveAtLeastOne) break;
134 sort(servers.begin(), servers.end(), ServerSorter());
137 void VDR::cancelFindingServer()
142 void VDR::setServerIP(char* newIP)
144 strcpy(serverIP, newIP);
149 maxChannelNumber = 0;
150 channelNumberWidth = 1;
154 if (tcp->connectTo(serverIP, 3024))
166 void VDR::disconnect()
172 Log::getInstance()->log("VDR", Log::DEBUG, "Disconnect");
175 void VDR::setReceiveWindow(size_t size)
177 if (connected) tcp->setReceiveWindow(size);
180 ///////////////////////////////////////////////////////
182 void VDR::threadMethod()
189 ULONG userDataLength;
194 VDR_ResponsePacket* vresp;
198 if (!tcp->readData((UCHAR*)&channelID, sizeof(ULONG)))
201 Log::getInstance()->log("VDR", Log::DEBUG, "Net read timeout");
205 //for(EDRL::iterator i = receivers.begin(); i != receivers.end(); i++)
211 channelID = ntohl(channelID);
213 vresp = new VDR_ResponsePacket();
215 if (channelID == CHANNEL_REQUEST_RESPONSE)
217 if (!tcp->readData((UCHAR*)&requestID, sizeof(ULONG))) break;
218 requestID = ntohl(requestID);
219 if (!tcp->readData((UCHAR*)&userDataLength, sizeof(ULONG))) break;
220 userDataLength = ntohl(userDataLength);
221 if (userDataLength > 5000000) break; // how big can these packets get?
222 if (userDataLength > 0)
224 userData = (UCHAR*)malloc(userDataLength);
225 if (!userData) break;
226 if (!tcp->readData(userData, userDataLength)) break;
232 vresp->setResponse(requestID, userData, userDataLength);
233 Log::getInstance()->log("VDR", Log::DEBUG, "Rxd a response packet, requestID=%lu, len=%lu", requestID, userDataLength);
235 else if (channelID == CHANNEL_STREAM)
237 if (!tcp->readData((UCHAR*)&streamID, sizeof(ULONG))) break;
238 streamID = ntohl(streamID);
239 if (!tcp->readData((UCHAR*)&userDataLength, sizeof(ULONG))) break;
240 userDataLength = ntohl(userDataLength);
241 if (userDataLength > 0)
243 userData = (UCHAR*)malloc(userDataLength);
244 if (!userData) break;
245 if (!tcp->readData(userData, userDataLength)) break;
251 vresp->setStream(streamID, userData, userDataLength);
252 Log::getInstance()->log("VDR", Log::DEBUG, "Rxd a stream packet, streamID=%lu, len=%lu", streamID, userDataLength);
256 Log::getInstance()->log("VDR", Log::ERR, "Rxd a response packet on channel %lu !!", channelID);
261 if (!edFindAndCall(vresp)) // makes ED lock, find receiver for vresp (using ed_cb_find() ) and then call (using ed_cb_call() )
263 // If edFindAndCall returns true, edr was called and vresp was handed off.
264 // else, delete vresp here.
268 // Who deletes vresp?
269 // If RR, the individual protocol functions must delete vresp.
270 // If stream, the data and length is taken out in ed_cb_call and vresp is deleted there.
274 bool VDR::ed_cb_find(EDReceiver* edr, void* userTag)
276 // edr is a VDR_PacketReceiver object made in VDR::RequestResponse
277 // userTag is a VDR_ResponsePacket made in threadMethod
279 VDR_PacketReceiver* vdrpr = (VDR_PacketReceiver*)edr;
280 VDR_ResponsePacket* vresp = (VDR_ResponsePacket*)userTag;
282 // Is vresp for vdrpr ?
284 ULONG packetChannel = vresp->getChannelID();
285 if (vdrpr->receiverChannel != packetChannel) return false;
287 if (packetChannel == CHANNEL_REQUEST_RESPONSE)
289 if (vdrpr->requestSerialNumber == vresp->getRequestID()) return true;
291 else if (packetChannel == CHANNEL_STREAM)
293 if (vdrpr->streamID == vresp->getStreamID()) return true;
299 VDR_ResponsePacket* VDR::RequestResponse(VDR_RequestPacket* vrp)
301 logger->log("VDR", Log::DEBUG, "RR %lu", vrp->getOpcode());
305 VDR_ResponsePacket* vresp = new VDR_ResponsePacket();
306 return vresp; // "no-response" return
309 // ED make new VDR and register
310 // make a VDR_PacketReceiver
311 // - init with serial number of request packet
313 VDR_PacketReceiver vdrpr;
314 // vdrpr.requestTime = time(NULL);
315 vdrpr.receiverChannel = VDR::CHANNEL_REQUEST_RESPONSE;
316 vdrpr.requestSerialNumber = vrp->getSerial();
320 if ((ULONG)tcp->sendData(vrp->getPtr(), vrp->getLen()) != vrp->getLen())
323 edUnregister(&vdrpr);
324 VDR_ResponsePacket* vresp = new VDR_ResponsePacket();
325 return vresp; // "no-response" return
328 // Sleep and block this thread. The sleep unlocks the mutex
329 logger->log("VDR", Log::DEBUG, "RR sleep");
330 edSleepThisReceiver(&vdrpr);
331 logger->log("VDR", Log::DEBUG, "RR unsleep");
333 // Woken because a response packet has arrived, mutex will be locked
336 return vdrpr.save_vresp;
339 /////////////////////////////////////////////////////////////////////////////
341 // Here VDR takes a break for the VDR_PacketReceiver helper class
343 bool VDR_PacketReceiver::call(void* userTag)
345 if (receiverChannel == VDR::CHANNEL_REQUEST_RESPONSE)
347 // It's a RR. Save vresp and, signal the waiting thread and return.
348 // VDR::RequestResponse will be blocking waiting for this to happen.
349 // That function has a pointer to this object and can read save_vresp.
350 save_vresp = (VDR_ResponsePacket*)userTag;
351 return true; // Signals ED to remove edr from receivers and wake up edr thread
354 if (receiverChannel == VDR::CHANNEL_STREAM)
356 // It's a stream packet.
357 VDR_ResponsePacket* vresp = (VDR_ResponsePacket*)userTag;
358 streamReceiver->streamReceive(vresp->getUserData(), vresp->getUserDataLength());
363 abort(); // unknown receiverChannel, should not happen
366 /////////////////////////////////////////////////////////////////////////////
370 VDR_RequestPacket vrp;
371 if (!vrp.init(VDR_LOGIN, true, 6)) return 0;
374 tcp->getMAC((char*)mactemp);
375 if (!vrp.copyin((UCHAR*)mactemp, 6)) return 0;
377 VDR_ResponsePacket* vresp = RequestResponse(&vrp);
378 if (vresp->noResponse()) { delete vresp; return 0; }
380 ULONG vdrTime = vresp->extractULONG();
381 logger->log("VDR", Log::DEBUG, "vdrtime = %lu", vdrTime);
382 long vdrTimeOffset = vresp->extractLONG();
383 logger->log("VDR", Log::DEBUG, "offset = %i", vdrTimeOffset);
387 // Set the time and zone on the MVP
390 struct timespec currentTime;
391 currentTime.tv_sec = vdrTime;
392 currentTime.tv_nsec = 0;
393 int b = clock_settime(CLOCK_REALTIME, ¤tTime);
395 logger->log("VDR", Log::DEBUG, "set clock = %u", b);
397 // now make a TZ variable and set it
401 if (vdrTimeOffset > 0) sign = '-';
404 vdrTimeOffset = abs(vdrTimeOffset);
406 hours = (int)vdrTimeOffset / 3600;
407 minutes = vdrTimeOffset % 3600;
409 logger->log("VDR", Log::DEBUG, "%c %i %i", sign, hours, minutes);
411 minutes = (int)minutes / 60;
413 logger->log("VDR", Log::DEBUG, "%c %i %i", sign, hours, minutes);
416 sprintf(newTZ, "MVP%c%i:%i", sign, hours, minutes);
417 setenv("TZ", newTZ, 1);
419 logger->log("VDR", Log::DEBUG, "Timezone data: %s", newTZ);
425 bool VDR::getRecordingsList(RecMan* recman)
427 VDR_RequestPacket vrp;
428 if (!vrp.init(VDR_GETRECORDINGLIST, true, 0)) return false;
430 VDR_ResponsePacket* vresp = RequestResponse(&vrp);
431 if (vresp->noResponse()) { delete vresp; return false; }
433 ULONG totalSpace = vresp->extractULONG();
434 ULONG freeSpace = vresp->extractULONG();
435 ULONG percent = vresp->extractULONG();
436 recman->setStats(totalSpace, freeSpace, percent);
442 while (!vresp->end())
444 start = vresp->extractULONG();
445 name = vresp->extractString();
446 fileName = vresp->extractString();
448 recman->addEntry(start, name, fileName);
459 int VDR::deleteRecording(char* fileName)
461 VDR_RequestPacket vrp;
462 if (!vrp.init(VDR_DELETERECORDING, true, strlen(fileName) + 1)) return 0;
463 if (!vrp.addString(fileName)) return 0;
465 VDR_ResponsePacket* vresp = RequestResponse(&vrp);
466 if (vresp->noResponse()) { delete vresp; return 0; }
468 int toReturn = (int)vresp->extractULONG();
474 char* VDR::moveRecording(char* fileName, char* newPath)
476 VDR_RequestPacket vrp;
477 if (!vrp.init(VDR_MOVERECORDING, true, strlen(fileName) + 1 + strlen(newPath) + 1)) return NULL;
478 if (!vrp.addString(fileName)) return NULL;
479 if (!vrp.addString(newPath)) return NULL;
481 VDR_ResponsePacket* vresp = RequestResponse(&vrp);
482 if (vresp->noResponse()) { delete vresp; return NULL; }
484 char* toReturn = NULL;
485 int success = (int)vresp->extractULONG();
488 toReturn = vresp->extractString();
496 ChannelList* VDR::getChannelsList(ULONG type)
498 VDR_RequestPacket vrp;
499 if (!vrp.init(VDR_GETCHANNELLIST, true, 0)) return NULL;
501 VDR_ResponsePacket* vresp = RequestResponse(&vrp);
502 if (vresp->noResponse()) { delete vresp; return NULL; }
504 ChannelList* chanList = new ChannelList();
506 while (!vresp->end())
508 Channel* chan = new Channel();
509 chan->number = vresp->extractULONG();
510 chan->type = vresp->extractULONG();
511 chan->name = vresp->extractString();
513 if (chan->type == type)
515 chanList->push_back(chan);
516 Log::getInstance()->log("VDR", Log::DEBUG, "Have added a channel to list. %lu %lu %s", chan->number, chan->type, chan->name);
517 if (chan->number > maxChannelNumber) maxChannelNumber = chan->number;
527 if (maxChannelNumber > 99999)
528 channelNumberWidth = 6;
529 else if (maxChannelNumber > 9999)
530 channelNumberWidth = 5;
531 else if (maxChannelNumber > 999)
532 channelNumberWidth = 4;
533 else if (maxChannelNumber > 99)
534 channelNumberWidth = 3;
535 else if (maxChannelNumber > 9)
536 channelNumberWidth = 2;
538 channelNumberWidth = 1;
544 int VDR::streamChannel(ULONG number)
550 int VDR::streamChannel(ULONG number, StreamReceiver* tstreamReceiver)
552 VDR_RequestPacket vrp;
553 if (!vrp.init(VDR_STREAMCHANNEL, true, sizeof(ULONG))) return 0;
554 if (!vrp.addULONG(number)) return 0;
557 VDR_PacketReceiver* vdrpr = new VDR_PacketReceiver(); // FIXME - leaked
558 vdrpr->receiverChannel = VDR::CHANNEL_STREAM;
559 vdrpr->streamID = vrp.getSerial();
560 vdrpr->streamReceiver = tstreamReceiver;
563 VDR_ResponsePacket* vresp = RequestResponse(&vrp);
564 if (vresp->noResponse())
572 int toReturn = (int)vresp->extractULONG();
578 int VDR::stopStreaming()
580 VDR_RequestPacket vrp;
581 if (!vrp.init(VDR_STOPSTREAMING, true, 0)) return 0;
583 VDR_ResponsePacket* vresp = RequestResponse(&vrp);
584 if (vresp->noResponse()) { delete vresp; return 0; }
586 int toReturn = (int)vresp->extractULONG();
592 UCHAR* VDR::getImageBlock(ULONG position, UINT maxAmount, UINT* amountReceived)
594 return getBlock(position, maxAmount, amountReceived, VDR_GETIMAGEBLOCK);
597 UCHAR* VDR::getBlock(ULLONG position, UINT maxAmount, UINT* amountReceived)
599 return getBlock(position, maxAmount, amountReceived, VDR_GETBLOCK);
602 UCHAR* VDR::getBlock(ULLONG position, UINT maxAmount, UINT* amountReceived, ULONG cmd)
604 VDR_RequestPacket vrp;
605 if (!vrp.init(cmd, true, sizeof(ULLONG) + sizeof(ULONG))) return NULL;
606 if (!vrp.addULLONG(position)) return NULL;
607 if (!vrp.addULONG(maxAmount)) return NULL;
609 VDR_ResponsePacket* vresp = RequestResponse(&vrp);
610 if (vresp->noResponse()) { delete vresp; return NULL; }
612 if (vresp->serverError())
614 Log::getInstance()->log("VDR", Log::DEBUG, "Detected getblock 0");
619 // Special handling for getblock
620 UCHAR* toReturn = vresp->getUserData();
621 *amountReceived = vresp->getUserDataLength();
628 ULLONG VDR::streamRecording(char* fileName, ULONG* totalFrames)
630 VDR_RequestPacket vrp;
631 if (!vrp.init(VDR_STREAMRECORDING, true, strlen(fileName) + 1)) return 0;
632 if (!vrp.addString(fileName)) return 0;
634 VDR_ResponsePacket* vresp = RequestResponse(&vrp);
635 if (vresp->noResponse()) { delete vresp; return 0; }
637 ULLONG lengthBytes = vresp->extractULLONG();
638 ULONG lengthFrames = vresp->extractULONG();
641 Log::getInstance()->log("VDR", Log::DEBUG, "VDR said length is: %llu %lu", lengthBytes, lengthFrames);
643 *totalFrames = lengthFrames;
647 ULLONG VDR::positionFromFrameNumber(ULONG frameNumber)
649 VDR_RequestPacket vrp;
650 if (!vrp.init(VDR_POSFROMFRAME, true, sizeof(ULONG))) return 0;
651 if (!vrp.addULONG(frameNumber)) return 0;
653 VDR_ResponsePacket* vresp = RequestResponse(&vrp);
654 if (vresp->noResponse()) { delete vresp; return 0; }
656 ULLONG position = vresp->extractULLONG();
659 Log::getInstance()->log("VDR", Log::DEBUG, "VDR said new position is: %llu", position);
664 ULONG VDR::frameNumberFromPosition(ULLONG position)
666 VDR_RequestPacket vrp;
667 if (!vrp.init(VDR_FRAMEFROMPOS, true, sizeof(ULLONG))) return 0;
668 if (!vrp.addULLONG(position)) return 0;
670 VDR_ResponsePacket* vresp = RequestResponse(&vrp);
671 if (vresp->noResponse()) { delete vresp; return 0; }
673 ULONG framenumber = vresp->extractULONG();
676 Log::getInstance()->log("VDR", Log::DEBUG, "VDR said new framenumber is: %u", framenumber);
681 bool VDR::getNextIFrame(ULONG frameNumber, ULONG direction, ULLONG* rfilePosition, ULONG* rframeNumber, ULONG* rframeLength)
683 VDR_RequestPacket vrp;
684 if (!vrp.init(VDR_GETNEXTIFRAME, true, sizeof(ULONG)*2)) return false;
685 if (!vrp.addULONG(frameNumber)) return false;
686 if (!vrp.addULONG(direction)) return false;
688 VDR_ResponsePacket* vresp = RequestResponse(&vrp);
689 if (vresp->noResponse()) { delete vresp; return false; }
691 if (vresp->serverError())
693 Log::getInstance()->log("VDR", Log::DEBUG, "Detected getNextIFrame error");
698 *rfilePosition = vresp->extractULLONG();
699 *rframeNumber = vresp->extractULONG();
700 *rframeLength = vresp->extractULONG();
704 // Log::getInstance()->log("VDR", Log::DEBUG, "VDR GNIF said %llu %lu %lu", *rfilePosition, *rframeNumber, *rframeLength);
709 EventList* VDR::getChannelSchedule(ULONG number)
713 return getChannelSchedule(number, now, 24 * 60 * 60);
716 EventList* VDR::getChannelSchedule(ULONG number, time_t start, ULONG duration)
718 // retrieve event list (vector of events) from vdr within filter window. duration is in seconds
720 VDR_RequestPacket vrp;
721 if (!vrp.init(VDR_GETCHANNELSCHEDULE, true, sizeof(ULONG)*3)) return NULL;
722 if (!vrp.addULONG(number)) return NULL;
723 if (!vrp.addULONG(start)) return NULL;
724 if (!vrp.addULONG(duration)) return NULL;
726 VDR_ResponsePacket* vresp = RequestResponse(&vrp);
727 if (vresp->noResponse()) { delete vresp; return NULL; }
729 // received a ulong(0) - schedules error in the plugin
730 if (vresp->serverError())
736 EventList* eventList = new EventList();
738 while (!vresp->end())
740 Event* event = new Event();
741 event->id = vresp->extractULONG();
742 event->time = vresp->extractULONG();
743 event->duration = vresp->extractULONG();
744 event->title = vresp->extractString();
745 event->subtitle = vresp->extractString();
746 event->description = vresp->extractString();
747 eventList->push_back(event);
752 Log::getInstance()->log("VDR", Log::DEBUG, "Success got to end of getChannelSchedule");
756 int VDR::configSave(const char* section, const char* key, const char* value)
758 VDR_RequestPacket vrp;
759 if (!vrp.init(VDR_CONFIGSAVE, false, 0)) return 0;
760 if (!vrp.addString(section)) return 0;
761 if (!vrp.addString(key)) return 0;
762 if (!vrp.addString(value)) return 0;
764 VDR_ResponsePacket* vresp = RequestResponse(&vrp);
765 if (vresp->noResponse()) { delete vresp; return 0; }
767 int toReturn = (int)vresp->extractULONG();
773 char* VDR::configLoad(const char* section, const char* key)
775 VDR_RequestPacket vrp;
776 if (!vrp.init(VDR_CONFIGLOAD, false, 0)) return NULL;
777 if (!vrp.addString(section)) return NULL;
778 if (!vrp.addString(key)) return NULL;
780 VDR_ResponsePacket* vresp = RequestResponse(&vrp);
781 if (vresp->noResponse()) { delete vresp; return NULL; }
783 char* toReturn = vresp->extractString();
789 RecTimerList* VDR::getRecTimersList()
791 VDR_RequestPacket vrp;
792 if (!vrp.init(VDR_GETTIMERS, true, 0)) return NULL;
794 VDR_ResponsePacket* vresp = RequestResponse(&vrp);
795 if (vresp->noResponse()) { delete vresp; return NULL; }
797 RecTimerList* recTimerList = new RecTimerList();
799 ULONG numTimers = vresp->extractULONG();
802 RecTimer* newRecTimer;
805 while (!vresp->end())
807 newRecTimer = new RecTimer();
808 newRecTimer->active = vresp->extractULONG();
809 newRecTimer->recording = vresp->extractULONG();
810 newRecTimer->pending = vresp->extractULONG();
811 newRecTimer->priority = vresp->extractULONG();
812 newRecTimer->lifeTime = vresp->extractULONG();
813 newRecTimer->channelNumber = vresp->extractULONG();
814 newRecTimer->startTime = vresp->extractULONG();
815 newRecTimer->stopTime = vresp->extractULONG();
816 newRecTimer->day = vresp->extractULONG();
817 newRecTimer->weekDays = vresp->extractULONG();
819 tempString = vresp->extractString();
820 newRecTimer->setFile(tempString);
823 recTimerList->push_back(newRecTimer);
824 Log::getInstance()->log("VDR", Log::DEBUG, "TL: %lu %lu %lu %lu %lu %lu %lu %lu %s",
825 newRecTimer->active, newRecTimer->recording, newRecTimer->pending, newRecTimer->priority, newRecTimer->lifeTime,
826 newRecTimer->channelNumber, newRecTimer->startTime, newRecTimer->stopTime, newRecTimer->getFile());
832 sort(recTimerList->begin(), recTimerList->end(), RecTimerSorter());
837 ULONG VDR::setEventTimer(char* timerString)
839 VDR_RequestPacket vrp;
840 if (!vrp.init(VDR_SETTIMER, true, strlen(timerString) + 1)) return 0;
841 if (!vrp.addString(timerString)) return 0;
843 VDR_ResponsePacket* vresp = RequestResponse(&vrp);
844 if (vresp->noResponse()) { delete vresp; return 0; }
846 ULONG toReturn = vresp->extractULONG();
852 RecInfo* VDR::getRecInfo(char* fileName)
854 VDR_RequestPacket vrp;
855 if (!vrp.init(VDR_GETRECINFO, true, strlen(fileName) + 1)) return NULL;
856 if (!vrp.addString(fileName)) return NULL;
858 VDR_ResponsePacket* vresp = RequestResponse(&vrp);
859 if (vresp->noResponse()) { delete vresp; return NULL; }
861 if (vresp->serverError())
863 Log::getInstance()->log("VDR", Log::DEBUG, "Could not get rec info");
868 RecInfo* recInfo = new RecInfo();
870 recInfo->timerStart = vresp->extractULONG();
871 recInfo->timerEnd = vresp->extractULONG();
872 recInfo->resumePoint = vresp->extractULONG();
873 recInfo->summary = vresp->extractString();
875 ULONG numComponents = vresp->extractULONG();
878 recInfo->setNumComponents(numComponents);
879 for (ULONG i = 0; i < numComponents; i++)
881 recInfo->streams[i] = vresp->extractUCHAR();
882 recInfo->types[i] = vresp->extractUCHAR();
883 recInfo->languages[i] = vresp->extractString();
884 recInfo->descriptions[i] = vresp->extractString();
895 ULLONG VDR::rescanRecording(ULONG* totalFrames)
897 VDR_RequestPacket vrp;
898 if (!vrp.init(VDR_RESCANRECORDING, true, 0)) return 0;
900 VDR_ResponsePacket* vresp = RequestResponse(&vrp);
901 if (vresp->noResponse()) { delete vresp; return 0; }
903 ULLONG lengthBytes = vresp->extractULLONG();
904 ULONG lengthFrames = vresp->extractULONG();
907 Log::getInstance()->log("VDR", Log::DEBUG, "VDR said length is: %llu %lu", lengthBytes, lengthFrames);
909 *totalFrames = lengthFrames;
913 MarkList* VDR::getMarks(char* fileName)
915 VDR_RequestPacket vrp;
916 if (!vrp.init(VDR_GETMARKS, true, strlen(fileName) + 1)) return NULL;
917 if (!vrp.addString(fileName)) return NULL;
919 VDR_ResponsePacket* vresp = RequestResponse(&vrp);
920 if (vresp->noResponse()) { delete vresp; return NULL; }
922 if (vresp->serverError())
928 MarkList* markList = new MarkList();
930 while (!vresp->end())
932 Mark* mark = new Mark();
933 mark->pos = vresp->extractULONG();
935 markList->push_back(mark);
936 Log::getInstance()->log("VDR", Log::DEBUG, "Have added a mark to list. %lu", mark->pos);
944 void VDR::getChannelPids(Channel* channel)
946 VDR_RequestPacket vrp;
947 if (!vrp.init(VDR_GETCHANNELPIDS, true, sizeof(ULONG))) return ;
948 if (!vrp.addULONG(channel->number)) return ;
950 VDR_ResponsePacket* vresp = RequestResponse(&vrp);
951 if (vresp->noResponse()) { delete vresp; return ; }
953 // Format of response
961 channel->vpid = vresp->extractULONG();
962 channel->numAPids = vresp->extractULONG();
964 for (ULONG i = 0; i < channel->numAPids; i++)
967 newapid.pid = vresp->extractULONG();
968 newapid.name = vresp->extractString();
969 channel->apids.push_back(newapid);
972 channel->numDPids = vresp->extractULONG();
974 for (ULONG i = 0; i < channel->numDPids; i++)
977 newdpid.pid = vresp->extractULONG();
978 newdpid.name = vresp->extractString();
979 channel->dpids.push_back(newdpid);
982 channel->numSPids = vresp->extractULONG();
984 for (ULONG i = 0; i < channel->numSPids; i++)
987 newspid.pid = vresp->extractULONG();
988 newspid.name = vresp->extractString();
989 channel->spids.push_back(newspid);
991 channel->tpid = vresp->extractULONG();
999 * media List Request:
1000 * 4 flags (currently unused)
1003 * Media List response:
1011 * 4 strlen (incl. 0 Byte)
1015 MediaList* VDR::getMediaList(const char* parent,int mediaType)
1017 Log::getInstance()->log("VDR", Log::DEBUG, "getMediaList %s,type=%d", (parent?parent:"NULL"), mediaType);
1019 VDR_RequestPacket vrp;
1020 if (!vrp.init(VDR_GETMEDIALIST, false, 0)) return NULL;
1021 if (!vrp.addULONG(0)) return NULL; // unused flags
1025 if (!vrp.addString(parent)) return NULL;
1028 VDR_ResponsePacket* vresp = RequestResponse(&vrp);
1029 if (vresp->noResponse()) { delete vresp; return NULL; }
1031 if (vresp->serverError())
1037 if (vresp->getUserDataLength() < 12)
1039 Log::getInstance()->log("VDR", Log::ERR, "receiveMediaList packet too short, expected 12, got %d", vresp->getUserDataLength());
1044 MediaList* mediaList = new MediaList();
1046 code = vresp->extractULONG();
1047 ULONG numEntries = vresp->extractULONG();
1048 Log::getInstance()->log("VDR", Log::DEBUG, "receiveMediaList with %d entries",numEntries);
1049 while (!vresp->end() && numEntries >0)
1051 Media* m = new Media();
1052 ULONG mtype = vresp->extractULONG();
1053 ULONG mtime=vresp->extractULONG();
1055 flags=vresp->extractULONG();
1056 ULONG stsize=vresp->extractULONG();
1057 char * name=vresp->extractString();
1058 if (! name || stsize != (strlen(name)+1)) {
1059 Log::getInstance()->log("VDR", Log::ERR, "receiveMediaList invalid packet entry, read size %d, strlen %d", stsize, strlen(name)+1);
1065 //ignore . and .. entries
1066 if (strcmp(name,".") == 0 || strcmp(name,"..")==0) {
1070 m->setFileName(name);
1072 m->setMediaType(mtype);
1073 mediaList->push_back(m);
1074 Log::getInstance()->log("VDR", Log::DEBUG, "Have added a media to list. %s, type=%d, time=%d", name,mtype,mtime);
1083 * get image Request:
1084 * 4 flags (currently unused)
1089 * get image response:
1094 ULONG VDR::loadImage(const char* fileName, ULONG x, ULONG y)
1096 VDR_RequestPacket vrp;
1097 if (!vrp.init(VDR_GETIMAGE, false, 0)) return 0;
1098 if (!vrp.addULONG(0)) return 0; // unused flags
1099 if (!vrp.addULONG(x)) return 0;
1100 if (!vrp.addULONG(y)) return 0;
1101 if (!vrp.addString(fileName)) return 0;
1103 VDR_ResponsePacket* vresp = RequestResponse(&vrp);
1104 if (vresp->noResponse()) { delete vresp; return 0; }
1106 ULONG cmd = vresp->extractULONG();
1107 ULONG lengthBytes = vresp->extractULONG();
1110 Log::getInstance()->log("VDR", Log::DEBUG, "getImage %s: cmd=%lu len=%lu", fileName, cmd, lengthBytes);
1114 int VDR::deleteTimer(RecTimer* delTimer)
1116 Log::getInstance()->log("VDR", Log::DEBUG, "Delete timer called");
1118 VDR_RequestPacket vrp;
1119 if (!vrp.init(VDR_DELETETIMER, false, 0)) return 0;
1120 if (!vrp.addULONG(delTimer->channelNumber)) return 0;
1121 if (!vrp.addULONG(delTimer->weekDays)) return 0;
1122 if (!vrp.addULONG(delTimer->day)) return 0;
1123 if (!vrp.addULONG(delTimer->startTime)) return 0;
1124 if (!vrp.addULONG(delTimer->stopTime)) return 0;
1126 VDR_ResponsePacket* vresp = RequestResponse(&vrp);
1127 if (vresp->noResponse()) { delete vresp; return 0; }
1129 int toReturn = (int)vresp->extractULONG();
1135 I18n::lang_code_list VDR::getLanguageList()
1137 I18n::lang_code_list CodeList;
1138 CodeList["en"] = "English"; // Default entry
1139 VDR_RequestPacket vrp;
1140 if (!vrp.init(VDR_GETLANGUAGELIST, false, 0)) return CodeList;
1141 VDR_ResponsePacket* vresp = RequestResponse(&vrp);
1142 if (vresp->noResponse() || vresp->end())
1148 while (!vresp->end())
1150 char* c_code = vresp->extractString();
1151 char* c_name = vresp->extractString();
1152 string code = c_code;
1153 string name = c_name;
1154 CodeList[code] = name;
1162 int VDR::getLanguageContent(const std::string code, I18n::trans_table& texts)
1164 VDR_RequestPacket vrp;
1165 if (!vrp.init(VDR_GETLANGUAGECONTENT, false, 0)) return 0;
1166 if (!vrp.addString(code.c_str())) return 0;
1167 VDR_ResponsePacket* vresp = RequestResponse(&vrp);
1168 if (vresp->noResponse()) { delete vresp; return 0; }
1170 while (!vresp->end())
1172 char* c_key = vresp->extractString();
1173 char* c_text = vresp->extractString();
1175 string text = c_text;