RedHawk Property query/Config from Component A to

2019-09-14 19:24发布

I'm very new to RedHawk and I have the following scenario:

I have three component A B and C, B and C both have a property skill, which is one keyword describing what B or C's capability. The flow is: A starts and queries B.skill and C.skill so A knows what B and C can do. Then when A encounters a task that fits in B's or C's skill set, A will start up that specific component to do the task.

My question is: how does component A access a property of B? I looked up online and found some simple redhawk query introduction (https://redhawksdr.github.io/Documentation/mainch4.html section 4.6.2), but I hope if someone can show me a code snippet that demos how A accesses B's property. Also, I can't find any detailed documentation of the query api. It would be great if someone can direct me to it.

Thank you.

1条回答
等我变得足够好
2楼-- · 2019-09-14 20:21

This example could probably get cleaned up a bit but in my example snippet, CompA has two output ports, both of type resource with the names compB_connection and compC_connection. We can then connect to compB and compC's resource port (also called the lollipop port) which is a direct connection to the component itself since it inherits from the resource API. This gives us access to methods on the component like start, stop, configure, query etc. For a full list see the idl files.

CompB and CompC both have a property with the id of "skill". We can use the query API to query the values of those properties.

std::string CompA_i::any_to_string(CORBA::Any value) {
    std::ostringstream result;
    const char* tmp;
    value >>= tmp;
    result << tmp;
    return result.str();
}

int CompA_i::serviceFunction() {
    CF::Properties compB_props, compC_props;

    compB_props.length(1);
    compC_props.length(1);

    compB_props[0].id = "skill";
    compC_props[0].id = "skill";

    compB_connection->query(compB_props);
    compC_connection->query(compC_props);

    std::cout << "CompB Skills: " << any_to_string(compB_props[0].value) << std::endl;
    std::cout << "CompC Skills: " << any_to_string(compC_props[0].value) << std::endl;

    return FINISH;
}

Now when we connect CompA up to CompB and CompC and Start the waveform, or sandbox we get the following output:

CompB Skills: nunchuck skills
CompC Skills: bow hunting skills

The any_to_string method was found in prop_helpers.cpp in the core framework code; there is probably a helper function in a header file somewhere that would be a better fix.

查看更多
登录 后发表回答