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
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++)
212 vresp = new VDR_ResponsePacket();
214 if (channelID == CHANNEL_REQUEST_RESPONSE)
216 if (!tcp->readData((UCHAR*)&requestID, sizeof(ULONG))) break;
217 if (!tcp->readData((UCHAR*)&userDataLength, sizeof(ULONG))) break;
218 if (userDataLength > 5000000) break; // how big can these packets get?
219 if (userDataLength > 0)
221 userData = (UCHAR*)malloc(userDataLength);
222 if (!userData) break;
223 if (!tcp->readData(userData, userDataLength)) break;
229 vresp->setResponse(requestID, userData, userDataLength);
230 Log::getInstance()->log("VDR", Log::DEBUG, "Rxd a response packet, requestID=%lu, len=%lu", requestID, userDataLength);
232 else if (channelID == CHANNEL_STREAM)
234 if (!tcp->readData((UCHAR*)&streamID, sizeof(ULONG))) break;
235 if (!tcp->readData((UCHAR*)&userDataLength, sizeof(ULONG))) break;
236 if (userDataLength > 0)
238 userData = (UCHAR*)malloc(userDataLength);
239 if (!userData) break;
240 if (!tcp->readData(userData, userDataLength)) break;
246 vresp->setStream(streamID, userData, userDataLength);
247 Log::getInstance()->log("VDR", Log::DEBUG, "Rxd a stream packet, streamID=%lu, len=%lu", streamID, userDataLength);
251 Log::getInstance()->log("VDR", Log::ERR, "Rxd a response packet on channel %lu !!", channelID);
256 if (!edFindAndCall(vresp)) // makes ED lock, find receiver for vresp (using ed_cb_find() ) and then call (using ed_cb_call() )
258 // If edFindAndCall returns true, edr was called and vresp was handed off.
259 // else, delete vresp here.
263 // Who deletes vresp?
264 // If RR, the individual protocol functions must delete vresp.
265 // If stream, the data and length is taken out in ed_cb_call and vresp is deleted there.
269 bool VDR::ed_cb_find(EDReceiver* edr, void* userTag)
271 // edr is a VDR_PacketReceiver object made in VDR::RequestResponse
272 // userTag is a VDR_ResponsePacket made in threadMethod
274 VDR_PacketReceiver* vdrpr = (VDR_PacketReceiver*)edr;
275 VDR_ResponsePacket* vresp = (VDR_ResponsePacket*)userTag;
277 // Is vresp for vdrpr ?
279 ULONG packetChannel = vresp->getChannelID();
280 if (vdrpr->receiverChannel != packetChannel) return false;
282 if (packetChannel == CHANNEL_REQUEST_RESPONSE)
284 if (vdrpr->requestSerialNumber == vresp->getRequestID()) return true;
286 else if (packetChannel == CHANNEL_STREAM)
288 if (vdrpr->streamID == vresp->getStreamID()) return true;
294 VDR_ResponsePacket* VDR::RequestResponse(VDR_RequestPacket* vrp)
296 logger->log("VDR", Log::DEBUG, "RR %lu", vrp->getOpcode());
300 VDR_ResponsePacket* vresp = new VDR_ResponsePacket();
301 return vresp; // "no-response" return
304 // ED make new VDR and register
305 // make a VDR_PacketReceiver
306 // - init with serial number of request packet
308 VDR_PacketReceiver vdrpr;
309 // vdrpr.requestTime = time(NULL);
310 vdrpr.receiverChannel = VDR::CHANNEL_REQUEST_RESPONSE;
311 vdrpr.requestSerialNumber = vrp->getSerial();
315 if ((ULONG)tcp->sendData(vrp->getPtr(), vrp->getLen()) != vrp->getLen())
318 edUnregister(&vdrpr);
319 VDR_ResponsePacket* vresp = new VDR_ResponsePacket();
320 return vresp; // "no-response" return
323 // Sleep and block this thread. The sleep unlocks the mutex
324 logger->log("VDR", Log::DEBUG, "RR sleep");
325 edSleepThisReceiver(&vdrpr);
326 logger->log("VDR", Log::DEBUG, "RR unsleep");
328 // Woken because a response packet has arrived, mutex will be locked
331 return vdrpr.save_vresp;
334 /////////////////////////////////////////////////////////////////////////////
336 // Here VDR takes a break for the VDR_PacketReceiver helper class
338 bool VDR_PacketReceiver::call(void* userTag)
340 if (receiverChannel == VDR::CHANNEL_REQUEST_RESPONSE)
342 // It's a RR. Save vresp and, signal the waiting thread and return.
343 // VDR::RequestResponse will be blocking waiting for this to happen.
344 // That function has a pointer to this object and can read save_vresp.
345 save_vresp = (VDR_ResponsePacket*)userTag;
346 return true; // Signals ED to remove edr from receivers and wake up edr thread
349 if (receiverChannel == VDR::CHANNEL_STREAM)
351 // It's a stream packet.
352 VDR_ResponsePacket* vresp = (VDR_ResponsePacket*)userTag;
353 streamReceiver->streamReceive(vresp->getUserData(), vresp->getUserDataLength());
358 abort(); // unknown receiverChannel, should not happen
361 /////////////////////////////////////////////////////////////////////////////
365 VDR_RequestPacket vrp;
366 if (!vrp.init(VDR_LOGIN, true, 6)) return 0;
369 tcp->getMAC((char*)mactemp);
370 if (!vrp.copyin((UCHAR*)mactemp, 6)) return 0;
372 VDR_ResponsePacket* vresp = RequestResponse(&vrp);
373 if (vresp->noResponse()) { delete vresp; return 0; }
375 ULONG vdrTime = vresp->extractULONG();
376 logger->log("VDR", Log::DEBUG, "vdrtime = %lu", vdrTime);
377 long vdrTimeOffset = vresp->extractLONG();
378 logger->log("VDR", Log::DEBUG, "offset = %i", vdrTimeOffset);
382 // Set the time and zone on the MVP
385 struct timespec currentTime;
386 currentTime.tv_sec = vdrTime;
387 currentTime.tv_nsec = 0;
388 int b = clock_settime(CLOCK_REALTIME, ¤tTime);
390 logger->log("VDR", Log::DEBUG, "set clock = %u", b);
392 // now make a TZ variable and set it
396 if (vdrTimeOffset > 0) sign = '-';
399 vdrTimeOffset = abs(vdrTimeOffset);
401 hours = (int)vdrTimeOffset / 3600;
402 minutes = vdrTimeOffset % 3600;
404 logger->log("VDR", Log::DEBUG, "%c %i %i", sign, hours, minutes);
406 minutes = (int)minutes / 60;
408 logger->log("VDR", Log::DEBUG, "%c %i %i", sign, hours, minutes);
411 sprintf(newTZ, "MVP%c%i:%i", sign, hours, minutes);
412 setenv("TZ", newTZ, 1);
414 logger->log("VDR", Log::DEBUG, "Timezone data: %s", newTZ);
420 bool VDR::getRecordingsList(RecMan* recman)
422 VDR_RequestPacket vrp;
423 if (!vrp.init(VDR_GETRECORDINGLIST, true, 0)) return false;
425 VDR_ResponsePacket* vresp = RequestResponse(&vrp);
426 if (vresp->noResponse()) { delete vresp; return false; }
428 ULONG totalSpace = vresp->extractULONG();
429 ULONG freeSpace = vresp->extractULONG();
430 ULONG percent = vresp->extractULONG();
431 recman->setStats(totalSpace, freeSpace, percent);
437 while (!vresp->end())
439 start = vresp->extractULONG();
440 name = vresp->extractString();
441 fileName = vresp->extractString();
443 recman->addEntry(start, name, fileName);
454 int VDR::deleteRecording(char* fileName)
456 VDR_RequestPacket vrp;
457 if (!vrp.init(VDR_DELETERECORDING, true, strlen(fileName) + 1)) return 0;
458 if (!vrp.addString(fileName)) return 0;
460 VDR_ResponsePacket* vresp = RequestResponse(&vrp);
461 if (vresp->noResponse()) { delete vresp; return 0; }
463 int toReturn = (int)vresp->extractULONG();
469 char* VDR::moveRecording(char* fileName, char* newPath)
471 VDR_RequestPacket vrp;
472 if (!vrp.init(VDR_MOVERECORDING, true, strlen(fileName) + 1 + strlen(newPath) + 1)) return NULL;
473 if (!vrp.addString(fileName)) return NULL;
474 if (!vrp.addString(newPath)) return NULL;
476 VDR_ResponsePacket* vresp = RequestResponse(&vrp);
477 if (vresp->noResponse()) { delete vresp; return NULL; }
479 char* toReturn = NULL;
480 int success = (int)vresp->extractULONG();
483 toReturn = vresp->extractString();
491 ChannelList* VDR::getChannelsList(ULONG type)
493 VDR_RequestPacket vrp;
494 if (!vrp.init(VDR_GETCHANNELLIST, true, 0)) return NULL;
496 VDR_ResponsePacket* vresp = RequestResponse(&vrp);
497 if (vresp->noResponse()) { delete vresp; return NULL; }
499 ChannelList* chanList = new ChannelList();
501 while (!vresp->end())
503 Channel* chan = new Channel();
504 chan->number = vresp->extractULONG();
505 chan->type = vresp->extractULONG();
506 chan->name = vresp->extractString();
508 if (chan->type == type)
510 chanList->push_back(chan);
511 Log::getInstance()->log("VDR", Log::DEBUG, "Have added a channel to list. %lu %lu %s", chan->number, chan->type, chan->name);
512 if (chan->number > maxChannelNumber) maxChannelNumber = chan->number;
522 if (maxChannelNumber > 99999)
523 channelNumberWidth = 6;
524 else if (maxChannelNumber > 9999)
525 channelNumberWidth = 5;
526 else if (maxChannelNumber > 999)
527 channelNumberWidth = 4;
528 else if (maxChannelNumber > 99)
529 channelNumberWidth = 3;
530 else if (maxChannelNumber > 9)
531 channelNumberWidth = 2;
533 channelNumberWidth = 1;
539 int VDR::streamChannel(ULONG number)
545 int VDR::streamChannel(ULONG number, StreamReceiver* tstreamReceiver)
547 VDR_RequestPacket vrp;
548 if (!vrp.init(VDR_STREAMCHANNEL, true, sizeof(ULONG))) return 0;
549 if (!vrp.addULONG(number)) return 0;
552 VDR_PacketReceiver* vdrpr = new VDR_PacketReceiver(); // FIXME - leaked
553 vdrpr->receiverChannel = VDR::CHANNEL_STREAM;
554 vdrpr->streamID = vrp.getSerial();
555 vdrpr->streamReceiver = tstreamReceiver;
558 VDR_ResponsePacket* vresp = RequestResponse(&vrp);
559 if (vresp->noResponse())
567 int toReturn = (int)vresp->extractULONG();
573 int VDR::stopStreaming()
575 VDR_RequestPacket vrp;
576 if (!vrp.init(VDR_STOPSTREAMING, true, 0)) return 0;
578 VDR_ResponsePacket* vresp = RequestResponse(&vrp);
579 if (vresp->noResponse()) { delete vresp; return 0; }
581 int toReturn = (int)vresp->extractULONG();
587 UCHAR* VDR::getImageBlock(ULONG position, UINT maxAmount, UINT* amountReceived)
589 return getBlock(position, maxAmount, amountReceived, VDR_GETIMAGEBLOCK);
592 UCHAR* VDR::getBlock(ULLONG position, UINT maxAmount, UINT* amountReceived)
594 return getBlock(position, maxAmount, amountReceived, VDR_GETBLOCK);
597 UCHAR* VDR::getBlock(ULLONG position, UINT maxAmount, UINT* amountReceived, ULONG cmd)
599 VDR_RequestPacket vrp;
600 if (!vrp.init(cmd, true, sizeof(ULLONG) + sizeof(ULONG))) return NULL;
601 if (!vrp.addULLONG(position)) return NULL;
602 if (!vrp.addULONG(maxAmount)) return NULL;
604 VDR_ResponsePacket* vresp = RequestResponse(&vrp);
605 if (vresp->noResponse()) { delete vresp; return NULL; }
607 if (vresp->serverError())
609 Log::getInstance()->log("VDR", Log::DEBUG, "Detected getblock 0");
614 // Special handling for getblock
615 UCHAR* toReturn = vresp->getUserData();
616 *amountReceived = vresp->getUserDataLength();
623 ULLONG VDR::streamRecording(char* fileName, ULONG* totalFrames)
625 VDR_RequestPacket vrp;
626 if (!vrp.init(VDR_STREAMRECORDING, true, strlen(fileName) + 1)) return 0;
627 if (!vrp.addString(fileName)) return 0;
629 VDR_ResponsePacket* vresp = RequestResponse(&vrp);
630 if (vresp->noResponse()) { delete vresp; return 0; }
632 ULLONG lengthBytes = vresp->extractULLONG();
633 ULONG lengthFrames = vresp->extractULONG();
636 Log::getInstance()->log("VDR", Log::DEBUG, "VDR said length is: %llu %lu", lengthBytes, lengthFrames);
638 *totalFrames = lengthFrames;
642 ULLONG VDR::positionFromFrameNumber(ULONG frameNumber)
644 VDR_RequestPacket vrp;
645 if (!vrp.init(VDR_POSFROMFRAME, true, sizeof(ULONG))) return 0;
646 if (!vrp.addULONG(frameNumber)) return 0;
648 VDR_ResponsePacket* vresp = RequestResponse(&vrp);
649 if (vresp->noResponse()) { delete vresp; return 0; }
651 ULLONG position = vresp->extractULLONG();
654 Log::getInstance()->log("VDR", Log::DEBUG, "VDR said new position is: %llu", position);
659 ULONG VDR::frameNumberFromPosition(ULLONG position)
661 VDR_RequestPacket vrp;
662 if (!vrp.init(VDR_FRAMEFROMPOS, true, sizeof(ULLONG))) return 0;
663 if (!vrp.addULLONG(position)) return 0;
665 VDR_ResponsePacket* vresp = RequestResponse(&vrp);
666 if (vresp->noResponse()) { delete vresp; return 0; }
668 ULONG framenumber = vresp->extractULONG();
671 Log::getInstance()->log("VDR", Log::DEBUG, "VDR said new framenumber is: %u", framenumber);
676 bool VDR::getNextIFrame(ULONG frameNumber, ULONG direction, ULLONG* rfilePosition, ULONG* rframeNumber, ULONG* rframeLength)
678 VDR_RequestPacket vrp;
679 if (!vrp.init(VDR_GETNEXTIFRAME, true, sizeof(ULONG)*2)) return false;
680 if (!vrp.addULONG(frameNumber)) return false;
681 if (!vrp.addULONG(direction)) return false;
683 VDR_ResponsePacket* vresp = RequestResponse(&vrp);
684 if (vresp->noResponse()) { delete vresp; return false; }
686 if (vresp->serverError())
688 Log::getInstance()->log("VDR", Log::DEBUG, "Detected getNextIFrame error");
693 *rfilePosition = vresp->extractULLONG();
694 *rframeNumber = vresp->extractULONG();
695 *rframeLength = vresp->extractULONG();
699 // Log::getInstance()->log("VDR", Log::DEBUG, "VDR GNIF said %llu %lu %lu", *rfilePosition, *rframeNumber, *rframeLength);
704 EventList* VDR::getChannelSchedule(ULONG number)
708 return getChannelSchedule(number, now, 24 * 60 * 60);
711 EventList* VDR::getChannelSchedule(ULONG number, time_t start, ULONG duration)
713 // retrieve event list (vector of events) from vdr within filter window. duration is in seconds
715 VDR_RequestPacket vrp;
716 if (!vrp.init(VDR_GETCHANNELSCHEDULE, true, sizeof(ULONG)*3)) return NULL;
717 if (!vrp.addULONG(number)) return NULL;
718 if (!vrp.addULONG(start)) return NULL;
719 if (!vrp.addULONG(duration)) return NULL;
721 VDR_ResponsePacket* vresp = RequestResponse(&vrp);
722 if (vresp->noResponse()) { delete vresp; return NULL; }
724 // received a ulong(0) - schedules error in the plugin
725 if (vresp->serverError())
731 EventList* eventList = new EventList();
733 while (!vresp->end())
735 Event* event = new Event();
736 event->id = vresp->extractULONG();
737 event->time = vresp->extractULONG();
738 event->duration = vresp->extractULONG();
739 event->title = vresp->extractString();
740 event->subtitle = vresp->extractString();
741 event->description = vresp->extractString();
742 eventList->push_back(event);
747 Log::getInstance()->log("VDR", Log::DEBUG, "Success got to end of getChannelSchedule");
751 int VDR::configSave(const char* section, const char* key, const char* value)
753 VDR_RequestPacket vrp;
754 if (!vrp.init(VDR_CONFIGSAVE, false, 0)) return 0;
755 if (!vrp.addString(section)) return 0;
756 if (!vrp.addString(key)) return 0;
757 if (!vrp.addString(value)) return 0;
759 VDR_ResponsePacket* vresp = RequestResponse(&vrp);
760 if (vresp->noResponse()) { delete vresp; return 0; }
762 int toReturn = (int)vresp->extractULONG();
768 char* VDR::configLoad(const char* section, const char* key)
770 VDR_RequestPacket vrp;
771 if (!vrp.init(VDR_CONFIGLOAD, false, 0)) return NULL;
772 if (!vrp.addString(section)) return NULL;
773 if (!vrp.addString(key)) return NULL;
775 VDR_ResponsePacket* vresp = RequestResponse(&vrp);
776 if (vresp->noResponse()) { delete vresp; return NULL; }
778 char* toReturn = vresp->extractString();
784 RecTimerList* VDR::getRecTimersList()
786 VDR_RequestPacket vrp;
787 if (!vrp.init(VDR_GETTIMERS, true, 0)) return NULL;
789 VDR_ResponsePacket* vresp = RequestResponse(&vrp);
790 if (vresp->noResponse()) { delete vresp; return NULL; }
792 RecTimerList* recTimerList = new RecTimerList();
794 ULONG numTimers = vresp->extractULONG();
797 RecTimer* newRecTimer;
800 while (!vresp->end())
802 newRecTimer = new RecTimer();
803 newRecTimer->active = vresp->extractULONG();
804 newRecTimer->recording = vresp->extractULONG();
805 newRecTimer->pending = vresp->extractULONG();
806 newRecTimer->priority = vresp->extractULONG();
807 newRecTimer->lifeTime = vresp->extractULONG();
808 newRecTimer->channelNumber = vresp->extractULONG();
809 newRecTimer->startTime = vresp->extractULONG();
810 newRecTimer->stopTime = vresp->extractULONG();
811 newRecTimer->day = vresp->extractULONG();
812 newRecTimer->weekDays = vresp->extractULONG();
814 tempString = vresp->extractString();
815 newRecTimer->setFile(tempString);
818 recTimerList->push_back(newRecTimer);
819 Log::getInstance()->log("VDR", Log::DEBUG, "TL: %lu %lu %lu %lu %lu %lu %lu %lu %s",
820 newRecTimer->active, newRecTimer->recording, newRecTimer->pending, newRecTimer->priority, newRecTimer->lifeTime,
821 newRecTimer->channelNumber, newRecTimer->startTime, newRecTimer->stopTime, newRecTimer->getFile());
827 sort(recTimerList->begin(), recTimerList->end(), RecTimerSorter());
832 ULONG VDR::setEventTimer(char* timerString)
834 VDR_RequestPacket vrp;
835 if (!vrp.init(VDR_SETTIMER, true, strlen(timerString) + 1)) return 0;
836 if (!vrp.addString(timerString)) return 0;
838 VDR_ResponsePacket* vresp = RequestResponse(&vrp);
839 if (vresp->noResponse()) { delete vresp; return 0; }
841 ULONG toReturn = vresp->extractULONG();
847 RecInfo* VDR::getRecInfo(char* fileName)
849 VDR_RequestPacket vrp;
850 if (!vrp.init(VDR_GETRECINFO, true, strlen(fileName) + 1)) return NULL;
851 if (!vrp.addString(fileName)) return NULL;
853 VDR_ResponsePacket* vresp = RequestResponse(&vrp);
854 if (vresp->noResponse()) { delete vresp; return NULL; }
856 if (vresp->serverError())
858 Log::getInstance()->log("VDR", Log::DEBUG, "Could not get rec info");
863 RecInfo* recInfo = new RecInfo();
865 recInfo->timerStart = vresp->extractULONG();
866 recInfo->timerEnd = vresp->extractULONG();
867 recInfo->resumePoint = vresp->extractULONG();
868 recInfo->summary = vresp->extractString();
870 ULONG numComponents = vresp->extractULONG();
873 recInfo->setNumComponents(numComponents);
874 for (ULONG i = 0; i < numComponents; i++)
876 recInfo->streams[i] = vresp->extractUCHAR();
877 recInfo->types[i] = vresp->extractUCHAR();
878 recInfo->languages[i] = vresp->extractString();
879 recInfo->descriptions[i] = vresp->extractString();
890 ULLONG VDR::rescanRecording(ULONG* totalFrames)
892 VDR_RequestPacket vrp;
893 if (!vrp.init(VDR_RESCANRECORDING, true, 0)) return 0;
895 VDR_ResponsePacket* vresp = RequestResponse(&vrp);
896 if (vresp->noResponse()) { delete vresp; return 0; }
898 ULLONG lengthBytes = vresp->extractULLONG();
899 ULONG lengthFrames = vresp->extractULONG();
902 Log::getInstance()->log("VDR", Log::DEBUG, "VDR said length is: %llu %lu", lengthBytes, lengthFrames);
904 *totalFrames = lengthFrames;
908 MarkList* VDR::getMarks(char* fileName)
910 VDR_RequestPacket vrp;
911 if (!vrp.init(VDR_GETMARKS, true, strlen(fileName) + 1)) return NULL;
912 if (!vrp.addString(fileName)) return NULL;
914 VDR_ResponsePacket* vresp = RequestResponse(&vrp);
915 if (vresp->noResponse()) { delete vresp; return NULL; }
917 if (vresp->serverError())
923 MarkList* markList = new MarkList();
925 while (!vresp->end())
927 Mark* mark = new Mark();
928 mark->pos = vresp->extractULONG();
930 markList->push_back(mark);
931 Log::getInstance()->log("VDR", Log::DEBUG, "Have added a mark to list. %lu", mark->pos);
939 void VDR::getChannelPids(Channel* channel)
941 VDR_RequestPacket vrp;
942 if (!vrp.init(VDR_GETCHANNELPIDS, true, sizeof(ULONG))) return ;
943 if (!vrp.addULONG(channel->number)) return ;
945 VDR_ResponsePacket* vresp = RequestResponse(&vrp);
946 if (vresp->noResponse()) { delete vresp; return ; }
948 // Format of response
956 channel->vpid = vresp->extractULONG();
957 channel->numAPids = vresp->extractULONG();
959 for (ULONG i = 0; i < channel->numAPids; i++)
962 newapid.pid = vresp->extractULONG();
963 newapid.name = vresp->extractString();
964 channel->apids.push_back(newapid);
973 * media List Request:
974 * 4 flags (currently unused)
977 * Media List response:
985 * 4 strlen (incl. 0 Byte)
989 MediaList* VDR::getMediaList(const char* parent,int mediaType)
991 Log::getInstance()->log("VDR", Log::DEBUG, "getMediaList %s,type=%d", (parent?parent:"NULL"), mediaType);
993 VDR_RequestPacket vrp;
994 if (!vrp.init(VDR_GETMEDIALIST, false, 0)) return NULL;
995 if (!vrp.addULONG(0)) return NULL; // unused flags
999 if (!vrp.addString(parent)) return NULL;
1002 VDR_ResponsePacket* vresp = RequestResponse(&vrp);
1003 if (vresp->noResponse()) { delete vresp; return NULL; }
1005 if (vresp->serverError())
1011 if (vresp->getUserDataLength() < 12)
1013 Log::getInstance()->log("VDR", Log::ERR, "receiveMediaList packet too short, expected 12, got %d", vresp->getUserDataLength());
1018 MediaList* mediaList = new MediaList();
1020 code = vresp->extractULONG();
1021 ULONG numEntries = vresp->extractULONG();
1022 Log::getInstance()->log("VDR", Log::DEBUG, "receiveMediaList with %d entries",numEntries);
1023 while (!vresp->end() && numEntries >0)
1025 Media* m = new Media();
1026 ULONG mtype = vresp->extractULONG();
1027 ULONG mtime=vresp->extractULONG();
1029 flags=vresp->extractULONG();
1030 ULONG stsize=vresp->extractULONG();
1031 char * name=vresp->extractString();
1032 if (! name || stsize != (strlen(name)+1)) {
1033 Log::getInstance()->log("VDR", Log::ERR, "receiveMediaList invalid packet entry, read size %d, strlen %d", stsize, strlen(name)+1);
1039 //ignore . and .. entries
1040 if (strcmp(name,".") == 0 || strcmp(name,"..")==0) {
1044 m->setFileName(name);
1046 m->setMediaType(mtype);
1047 mediaList->push_back(m);
1048 Log::getInstance()->log("VDR", Log::DEBUG, "Have added a media to list. %s, type=%d, time=%d", name,mtype,mtime);
1057 * get image Request:
1058 * 4 flags (currently unused)
1063 * get image response:
1068 ULONG VDR::loadImage(const char* fileName, ULONG x, ULONG y)
1070 VDR_RequestPacket vrp;
1071 if (!vrp.init(VDR_GETIMAGE, false, 0)) return 0;
1072 if (!vrp.addULONG(0)) return 0; // unused flags
1073 if (!vrp.addULONG(x)) return 0;
1074 if (!vrp.addULONG(y)) return 0;
1075 if (!vrp.addString(fileName)) return 0;
1077 VDR_ResponsePacket* vresp = RequestResponse(&vrp);
1078 if (vresp->noResponse()) { delete vresp; return 0; }
1080 ULONG cmd = vresp->extractULONG();
1081 ULONG lengthBytes = vresp->extractULONG();
1084 Log::getInstance()->log("VDR", Log::DEBUG, "getImage %s: cmd=%lu len=%lu", fileName, cmd, lengthBytes);
1088 int VDR::deleteTimer(RecTimer* delTimer)
1090 Log::getInstance()->log("VDR", Log::DEBUG, "Delete timer called");
1092 VDR_RequestPacket vrp;
1093 if (!vrp.init(VDR_DELETETIMER, false, 0)) return 0;
1094 if (!vrp.addULONG(delTimer->channelNumber)) return 0;
1095 if (!vrp.addULONG(delTimer->weekDays)) return 0;
1096 if (!vrp.addULONG(delTimer->day)) return 0;
1097 if (!vrp.addULONG(delTimer->startTime)) return 0;
1098 if (!vrp.addULONG(delTimer->stopTime)) return 0;
1100 VDR_ResponsePacket* vresp = RequestResponse(&vrp);
1101 if (vresp->noResponse()) { delete vresp; return 0; }
1103 int toReturn = (int)vresp->extractULONG();