[PATCH v2 6/8] agent: Add multi agent support

Patrik Flykt patrik.flykt at linux.intel.com
Mon Sep 9 03:14:52 PDT 2013


	Hi,

On Fri, 2013-09-06 at 14:12 +0300, Jukka Rissanen wrote:
> -void connman_agent_cancel(void *user_context)
> +static void set_default_agent(struct connman_agent *agent)
>  {
> -       GList *item, *next;
> -       struct connman_agent_request *queued_req;
> -       int err;
> +       if (default_agent == agent)
> +               return;
> +
> +       if (agent)
> +               DBG("default agent set to %s %s", agent->owner,
> agent->path);
> +       else
> +               DBG("default agent cleared");
>  
> -       DBG("context %p", user_context);
> +       default_agent = agent;
> +}
>  
> -       item = agent_queue;
> +static struct connman_agent *elect_default_agent(void)
> +{
> +       GHashTableIter iter;
> +       gpointer key, value;
> +       struct connman_agent *agent = NULL;
>  
> -       while (item) {
> -               next = g_list_next(item);
> -               queued_req = item->data;
> +       g_hash_table_iter_init(&iter, agent_hash);
> +       while (g_hash_table_iter_next(&iter, &key, &value)) {
> +               agent = value;
>  
> -               if (queued_req->user_context == user_context ||
> -                                                       !user_context)
> {
> -                       agent_data_free(queued_req);
> -                       agent_queue = g_list_delete_link(agent_queue,
> item);
> -               }
> +               if (default_agent != agent)
> +                       break;
>  
> -               item = next;
> +               agent = NULL;
>         }
>  
> -       if (!agent_request)
> -               return;
> +       return agent;
> +}
>  
> -       if (agent_request->user_context != user_context &&
> -                                               user_context)
> -               return; 

The functionality of elect_default_agent() can be embedded into
set_default_agent(). This since calling elect_default_agent() is done in
agent_unref_debug() after the struct connman_agent is removed from
agent_hash. This means it does not exist in the hash anymore and a new
one can be selected. The test if (agent == default_agent) should be
performed when unreffing the agent. set_default_agent() does not need
any arguments either, as there only is the hash to look at.

Cheers, 

	Patrik




More information about the connman mailing list