Re: [PATCH BlueZ 4/9] mesh: Generalize mesh-config APIs

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Hi Inga,

On 07/09, Inga Stotland wrote:
> This changes argument for each mesh-config API to use void* as
> a pointer to a node configuration object. This makes usage of JSON
> opaque for the rest of the code and allows to plug in a non-JSON
> configuration storage implementation.
> ---
>  mesh/mesh-config-json.c | 228 +++++++++++++++++++++++-----------------
>  mesh/mesh-config.h      | 107 +++++++++----------
>  2 files changed, 180 insertions(+), 155 deletions(-)
> 
> diff --git a/mesh/mesh-config-json.c b/mesh/mesh-config-json.c
> index 8fcb8afe3..5ca086ad0 100644
> --- a/mesh/mesh-config-json.c
> +++ b/mesh/mesh-config-json.c
> @@ -252,10 +252,14 @@ static json_object *jarray_key_del(json_object *jarray, int16_t idx)
>  	return jarray_new;
>  }
>  
> -bool mesh_config_read_iv_index(json_object *jobj, uint32_t *idx, bool *update)
> +bool mesh_config_read_iv_index(void *cfg, uint32_t *idx, bool *update)

I'm not a fan of using void* for polymorphism. While there are places
this makes sense (e.g. user_data pointers in callbacks), I think we
should try to avoid this in our APIs.

Since the proposed patch assumes that we would switch backends during
the build, and you can't have two different config formats compiled in
at the same time, how about this:

mesh-config.h:
    union mesh_config;

    union mesh_config *mesh_config_create_config(void);
    void mesh_config_release_config(union mesh_config *config);

mesh-config-json.c:
    union mesh_config {
        json_object *json
    };

    union mesh_config *mesh_config_create_config(void)
    {
        return (union mesh_config*)json_object_new_object();
    }

    void mesh_config_release_config(union mesh_config *cfg)
    {
        json_object *jnode = (json_object *)cfg;

        if (!cfg)
            return;

        json_object_put(jnode);
    }

etc.

-- 
Michał Lowas-Rzechonek <michal.lowas-rzechonek@xxxxxxxxxxx>
Silvair http://silvair.com
Jasnogórska 44, 31-358 Krakow, POLAND



[Index of Archives]     [Bluez Devel]     [Linux Wireless Networking]     [Linux Wireless Personal Area Networking]     [Linux ATH6KL]     [Linux USB Devel]     [Linux Media Drivers]     [Linux Audio Users]     [Linux Kernel]     [Linux SCSI]     [Big List of Linux Books]

  Powered by Linux