Comment 1 for bug 1457327

Revision history for this message
Tapan Karwa (tkarwa) wrote :

Currently, if config sets a boolean value in any node, we receive the right value in the incoming ifmap packet. But, the autogen code does not set the field with the incoming value.

Here is an example from today's codebase:

bool IsShared_ParseMetadata(const pugi::xml_node &parent, std::auto_ptr<AutogenProperty > *resultp) {
    VirtualNetwork::OolProperty *data = new VirtualNetwork::OolProperty();
    resultp->reset(data);
         <<<<<<<<<<<<<<<<< we should set data->data from the value in parent here.
    return true;
}

Here is the XML:
<contrail:is-shared xmlns:contrail="http://www.contrailsystems.com/vnc_cfg.xsd" ifmap-cardinality="singleValue" ifmap-publisher-id="api-server-1--0000000001-1" ifmap-timestamp="2015-05-22T09:25:59-07:00">
False
</contrail:is-shared>

Fixed autogen-code will look like:

bool IsShared_ParseMetadata(const pugi::xml_node &parent, std::auto_ptr<AutogenProperty > *resultp) {
    VirtualNetwork::OolProperty *data = new VirtualNetwork::OolProperty();
    resultp->reset(data);
    data->data = parent.text().as_bool();
    return true;
}

(gdb) p parent.type()
$11 = pugi::node_element
(gdb) p child.type()
$12 = pugi::node_pcdata
(gdb) p parent.value()
$13 = (const pugi::char_t *) 0xecf7c5 ""
(gdb) p child.value()
$14 = (const pugi::char_t *) 0x7f376576c66d "True"

The documentation says:
You can get the text object from a node by using text() method. If the node has a type node_pcdata or node_cdata, then the node itself is used to return data; otherwise, a first child node of type node_pcdata or node_cdata is used.
as_bool converts attribute value to boolean as follows: if attribute handle is null, def argument is returned (which is false by default). If attribute value is empty, false is returned. Otherwise, true is returned if the first character is one of '1', 't', 'T', 'y', 'Y'. This means that strings like "true" and "yes" are recognized as true, while strings like "false" and "no" are recognized as false.