Skip to content

Commit

Permalink
switching to recording by calling /recordings/play/<recording-number>…
Browse files Browse the repository at this point in the history
… - untested
  • Loading branch information
MichaEiler committed Apr 30, 2012
1 parent 7f2e269 commit fed3551
Show file tree
Hide file tree
Showing 4 changed files with 40 additions and 2 deletions.
25 changes: 25 additions & 0 deletions recordings.cpp
Expand Up @@ -6,6 +6,15 @@ void RecordingsResponder::reply(ostream& out, cxxtools::http::Request& request,
QueryHandler::addHeader(reply);
bool found = false;

if ((int)request.url().find("/recordings/play") == 0 ) {
if ( request.method() == "GET" ) {
playRecording(out, request, reply);
} else {
reply.httpReturn(501, "Only GET method is supported by the /recordings/play service.");
}
found = true;
}

if ((int)request.url().find("/recordings/cut") == 0 ) {
if ( request.method() == "GET" ) {
showCutterStatus(out, request, reply);
Expand Down Expand Up @@ -47,6 +56,22 @@ void RecordingsResponder::reply(ostream& out, cxxtools::http::Request& request,
}
}

void RecordingsResponder::playRecording(std::ostream& out, cxxtools::http::Request& request, cxxtools::http::Reply& reply)
{
QueryHandler q("/recordings/play", request);
int recording_number = q.getParamAsInt(0);
if ( recording_number < 0 || recording_number >= Recordings.Count() ) {
reply.httpReturn(404, "Wrong recording number!");
} else {
cRecording* recording = Recordings.Get(recording_number);
if ( recording != NULL ) {
TaskScheduler::get()->SwitchableRecording(recording);
} else {
reply.httpReturn(404, "Wrong recording number!");
}
}
}

void RecordingsResponder::deleteRecording(ostream& out, cxxtools::http::Request& request, cxxtools::http::Reply& reply)
{
QueryHandler q("/recordings", request);
Expand Down
1 change: 1 addition & 0 deletions recordings.h
Expand Up @@ -27,6 +27,7 @@ class RecordingsResponder : public cxxtools::http::Responder
void deleteMarks(std::ostream& out, cxxtools::http::Request& request, cxxtools::http::Reply& reply);
void cutRecording(std::ostream& out, cxxtools::http::Request& request, cxxtools::http::Reply& reply);
void showCutterStatus(std::ostream& out, cxxtools::http::Request& request, cxxtools::http::Reply& reply);
void playRecording(std::ostream& out, cxxtools::http::Request& request, cxxtools::http::Reply& reply);
};

typedef cxxtools::http::CachedService<RecordingsResponder> RecordingsService;
Expand Down
11 changes: 10 additions & 1 deletion restfulapi.cpp
Expand Up @@ -155,8 +155,17 @@ void cPluginRestfulapi::MainThreadHook(void)

if (!( channelID == tChannelID::InvalidID )) {
cChannel* channel = Channels.GetByChannelID(channelID);
if (channel != NULL)
if (channel != NULL) {
Channels.SwitchTo( channel->Number() );
scheduler->SwitchableChannel(tChannelID::InvalidID);
}
}

cRecording* recording = scheduler->SwitchableRecording();

if (recording != NULL) {
cReplayControl::SetRecording(recording->FileName(), recording->Title());
scheduler->SwitchableRecording(NULL);
}
}

Expand Down
5 changes: 4 additions & 1 deletion tools.h
Expand Up @@ -315,15 +315,18 @@ class TaskScheduler
protected:
std::list<BaseTask*> tasks;
tChannelID _channel;
cRecording* _recording;
cMutex _channelMutex;
public:
TaskScheduler() { _channel = tChannelID::InvalidID; };
TaskScheduler() { _channel = tChannelID::InvalidID; _recording = NULL; };
~TaskScheduler();
static TaskScheduler* get();
void AddTask(BaseTask* task) { tasks.push_back(task); };
void DoTasks();
void SwitchableChannel(tChannelID channel);
tChannelID SwitchableChannel();
void SwitchableRecording(cRecording* recording) { _recording = recording; }
cRecording* SwitchableRecording() { return _recording; }
};

#endif
Expand Down

0 comments on commit fed3551

Please sign in to comment.