29 bool bExceptionThrown =
false;
33 throw QString(
"Invalid argument to MethodInfo::Invoke. pService in nullptr");
36 for (
auto it = reqParams.cbegin(); it != reqParams.cend(); ++it)
38 lowerParams[it.key().toLower()] = *it;
48 QList<QByteArray> paramNames =
m_oMethod.parameterNames();
49 QList<QByteArray> paramTypes =
m_oMethod.parameterTypes();
56 std::array<void*,MAX_PARAMS> param {};
57 std::array<int,MAX_PARAMS>
types {};
65#if QT_VERSION < QT_VERSION_CHECK(6,0,0)
67 QMetaType oRetType = QMetaType(nRetIdx);
70 QMetaType oRetType =
m_oMethod.returnMetaType();
73 if (nRetIdx != QMetaType::UnknownType)
75 param[ 0 ] = oRetType.create();
81 types[ 0 ] = QMetaType::UnknownType;
88 for(
int nIdx = 0; nIdx < paramNames.length(); ++nIdx )
90 QString sValue = lowerParams[ paramNames[ nIdx ].toLower() ];
91 QString sParamType = paramTypes[ nIdx ];
93#if QT_VERSION < QT_VERSION_CHECK(6,0,0)
95 void *pParam =
nullptr;
97 if (nId != QMetaType::UnknownType)
99 pParam = QMetaType::create( nId );
102 QMetaType metaType = QMetaType::fromName( paramTypes[ nIdx ] );
103 void *pParam = metaType.create();
104 int nId = metaType.id();
106 if (nId == QMetaType::UnknownType)
108 LOG(VB_GENERAL, LOG_ERR,
109 QString(
"MethodInfo::Invoke - Type unknown '%1'")
111 throw QString(
"MethodInfo::Invoke - Type unknown '%1'")
121 QThread *currentThread = QThread::currentThread();
122 QThread *objectThread = pService->thread();
124 if (currentThread == objectThread)
125 LOG(VB_HTTP, LOG_DEBUG,
"*** Threads are same ***");
127 LOG(VB_HTTP, LOG_DEBUG,
"*** Threads are Different!!! ***");
130 if (pService->qt_metacall(QMetaObject::InvokeMetaMethod,
m_nMethodIndex, param.data()) >= 0)
131 LOG(VB_GENERAL, LOG_WARNING,
"qt_metacall error");
138 for (
int nIdx=1; nIdx < paramNames.length()+1; ++nIdx)
140 if ((
types[ nIdx ] != QMetaType::UnknownType) && (param[ nIdx ] !=
nullptr))
142 auto metaType = QMetaType(
types[ nIdx ] );
143 metaType.destroy(param[ nIdx ]);
147 catch (QString &sMsg)
149 LOG(VB_GENERAL, LOG_ERR,
150 QString(
"MethodInfo::Invoke - An Exception Occurred: %1")
153 if ((
types[ 0 ] != QMetaType::UnknownType) && (param[ 0 ] !=
nullptr ))
155 auto metaType = QMetaType(
types[ 0 ] );
156 metaType.destroy(param[ 0 ]);
163 bExceptionThrown =
true;
168 LOG(VB_GENERAL, LOG_INFO,
169 "MethodInfo::Invoke - An Exception Occurred" );
178 if ( param[ 0 ] !=
nullptr)
182 if (
types[ 0 ] != QMetaType::UnknownType)
184 auto metaType = QMetaType(
types[ 0 ] );
185 metaType.destroy(param[ 0 ]);
193 if (bExceptionThrown)
208 const QString &sExtensionName,
210 const QString &sSharePath )
212 m_sBaseUrl(
std::move(sBaseUrl)),
213 m_oMetaObject(metaObject)
225 for (
int nIdx = 0; nIdx <
m_oMetaObject.methodCount(); nIdx++)
229 if ((method.methodType() == QMetaMethod::Slot ) &&
230 (method.access() == QMetaMethod::Public ))
232 QString sName( method.methodSignature() );
238 if (sName ==
"deleteLater()")
246 oInfo.
m_sName = sName.section(
'(', 0, 0 );
252 QString sMethodClassInfo = oInfo.
m_sName +
"_Method";
259 QString sRequestType =
262 if (sRequestType ==
"POST")
264 else if (sRequestType ==
"GET" )
293 bool bHandled =
false;
303 LOG(VB_HTTP, LOG_INFO,
304 QString(
"ServiceHost::ProcessRequest: %1 : %2")
314 pService = qobject_cast<Service*>(
m_oMetaObject.newInstance());
331 bool bHandled2 =
false;
334 pService = qobject_cast<Service*>(
m_oMetaObject.newInstance());
347 throw QString(
"Invalid arguments to xsd query: %1")
376 QString sMethodName = pRequest->
m_sMethod;
377 bool bMethodFound =
false;
387 sMethodName =
"Get" + sMethodName;
390 sMethodName =
"Put" + sMethodName;
422 QVariant vResult = oInfo.
Invoke(pService,
446 catch (QString &sMsg)
448 LOG(VB_GENERAL, LOG_ERR, sMsg);
455 QString sMsg(
"ServiceHost::ProcessRequest - Unexpected Exception" );
457 LOG(VB_GENERAL, LOG_ERR, sMsg);
473 if (pResults !=
nullptr)
498 if (oInfo.isSymLink())
519 if ( vValue.canConvert< QObject* >())
521 const QObject *pObject = vValue.value< QObject* >();
526 if ( vValue.canConvert< QFileInfo >())
528 const auto oFileInfo = vValue.value< QFileInfo >();
539 pSer->
Serialize( vValue, vValue.typeName() );
void FormatFileResponse(const QString &sFileName)
Serializer * GetSerializer()
void FormatActionResponse(Serializer *ser)
HttpRequestType m_eRequestType
QVariant Invoke(Service *pService, const QStringMap &reqParams) const
virtual void Serialize(const QObject *pObject, const QString &_sName=QString())
virtual bool FormatResponse(HTTPRequest *pRequest, QObject *pResults)
bool ProcessRequest(HTTPRequest *pRequest) override
QStringList GetBasePaths() override
ServiceHost(const QMetaObject &metaObject, const QString &sExtensionName, QString sBaseUrl, const QString &sSharePath)
QMetaObject m_oMetaObject
QList< QString > m_parsedParams
virtual void * ConvertToParameterPtr(int nTypeId, const QString &sParamType, void *pParam, const QString &sValue)
virtual QVariant ConvertToVariant(int nType, void *pValue)
static void FormatRedirectResponse(HTTPRequest *pRequest, const QString &hostName)
static void FormatErrorResponse(HTTPRequest *pRequest, UPnPResultCode eCode, const QString &sMsg="")
bool GetWSDL(HTTPRequest *pRequest)
bool GetEnumXSD(HTTPRequest *pRequest, const QString &sEnumName)
bool GetXSD(HTTPRequest *pRequest, QString sTypeName)
static const struct wl_interface * types[]
#define LOG(_MASK_, _LEVEL_, _QSTRING_)
static constexpr int MAX_PARAMS
@ UPnPResult_InvalidAction
@ UPnPResult_ActionFailed
QMap< QString, QString > QStringMap