void VehicleEmulator::parseRxProtoBuf(std::vector<uint8_t>& msg) { emulator::EmulatorMessage rxMsg; emulator::EmulatorMessage respMsg; if (rxMsg.ParseFromArray(msg.data(), static_cast<int32_t>(msg.size()))) { switch (rxMsg.msg_type()) { case emulator::GET_CONFIG_CMD: doGetConfig(rxMsg, respMsg); break; case emulator::GET_CONFIG_ALL_CMD: doGetConfigAll(rxMsg, respMsg); break; case emulator::GET_PROPERTY_CMD: doGetProperty(rxMsg, respMsg); break; case emulator::GET_PROPERTY_ALL_CMD: doGetPropertyAll(rxMsg, respMsg); break; case emulator::SET_PROPERTY_CMD: doSetProperty(rxMsg, respMsg); break; default: ALOGW("%s: Unknown message received, type = %d", __func__, rxMsg.msg_type()); respMsg.set_status(emulator::ERROR_UNIMPLEMENTED_CMD); break; } // Send the reply txMsg(respMsg); } else { ALOGE("%s: ParseFromString() failed. msgSize=%d", __func__, static_cast<int>(msg.size())); } }
void QObjectProxy::customEvent( QEvent *event ) { if( event->type() == (QEvent::Type) ScMethodCallType ) { scMethodCallEvent( static_cast<ScMethodCallEvent*>( event ) ); return; } if( event->type() != (QEvent::Type) CustomType ) return; CustomEvent *e = ( CustomEvent * ) event; PropertyData p; EventHandlerData eh; switch ( e->_type ) { case SetProperty: p = e->_data.value<PropertyData>(); doSetProperty( p.name, p.value ); break; case GetProperty: p = e->_data.value<PropertyData>(); *e->_return = QVariant( doGetProperty( p.name, p.slot ) ); break; case SetEventHandler: eh = e->_data.value<EventHandlerData>(); doSetEventHandler( eh ); break; default: qscErrorMsg("Unhandled custom event\n"); } }
/*static*/ PyObject* PythonScript::getAttribute(PyObject * o, PyObject * attr_name) { QObject * obj; QMetaMethod method; QString propName; QVariant result; pyQObjectMethodObject * pyMethod; // Get the QObject* we operate on if (!PyObject_TypeCheck(o, &pyQObjectType)) { PyErr_SetString(PyExc_TypeError, qPrintable(tr("getattr: not a valid TW object"))); return NULL; } if (!IS_ENCAPSULATED_C_POINTER(((pyQObject*)o)->_TWcontext)) { PyErr_SetString(PyExc_TypeError, qPrintable(tr("getattr: not a valid TW object"))); return NULL; } obj = (QObject*)GET_ENCAPSULATED_C_POINTER((PyObject*)(((pyQObject*)o)->_TWcontext)); if (!asQString(attr_name, propName)) { PyErr_SetString(PyExc_TypeError, qPrintable(tr("getattr: invalid property name"))); return NULL; } if (propName.length() > 1 && propName.endsWith(QChar('_'))) propName.chop(1); switch (doGetProperty(obj, propName, result)) { case Property_DoesNotExist: PyErr_Format(PyExc_AttributeError, qPrintable(tr("getattr: object doesn't have property/method %s")), qPrintable(propName)); return NULL; case Property_NotReadable: PyErr_Format(PyExc_AttributeError, qPrintable(tr("getattr: property %s is not readable")), qPrintable(propName)); return NULL; case Property_Method: pyMethod = PyObject_New(pyQObjectMethodObject, &pyQObjectMethodType); pyMethod = (pyQObjectMethodObject*)PyObject_Init((PyObject*)pyMethod, &pyQObjectMethodType); Py_INCREF(pyMethod); pyMethod->_TWcontext = ENCAPSULATE_C_POINTER(obj); Py_XINCREF(attr_name); pyMethod->_methodName = (PyObject*)attr_name; return (PyObject*)pyMethod; case Property_OK: return PythonScript::VariantToPython(result); default: break; } // we should never reach this point return NULL; }
void Image_GPhoto::registerAttributes() { Image::registerAttributes(); addAttribute("aperture", [&](const Values& args) { return doSetProperty("aperture", args[0].as<string>()); }, [&]() -> Values { string value; if (doGetProperty("aperture", value)) return {value}; else return {}; }, {'n'}); setAttributeDescription("aperture", "Set the aperture of the lens"); addAttribute("isospeed", [&](const Values& args) { return doSetProperty("iso", args[0].as<string>()); }, [&]() -> Values { string value; if (doGetProperty("iso", value)) return {value}; else return {}; }, {'n'}); setAttributeDescription("isospeed", "Set the ISO value of the camera"); addAttribute("shutterspeed", [&](const Values& args) { doSetProperty("shutterspeed", getShutterspeedStringFromFloat(args[0].as<float>())); return true; }, [&]() -> Values { string value; doGetProperty("shutterspeed", value); float duration = getFloatFromShutterspeedString(value); return {duration}; }, {'n'}); setAttributeDescription("shutterspeed", "Set the camera shutter speed"); // Actions addAttribute("capture", [&](const Values&) { runAsyncTask([=]() { capture(); }); return true; }); setAttributeDescription("capture", "Ask for the camera to shoot"); addAttribute("detect", [&](const Values&) { runAsyncTask([=]() { detectCameras(); }); return true; }); setAttributeDescription("detect", "Ask for camera detection"); // Status addAttribute("ready", [&](const Values&) { return false; }, [&]() -> Values { lock_guard<recursive_mutex> lock(_gpMutex); if (_selectedCameraIndex == -1) return {0}; else return {1}; }); setAttributeDescription("ready", "Ask whether the camera is ready to shoot"); }