Skip to content

Commit

Permalink
added player-info to info-service
Browse files Browse the repository at this point in the history
  • Loading branch information
MichaEiler committed Jul 16, 2011
1 parent cf2d4ca commit 3a37f7f
Show file tree
Hide file tree
Showing 4 changed files with 47 additions and 5 deletions.
26 changes: 26 additions & 0 deletions info.cpp
Expand Up @@ -33,6 +33,7 @@ void InfoResponder::replyHtml(StreamExtension& se)
void InfoResponder::replyJson(StreamExtension& se)
{
time_t now = time(0);
StatusMonitor* statm = StatusMonitor::get();

cxxtools::JsonSerializer serializer(*se.getBasicStream());
serializer.serialize("0.0.1", "version");
Expand Down Expand Up @@ -61,13 +62,25 @@ void InfoResponder::replyJson(StreamExtension& se)
}

serializer.serialize(services, "services");

if ( statm->getRecordingName().length() > 0 || statm->getRecordingFile().length() > 0 ) {
SerPlayerInfo pi;
pi.Name = StringExtension::UTF8Decode(statm->getRecordingName());
pi.FileName = StringExtension::UTF8Decode(statm->getRecordingFile());
serializer.serialize(pi, "video");
} else {
serializer.serialize(statm->getChannel(), "channel");
}

serializer.serialize(pl, "vdr");
serializer.finish();
}

void InfoResponder::replyXml(StreamExtension& se)
{
time_t now = time(0);
StatusMonitor* statm = StatusMonitor::get();


se.writeXmlHeader();
se.write("<info xmlns=\"http://www.domain.org/restfulapi/2011/info-xml\">\n");
Expand All @@ -84,6 +97,13 @@ void InfoResponder::replyXml(StreamExtension& se)
}
se.write(" </services>\n");


if ( statm->getRecordingName().length() > 0 || statm->getRecordingFile().length() > 0 ) {
se.write((const char*)cString::sprintf(" <video name=\"%s\">%s</video>\n", StringExtension::encodeToXml(statm->getRecordingName()).c_str(), StringExtension::encodeToXml(statm->getRecordingFile()).c_str()));
} else {
se.write((const char*)cString::sprintf(" <channel>%i</channel>\n", statm->getChannel()));
}

se.write(" <vdr>\n");
se.write(" <plugins>\n");

Expand Down Expand Up @@ -117,3 +137,9 @@ void operator<<= (cxxtools::SerializationInfo& si, const SerPluginList& pl)
si.addMember("plugins") <<= pl.plugins;
}

void operator<<= (cxxtools::SerializationInfo& si, const SerPlayerInfo& pi)
{
si.addMember("name") <<= pi.Name;
si.addMember("filename") <<= pi.FileName;
}

8 changes: 8 additions & 0 deletions info.h
Expand Up @@ -6,6 +6,7 @@
#include "tools.h"
#include <time.h>
#include <vector>
#include "statusmonitor.h"

struct SerService
{
Expand All @@ -25,9 +26,16 @@ struct SerPluginList
std::vector< struct SerPlugin > plugins;
};

struct SerPlayerInfo
{
cxxtools::String Name;
cxxtools::String FileName;
};

void operator<<= (cxxtools::SerializationInfo& si, const SerService& s);
void operator<<= (cxxtools::SerializationInfo& si, const SerPlugin& p);
void operator<<= (cxxtools::SerializationInfo& si, const SerPluginList& pl);
void operator<<= (cxxtools::SerializationInfo& si, const SerPlayerInfo& pi);

class InfoResponder : public cxxtools::http::Responder
{
Expand Down
14 changes: 10 additions & 4 deletions statusmonitor.cpp
Expand Up @@ -173,8 +173,9 @@ void StatusMonitor::TimerChange(const cTimer *Timer, eTimerChange Change)

void StatusMonitor::ChannelSwitch(const cDevice *Device, int ChannelNumber)
{
device = (cDevice*)Device;
channel_number = ChannelNumber;
if (ChannelNumber != 0) {
channel_number = ChannelNumber;
}
}

void StatusMonitor::Recording(const cDevice *Device, const char *Name, const char *FileName, bool On)
Expand All @@ -184,8 +185,13 @@ void StatusMonitor::Recording(const cDevice *Device, const char *Name, const cha

void StatusMonitor::Replaying(const cControl *Control, const char *Name, const char *FileName, bool On)
{
recording_name = std::string(Name);
recording_file = std::string(FileName);
if (On) {
if(Name != NULL) recording_name = std::string(Name); else recording_name = "";
if(FileName != NULL) recording_file = std::string(FileName); else recording_file = "";
} else {
recording_name = "";
recording_file = "";
}
}

void StatusMonitor::SetVolume(int Volume, bool Absolute)
Expand Down
4 changes: 3 additions & 1 deletion statusmonitor.h
Expand Up @@ -143,7 +143,9 @@ class StatusMonitor : public cStatus
~StatusMonitor() { };
static StatusMonitor* get();
BasicOsd* getOsd() { return _osd; }
//Add methods for other information, now only Osd can be returned!
int getChannel() { return channel_number; }
std::string getRecordingName() { return recording_name; }
std::string getRecordingFile() { return recording_file; }
};

class DeleteOsdTask : BaseTask
Expand Down

0 comments on commit 3a37f7f

Please sign in to comment.