// based on https://gist.github.com/andref/2838534. bool JsonRpcServer::doCall(QObject* object, const QMetaMethod& meta_method, QVariantList& converted_args, QVariant& return_value) { QList<QGenericArgument> arguments; for (int i = 0; i < converted_args.size(); i++) { // Notice that we have to take a reference to the argument, else we'd be // pointing to a copy that will be destroyed when this loop exits. QVariant& argument = converted_args[i]; // A const_cast is needed because calling data() would detach the // QVariant. QGenericArgument generic_argument( QMetaType::typeName(argument.userType()), const_cast<void*>(argument.constData()) ); arguments << generic_argument; } const char* return_type_name = meta_method.typeName(); int return_type = QMetaType::type(return_type_name); if (return_type != QMetaType::Void) { return_value = QVariant(return_type, nullptr); } QGenericReturnArgument return_argument( return_type_name, const_cast<void*>(return_value.constData()) ); // perform the call bool ok = meta_method.invoke( object, Qt::DirectConnection, return_argument, arguments.value(0), arguments.value(1), arguments.value(2), arguments.value(3), arguments.value(4), arguments.value(5), arguments.value(6), arguments.value(7), arguments.value(8), arguments.value(9) ); if (!ok) { // qDebug() << "calling" << meta_method.methodSignature() << "failed."; return false; } logInfo(logInvoke(meta_method, converted_args, return_value)); return true; }
bool IOHandler::feof_exec() { if (!m_file) return false; return return_argument(feof(m_file)); }
bool IOHandler::ftell_exec() { if (!m_file) return false; int64_t ret = ftell(m_file); if (!return_argument(ret)) return false; return true; }
bool IOHandler::ungetc_exec() { if (!m_file) return false; int64_t c; if (!get_argument(c)) return false; return return_argument(ungetc(c, m_file)); }
bool IOHandler::fseek_exec() { if (!m_file) return false; int64_t offset, whence; if (!get_argument(offset, whence)) return false; return return_argument(fseek(m_file, offset, whence)); }
bool IOHandler::fwrite_exec() { if (!m_file) return false; int64_t size; if (!get_argument(size)) return false; std::vector<char> buf(size); int64_t rc; if ((rc = read_all(&buf[0], size)) == 0) return false; rc = fwrite(&buf[0], 1, rc, m_file); return return_argument(rc); }
bool IOHandler::fopen_exec() { std::cerr << "Running fopen_exec" << std::endl; std::string path, mode; if (!get_argument(path, mode)) return false; std::cout << "-- OPEN: " << path << std::endl; m_file = fopen(path.c_str(), mode.c_str()); if (m_file == NULL) std::cout << "-- FAIL OPEN: " << path << std::endl; m_path = path; return return_argument(m_file != NULL ? 0 : -1); }
bool IOHandler::fread_exec() { if (!m_file) return false; int64_t size; if (!get_argument(size)) return false; std::vector<char> buf(size); int64_t rc = fread(&buf[0], 1, size, m_file); if (!return_argument(rc)) return false; if (write_all(&buf[0], rc) < rc) return false; return true; }