Exemplo n.º 1
0
std::function<void(const ShmdataStat&)> ShmdataStat::make_tree_updater(Quiddity* quid,
                                                                       const std::string& key) {
  return [quid, key](const ShmdataStat& stat) {
    auto tree = InfoTree::make();
    tree->graft(".byte_rate", InfoTree::make(stat.bytes_));
    tree->graft(".rate", InfoTree::make(stat.accesses_));
    quid->graft_tree(key + ".stat", tree);
  };
}
Exemplo n.º 2
0
InfoTree::ptr QuiddityCommand::get_info_tree() const {
  auto tree = InfoTree::make();
  tree->graft("command", InfoTree::make(command_names_.at(id_)));
  tree->graft("calling time", InfoTree::make((gint)time_));
  for (unsigned int i = 0; i < args_.size(); i++) {
    tree->graft(std::string("arguments.") + std::to_string(i), InfoTree::make(args_[i]));
  }
  tree->tag_as_array("arguments", true);
  if (vector_arg_.empty()) {
    tree->graft("vector argument.", InfoTree::make());
  } else {
    for (unsigned int i = 0; i < vector_arg_.size(); i++) {
      tree->graft(std::string("vector argument.") + std::to_string(i),
                  InfoTree::make(vector_arg_[i]));
    }
  }
  tree->tag_as_array("vector argument", true);
  if (result_.empty()) {
    tree->graft("results.0.", InfoTree::make(""));
  } else {
    for (unsigned int i = 0; i < result_.size(); i++) {
      tree->graft(std::string("results.") + std::to_string(i), InfoTree::make(result_[i]));
    }
  }
  tree->tag_as_array("results", true);
  return tree;
}
Exemplo n.º 3
0
PContainer::prop_id_t PContainer::push_parented(const std::string& strid,
                                                const std::string& parent_strid,
                                                std::unique_ptr<PropertyBase>&& prop_ptr) {
  if (ids_.cend() != ids_.find(strid)) return 0;  // strid already taken
  if (parent_strid != "" && ids_.cend() == ids_.find(parent_strid)) return 0;  // parent not found
  props_[++counter_] = std::forward<std::unique_ptr<PropertyBase>>(prop_ptr);
  ids_[strid] = counter_;
  strids_[counter_] = strid;
  auto* prop = props_[counter_].get();
  prop->set_id(counter_);
  auto tree = prop->get_spec();
  auto key = std::string("property.") + strid;
  tree_->graft(key, tree);
  tree->graft("id", InfoTree::make(strid));
  tree->graft("prop_id", InfoTree::make(counter_));
  tree->graft("order", InfoTree::make(20 * (suborders_.get_count(parent_strid) + 1)));
  tree->graft("parent", InfoTree::make(parent_strid));
  tree->graft("enabled", InfoTree::make(true));
  if (on_tree_grafted_cb_) on_tree_grafted_cb_(key);
  return counter_;
}
Exemplo n.º 4
0
bool PContainer::replace(prop_id_t prop_id, std::unique_ptr<PropertyBase>&& prop_ptr) {
  auto it = strids_.find(prop_id);
  auto strid = it->second;
  if (strids_.end() == it) return false;  // prop not found
  auto old_value = get_str(prop_id);
  // keep a reference to the old property documentation tree
  auto old_tree = props_[prop_id].get()->get_spec();
  // copy notification cbs
  auto notification_cbs = props_[prop_id].get()->get_notify_cbs();
  // replace with new prop
  props_[prop_id] = std::forward<std::unique_ptr<PropertyBase>>(prop_ptr);
  auto* prop = props_[prop_id].get();
  prop->set_notify_cbs(notification_cbs);
  prop->set_id(prop_id);
  prop->set_str(old_value);
  // place old tree into new property
  auto tree = prop->get_spec();
  tree->graft(".", old_tree);
  // updating tree_
  tree_->graft(std::string("property.") + strid, tree);
  return true;
}