PyObject* Robot::getDefaultClassInstance() { if (pInstance == NULL) { PyObject* pClass = getClassObject("Robots.robotFactory", "Factory"); if (pClass == NULL) { std::cerr << "Error locating class object Robots.robotFactory.Factory" << std::endl; } else { if (Robot::name != "") { std::cout << "Getting class for robot: " << name << std::endl; pInstance = callMethod(pClass, "getRobot", Robot::name.c_str()); } else { std::cout << "Getting class for active robot" << std::endl; pInstance = callMethod(pClass, "getCurrentRobot"); } { PythonLock lock = PythonLock(); const char* pName = strdup("name"); PyObject* nm = PyObject_GetAttrString(getDefaultClassInstance(), pName); Robot::name = std::string(PyString_AsString(nm)); Py_XDECREF(nm); Py_DECREF(pClass); } } } return pInstance; }
QDeclarativeObjectMethodScriptClass::Value QDeclarativeObjectMethodScriptClass::callPrecise(QObject *object, const QDeclarativePropertyCache::Data &data, QScriptContext *ctxt) { if (data.flags & QDeclarativePropertyCache::Data::HasArguments) { QMetaMethod m = object->metaObject()->method(data.coreIndex); QList<QByteArray> argTypeNames = m.parameterTypes(); QVarLengthArray<int, 9> argTypes(argTypeNames.count()); // ### Cache for (int ii = 0; ii < argTypeNames.count(); ++ii) { argTypes[ii] = QMetaType::type(argTypeNames.at(ii)); if (argTypes[ii] == QVariant::Invalid) argTypes[ii] = enumType(object->metaObject(), QString::fromLatin1(argTypeNames.at(ii))); if (argTypes[ii] == QVariant::Invalid) return Value(ctxt, ctxt->throwError(QString::fromLatin1("Unknown method parameter type: %1").arg(QLatin1String(argTypeNames.at(ii))))); } if (argTypes.count() > ctxt->argumentCount()) return Value(ctxt, ctxt->throwError(QLatin1String("Insufficient arguments"))); return callMethod(object, data.coreIndex, data.propType, argTypes.count(), argTypes.data(), ctxt); } else { return callMethod(object, data.coreIndex, data.propType, 0, 0, ctxt); } }
void XMLSocket_as::update() { // This function should never be called unless a connection is active // or a connection attempt is being made. // If the connection was not complete, check to see if it is. if (!ready()) { if (_socket.bad()) { // Connection failed during connect() // Notify onConnect and stop callback. This means update() // will not be called again until XMLSocket.connect() is invoked. callMethod(&owner(), NSV::PROP_ON_CONNECT, false); getRoot(owner()).removeAdvanceCallback(this); return; } // Not yet ready. if (!_socket.connected()) return; // Connection succeeded. _ready = true; callMethod(&owner(), NSV::PROP_ON_CONNECT, true); } // Now the connection is established we can receive data. checkForIncomingData(); }
Status doCommand ( RPC::Context& context, Json::Value& result) { Handler const * handler = nullptr; if (auto error = fillHandler (context, handler)) { inject_error (error, result); return error; } if (auto method = handler->valueMethod_) { if (! context.headers.user.empty() || ! context.headers.forwardedFor.empty()) { JLOG(context.j.debug()) << "start command: " << handler->name_ << ", X-User: "******", X-Forwarded-For: " << context.headers.forwardedFor; auto ret = callMethod (context, method, handler->name_, result); JLOG(context.j.debug()) << "finish command: " << handler->name_ << ", X-User: "******", X-Forwarded-For: " << context.headers.forwardedFor; return ret; } else { return callMethod (context, method, handler->name_, result); } } return rpcUNKNOWN_COMMAND; }
void FKRealmComponent::guestConnection(FKConnector* connector){ connector->moveToThread(component()->thread()); const bool activation=true; if(!callMethod("incomeConnection",connector,"FKConnector*",activation,"bool")){ emit messageRequested(QString(tr("Unable add guest connection"))); } }
/** * @brief Inicializa a JVM; Aloca memória para as estruturas principais; Chama o carregador para a primeira classe; inicializa a primeira classe * * @param classHeap * @param objectHeap * @param stackFrame * @param classPathF_ptr */ void jvmStartup(ClassFile *classHeap_ptr, Object *objectHeap_ptr, Frame *stackFrame_ptr, FILE *classPathF_ptr, dataMSize_t *dmSize_ptr){ classHeap_ptr = malloc( CLSHEAP_MAX*sizeof( ClassFile ) ); objectHeap_ptr = malloc( OBJHEAP_MAX*sizeof( Object_t ) ); stackFrame_ptr = malloc( STKFRAME_MAX*sizeof( Frame ) ); dmSize_ptr->clsHeap_size = 0; dmSize_ptr->objHeap_size = 0; dmSize_ptr->stkHeap_size = 0; //Carrega a classe inicial //OK! loadClass(classPathF_ptr, classHeap_ptr, dmSize_ptr); printf("\nstatic_values_size %d", classHeap_ptr->static_values_size); for(int i = 0; i < classHeap_ptr->static_values_size; i++) printf("\nname %s", classHeap_ptr->static_values[i].field_name); //Checa a consistência da classe printf("\n\nConteudo do .class"); printf("\n--------------------------------"); print_ClassFile(classHeap_ptr); //Inicializa a classe inicial, roda clinit //OK! initializeClass(classHeap_ptr, stackFrame_ptr, dmSize_ptr, classHeap_ptr); //initializeClass(classHeap_ptr, stackFrame_ptr, &dmSize_ptr->stkHeap_size); //Sei que o primeiro elemento da classHeap é a classe inicial //Chamo o método main callMethod(classHeap_ptr, stackFrame_ptr, dmSize_ptr, classHeap_ptr, "main", "([Ljava/lang/String;)V"); }
void QDBusViewer::activate(const QModelIndex &item) { if (!item.isValid()) return; const QDBusModel *model = static_cast<const QDBusModel *>(item.model()); BusSignature sig; sig.mService = currentService; sig.mPath = model->dBusPath(item); sig.mInterface = model->dBusInterface(item); sig.mName = model->dBusMethodName(item); sig.mTypeSig = model->dBusTypeSignature(item); switch (model->itemType(item)) { case QDBusModel::SignalItem: connectionRequested(sig); break; case QDBusModel::MethodItem: callMethod(sig); break; case QDBusModel::PropertyItem: getProperty(sig); break; default: break; } }
std::vector<Robot::Position> Robot::getComponentPositions(std::string componentName) { PyObject *pValue = callMethod("getComponentPositions", componentName); /** pValue = {folded:(0.0, 1.1, ...)), wave:(in, out), joint_names:('elbo', 'wrist'), ...} **/ std::vector<Robot::Position> ret = std::vector<Robot::Position>(); if (pValue != NULL) { PythonLock lock = PythonLock(); if (!PyDict_Check(pValue)) { std::cerr << "Expected dictionary from getComponentPositions, got " << pValue->ob_type->tp_name << std::endl; } else { PyObject *key, *value; Py_ssize_t pos = 0; while (PyDict_Next(pValue, &pos, &key, &value)) { Robot::Position p; p.name = std::string(PyString_AsString(key)); p.positions = parseDoubleArray(value); ret.push_back(p); } } Py_DECREF(pValue); } return ret; }
void QDBusViewer::showContextMenu(const QPoint &point) { QModelIndex item = tree->indexAt(point); if (!item.isValid()) return; const QDBusModel *model = static_cast<const QDBusModel *>(item.model()); BusSignature sig; sig.mService = currentService; sig.mPath = model->dBusPath(item); sig.mInterface = model->dBusInterface(item); sig.mName = model->dBusMethodName(item); sig.mTypeSig = model->dBusTypeSignature(item); QMenu menu; menu.addAction(refreshAction); switch (model->itemType(item)) { case QDBusModel::SignalItem: { QAction *action = new QAction(tr("&Connect"), &menu); action->setData(1); menu.addAction(action); break; } case QDBusModel::MethodItem: { QAction *action = new QAction(tr("&Call"), &menu); action->setData(2); menu.addAction(action); break; } case QDBusModel::PropertyItem: { QAction *actionSet = new QAction(tr("&Set value"), &menu); actionSet->setData(3); QAction *actionGet = new QAction(tr("&Get value"), &menu); actionGet->setData(4); menu.addAction(actionSet); menu.addAction(actionGet); break; } default: break; } QAction *selectedAction = menu.exec(tree->viewport()->mapToGlobal(point)); if (!selectedAction) return; switch (selectedAction->data().toInt()) { case 1: connectionRequested(sig); break; case 2: callMethod(sig); break; case 3: setProperty(sig); break; case 4: getProperty(sig); break; } }
Robot::State Robot::getComponentState(std::string componentName) { PyObject *pValue = callMethod("getComponentState", componentName); /** pValue = ('home', {name:'arm', joints:('elbo', 'wrist', ...), positions:(0.0, 1.1, ...), goals:(0.0, 1.1, ...)}) **/ Robot::State s; if (pValue != NULL) { PythonLock lock = PythonLock(); if (!PySequence_Check(pValue)) { //Error! } else { s.name = std::string(PyString_AsString(PySequence_GetItem(pValue, 0))); PyObject* values = PySequence_GetItem(pValue, 1); if (PyDict_Check(values)) { PyObject* key = PyString_FromString("goals"); s.goals = parseDoubleArray(PyDict_GetItem(values, key)); Py_DecRef(key); key = PyString_FromString("positions"); s.positions = parseDoubleArray(PyDict_GetItem(values, key)); Py_DecRef(key); key = PyString_FromString("joints"); s.joints = parseStringArray(PyDict_GetItem(values, key)); Py_DecRef(key); } } Py_DecRef(pValue); } return s; }
/* Process all enqueued heap work, including finalizers and reference * enqueueing. Clearing has already been done by the VM. * * Caller must hold gDvm.heapWorkerLock. */ static void doHeapWork(Thread *self) { Object *obj; HeapWorkerOperation op; int numFinalizersCalled, numReferencesEnqueued; assert(gDvm.voffJavaLangObject_finalize >= 0); assert(gDvm.methJavaLangRefReference_enqueueInternal != NULL); numFinalizersCalled = 0; numReferencesEnqueued = 0; while ((obj = dvmGetNextHeapWorkerObject(&op)) != NULL) { Method *method = NULL; /* Make sure the object hasn't been collected since * being scheduled. */ assert(dvmIsValidObject(obj)); /* Call the appropriate method(s). */ if (op == WORKER_FINALIZE) { numFinalizersCalled++; method = obj->clazz->vtable[gDvm.voffJavaLangObject_finalize]; assert(dvmCompareNameDescriptorAndMethod("finalize", "()V", method) == 0); assert(method->clazz != gDvm.classJavaLangObject); callMethod(self, obj, method); } else { assert(op == WORKER_ENQUEUE); assert(dvmGetFieldObject( obj, gDvm.offJavaLangRefReference_queue) != NULL); assert(dvmGetFieldObject( obj, gDvm.offJavaLangRefReference_queueNext) == NULL); numReferencesEnqueued++; callMethod(self, obj, gDvm.methJavaLangRefReference_enqueueInternal); } /* Let the GC collect the object. */ dvmReleaseTrackedAlloc(obj, self); } LOGV("Called %d finalizers\n", numFinalizersCalled); LOGV("Enqueued %d references\n", numReferencesEnqueued); }
void Robot::stop(std::string componentName) { PyObject *pValue = callMethod("stop", componentName); { PythonLock lock = PythonLock(); Py_XDECREF(pValue); } }
BOOL ScriptObj::callMethod(TCHAR* method, int value){ if (!IsCallable()) return false; VARIANTARG arg; arg.intVal = value; arg.vt = VT_INT; return callMethod(method, &arg,1); }
BOOL ScriptObj::callMethod(TCHAR* method, BSTR value){ if (!IsCallable()) return false; VARIANTARG arg; arg.bstrVal = value; arg.vt = VT_BSTR; return callMethod(method, &arg,1); }
static Value classNew(Context *ctx, const List<Value>& args) { if (args.getCount() < 1) { ctx->throwException(createException(ExcType::ValueError, "__new__/__call__ takes at least 1 argument.")); } Value class_ = args[0]; Value __base__ = createString("__base__"); Value base = getMember(ctx, class_, __base__); destroy(ctx, __base__); Value __typeID__ = createString("__typeID__"); Value typeID = getMember(ctx, class_, __typeID__); destroy(ctx, __typeID__); if (base.type != ValueType::Object) { ctx->throwException(createException(ExcType::TypeError, "Class base must be an object.")); } if (typeID.type != ValueType::Int) { ctx->throwException(createException(ExcType::TypeError, "Class type ID must be an integer.")); } Value resultHead = createObject(); HashMap<Str, Value>& resultMembers = ((ObjectData *)resultHead.p)->members; HashMap<Str, Value>& baseMembers = ((ObjectData *)base.p)->members; for (auto kv : baseMembers) { resultMembers.set(kv.first, createCopy(kv.second)); } resultMembers.set("__classTypeID__", createInt(typeID.i)); resultMembers.set("__class__", createCopy(args[0])); auto pos = resultMembers.find("__init__"); if (pos != resultMembers.end()) { destroy(ctx, callMethod(ctx, resultHead, "__init__", List<Value>(args.getCount()-1, args.getData()+1))); } else { if (args.getCount() != 1) { ctx->throwException(createException(ExcType::ValueError, "__new__/__call__ takes 1 argument.")); } } destroy(ctx, typeID); destroy(ctx, base); return resultHead; }
// use text to speech to say the specified string, using the specified language code (and optional sub-code) // http://en.wikipedia.org/wiki/Language_localisation#Language_tags_and_codes void Robot::say(std::string text, std::string languageCode, bool blocking) { if (!text.empty()) { if (languageCode.empty()) { languageCode = "en-gb"; } char* lc = strdup(languageCode.c_str()); char* te = strdup(text.c_str()); callMethod("say", "(s, s, b)", te, lc, blocking); } }
void MethodCall::next() { int oldcur = _cur; _cur++; while(!_called && _cur < _items) { Marshall::HandlerFn fn = getMarshallFn(type()); (*fn)(this); _cur++; } callMethod(); _cur = oldcur; }
int main(int argc, char** argv) { verbose = getenv("PEGASUS_TEST_VERBOSE") ? true : false; try { if (verbose) { cout << "Calling test2" << endl; } callMethod("test2"); if (verbose) { cout << "Calling test1" << endl; } callMethod("test1"); if (verbose) { cout << "Calling test3" << endl; } callMethodRefParam("test3"); if (verbose) { cout << "Calling test4" << endl; } callMethodRefParamArray("test4"); } catch (Exception& e) { cerr << "Error: " << e.getMessage() << endl; exit(1); } cout << argv[0] << " +++++ passed all tests" << endl; return 0; }
/** * call 処理用の口 * TJSインスタンスからjavascriptインスタンスのメソッドを直接呼び出す */ tjs_error TJSInstance::call(tjs_uint32 flag, const tjs_char * membername, tjs_uint32 *hint, tTJSVariant *result, tjs_int numparams, tTJSVariant **param, iTJSDispatch2 *objthis) { if (numparams < 1) {return TJS_E_BADPARAMCOUNT;}; iTJSNativeInstance *ninstance; if (TJS_SUCCEEDED(objthis->NativeInstanceSupport(TJS_NIS_GETINSTANCE, classId, &ninstance))) { TJSInstance *self = (TJSInstance*)ninstance; HandleScope handle_scope(self->isolate); return callMethod(self->isolate, self->getObject(), param[0]->GetString(), result, numparams-1, param+1, objthis); } return TJS_E_NATIVECLASSCRASH; }
as_object* getArguments(Function& callee, as_object& args, const fn_call& fn, as_object* caller) { for (size_t i = 0; i < fn.nargs; ++i) { callMethod(&args, NSV::PROP_PUSH, fn.arg(i)); } args.init_member(NSV::PROP_CALLEE, &callee); args.init_member(NSV::PROP_CALLER, caller); return &args; }
void VirtualMethodCall::next() { int previous = m_current; m_current++; while (!m_called && m_current < m_methodRef.numArgs) { Marshall::HandlerFn fn = getMarshallFn(type()); (*fn)(this); m_current++; } callMethod(); m_current = previous; }
void Robot::setLight(int color[]) { PyObject *pValue = callMethod("setLight", "([i,i,i])", color[0], color[1], color[2]); { PythonLock lock = PythonLock(); if (pValue == NULL) { std::cerr << "Error while calling setLight (" << color[0] << "," << color[1] << "," << color[2] << ")" << std::endl; PyErr_Print(); PyErr_Clear(); } Py_XDECREF(pValue); } }
std::vector<std::string> Robot::getComponents() { PyObject *pValue = callMethod("getComponents"); /** pValue = ('arm', 'head', ...) **/ std::vector<std::string> ret = std::vector<std::string>(); if (pValue != NULL) { ret = parseStringArray(pValue); { PythonLock lock = PythonLock(); Py_DECREF(pValue); } } return ret; }
RemoteRcUnitServer::RemoteRcUnitServer(RcUnits* rcUnits, QIODevice *device, bool doInitialize) : RemoteRcUnitServerBase(device, device, false) { mRcUnits = rcUnits; connect(this, SIGNAL(listUnits()), this, SLOT(onListUnits())); connect(this, SIGNAL(callMethod(uint,QByteArray,QByteArray,QVariantList)), rcUnits, SLOT(callAsync(uint,QByteArray,QByteArray,QVariantList))); connect(rcUnits, SIGNAL(asyncError(uint,QString)), SLOT(methodError(uint,QString))); connect(rcUnits, SIGNAL(asyncResponse(uint,QVariant)), SLOT(methodResponse(uint,QVariant))); connect(this, SIGNAL(enableTelecontrol(uint,QString)), SLOT(onEnableTelecontrol(uint,QString))); connect(this, SIGNAL(disableTelecontrol(uint,QString)), SLOT(onDisableTelecontrol(uint,QString))); connect(this, SIGNAL(handleTcData(uint,QMap<int,double>)), SLOT(onHandleTcData(uint,QMap<int,double>))); connect(this, SIGNAL(setTcButton(uint,int,bool)), SLOT(onSetTcButton(uint,int,bool))); connect(this, SIGNAL(updateTcSensitivity(uint,QString,QString,double,QList<bool>)), SLOT(onUpdateTcSensitivity(uint,QString,QString,double,QList<bool>))); if(doInitialize) initialize(); }
void Robot::setLight(std::string color) { PyObject *pValue = callMethod("setLight", color); { PythonLock lock = PythonLock(); if (pValue == NULL) { std::cerr << "Error while calling setLight (" << color << ")" << std::endl; PyErr_Print(); PyErr_Clear(); } Py_XDECREF(pValue); } }
/// This provides the prototype and static methods for TextField. // /// For SWF5 there is initially no prototype, for SWF6+ there is a /// limited prototype. This is changed later on instantiation of a /// TextField. void textfield_class_init(as_object& where, const ObjectURI& uri) { Global_as& gl = getGlobal(where); as_object* proto = createObject(gl); as_object* cl = gl.createClass(&textfield_ctor, proto); attachTextFieldInterface(*proto); attachTextFieldStaticMembers(*cl); where.init_member(uri, cl, as_object::DefaultFlags); // ASSetPropFlags is called on the TextField class. as_object* null = nullptr; callMethod(&gl, NSV::PROP_AS_SET_PROP_FLAGS, cl, null, 131); }
void NetConnection_as::notifyStatus(StatusCode code) { std::pair<std::string, std::string> info; getStatusCodeInfo(code, info); /// This is a new normal object each time (see NetConnection.as) as_object* o = getGlobal(owner()).createObject(); const int flags = 0; o->init_member("code", info.first, flags); o->init_member("level", info.second, flags); callMethod(&owner(), NSV::PROP_ON_STATUS, o); }
void Service_Call(UA_Server *server, UA_Session *session, const UA_CallRequest *request, UA_CallResponse *response) { if(request->methodsToCallSize <= 0) { response->responseHeader.serviceResult = UA_STATUSCODE_BADNOTHINGTODO; return; } response->results = UA_Array_new(&UA_TYPES[UA_TYPES_CALLMETHODRESULT], request->methodsToCallSize); if(!response->results) { response->responseHeader.serviceResult = UA_STATUSCODE_BADOUTOFMEMORY; return; } response->resultsSize = request->methodsToCallSize; for(UA_Int32 i = 0; i < request->methodsToCallSize;i++) callMethod(server, session, &request->methodsToCall[i], &response->results[i]); }
char* Robot::getImage(std::string retFormat) { char* img = NULL; char* r = strdup(retFormat.c_str()); PyObject *pValue = callMethod("getImage", r); if (pValue != NULL) { PythonLock lock = PythonLock(); //Create a copy of the string as PyString returns a pointer to its internal buffer // which must be modified and will be dereferenced when this function returns char* src = PyString_AsString(pValue); Py_DECREF(pValue); img = new char[strlen(src)]; strcpy(img, src); } return img; }
/// Extern. void moviecliploader_class_init(as_object& where, const ObjectURI& uri) { // This is going to be the where Number "class"/"function" Global_as& gl = getGlobal(where); as_object* proto = createObject(gl);; as_object* cl = gl.createClass(&moviecliploader_new, proto); attachMovieClipLoaderInterface(*proto); AsBroadcaster::initialize(*proto); as_object* null = 0; callMethod(&gl, NSV::PROP_AS_SET_PROP_FLAGS, proto, null, 1027); where.init_member(uri, cl, as_object::DefaultFlags); }