10 #define LOC QString("MetaMethod: ")
20 const QString& ReturnName,
bool Slot)
22 m_requestTypes(RequestTypes),
26 static const std::vector<int> s_invalidTypes =
28 QMetaType::UnknownType, QMetaType::VoidStar, QMetaType::QObjectStar,
29 QMetaType::QVariantHash, QMetaType::QRect, QMetaType::QRectF,
30 QMetaType::QSize, QMetaType::QSizeF, QMetaType::QLine,
31 QMetaType::QLineF, QMetaType::QPoint, QMetaType::QPointF
35 static const std::vector<int> s_invalidParams =
37 QMetaType::UnknownType, QMetaType::VoidStar, QMetaType::QObjectStar,
38 QMetaType::QVariantHash, QMetaType::QRect, QMetaType::QRectF,
39 QMetaType::QSize, QMetaType::QSizeF, QMetaType::QLine,
40 QMetaType::QLineF, QMetaType::QPoint, QMetaType::QPointF,
41 QMetaType::QVariantMap, QMetaType::QStringList, QMetaType::QVariantList
44 int returntype = Method.returnType();
47 if (std::any_of(s_invalidTypes.cbegin(), s_invalidTypes.cend(), [&returntype](
int Type) { return Type == returntype; }))
49 LOG(VB_HTTP, LOG_ERR,
LOC + QString(
"Method '%1' has unsupported return type '%2'").arg(Method.name().constData(), Method.typeName()));
55 if (Method.parameterCount() > (Q_METAMETHOD_INVOKE_MAX_ARGS - 1))
57 LOG(VB_HTTP, LOG_WARNING,
LOC + QString(
"Method '%1' takes more than %2 parameters; will probably fail")
58 .arg(Method.name().constData()).arg(Q_METAMETHOD_INVOKE_MAX_ARGS - 1));
70 if (returntype <= QMetaType::User)
71 if (QString(Method.name()).startsWith(QStringLiteral(
"Get"), Qt::CaseInsensitive))
85 m_types.emplace_back(returntype >= 0 ? returntype : 0);
86 m_names.emplace_back(Method.name());
89 auto names = Method.parameterNames();
90 auto types = Method.parameterTypes();
93 for (
int i = 0; i < names.size(); ++i)
95 #if QT_VERSION < QT_VERSION_CHECK(6,0,0)
98 int type = QMetaType::fromName(
types[i]).id();
103 if (Slot && std::any_of(s_invalidParams.cbegin(), s_invalidParams.cend(), [&
type](
int Type) { return type == Type; }))
105 LOG(VB_GENERAL, LOG_ERR,
LOC + QString(
"Method '%1' has unsupported parameter type '%2' (%3)")
106 .arg(Method.name().constData(),
types[i].constData()).arg(
type));
110 m_names.emplace_back(names[i]);
118 const QString &ReturnName,
bool Slot)
121 std::shared_ptr<MythHTTPMetaMethod>(
new MythHTTPMetaMethod(Index, Method, RequestTypes, ReturnName, Slot));
134 #if QT_VERSION < QT_VERSION_CHECK(6,0,0)
135 QByteArray typeName = QMetaType::typeName(Type);
137 QByteArray typeName = QMetaType(Type).name();
141 #if QT_VERSION < QT_VERSION_CHECK(6,0,0)
142 auto typeflags = QMetaType::typeFlags(Type);
144 auto typeflags = QMetaType(Type).flags();
146 if ((typeflags & QMetaType::IsEnumeration) == QMetaType::IsEnumeration)
151 if (
int index = typeName.lastIndexOf(
"::" ); index > -1)
153 QString enumname = typeName.mid(index + 2);
154 #if QT_VERSION < QT_VERSION_CHECK(6,0,0)
155 const auto * metaobject = QMetaType::metaObjectForType(Type);
157 const auto * metaobject = QMetaType(Type).metaObject();
161 int enumindex = metaobject->indexOfEnumerator(enumname.toUtf8());
164 QMetaEnum metaEnum = metaobject->enumerator(enumindex);
165 value = metaEnum.keyToValue(Value.toUtf8());
169 *(
static_cast<int*
>(Parameter)) = value;
174 if (typeName ==
"std::chrono::seconds")
176 *(
static_cast<std::chrono::seconds*
>(Parameter)) = std::chrono::seconds(Value.toInt());
182 case QMetaType::QVariant : *(
static_cast<QVariant *
>(Parameter)) = QVariant(Value);
break;
183 case QMetaType::Bool : *(
static_cast<bool *
>(Parameter)) =
ToBool(Value );
break;
184 case QMetaType::Char : *(
static_cast<char *
>(Parameter)) = (Value.length() > 0) ? Value.at(0).toLatin1() : 0;
break;
185 case QMetaType::UChar : *(
static_cast<unsigned char*
>(Parameter)) = (Value.length() > 0) ?
static_cast<unsigned char>(Value.at(0).toLatin1()) : 0;
break;
186 case QMetaType::QChar : *(
static_cast<QChar *
>(Parameter)) = (Value.length() > 0) ? Value.at(0) : QChar(0);
break;
187 case QMetaType::Short : *(
static_cast<short *
>(Parameter)) = Value.toShort();
break;
188 case QMetaType::UShort : *(
static_cast<ushort *
>(Parameter)) = Value.toUShort();
break;
189 case QMetaType::Int : *(
static_cast<int *
>(Parameter)) = Value.toInt();
break;
190 case QMetaType::UInt : *(
static_cast<uint *
>(Parameter)) = Value.toUInt();
break;
191 case QMetaType::Long : *(
static_cast<long *
>(Parameter)) = Value.toLong();
break;
192 case QMetaType::ULong : *(
static_cast<ulong *
>(Parameter)) = Value.toULong();
break;
193 case QMetaType::LongLong : *(
static_cast<qlonglong *
>(Parameter)) = Value.toLongLong();
break;
194 case QMetaType::ULongLong : *(
static_cast<qulonglong *
>(Parameter)) = Value.toULongLong();
break;
195 case QMetaType::Double : *(
static_cast<double *
>(Parameter)) = Value.toDouble();
break;
196 case QMetaType::Float : *(
static_cast<float *
>(Parameter)) = Value.toFloat();
break;
197 case QMetaType::QString : *(
static_cast<QString *
>(Parameter)) = Value;
break;
198 case QMetaType::QByteArray: *(
static_cast<QByteArray *
>(Parameter)) = Value.toUtf8();
break;
201 case QMetaType::QDateTime :
204 #if QT_VERSION < QT_VERSION_CHECK(6,5,0)
205 dt.setTimeSpec(Qt::UTC);
207 dt.setTimeZone(QTimeZone(QTimeZone::UTC));
209 *(
static_cast<QDateTime*
>(Parameter)) = dt;
213 LOG(VB_GENERAL, LOG_WARNING,
LOC + QString(
"Unknown QMetaType:%1 %2").arg(Type).arg(QString(typeName)));
227 #
if QT_VERSION < QT_VERSION_CHECK(6,0,0)
230 Type == QMetaType::fromName(
"QFileInfo").
id()
233 return QVariant::fromValue<QFileInfo>(*(
static_cast<QFileInfo*
>(Value)));
235 if (Type > QMetaType::User)
237 QObject*
object = *(
static_cast<QObject**
>(Value));
238 return QVariant::fromValue<QObject*>(
object);
241 #if QT_VERSION < QT_VERSION_CHECK(6,0,0)
242 return {Type, Value};
244 return QVariant(QMetaType(Type), Value);