diff options
author | Denis Kenzior <denkenz@gmail.com> | 2013-02-21 08:27:55 -0600 |
---|---|---|
committer | Denis Kenzior <denkenz@gmail.com> | 2013-02-21 08:27:55 -0600 |
commit | 951e03dfeadf4d4594c886c17792b7d47034d4de (patch) | |
tree | b4a0eb6f4007bc052fedf6dae462b23f25031660 /src/handsfree-audio.c | |
parent | 3e16bc5e88bd8d5ca45b60ceba2037e2dfcb456a (diff) | |
download | ofono-951e03dfeadf4d4594c886c17792b7d47034d4de.tar.bz2 |
handsfree-audio: Add ref / unref support
Diffstat (limited to 'src/handsfree-audio.c')
-rw-r--r-- | src/handsfree-audio.c | 46 |
1 files changed, 39 insertions, 7 deletions
diff --git a/src/handsfree-audio.c b/src/handsfree-audio.c index dd398549..4e2cf936 100644 --- a/src/handsfree-audio.c +++ b/src/handsfree-audio.c @@ -29,6 +29,8 @@ #include <gdbus.h> +#include <ofono/handsfree-audio.h> + #include "ofono.h" #define HFP_AUDIO_MANAGER_INTERFACE OFONO_SERVICE ".HandsfreeAudioManager" @@ -49,6 +51,7 @@ struct agent { }; static struct agent *agent = NULL; +static int ref_count = 0; static void agent_free(struct agent *agent) { @@ -168,19 +171,31 @@ static const GDBusMethodTable am_methods[] = { { } }; -int __ofono_handsfree_audio_manager_init(void) +void ofono_handsfree_audio_ref(void) { + ref_count += 1; + + if (ref_count != 1) + return; + if (!g_dbus_register_interface(ofono_dbus_get_connection(), "/", HFP_AUDIO_MANAGER_INTERFACE, - am_methods, NULL, NULL, NULL, NULL)) { - return -EIO; - } - - return 0; + am_methods, NULL, NULL, NULL, NULL)) + ofono_error("Unable to register Handsfree Audio Manager"); } -void __ofono_handsfree_audio_manager_cleanup(void) +void ofono_handsfree_audio_unref(void) { + if (ref_count == 0) { + ofono_error("Error in handsfree audio manager ref counting"); + return; + } + + ref_count -= 1; + + if (ref_count > 0) + return; + g_dbus_unregister_interface(ofono_dbus_get_connection(), "/", HFP_AUDIO_MANAGER_INTERFACE); @@ -189,3 +204,20 @@ void __ofono_handsfree_audio_manager_cleanup(void) agent_free(agent); } } + +int __ofono_handsfree_audio_manager_init(void) +{ + return 0; +} + +void __ofono_handsfree_audio_manager_cleanup(void) +{ + if (ref_count == 0) + return; + + ofono_error("Handsfree Audio manager not cleaned up properly," + "fixing..."); + + ref_count = 1; + ofono_handsfree_audio_unref(); +} |