Skip to content

Commit

Permalink
Add user_data to Adapter and Device
Browse files Browse the repository at this point in the history
  • Loading branch information
charlesnicholson committed Apr 9, 2024
1 parent bd76e81 commit 00355b1
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 0 deletions.
12 changes: 12 additions & 0 deletions binc/adapter.c
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,7 @@ struct binc_adapter {
AdapterDiscoveryStateChangeCallback discoveryStateCallback;
AdapterPoweredStateChangeCallback poweredStateCallback;
RemoteCentralConnectionStateCallback centralStateCallback;
void *user_data; // Borrowed
GHashTable *devices_cache; // Owned

Advertisement *advertisement; // Borrowed
Expand Down Expand Up @@ -530,6 +531,7 @@ static Adapter *binc_adapter_create(GDBusConnection *connection, const char *pat
adapter->discovery_filter.rssi = -255;
adapter->devices_cache = g_hash_table_new_full(g_str_hash, g_str_equal,
g_free, (GDestroyNotify) binc_device_free);
adapter->user_data = NULL;
setup_signal_subscribers(adapter);
return adapter;
}
Expand Down Expand Up @@ -1123,3 +1125,13 @@ void binc_adapter_set_remote_central_cb(Adapter *adapter, RemoteCentralConnectio
g_assert(adapter != NULL);
adapter->centralStateCallback = callback;
}

void binc_adapter_set_user_data(Adapter *adapter, void *user_data) {
g_assert(adapter != NULL);
adapter->user_data = user_data;
}

void *binc_adapter_get_user_data(const Adapter *adapter) {
g_assert(adapter != NULL);
return adapter->user_data;
}
4 changes: 4 additions & 0 deletions binc/adapter.h
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,10 @@ void binc_adapter_unregister_application(Adapter *adapter, Application *applicat

void binc_adapter_set_remote_central_cb(Adapter *adapter, RemoteCentralConnectionStateCallback callback);

void binc_adapter_set_user_data(Adapter *adapter, void *user_data);

void *binc_adapter_get_user_data(const Adapter *adapter);

#ifdef __cplusplus
}
#endif
Expand Down
13 changes: 13 additions & 0 deletions binc/device.c
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,7 @@ struct binc_device {
OnNotifyingStateChangedCallback on_notify_state_callback;
OnDescReadCallback on_read_desc_cb;
OnDescWriteCallback on_write_desc_cb;
void *user_data; // Borrowed
};


Expand All @@ -117,6 +118,7 @@ Device *binc_device_create(const char *path, Adapter *adapter) {
device->rssi = -255;
device->txpower = -255;
device->mtu = 23;
device->user_data = NULL;
return device;
}

Expand Down Expand Up @@ -1194,3 +1196,14 @@ void binc_internal_device_update_property(Device *device, const char *property_n
g_variant_iter_free(iter);
}
}

void binc_device_set_user_data(Device *device, void *user_data) {
g_assert(device != NULL);
device->user_data = user_data;
}

void *binc_device_get_user_data(const Device *device) {
g_assert(device != NULL);
return device->user_data;
}

4 changes: 4 additions & 0 deletions binc/device.h
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,10 @@ gboolean binc_device_is_central(const Device *device);

char *binc_device_to_string(const Device *device);

void binc_device_set_user_data(Device *device, void *user_data);

void *binc_device_get_user_data(const Device *device);

#ifdef __cplusplus
}
#endif
Expand Down

0 comments on commit 00355b1

Please sign in to comment.