Say I have two Redhawk components. Component 1 has a property called "taps". Component 2 also needs to know the value of "taps". It would make things a lot easier if Component 2 could look up the value of "taps" for Component 1, rather than having its own value of "taps" given to it. How can Component 2 access the properties of Component 1? I'm implementing these components in c++.
I've tried a resource port using the following code.
int NeedsProperties_i::serviceFunction(){
CF::Properties otherProperties;
otherProperties.length(1);
otherProperties[0].id = "name";
resourceOut->query(otherProperties);
std::cout << "name: " << any_to_string(otherProperties[0].value) <<
std::endl;
sleep(1);
return NORMAL;
}
std::string NeedsProperties_i::any_to_string(CORBA::Any value) {
std::ostringstream result;
const char* tmp;
value >>= tmp;
result << tmp;
return result.str();
}
NeedsProperties is Component 2 in this case and is trying to get the property "name" from another component. NeedsProperties has the output resource port "resourceOut" connected to the component. The code just prints empty strings regardless if the resource port is connected or not. Whats going on here? Also, is the resource port even a good way to implement this, or is there a better implementation?
The issue with my code above was that I had connected the output resource port of "NeedsProperties" to my own input resource port on the other component that I created. You are supposed to connect the output port to the "lollipop" on the other component. It is that little dot protruding from the name.
Thanks for the answers though.