From 9a90d31b789f7cab0ea33d7d8445b6d5b61d2ba8 Mon Sep 17 00:00:00 2001 From: Mark Kendall Date: Fri, 11 Nov 2011 11:44:00 +0000 Subject: [PATCH] Frontend Services: Move action handling from MythFEXML to service. - The 'helper' method GetActionTest remains in MythFEXML. - Arguments are now capitalised for consistency with the rest of the services API. - the Frontend Remote Control is modified for the new urls and methods. Old methods: http://frontend-ip:6547/MythFE/SendAction?action=UP http://frontend- New methods: http://frontend-ip:6547/Frontend/SendAction?Action=UP http://frontend- --- .../datacontracts/frontendActionList.h | 47 ++++++ .../libmythservicecontracts.pro | 2 + .../services/frontendServices.h | 6 + mythtv/programs/mythfrontend/mythfexml.cpp | 139 +----------------- mythtv/programs/mythfrontend/mythfexml.h | 19 --- .../mythfrontend/services/frontend.cpp | 116 +++++++++++++++ .../programs/mythfrontend/services/frontend.h | 12 ++ 7 files changed, 189 insertions(+), 152 deletions(-) create mode 100644 mythtv/libs/libmythservicecontracts/datacontracts/frontendActionList.h diff --git a/mythtv/libs/libmythservicecontracts/datacontracts/frontendActionList.h b/mythtv/libs/libmythservicecontracts/datacontracts/frontendActionList.h new file mode 100644 index 00000000000..7adcbe4bbe8 --- /dev/null +++ b/mythtv/libs/libmythservicecontracts/datacontracts/frontendActionList.h @@ -0,0 +1,47 @@ +#ifndef FRONTENDACTIONLIST_H +#define FRONTENDACTIONLIST_H + +#include "serviceexp.h" +#include "datacontracthelper.h" + +namespace DTC +{ + class SERVICE_PUBLIC FrontendActionList : public QObject + { + Q_OBJECT + Q_CLASSINFO("version", "1.0"); + + Q_CLASSINFO("ActionList_type", "Action"); // is this legal? + + Q_PROPERTY(QVariantMap ActionList READ ActionList DESIGNABLE true) + + PROPERTYIMP_RO_REF(QVariantMap, ActionList) + + public: + static void InitializeCustomTypes() + { + qRegisterMetaType(); + qRegisterMetaType(); + } + + public: + FrontendActionList(QObject *parent = 0) : QObject(parent) + { + } + + FrontendActionList(const FrontendActionList &src) + { + Copy(src); + } + + void Copy(const FrontendActionList &src) + { + m_ActionList = src.m_ActionList; + } + }; +}; + +Q_DECLARE_METATYPE(DTC::FrontendActionList) +Q_DECLARE_METATYPE(DTC::FrontendActionList*) + +#endif // FRONTENDACTIONLIST_H diff --git a/mythtv/libs/libmythservicecontracts/libmythservicecontracts.pro b/mythtv/libs/libmythservicecontracts/libmythservicecontracts.pro index 625ca5ccdcf..a9141ef1c0c 100644 --- a/mythtv/libs/libmythservicecontracts/libmythservicecontracts.pro +++ b/mythtv/libs/libmythservicecontracts/libmythservicecontracts.pro @@ -36,6 +36,7 @@ HEADERS += datacontracts/lineup.h datacontracts/captureCard.h HEADERS += datacontracts/captureCardList.h datacontracts/recRule.h HEADERS += datacontracts/recRuleList.h HEADERS += datacontracts/frontendStatus.h +HEADERS += datacontracts/frontendActionList.h SOURCES += service.cpp @@ -71,6 +72,7 @@ incDatacontracts.files += datacontracts/versionInfo.h datacontracts/line incDatacontracts.files += datacontracts/captureCard.h datacontracts/captureCardList.h incDatacontracts.files += datacontracts/recRule.h datacontracts/recRuleList.h incDatacontracts.files += datacontracts/frontendStatus.h +incDatacontracts.files += datacontracts/frontendActionList.h INSTALLS += inc incServices incDatacontracts diff --git a/mythtv/libs/libmythservicecontracts/services/frontendServices.h b/mythtv/libs/libmythservicecontracts/services/frontendServices.h index 60f6b499904..8af540fe15e 100644 --- a/mythtv/libs/libmythservicecontracts/services/frontendServices.h +++ b/mythtv/libs/libmythservicecontracts/services/frontendServices.h @@ -3,6 +3,7 @@ #include "service.h" #include "datacontracts/frontendStatus.h" +#include "datacontracts/frontendActionList.h" class SERVICE_PUBLIC FrontendServices : public Service { @@ -13,11 +14,16 @@ class SERVICE_PUBLIC FrontendServices : public Service FrontendServices(QObject *parent = 0) : Service(parent) { DTC::FrontendStatus::InitializeCustomTypes(); + DTC::FrontendActionList::InitializeCustomTypes(); } public slots: virtual DTC::FrontendStatus* GetStatus(void) = 0; virtual bool SendMessage(const QString &Message) = 0; + virtual bool SendAction(const QString &Action, + const QString &File, + uint Width, uint Height) = 0; + virtual DTC::FrontendActionList* GetActionList(void) = 0; }; #endif // FRONTENDSERVICES_H diff --git a/mythtv/programs/mythfrontend/mythfexml.cpp b/mythtv/programs/mythfrontend/mythfexml.cpp index 02cc0df2229..66bc53c3806 100644 --- a/mythtv/programs/mythfrontend/mythfexml.cpp +++ b/mythtv/programs/mythfrontend/mythfexml.cpp @@ -26,6 +26,8 @@ #include "keybindings.h" +#include "services/frontend.h" + ///////////////////////////////////////////////////////////////////////////// // ///////////////////////////////////////////////////////////////////////////// @@ -61,8 +63,6 @@ MythFEXMLMethod MythFEXML::GetMethod(const QString &sURI) { if (sURI == "GetServDesc") return MFEXML_GetServiceDescription; if (sURI == "GetScreenShot") return MFEXML_GetScreenShot; - if (sURI == "SendAction") return MFEXML_Action; - if (sURI == "GetActionList") return MFEXML_ActionList; if (sURI == "GetActionTest") return MFEXML_ActionListTest; if (sURI == "GetRemote") return MFEXML_GetRemote; @@ -101,12 +101,6 @@ bool MythFEXML::ProcessRequest( HTTPRequest *pRequest ) case MFEXML_GetScreenShot: GetScreenShot(pRequest); break; - case MFEXML_Action: - SendAction(pRequest); - break; - case MFEXML_ActionList: - GetActionList(pRequest); - break; case MFEXML_ActionListTest: GetActionListTest(pRequest); break; @@ -159,59 +153,15 @@ void MythFEXML::GetScreenShot(HTTPRequest *pRequest) pRequest->m_sFileName = sFileName; } -void MythFEXML::SendAction(HTTPRequest *pRequest) -{ - QStringMap* map = &pRequest->m_mapParams; - pRequest->m_eResponseType = ResponseTypeHTML; - QString sText = map->value("action"); - uint pcount = map->size(); - - LOG(VB_UPNP, LOG_INFO, QString("UPNP Action: %1 (total %2 params)") - .arg(sText).arg(pcount)); - - if (!IsValidAction(sText)) - return; - - if (pcount > 1) - { - bool valid = false; - QStringList args; - if (ACTION_SCREENSHOT == sText && 3 == pcount) - { - args << map->value("width"); - args << map->value("height"); - valid = true; - } - else if (ACTION_HANDLEMEDIA == sText && 2 == pcount) - { - args << map->value("file"); - valid = true; - } - - if (valid) - { - MythEvent* me = new MythEvent(sText, args); - qApp->postEvent(GetMythMainWindow(), me); - return; - } - - LOG(VB_UPNP, LOG_WARNING, - "Failed to validate extra paramaters - ignoring"); - } - - QKeyEvent* ke = new QKeyEvent(QEvent::KeyPress, 0, Qt::NoModifier, sText); - qApp->postEvent(GetMythMainWindow(), (QEvent*)ke); -} - static const QString PROCESS_ACTION = "