13 #include <QDomDocument>
30 bool bExceptionThrown =
false;
34 throw QString(
"Invalid argument to MethodInfo::Invoke. pService in nullptr");
37 for (
auto it = reqParams.cbegin(); it != reqParams.cend(); ++it)
39 lowerParams[it.key().toLower()] = *it;
49 QList<QByteArray> paramNames =
m_oMethod.parameterNames();
50 QList<QByteArray> paramTypes =
m_oMethod.parameterTypes();
57 std::array<void*,MAX_PARAMS> param {};
58 std::array<int,MAX_PARAMS>
types {};
66 #if QT_VERSION < QT_VERSION_CHECK(6,0,0)
68 QMetaType oRetType = QMetaType(nRetIdx);
71 QMetaType oRetType =
m_oMethod.returnMetaType();
74 if (nRetIdx != QMetaType::UnknownType)
76 param[ 0 ] = oRetType.create();
82 types[ 0 ] = QMetaType::UnknownType;
89 for(
int nIdx = 0; nIdx < paramNames.length(); ++nIdx )
91 QString sValue = lowerParams[ paramNames[ nIdx ].toLower() ];
92 QString sParamType = paramTypes[ nIdx ];
94 #if QT_VERSION < QT_VERSION_CHECK(6,0,0)
96 void *pParam =
nullptr;
98 if (nId != QMetaType::UnknownType)
100 pParam = QMetaType::create( nId );
103 QMetaType metaType = QMetaType::fromName( paramTypes[ nIdx ] );
104 void *pParam = metaType.create();
105 int nId = metaType.id();
107 if (nId == QMetaType::UnknownType)
109 LOG(VB_GENERAL, LOG_ERR,
110 QString(
"MethodInfo::Invoke - Type unknown '%1'")
112 throw QString(
"MethodInfo::Invoke - Type unknown '%1'")
122 QThread *currentThread = QThread::currentThread();
123 QThread *objectThread = pService->thread();
125 if (currentThread == objectThread)
126 LOG(VB_HTTP, LOG_DEBUG,
"*** Threads are same ***");
128 LOG(VB_HTTP, LOG_DEBUG,
"*** Threads are Different!!! ***");
131 if (pService->qt_metacall(QMetaObject::InvokeMetaMethod,
m_nMethodIndex, param.data()) >= 0)
132 LOG(VB_GENERAL, LOG_WARNING,
"qt_metacall error");
139 for (
int nIdx=1; nIdx < paramNames.length()+1; ++nIdx)
141 if ((
types[ nIdx ] != QMetaType::UnknownType) && (param[ nIdx ] !=
nullptr))
143 auto metaType = QMetaType(
types[ nIdx ] );
144 metaType.destroy(param[ nIdx ]);
148 catch (QString &sMsg)
150 LOG(VB_GENERAL, LOG_ERR,
151 QString(
"MethodInfo::Invoke - An Exception Occurred: %1")
154 if ((
types[ 0 ] != QMetaType::UnknownType) && (param[ 0 ] !=
nullptr ))
156 auto metaType = QMetaType(
types[ 0 ] );
157 metaType.destroy(param[ 0 ]);
164 bExceptionThrown =
true;
169 LOG(VB_GENERAL, LOG_INFO,
170 "MethodInfo::Invoke - An Exception Occurred" );
179 if ( param[ 0 ] !=
nullptr)
183 if (
types[ 0 ] != QMetaType::UnknownType)
185 auto metaType = QMetaType(
types[ 0 ] );
186 metaType.destroy(param[ 0 ]);
194 if (bExceptionThrown)
209 const QString &sExtensionName,
211 const QString &sSharePath )
213 m_sBaseUrl(
std::move(sBaseUrl)),
214 m_oMetaObject(metaObject)
226 for (
int nIdx = 0; nIdx <
m_oMetaObject.methodCount(); nIdx++)
230 if ((method.methodType() == QMetaMethod::Slot ) &&
231 (method.access() == QMetaMethod::Public ))
233 QString sName( method.methodSignature() );
239 if (sName ==
"deleteLater()")
247 oInfo.
m_sName = sName.section(
'(', 0, 0 );
253 QString sMethodClassInfo = oInfo.
m_sName +
"_Method";
260 QString sRequestType =
263 if (sRequestType ==
"POST")
265 else if (sRequestType ==
"GET" )
294 bool bHandled =
false;
304 LOG(VB_HTTP, LOG_INFO,
305 QString(
"ServiceHost::ProcessRequest: %1 : %2")
315 pService = qobject_cast<Service*>(
m_oMetaObject.newInstance());
332 bool bHandled2 =
false;
335 pService = qobject_cast<Service*>(
m_oMetaObject.newInstance());
348 throw QString(
"Invalid arguments to xsd query: %1")
377 QString sMethodName = pRequest->
m_sMethod;
378 bool bMethodFound =
false;
388 sMethodName =
"Get" + sMethodName;
391 sMethodName =
"Put" + sMethodName;
423 QVariant vResult = oInfo.
Invoke(pService,
447 catch (QString &sMsg)
449 LOG(VB_GENERAL, LOG_ERR, sMsg);
456 QString sMsg(
"ServiceHost::ProcessRequest - Unexpected Exception" );
458 LOG(VB_GENERAL, LOG_ERR, sMsg);
474 if (pResults !=
nullptr)
499 if (oInfo.isSymLink())
520 if ( vValue.canConvert< QObject* >())
522 const QObject *pObject = vValue.value< QObject* >();
527 if ( vValue.canConvert< QFileInfo >())
529 const auto oFileInfo = vValue.value< QFileInfo >();
540 pSer->
Serialize( vValue, vValue.typeName() );