Hi Claudio / Vinicius, On 02/19/2013 02:44 PM, Claudio Takahasi wrote: > From: Vinicius Costa Gomes > > This patch checks if the Handsfree Audio Manager already has an agent > registered for the same owner and object path. > --- > plugins/hfp_audio.c | 41 ++++++++++++++++++++++++++++++++++++++++- > 1 file changed, 40 insertions(+), 1 deletion(-) > > diff --git a/plugins/hfp_audio.c b/plugins/hfp_audio.c > index db21a5d..32ddebc 100644 > --- a/plugins/hfp_audio.c > +++ b/plugins/hfp_audio.c > @@ -25,6 +25,7 @@ > > #include > #include > +#include > > #include > > @@ -35,12 +36,34 @@ > > #define HFP_AUDIO_MANAGER_INTERFACE OFONO_SERVICE ".HandsfreeAudioManager" > > +struct agent { > + char *owner; > + char *path; > + unsigned char *codecs; > + int codecs_len; > +}; > + > /* Supported agents codecs */ > enum hfp_codec { > HFP_CODEC_CVSD = 0x01, > HFP_CODEC_MSBC = 0x02, > }; > > +static GSList *agents = NULL; > + > +static int agent_cmp(gconstpointer a, gconstpointer b) > +{ > + const struct agent *agent = a; > + const struct agent *match = b; > + int ret; > + > + ret = strcmp(agent->owner, match->owner); > + if (ret != 0) > + return ret; > + > + return strcmp(agent->path, match->path); > +} > + > static DBusMessage *am_get_cards(DBusConnection *conn, > DBusMessage *msg, void *user_data) > { > @@ -52,11 +75,14 @@ static DBusMessage *am_get_cards(DBusConnection *conn, > static DBusMessage *am_agent_register(DBusConnection *conn, > DBusMessage *msg, void *user_data) > { > - const char *path; > + struct agent match, *agent; > + const char *sender, *path; > unsigned char *codecs; > DBusMessageIter iter, array; > int length, i; > > + sender = dbus_message_get_sender(msg); > + > if (dbus_message_iter_init(msg,&iter) == FALSE) > goto invalid_args; > > @@ -75,6 +101,19 @@ static DBusMessage *am_agent_register(DBusConnection *conn, > goto invalid_args; > } > > + match.owner = (char *) sender; > + match.path = (char *) path; > + if (g_slist_find_custom(agents,&match, agent_cmp)) > + goto invalid_args; > + > + agent = g_new0(struct agent, 1); > + agent->owner = g_strdup(sender); > + agent->path = g_strdup(path); > + agent->codecs = g_memdup(codecs, length); > + agent->codecs_len = length; > + > + agents = g_slist_prepend(agents, agent); > + How do you plan on using multiple agents? Unless there is dire need, I suggest only allowing 1 agent to be registered at a time. > return dbus_message_new_method_return(msg); > > invalid_args: Regards, -Denis