macchina-io / macchina.io

macchina.io EDGE is a powerful C++ and JavaScript SDK for edge devices, multi-service IoT gateways and connected embedded systems.
https://macchina.io
GNU General Public License v3.0
512 stars 152 forks source link

Get service reference in getDisplayValue() method #105

Open zaleksa opened 3 years ago

zaleksa commented 3 years ago

Hi,

I need advice on following example:

If there is few references in Service Registry pointed to the same object but with different names, how can I differentiate them in call of some property method in pointed object?

Example:


BundleActivator:

BundleContext::Ptr _pContext; std::vector _serviceRefs;

Properties props; props.set("io.macchina.device", MyObject::SYMBOLIC_NAME); props.set("io.macchina.deviceType", MyObject::TYPE);

std::string oid_1; std::string oid_2; std::string oid_3;

_serviceRefs.push_back(_pContext->registry().registerService(oid_1, pMyObject, props)); _serviceRefs.push_back(_pContext->registry().registerService(oid_2, pMyObject, props)); _serviceRefs.push_back(_pContext->registry().registerService(oid_3, pMyObject, props));


class MyObject: public IoT::Devices::DeviceImpl<IoT::Devices::MyDevice, MyObject> { protected: Poco::Any getDisplayValue(const std::string&) const; }

MyObject() ( addProperty("displayValue", &MyObject::getDisplayValue); ... )

Poco::Any MyObject::getDisplayValue(const std::string&) const { if(calling_reference == oid_1) // how to get calling_reference? { return value_1; } else if(calling_reference == oid_2) // how to get calling_reference? { return value_2; } else if(calling_reference == oid_3) // how to get calling_reference? { return value_3; } }


Thanks in advance,

Aleksandar