Skip to content

Commit

Permalink
Fix oFono registration after changes in 6e05991
Browse files Browse the repository at this point in the history
After changes in commit 6e05991 it is no longer required to call
the registration code outside of the "appeared" callback of the
g_bus_watch_name*() function.
  • Loading branch information
arkq committed Feb 16, 2022
1 parent ec8a513 commit 6e4ff9e
Show file tree
Hide file tree
Showing 7 changed files with 62 additions and 60 deletions.
27 changes: 18 additions & 9 deletions src/bluez.c
Original file line number Diff line number Diff line change
Expand Up @@ -985,11 +985,7 @@ static void bluez_register_hfp_all(void) {

/**
* Register to the BlueZ service. */
void bluez_register(void) {

if (dbus_object_data_map == NULL)
dbus_object_data_map = g_hash_table_new_full(g_str_hash, g_str_equal,
NULL, (GDestroyNotify)bluez_dbus_object_data_unref);
static void bluez_register(void) {

GError *err = NULL;
GVariantIter *objects = NULL;
Expand Down Expand Up @@ -1307,10 +1303,8 @@ static void bluez_disappeared(GDBusConnection *conn, const char *name,
}

/**
* Subscribe to BlueZ signals.
*
* @return On success this function returns 0. Otherwise -1 is returned. */
int bluez_subscribe_signals(void) {
* Subscribe to BlueZ signals. */
static void bluez_subscribe_signals(void) {

g_dbus_connection_signal_subscribe(config.dbus, BLUEZ_SERVICE,
DBUS_IFACE_OBJECT_MANAGER, "InterfacesAdded", NULL, NULL,
Expand All @@ -1327,6 +1321,21 @@ int bluez_subscribe_signals(void) {
G_BUS_NAME_WATCHER_FLAGS_NONE, NULL, bluez_disappeared,
NULL, NULL);

}

/**
* Initialize integration with BlueZ service.
*
* @return On success this function returns 0. Otherwise -1 is returned. */
int bluez_init(void) {

if (dbus_object_data_map == NULL)
dbus_object_data_map = g_hash_table_new_full(g_str_hash, g_str_equal,
NULL, (GDestroyNotify)bluez_dbus_object_data_unref);

bluez_subscribe_signals();
bluez_register();

return 0;
}

Expand Down
5 changes: 2 additions & 3 deletions src/bluez.h
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/*
* BlueALSA - bluez.h
* Copyright (c) 2016-2021 Arkadiusz Bokowy
* Copyright (c) 2016-2022 Arkadiusz Bokowy
*
* This file is a part of bluez-alsa.
*
Expand Down Expand Up @@ -33,8 +33,7 @@ enum bluez_a2dp_transport_state {
BLUEZ_A2DP_TRANSPORT_STATE_ACTIVE,
};

void bluez_register(void);
int bluez_subscribe_signals(void);
int bluez_init(void);

bool bluez_a2dp_set_configuration(
const char *dbus_current_sep_path,
Expand Down
11 changes: 3 additions & 8 deletions src/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -113,17 +113,12 @@ static void g_bus_name_acquired(GDBusConnection *conn, const char *name, void *u

bluealsa_dbus_register();

bluez_subscribe_signals();
bluez_register();

bluez_init();
#if ENABLE_OFONO
ofono_subscribe_signals();
ofono_register();
ofono_init();
#endif

#if ENABLE_UPOWER
upower_subscribe_signals();
upower_initialize();
upower_init();
#endif

}
Expand Down
10 changes: 5 additions & 5 deletions src/ofono.c
Original file line number Diff line number Diff line change
Expand Up @@ -465,9 +465,6 @@ int ofono_register(void) {

debug("Registering oFono audio agent: %s", dbus_agent_object_path);

if (ofono_card_data_map == NULL)
ofono_card_data_map = g_hash_table_new_full(g_str_hash, g_str_equal, g_free, g_free);

if (dbus_hf_agent == NULL) {
ofono_HFAudioAgentIfaceSkeleton *ifs_hf_agent;
if ((ifs_hf_agent = ofono_hf_audio_agent_iface_skeleton_new(&vtable, NULL, NULL)) == NULL)
Expand Down Expand Up @@ -599,14 +596,17 @@ static void ofono_disappeared(GDBusConnection *conn, const char *name,
}

/**
* Subscribe to oFono signals.
* Initialize integration with oFono service.
*
* @return On success this function returns 0. Otherwise -1 is returned. */
int ofono_subscribe_signals(void) {
int ofono_init(void) {

if (!config.profile.hfp_ofono)
return 0;

if (ofono_card_data_map == NULL)
ofono_card_data_map = g_hash_table_new_full(g_str_hash, g_str_equal, g_free, g_free);

g_dbus_connection_signal_subscribe(config.dbus, OFONO_SERVICE,
OFONO_IFACE_HF_AUDIO_MANAGER, "CardAdded", NULL, NULL,
G_DBUS_SIGNAL_FLAGS_NONE, ofono_signal_card_added, NULL, NULL);
Expand Down
6 changes: 3 additions & 3 deletions src/ofono.h
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/*
* BlueALSA - ofono.h
* Copyright (c) 2016-2019 Arkadiusz Bokowy
* Copyright (c) 2016-2022 Arkadiusz Bokowy
* 2018 Thierry Bultel
*
* This file is a part of bluez-alsa.
Expand All @@ -9,13 +9,13 @@
*
*/

#pragma once
#ifndef BLUEALSA_OFONO_H_
#define BLUEALSA_OFONO_H_

#include <stdbool.h>

int ofono_register(void);
int ofono_subscribe_signals(void);
int ofono_init(void);
bool ofono_detect_service(void);

#endif
57 changes: 28 additions & 29 deletions src/upower.c
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/*
* BlueALSA - upower.c
* Copyright (c) 2016-2021 Arkadiusz Bokowy
* Copyright (c) 2016-2022 Arkadiusz Bokowy
*
* This file is a part of bluez-alsa.
*
Expand Down Expand Up @@ -30,30 +30,6 @@
#include "utils.h"
#include "shared/log.h"

/**
* Get initial setup from UPower service.
*
* @return On success this function returns 0. Otherwise -1 is returned. */
int upower_initialize(void) {

GVariant *present = g_dbus_get_property(config.dbus, UPOWER_SERVICE,
UPOWER_PATH_DISPLAY_DEVICE, UPOWER_IFACE_DEVICE, "IsPresent", NULL);
GVariant *percentage = g_dbus_get_property(config.dbus, UPOWER_SERVICE,
UPOWER_PATH_DISPLAY_DEVICE, UPOWER_IFACE_DEVICE, "Percentage", NULL);

if (present != NULL) {
config.battery.available = g_variant_get_boolean(present);
g_variant_unref(present);
}

if (percentage != NULL) {
config.battery.level = lround(g_variant_get_double(percentage));
g_variant_unref(percentage);
}

return 0;
}

static void upower_signal_display_device_changed(GDBusConnection *conn, const char *sender,
const char *path, const char *interface_, const char *signal, GVariant *params,
void *userdata) {
Expand Down Expand Up @@ -121,14 +97,37 @@ static void upower_signal_display_device_changed(GDBusConnection *conn, const ch
}

/**
* Subscribe to UPower service signals.
*
* @return On success this function returns 0. Otherwise -1 is returned. */
int upower_subscribe_signals(void) {
* Subscribe to UPower service signals. */
static void upower_subscribe_signals(void) {

g_dbus_connection_signal_subscribe(config.dbus, UPOWER_SERVICE,
DBUS_IFACE_PROPERTIES, "PropertiesChanged", UPOWER_PATH_DISPLAY_DEVICE,
NULL, G_DBUS_SIGNAL_FLAGS_NONE, upower_signal_display_device_changed, NULL, NULL);

}

/**
* Initialize integration with UPower service.
*
* @return On success this function returns 0. Otherwise -1 is returned. */
int upower_init(void) {

upower_subscribe_signals();

GVariant *present = g_dbus_get_property(config.dbus, UPOWER_SERVICE,
UPOWER_PATH_DISPLAY_DEVICE, UPOWER_IFACE_DEVICE, "IsPresent", NULL);
GVariant *percentage = g_dbus_get_property(config.dbus, UPOWER_SERVICE,
UPOWER_PATH_DISPLAY_DEVICE, UPOWER_IFACE_DEVICE, "Percentage", NULL);

if (present != NULL) {
config.battery.available = g_variant_get_boolean(present);
g_variant_unref(present);
}

if (percentage != NULL) {
config.battery.level = lround(g_variant_get_double(percentage));
g_variant_unref(percentage);
}

return 0;
}
6 changes: 3 additions & 3 deletions src/upower.h
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
/*
* BlueALSA - upower.h
* Copyright (c) 2016-2019 Arkadiusz Bokowy
* Copyright (c) 2016-2021 Arkadiusz Bokowy
*
* This file is a part of bluez-alsa.
*
* This project is licensed under the terms of the MIT license.
*
*/

#pragma once
#ifndef BLUEALSA_UPOWER_H_
#define BLUEALSA_UPOWER_H_

Expand All @@ -17,7 +18,6 @@
#define UPOWER_IFACE_DEVICE UPOWER_SERVICE ".Device"
#define UPOWER_PATH_DISPLAY_DEVICE "/org/freedesktop/UPower/devices/DisplayDevice"

int upower_initialize(void);
int upower_subscribe_signals(void);
int upower_init(void);

#endif

0 comments on commit 6e4ff9e

Please sign in to comment.