From 84c6cb876b34ec310f9b34a9aaf45105f341f595 Mon Sep 17 00:00:00 2001 From: Chris Tallon Date: Wed, 3 Apr 2013 19:41:34 +0100 Subject: [PATCH] Fill out get rec info call --- handler.c | 73 +++++++++++++++++++++++++++++++++++++++++++++---------- 1 file changed, 60 insertions(+), 13 deletions(-) diff --git a/handler.c b/handler.c index 6076d6c..973dbf9 100644 --- a/handler.c +++ b/handler.c @@ -60,6 +60,7 @@ int jsonserver_request_handler(struct mg_connection *conn) log->log("JSONServer", Log::DEBUG, "Could not read up to contentLength"); return 0; } + postData[contentLengthI] = '\0'; } } @@ -155,8 +156,6 @@ bool jsonserver_reclist(Json::Value& js) bool jsonserver_recinfo(Json::Value& js, const char* postData) { - // For now this returns just the string summary of the recording - Log* log = Log::getInstance(); log->log("JSONServer", Log::DEBUG, "recinfo"); @@ -176,21 +175,69 @@ bool jsonserver_recinfo(Json::Value& js, const char* postData) Recordings.Load(); // probably have to do this cRecording *recording = Recordings.GetByName(reqfilename); - if (recording) - { - const cRecordingInfo *Info = recording->Info(); - char* summary = (char*)Info->ShortText(); - if (isempty(summary)) summary = (char*)Info->Description(); - js["Result"] = true; - js["Summary"] = summary; - } - else + if (!recording) { log->log("JSONServer", Log::ERR, "recinfo found no recording"); js["Result"] = false; - js["Summary"] = ""; - } + return true; + } + + js["IsNew"] = recording->IsNew(); + js["LengthInSeconds"] = recording->LengthInSeconds(); + js["FileSizeMB"] = recording->FileSizeMB(); + js["Name"] = recording->Name() ? recording->Name() : Json::Value::null; + js["Priority"] = recording->Priority(); + js["LifeTime"] = recording->Lifetime(); + js["Start"] = (Json::UInt)recording->Start(); + + js["ResumePoint"] = 0; + cResumeFile ResumeFile(recording->FileName(), recording->IsPesRecording()); + if (ResumeFile.Read() >= 0) js["ResumePoint"] = ResumeFile.Read(); + + js["CurrentlyRecordingStart"] = 0; + js["CurrentlyRecordingStop"] = 0; + cRecordControl *rc = cRecordControls::GetRecordControl(recording->FileName()); + if (rc) + { + js["CurrentlyRecordingStart"] = (Json::UInt)rc->Timer()->StartTime(); + js["CurrentlyRecordingStop"] = (Json::UInt)rc->Timer()->StopTime(); + } + const cRecordingInfo *info = recording->Info(); + if (info) + { + js["ChannelName"] = info->ChannelName() ? info->ChannelName() : Json::Value::null; + js["Title"] = info->Title() ? info->Title() : Json::Value::null; + js["ShortText"] = info->ShortText() ? info->ShortText() : Json::Value::null; + js["Description"] = info->Description() ? info->Description() : Json::Value::null; + + const cComponents* components = info->Components(); + if (!components) + { + js["Components"] = Json::Value::null; + } + else + { + Json::Value jscomponents; + + tComponent* component; + for (int i = 0; i < components->NumComponents(); i++) + { + component = components->Component(i); + + Json::Value oneComponent; + oneComponent["Stream"] = component->stream; + oneComponent["Type"] = component->type; + oneComponent["Language"] = component->language ? component->language : Json::Value::null; + oneComponent["Description"] = component->description ? component->description : Json::Value::null; + jscomponents.append(oneComponent); + } + + js["Components"] = jscomponents; + } + } + + js["Result"] = true; return true; } -- 2.39.2