sd-netlink: add functions which manage sd_netlink_slot object
This commit is contained in:
parent
ee38400bba
commit
1a7baaa9e2
|
@ -107,3 +107,70 @@ static sd_netlink_slot* netlink_slot_free(sd_netlink_slot *slot) {
|
|||
}
|
||||
|
||||
DEFINE_PUBLIC_TRIVIAL_REF_UNREF_FUNC(sd_netlink_slot, sd_netlink_slot, netlink_slot_free);
|
||||
|
||||
sd_netlink *sd_netlink_slot_get_netlink(sd_netlink_slot *slot) {
|
||||
assert_return(slot, NULL);
|
||||
|
||||
return slot->netlink;
|
||||
}
|
||||
|
||||
void *sd_netlink_slot_get_userdata(sd_netlink_slot *slot) {
|
||||
assert_return(slot, NULL);
|
||||
|
||||
return slot->userdata;
|
||||
}
|
||||
|
||||
void *sd_netlink_slot_set_userdata(sd_netlink_slot *slot, void *userdata) {
|
||||
void *ret;
|
||||
|
||||
assert_return(slot, NULL);
|
||||
|
||||
ret = slot->userdata;
|
||||
slot->userdata = userdata;
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
int sd_netlink_slot_get_destroy_callback(sd_netlink_slot *slot, sd_netlink_destroy_t *callback) {
|
||||
assert_return(slot, -EINVAL);
|
||||
|
||||
if (callback)
|
||||
*callback = slot->destroy_callback;
|
||||
|
||||
return !!slot->destroy_callback;
|
||||
}
|
||||
|
||||
int sd_netlink_slot_set_destroy_callback(sd_netlink_slot *slot, sd_netlink_destroy_t callback) {
|
||||
assert_return(slot, -EINVAL);
|
||||
|
||||
slot->destroy_callback = callback;
|
||||
return 0;
|
||||
}
|
||||
|
||||
int sd_netlink_slot_get_floating(sd_netlink_slot *slot) {
|
||||
assert_return(slot, -EINVAL);
|
||||
|
||||
return slot->floating;
|
||||
}
|
||||
|
||||
int sd_netlink_slot_set_floating(sd_netlink_slot *slot, int b) {
|
||||
assert_return(slot, -EINVAL);
|
||||
|
||||
if (slot->floating == !!b)
|
||||
return 0;
|
||||
|
||||
if (!slot->netlink) /* Already disconnected */
|
||||
return -ESTALE;
|
||||
|
||||
slot->floating = b;
|
||||
|
||||
if (b) {
|
||||
sd_netlink_slot_ref(slot);
|
||||
sd_netlink_unref(slot->netlink);
|
||||
} else {
|
||||
sd_netlink_ref(slot->netlink);
|
||||
sd_netlink_slot_unref(slot);
|
||||
}
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
|
|
@ -186,6 +186,14 @@ int sd_genl_message_new(sd_netlink *nl, sd_genl_family family, uint8_t cmd, sd_n
|
|||
sd_netlink_slot *sd_netlink_slot_ref(sd_netlink_slot *nl);
|
||||
sd_netlink_slot *sd_netlink_slot_unref(sd_netlink_slot *nl);
|
||||
|
||||
sd_netlink *sd_netlink_slot_get_netlink(sd_netlink_slot *slot);
|
||||
void *sd_netlink_slot_get_userdata(sd_netlink_slot *slot);
|
||||
void *sd_netlink_slot_set_userdata(sd_netlink_slot *slot, void *userdata);
|
||||
int sd_netlink_slot_get_destroy_callback(sd_netlink_slot *slot, sd_netlink_destroy_t *callback);
|
||||
int sd_netlink_slot_set_destroy_callback(sd_netlink_slot *slot, sd_netlink_destroy_t callback);
|
||||
int sd_netlink_slot_get_floating(sd_netlink_slot *slot);
|
||||
int sd_netlink_slot_set_floating(sd_netlink_slot *slot, int b);
|
||||
|
||||
_SD_DEFINE_POINTER_CLEANUP_FUNC(sd_netlink, sd_netlink_unref);
|
||||
_SD_DEFINE_POINTER_CLEANUP_FUNC(sd_netlink_message, sd_netlink_message_unref);
|
||||
_SD_DEFINE_POINTER_CLEANUP_FUNC(sd_netlink_slot, sd_netlink_slot_unref);
|
||||
|
|
Loading…
Reference in a new issue