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*/ int PythonScript::setAttribute(PyObject * o, PyObject * attr_name, PyObject * v) { QObject * obj; QString propName; QMetaProperty prop; // Get the QObject* we operate on if (!PyObject_TypeCheck(o, &pyQObjectType)) { PyErr_SetString(PyExc_TypeError, qPrintable(tr("setattr: not a valid TW object"))); return -1; } if (!IS_ENCAPSULATED_C_POINTER(((pyQObject*)o)->_TWcontext)) { PyErr_SetString(PyExc_TypeError, qPrintable(tr("setattr: not a valid TW object"))); return -1; } obj = (QObject*)GET_ENCAPSULATED_C_POINTER((PyObject*)(((pyQObject*)o)->_TWcontext)); // Get the parameters if (!asQString(attr_name, propName)) { PyErr_SetString(PyExc_TypeError, qPrintable(tr("setattr: invalid property name"))); return -1; } switch (doSetProperty(obj, propName, PythonScript::PythonToVariant(v))) { case Property_DoesNotExist: PyErr_Format(PyExc_AttributeError, qPrintable(tr("setattr: object doesn't have property %s")), qPrintable(propName)); return -1; case Property_NotWritable: PyErr_Format(PyExc_AttributeError, qPrintable(tr("setattr: property %s is not writable")), qPrintable(propName)); return -1; case Property_OK: return 0; default: break; } // we should never reach this point return -1; }
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"); }