based on https://gist.github.com/andref/2838534.
| 304 | |
| 305 | // based on https://gist.github.com/andref/2838534. |
| 306 | bool JsonRpcServer::doCall(QObject* object, |
| 307 | const QMetaMethod& meta_method, |
| 308 | QVariantList& converted_args, |
| 309 | QVariant& return_value) |
| 310 | { |
| 311 | QList<QGenericArgument> arguments; |
| 312 | |
| 313 | for (int i = 0; i < converted_args.size(); i++) { |
| 314 | |
| 315 | // Notice that we have to take a reference to the argument, else we'd be |
| 316 | // pointing to a copy that will be destroyed when this loop exits. |
| 317 | QVariant& argument = converted_args[i]; |
| 318 | |
| 319 | // A const_cast is needed because calling data() would detach the |
| 320 | // QVariant. |
| 321 | QGenericArgument generic_argument( |
| 322 | QMetaType::typeName(argument.userType()), |
| 323 | const_cast<void*>(argument.constData()) |
| 324 | ); |
| 325 | |
| 326 | arguments << generic_argument; |
| 327 | } |
| 328 | |
| 329 | const char* return_type_name = meta_method.typeName(); |
| 330 | int return_type = QMetaType::type(return_type_name); |
| 331 | if (return_type != QMetaType::Void) { |
| 332 | return_value = QVariant(return_type, nullptr); |
| 333 | } |
| 334 | |
| 335 | QGenericReturnArgument return_argument( |
| 336 | return_type_name, |
| 337 | const_cast<void*>(return_value.constData()) |
| 338 | ); |
| 339 | |
| 340 | // perform the call |
| 341 | bool ok = meta_method.invoke( |
| 342 | object, |
| 343 | Qt::DirectConnection, |
| 344 | return_argument, |
| 345 | arguments.value(0), |
| 346 | arguments.value(1), |
| 347 | arguments.value(2), |
| 348 | arguments.value(3), |
| 349 | arguments.value(4), |
| 350 | arguments.value(5), |
| 351 | arguments.value(6), |
| 352 | arguments.value(7), |
| 353 | arguments.value(8), |
| 354 | arguments.value(9) |
| 355 | ); |
| 356 | |
| 357 | if (!ok) { |
| 358 | // qDebug() << "calling" << meta_method.methodSignature() << "failed."; |
| 359 | return false; |
| 360 | } |
| 361 | |
| 362 | logInfo(logInvoke(meta_method, converted_args, return_value)); |
| 363 |