Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Get service reference in getDisplayValue() method #105

Open
zaleksa opened this issue Apr 2, 2021 · 0 comments
Open

Get service reference in getDisplayValue() method #105

zaleksa opened this issue Apr 2, 2021 · 0 comments

Comments

@zaleksa
Copy link

zaleksa commented Apr 2, 2021

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::vectorServiceRef::Ptr _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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant