// 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; }
int main(int argc, char **argv) { string_ty *s; string_list_ty sl; size_t j; arglex_init(argc, argv, argtab); str_initialize(); switch (arglex()) { case arglex_token_help: help((char *)0, usage); exit(0); case arglex_token_version: version(); exit(0); default: break; } string_list_constructor(&sl); while (arglex_token != arglex_token_eoln) { switch (arglex_token) { default: generic_argument(usage); continue; case arglex_token_warning: warning++; break; case arglex_token_string: s = str_from_c(arglex_value.alv_string); string_list_append_unique(&sl, s); str_free(s); break; } arglex(); } if (!sl.nstrings) { error_intl(0, i18n("no files named")); usage(); } for (j = 0; j < sl.nstrings; ++j) file_check(sl.string[j]); exit(0); return 0; }
static void argparse(option_level_ty level) { option_number_ty type; string_ty *s; sub_context_ty *scp; int fingerprint_update; type = -1; fingerprint_update = 0; switch (arglex()) { case arglex_token_help: if (level != OPTION_LEVEL_COMMAND_LINE) { not_in_env: scp = sub_context_new(); sub_var_set(scp, "Name", "%s", arglex_value.alv_string); fatal_intl(scp, i18n("may not use $name in environment variable")); /* NOTREACHED */ } help((char *)0, usage); quit(0); case arglex_token_version: if (level != OPTION_LEVEL_COMMAND_LINE) goto not_in_env; version(); quit(0); default: break; } while (arglex_token != arglex_token_eoln) { switch (arglex_token) { default: generic_argument(usage); continue; case arglex_token_include: if (arglex() != arglex_token_string) { arg_needs_string(arglex_token_include, usage); /* NOTREACHED */ } s = str_from_c(arglex_value.alv_string); string_list_append_unique(&option.o_search_path, s); str_free(s); break; case arglex_token_reason: type = OPTION_REASON; normal_on: if (option_already(type, level)) { too_many: arg_duplicate_cur(usage); /* NOTREACHED */ } option_set(type, level, 1); break; case arglex_token_reason_not: type = OPTION_REASON; normal_off: if (option_already(type, level)) goto too_many; option_set(type, level, 0); break; case arglex_token_cascade: type = OPTION_CASCADE; goto normal_on; case arglex_token_cascade_not: type = OPTION_CASCADE; goto normal_off; case arglex_token_disassemble: type = OPTION_DISASSEMBLE; goto normal_on; case arglex_token_disassemble_not: type = OPTION_DISASSEMBLE; goto normal_off; case arglex_token_tty: type = OPTION_TERMINAL; goto normal_on; case arglex_token_tty_not: type = OPTION_TERMINAL; goto normal_off; case arglex_token_precious: type = OPTION_PRECIOUS; goto normal_on; case arglex_token_precious_not: type = OPTION_PRECIOUS; goto normal_off; case arglex_token_log: if (option_already(OPTION_LOGGING, level)) goto too_many; option_set(OPTION_LOGGING, level, 1); if (arglex() != arglex_token_string) continue; if (option.o_logfile) str_free(option.o_logfile); option.o_logfile = str_from_c(arglex_value.alv_string); break; case arglex_token_log_not: type = OPTION_LOGGING; goto normal_off; case arglex_token_book: if (option_already(OPTION_BOOK, level)) goto too_many; option_set(OPTION_BOOK, level, 1); if (arglex() != arglex_token_string) continue; if (option.o_book) str_free(option.o_book); option.o_book = str_from_c(arglex_value.alv_string); break; case arglex_token_book_not: type = OPTION_BOOK; goto normal_off; case arglex_token_include_cooked: type = OPTION_INCLUDE_COOKED; goto normal_on; case arglex_token_include_cooked_not: type = OPTION_INCLUDE_COOKED; goto normal_off; case arglex_token_include_cooked_warning: type = OPTION_INCLUDE_COOKED_WARNING; goto normal_on; case arglex_token_include_cooked_warning_not: type = OPTION_INCLUDE_COOKED_WARNING; goto normal_off; case arglex_token_silent: type = OPTION_SILENT; goto normal_on; case arglex_token_silent_not: type = OPTION_SILENT; goto normal_off; case arglex_token_tell_position: type = OPTION_TELL_POSITION; goto normal_on; case arglex_token_tell_position_not: type = OPTION_TELL_POSITION; goto normal_off; case arglex_token_metering: type = OPTION_METER; goto normal_on; case arglex_token_metering_not: type = OPTION_METER; goto normal_off; case arglex_token_touch: type = OPTION_TOUCH; goto normal_on; case arglex_token_touch_not: type = OPTION_TOUCH; goto normal_off; case arglex_token_action: type = OPTION_ACTION; goto normal_on; case arglex_token_action_not: type = OPTION_ACTION; goto normal_off; case arglex_token_persevere: type = OPTION_PERSEVERE; goto normal_on; case arglex_token_persevere_not: type = OPTION_PERSEVERE; goto normal_off; case arglex_token_errok: type = OPTION_ERROK; goto normal_on; case arglex_token_errok_not: type = OPTION_ERROK; goto normal_off; case arglex_token_force: type = OPTION_FORCE; goto normal_on; case arglex_token_force_not: type = OPTION_FORCE; goto normal_off; case arglex_token_fingerprint: type = OPTION_FINGERPRINT; goto normal_on; case arglex_token_fingerprint_not: type = OPTION_FINGERPRINT; goto normal_off; case arglex_token_fingerprint_update: if (level != OPTION_LEVEL_COMMAND_LINE) goto not_in_env; if (option.fingerprint_update) goto too_many; option.fingerprint_update++; break; case arglex_token_pairs: if (level != OPTION_LEVEL_COMMAND_LINE) goto not_in_env; if (option.pairs) goto too_many; option.pairs++; break; case arglex_token_script: if (level != OPTION_LEVEL_COMMAND_LINE) goto not_in_env; if (option.script) goto too_many; option.script++; break; case arglex_token_web: if (level != OPTION_LEVEL_COMMAND_LINE) goto not_in_env; if (option.web) goto too_many; option.web++; break; case arglex_token_string: if (level != OPTION_LEVEL_COMMAND_LINE) { if (strchr(arglex_value.alv_string, '=')) { fatal_intl ( 0, i18n("may not assign variables in environment variable") ); } else { fatal_intl ( 0, i18n("may not name targets in environment variable") ); } } else { char *cp; cp = strchr(arglex_value.alv_string, '='); if (!cp) { s = str_from_c(arglex_value.alv_string); string_list_append(&option.o_target, s); str_free(s); } else { s = str_from_c(arglex_value.alv_string); string_list_append(&option.o_vardef, s); str_free(s); } } break; case arglex_token_star: type = OPTION_STAR; goto normal_on; case arglex_token_star_not: type = OPTION_STAR; goto normal_off; case arglex_token_strip_dot: type = OPTION_STRIP_DOT; goto normal_on; case arglex_token_strip_dot_not: type = OPTION_STRIP_DOT; goto normal_off; case arglex_token_update: type = OPTION_UPDATE; goto normal_on; case arglex_token_update_not: type = OPTION_UPDATE; goto normal_off; case arglex_token_parallel: if (arglex() != arglex_token_number) { s = str_from_c("parallel_jobs=4"); string_list_append(&option.o_vardef, s); str_free(s); continue; } s = str_format("parallel_jobs=%d", (int)arglex_value.alv_number); string_list_append(&option.o_vardef, s); str_free(s); break; case arglex_token_parallel_not: s = str_from_c("parallel_jobs=1"); string_list_append(&option.o_vardef, s); str_free(s); break; case arglex_token_shallow: type = OPTION_SHALLOW; goto normal_on; case arglex_token_shallow_not: type = OPTION_SHALLOW; goto normal_off; } arglex(); } }