summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorThomas Haller <thaller@redhat.com>2017-06-03 13:31:46 +0200
committerThomas Haller <thaller@redhat.com>2017-06-07 09:07:18 +0200
commit113e8ad6e633e2ca34e7bb05eb92850dd0b9cd20 (patch)
tree517b1dace74b1553f201c1094cb2b08e8131b3e0
parent4c094adfb7216dccb14f5ba3783a33809562390a (diff)
downloadNetworkManager-113e8ad6e633e2ca34e7bb05eb92850dd0b9cd20.tar.gz
device: inline bluetooth function in nm-device-bridge.c
The 3 bluetooth NAP hooks are called each only once. Inline them. It is still very easy to understand where the bluetooth related functions are invoked: grep for nm_bt_vtable_network_server. In deactivate(), don't bother checking whether the current active connection is a bluetooth type. Just always call unregister_bridge(). It's fast, and does nothing in case the bridge isn't registered. I change it because I disagree with the previous naming. For example bt_network_server_available() would not only call is_available(). Instead, it checks whether the connection can activate regarding availability of the bluetooth connection (meaning, it returns TRUE if it's not a bluetooth connection or if the bluez manager gives green light). In the bridge case, it doesn't check any network-server availability. There is already a function with a meaningful name for this behavior: check_connection_available(). Same with bt_network_server_register(). It would indicate success, if the applied connection is not a bluetooth connection. In cases, where it didn't actually register anything. A function called bt_network_server_register() should only return success if it actually registered anything.
-rw-r--r--src/devices/nm-device-bridge.c82
1 files changed, 29 insertions, 53 deletions
diff --git a/src/devices/nm-device-bridge.c b/src/devices/nm-device-bridge.c
index 6a0d383c3c..58400211b2 100644
--- a/src/devices/nm-device-bridge.c
+++ b/src/devices/nm-device-bridge.c
@@ -51,52 +51,6 @@ G_DEFINE_TYPE (NMDeviceBridge, nm_device_bridge, NM_TYPE_DEVICE)
const NMBtVTableNetworkServer *nm_bt_vtable_network_server = NULL;
-static gboolean
-bt_network_server_available (NMConnection *connection)
-{
- NMSettingBluetooth *s_bt = _nm_connection_get_setting_bluetooth_for_nap (connection);
-
- if (!s_bt)
- return TRUE;
- if (!nm_bt_vtable_network_server)
- return FALSE;
- return nm_bt_vtable_network_server->is_available (nm_bt_vtable_network_server,
- nm_setting_bluetooth_get_bdaddr (s_bt));
-}
-
-static gboolean
-bt_network_server_register (NMDevice *self)
-{
- NMConnection *connection = nm_device_get_applied_connection (self);
- NMSettingBluetooth *s_bt = _nm_connection_get_setting_bluetooth_for_nap (connection);
-
- if (!s_bt)
- return TRUE;
- if (!nm_bt_vtable_network_server)
- return FALSE;
- return nm_bt_vtable_network_server->register_bridge (nm_bt_vtable_network_server,
- nm_setting_bluetooth_get_bdaddr (s_bt),
- self);
-}
-
-static void
-bt_network_server_unregister (NMDevice *self)
-{
- NMConnection *connection = nm_device_get_applied_connection (self);
- NMSettingBluetooth *s_bt;
-
- if (!connection)
- return;
- s_bt = _nm_connection_get_setting_bluetooth_for_nap (connection);
- if (!s_bt)
- return;
-
- if (!nm_bt_vtable_network_server)
- return;
- nm_bt_vtable_network_server->unregister_bridge (nm_bt_vtable_network_server,
- self);
-}
-
/*****************************************************************************/
static NMDeviceCapabilities
@@ -117,8 +71,14 @@ check_connection_available (NMDevice *device,
NMDeviceCheckConAvailableFlags flags,
const char *specific_object)
{
- if (!bt_network_server_available (connection))
- return FALSE;
+ NMSettingBluetooth *s_bt;
+
+ s_bt = _nm_connection_get_setting_bluetooth_for_nap (connection);
+ if (s_bt) {
+ return nm_bt_vtable_network_server
+ && nm_bt_vtable_network_server->is_available (nm_bt_vtable_network_server,
+ nm_setting_bluetooth_get_bdaddr (s_bt));
+ }
/* Connections are always available because the carrier state is determined
* by the bridge port carrier states, not the bridge's state.
@@ -388,10 +348,21 @@ act_stage1_prepare (NMDevice *device, NMDeviceStateReason *out_failure_reason)
static NMActStageReturn
act_stage2_config (NMDevice *device, NMDeviceStateReason *out_failure_reason)
{
- if (!bt_network_server_register (device)) {
- /* The HCI we could use is no longer present. */
- *out_failure_reason = NM_DEVICE_STATE_REASON_REMOVED;
- return NM_ACT_STAGE_RETURN_FAILURE;
+ NMConnection *connection;
+ NMSettingBluetooth *s_bt;
+
+ connection = nm_device_get_applied_connection (device);
+
+ s_bt = _nm_connection_get_setting_bluetooth_for_nap (connection);
+ if (s_bt) {
+ if ( !nm_bt_vtable_network_server
+ || !nm_bt_vtable_network_server->register_bridge (nm_bt_vtable_network_server,
+ nm_setting_bluetooth_get_bdaddr (s_bt),
+ device)) {
+ /* The HCI we could use is no longer present. */
+ *out_failure_reason = NM_DEVICE_STATE_REASON_REMOVED;
+ return NM_ACT_STAGE_RETURN_FAILURE;
+ }
}
return NM_ACT_STAGE_RETURN_SUCCESS;
@@ -400,7 +371,12 @@ act_stage2_config (NMDevice *device, NMDeviceStateReason *out_failure_reason)
static void
deactivate (NMDevice *device)
{
- bt_network_server_unregister (device);
+ if (nm_bt_vtable_network_server) {
+ /* always call unregister. It does nothing if the device
+ * isn't registered as a hotspot bridge. */
+ nm_bt_vtable_network_server->unregister_bridge (nm_bt_vtable_network_server,
+ device);
+ }
}
static gboolean