Beispiel #1
0
static
unsigned rw_pb_create_field_indices(const rw_yang_pb_msgdesc_t* ypbc_msgdesc,
                               YangNode* ynode,
                               std::vector<int>& fields)
{
  RW_ASSERT(ypbc_msgdesc);
  RW_ASSERT(ynode);

  auto ypbc_fdescs = ypbc_msgdesc->ypbc_flddescs;
  unsigned nkeys = 0;

  if (ynode->get_stmt_type() == RW_YANG_STMT_TYPE_LIST) {
    for (YangKeyIter yki = ynode->key_begin(); yki != ynode->key_end(); yki++) {
      YangNode *knode = yki->get_key_node();
      for (unsigned i = 0; i < ypbc_msgdesc->num_fields; i++) {
        if (!strcmp(knode->get_name(), ypbc_fdescs[i].yang_node_name)) {
          fields.push_back(ypbc_fdescs[i].pbc_order);
        }
      }
      nkeys++;
    }
  }

  RW_ASSERT(fields.size() == nkeys);

  // Remaining fields in the yang-order, though it doesn't matter.
  for (unsigned i = 0; i < ypbc_msgdesc->num_fields; i++) {
    if (!(ypbc_fdescs[i].pbc_fdesc->rw_flags & RW_PROTOBUF_FOPT_KEY)) {
      fields.push_back(ypbc_fdescs[i].pbc_order);
    }
  }

  return nkeys;
}
Beispiel #2
0
rw_status_t get_current_key_and_next_node (
    XMLNode *node,
    confd_cs_node *parent,
    XMLNode **next_node,
    confd_value_t *values,
    int *values_count)
{
  *values_count = 0;
  YangNode* yang_node = node->get_descend_yang_node();
  rw_status_t status = RW_STATUS_SUCCESS;

  *next_node = nullptr;

  RW_ASSERT (yang_node);
  RW_ASSERT (yang_node->get_stmt_type() == RW_YANG_STMT_TYPE_LIST);

  *next_node = node->get_next_sibling(node->get_local_name(), node->get_name_space());

  if (!yang_node->has_keys()) {
    values[0].type = C_INT64;
    values[0].val.i64 = (int64_t )node;
    *values_count = 1;
    return RW_STATUS_SUCCESS;
  }
  
  YangKeyIter yki = yang_node->key_begin();
  
  for (yki=yang_node->key_begin(); yki != yang_node->key_end(); yki++) {
    
    YangNode *key_yang_node = yki->get_key_node();
    RW_ASSERT (key_yang_node->get_stmt_type() == RW_YANG_STMT_TYPE_LEAF);
    XMLNode *key_node = node->find (key_yang_node->get_name(),yang_node->get_ns());
    RW_ASSERT (key_node);

    
    struct xml_tag tag = {0};
    status = find_confd_hash_values(key_yang_node, &tag);
    RW_ASSERT(RW_STATUS_SUCCESS == status);
    
    // find the node corresponding to this type from confd land
    struct confd_cs_node *cs_node = confd_find_cs_node_child(parent, tag);
    RW_ASSERT (cs_node);
    RW_ASSERT (cs_node->info.type);
    std::string value_string = key_node->get_text_value();
    if (!value_string.length()) {
      RW_CRASH();
      break;
    }
    
    int ret = confd_str2val (cs_node->info.type, value_string.c_str(),
                             &values[*values_count]);
    RW_ASSERT(CONFD_OK == ret);
    (*values_count)++;
  }
 
  return RW_STATUS_SUCCESS;

}