#include "NativeToolbar.h" #include "MethodResultJni.h" #include "ext/rho/rhoruby.h" #include "rhodes/JNIRhoRuby.h" #include "logging/RhoLog.h" #undef DEFAULT_LOGCATEGORY #define DEFAULT_LOGCATEGORY "NativeToolbarRUBY" typedef rho::CNativeToolbarProxy > > ObjectProxy; using namespace rho::apiGenerator; extern "C" { VALUE getRuby_NativeToolbar_Module(); VALUE rb_s_NativeToolbar_create(int argc, VALUE *argv) { RAWTRACE2("%s - argc: %d", __FUNCTION__, argc); MethodResultJni result(true); if(!result) { RAWLOG_ERROR("JNI error: failed to initialize MethodResult java object ^^^"); result.setError("JNI error: failed to initialize MethodResult java object"); return CMethodResultConvertor().toRuby(result, false); } RAWTRACE("MethodResultJni instance is created"); if((argc < 2) || (argc > 2)) { RAWLOG_ERROR1("Wrong number of arguments: %d ^^^", argc); result.setArgError("Wrong number of arguments"); return CMethodResultConvertor().toRuby(result, false); } unsigned realParamCount = (argc < 2) ? argc : 2; std::vector arguments(argv, argv + realParamCount); RAWTRACE1("Count of passed arguments: %d", arguments.size()); if(argc > 2) { if (rho_ruby_is_proc(argv[2]) || rho_ruby_is_method(argv[2])) { result.setRubyProcCallBack(argv[2]); RAWTRACE("Ruby proc callback is set"); } else { if(argc > 3) result.setCallBack(argv[2], argv[3]); else result.setCallBack(argv[2]); RAWTRACE("Callback URL is set"); } if(!result.hasCallback()) { RAWLOG_ERROR("Error setting callback ^^^"); return CMethodResultConvertor().toRuby(result, false); } } ObjectProxy::create(argumentsAdapter(arguments), result); RAWTRACE("Native metod has invoked, converting result"); VALUE res = CMethodResultConvertor().toRuby(result, false); RAWTRACE(__FUNCTION__); return res; } VALUE rb_s_NativeToolbar_remove(int argc, VALUE *argv) { RAWTRACE2("%s - argc: %d", __FUNCTION__, argc); MethodResultJni result(true); if(!result) { RAWLOG_ERROR("JNI error: failed to initialize MethodResult java object ^^^"); result.setError("JNI error: failed to initialize MethodResult java object"); return CMethodResultConvertor().toRuby(result, false); } RAWTRACE("MethodResultJni instance is created"); if((argc < 0) || (argc > 0)) { RAWLOG_ERROR1("Wrong number of arguments: %d ^^^", argc); result.setArgError("Wrong number of arguments"); return CMethodResultConvertor().toRuby(result, false); } unsigned realParamCount = (argc < 0) ? argc : 0; std::vector arguments(argv, argv + realParamCount); RAWTRACE1("Count of passed arguments: %d", arguments.size()); if(argc > 0) { if (rho_ruby_is_proc(argv[0]) || rho_ruby_is_method(argv[0])) { result.setRubyProcCallBack(argv[0]); RAWTRACE("Ruby proc callback is set"); } else { if(argc > 1) result.setCallBack(argv[0], argv[1]); else result.setCallBack(argv[0]); RAWTRACE("Callback URL is set"); } if(!result.hasCallback()) { RAWLOG_ERROR("Error setting callback ^^^"); return CMethodResultConvertor().toRuby(result, false); } } ObjectProxy::remove(argumentsAdapter(arguments), result); RAWTRACE("Native metod has invoked, converting result"); VALUE res = CMethodResultConvertor().toRuby(result, false); RAWTRACE(__FUNCTION__); return res; } VALUE rb_s_NativeToolbar_isCreated(int argc, VALUE *argv) { RAWTRACE2("%s - argc: %d", __FUNCTION__, argc); MethodResultJni result(true); if(!result) { RAWLOG_ERROR("JNI error: failed to initialize MethodResult java object ^^^"); result.setError("JNI error: failed to initialize MethodResult java object"); return CMethodResultConvertor().toRuby(result, false); } RAWTRACE("MethodResultJni instance is created"); if((argc < 0) || (argc > 0)) { RAWLOG_ERROR1("Wrong number of arguments: %d ^^^", argc); result.setArgError("Wrong number of arguments"); return CMethodResultConvertor().toRuby(result, false); } unsigned realParamCount = (argc < 0) ? argc : 0; std::vector arguments(argv, argv + realParamCount); RAWTRACE1("Count of passed arguments: %d", arguments.size()); if(argc > 0) { if (rho_ruby_is_proc(argv[0]) || rho_ruby_is_method(argv[0])) { result.setRubyProcCallBack(argv[0]); RAWTRACE("Ruby proc callback is set"); } else { if(argc > 1) result.setCallBack(argv[0], argv[1]); else result.setCallBack(argv[0]); RAWTRACE("Callback URL is set"); } if(!result.hasCallback()) { RAWLOG_ERROR("Error setting callback ^^^"); return CMethodResultConvertor().toRuby(result, false); } } ObjectProxy::isCreated(argumentsAdapter(arguments), result); RAWTRACE("Native metod has invoked, converting result"); VALUE res = CMethodResultConvertor().toRuby(result, false); RAWTRACE(__FUNCTION__); return res; } }