[vlc-devel] [PATCH] Sqlite Module for VLC, GSoC 09

Laurent Aimar fenrir at via.ecp.fr
Tue Sep 22 23:11:48 CEST 2009


Hi,

> diff --git a/include/vlc_sql.h b/include/vlc_sql.h
> new file mode 100644
> index 0000000..be1be75
> --- /dev/null
> +++ b/include/vlc_sql.h
> @@ -0,0 +1,247 @@
> +/*****************************************************************************
> + * vlc_sql.h: SQL abstraction layer
> + *****************************************************************************
> + * Copyright (C) 2009 the VideoLAN team
> + * $Id$
> + *
> + * Authors: Antoine Lejeune <phytos at videolan.org>
> + *          Jean-Philippe André <jpeg at videolan.org>
> + *          Srikanth Raju <srikiraju at gmail.com>
> + *
> + * This program is free software; you can redistribute it and/or modify
> + * it under the terms of the GNU General Public License as published by
> + * the Free Software Foundation; either version 2 of the License, or
> + * (at your option) any later version.
> + *
> + * This program is distributed in the hope that it will be useful,
> + * but WITHOUT ANY WARRANTY; without even the implied warranty of
> + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
> + * GNU General Public License for more details.
> + *
> + * You should have received a copy of the GNU General Public License
> + * along with this program; if not, write to the Free Software
> + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
> + *****************************************************************************/
> +
> +#if !defined( __LIBVLC__ )
> +# error You are not libvlc or one of its plugins. You cannot include this file
> +#endif
> +
> +#ifndef VLC_SQL_H
> +# define VLC_SQL_H
> +
> +# ifdef __cplusplus
> +extern "C" {
> +# endif
> +
> +
> +/*****************************************************************************
> + * General structure: SQL object.
> + *****************************************************************************/
> +
> +typedef struct sql_t sql_t;
> +typedef struct sql_sys_t sql_sys_t;
> +
> +typedef int ( *pf_query_callback_t ) ( void*, int, char**, char** );
 sql_query_callback_t would be better (it will not clash too easily).

> +VLC_EXPORT( sql_t*, sql_Create, ( vlc_object_t *p_this, char *psz_name,
> +            char* psz_host, int i_port, char* psz_user, char* psz_pass ) );
 I am sorry I have missed that the first time, but you should add "const" there
for all char* parameters.

> diff --git a/src/misc/sql.c b/src/misc/sql.c
> new file mode 100644
> index 0000000..9ea0fcb
> --- /dev/null
> +++ b/src/misc/sql.c
> @@ -0,0 +1,95 @@
> +/*****************************************************************************
> + * sql.c: SQL Connection: Creators and destructors
> + *****************************************************************************
> + * Copyright (C) 2008-2009 the VideoLAN team
> + * $Id$
> + *
> + * Authors: Srikanth Raju <srikiraju at gmail dot com>
> + *
> + * This program is free software; you can redistribute it and/or modify
> + * it under the terms of the GNU General Public License as published by
> + * the Free Software Foundation; either version 2 of the License, or
> + * (at your option) any later version.
> + *
> + * This program is distributed in the hope that it will be useful,
> + * but WITHOUT ANY WARRANTY; without even the implied warranty of
> + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
> + * GNU General Public License for more details.
> + *
> + * You should have received a copy of the GNU General Public License
> + * along with this program; if not, write to the Free Software
> + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
> + *****************************************************************************/
> +
> +#if !defined( __LIBVLC__ )
> +  #error You are not libvlc or one of its plugins. You cannot include this file
> +#endif
> +
> +#ifdef HAVE_CONFIG_H
> +#include "config.h"
> +#endif
> +
> +#include <vlc_common.h>
> +#include <vlc_sql.h>
> +#include <assert.h>
> +#include "libvlc.h"
> +
> +#undef sql_Create
> +/*
> + * @brief Create an instance of an SQL connection
> + * @param p_this Parent object
> + * @param psz_name Name which is passed to module_need (not needed)
> + * @return p_sql created and attached, module loaded
> + */
> +sql_t *sql_Create( vlc_object_t *p_this, char *psz_name, char* psz_host,
> +       int i_port, char* psz_user, char* psz_pass )
 Do not repeat the documentation (keept it either in the .h or the .c),
otherwise they will drift apart in time.

> +{
> +    sql_t *p_sql;
> +
> +    p_sql = ( sql_t * ) vlc_custom_create( p_this, sizeof( sql_t ),
> +                                           VLC_OBJECT_GENERIC, "sql" );
> +    if( !p_sql )
> +    {
> +        msg_Err( p_this, "unable to create sql object" );
> +        return NULL;
> +    }
> +    vlc_object_attach( p_sql, p_this );
> +
> +    p_sql->psz_host = strdup( psz_host );
> +    p_sql->psz_user = strdup( psz_user );
> +    p_sql->psz_pass = strdup( psz_pass );
> +    p_sql->i_port = i_port;
> +
> +    p_sql->p_module = module_need( p_sql, "sql", psz_name, false );
I think that
 module_need( p_sql, "sql", psz_name, psz_name && *psz_name );
is better. If you specify a module name, I don't think it is wise
to try everything in these case.

Otherwise, this first patch is fine by me.

Regards,

-- 
fenrir




More information about the vlc-devel mailing list