gboolean nm_netlink_monitor_subscribe (NMNetlinkMonitor *self, int group, GError **error) { NMNetlinkMonitorPrivate *priv; int subs, err; g_return_val_if_fail (NM_IS_NETLINK_MONITOR (self), FALSE); priv = NM_NETLINK_MONITOR_GET_PRIVATE (self); if (!priv->nlh_event) { if (!nm_netlink_monitor_open_connection (self, error)) return FALSE; } subs = get_subs (self, group) + 1; if (subs == 1) { err = nl_socket_add_membership (priv->nlh_event, group); if (err < 0) { g_set_error (error, NM_NETLINK_MONITOR_ERROR, NM_NETLINK_MONITOR_ERROR_NETLINK_JOIN_GROUP, _("unable to join netlink group: %s"), nl_geterror (err)); return FALSE; } } /* Update # of subscriptions for this group */ set_subs (self, group, subs); return TRUE; }
pbm::PathedMapT list_bases (void) const override { pbm::PathedMapT out; auto marshalers = get_subs(); for (MarsptrT& marshal : marshalers) { auto temp = marshal->list_bases(); for (auto& bpairs : temp) { bpairs.second.push_front(marshal->get_label()); } out.insert(temp.begin(), temp.end()); } return out; }
void set_variables (pbm::PathedTens* storage) override { auto marshalers = get_subs(); for (MarsptrT& marshal : marshalers) { std::string child_label = marshal->get_label(); auto it = storage->children_.find(child_label); if (storage->children_.end() == it) { logs::warnf("label %s not found", child_label.c_str()); continue; } marshal->set_variables(it->second); } }
void nm_netlink_monitor_unsubscribe (NMNetlinkMonitor *self, int group) { NMNetlinkMonitorPrivate *priv; int subs; g_return_if_fail (self != NULL); g_return_if_fail (NM_IS_NETLINK_MONITOR (self)); priv = NM_NETLINK_MONITOR_GET_PRIVATE (self); g_return_if_fail (priv->nlh_event != NULL); subs = get_subs (self, group) - 1; if (subs == 0) nl_socket_drop_membership (priv->nlh_event, group); /* Update # of subscriptions for this group */ set_subs (self, group, subs); }
pbm::PathedTens* get_variables (void) const override { auto out = new pbm::PathedTens(); auto marshalers = get_subs(); for (MarsptrT& marshal : marshalers) { std::string child_label = marshal->get_label(); auto child = marshal->get_variables(); auto it = out->children_.find(child_label); if (out->children_.end() != it) { it->second->join(child); delete child; } else { out->children_.emplace(child_label, child); } } return out; }