1

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?

3 Answers3

0

Using REDHAWK 2.1.3, I was able to successfully query Component 1(with a property that had the ID 'name') from Component 2 using your example code.

Two things to note are that you will get an exception from query for a property that doesn't exist - does Component1 have a property with the id 'name'? If you try to unmarshall the wrong type out of the property, you will get no value. Using the ossie::any_to_string() helper is the preferred way to unmarshall simple CORBA objects.

An alternate implementation would use PropertyChangeListeners. When a Property gets a new value, there is an event generated and published for anyone to grab. In Component2, you would need to inherit from PropertyChangeListener, call registerPropertyChangeListener() with the id of the property on Component1 and handle the change event. You can see redhawk/src/testing/tests/test_08_PropertyChange*.py for python code that handles PropertyChangeEvents.

Kevin V
  • 26
  • 2
  • Where is the python file you are referring to located? Are you referring to an online repository or does it come with the installation files? – Justin Kuric Aug 23 '18 at 18:29
  • Yes, it's available in the source for the REDHAWK core framework. See [core-framework](https://github.com/RedhawkSDR/core-framework) for the source. – Kevin V Aug 28 '18 at 21:49
0

try this:

int NeedsProperties_i::serviceFunction(){

    CF::Properties otherProperties;

    otherProperties.length(1);

    otherProperties[0].id = CORBA::string_dup("name");

    if(resourceOut->isActive()){

        resourceOut->query(otherProperties);

        std::cout << "name: " << any_to_string(otherProperties[0].value) << 
        std::endl;

        sleep(1);
        return NORMAL;
    }else{
        sleep(1);
        return NOOP;   
    }
}
0

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.