-/*
- * repository.c -- provides a map between service and shared objects
- * Copyright (C) 2003-2004 Ushodaya Enterprises Limited
- * Author: Charles Yates <charles.yates@pandora.be>
- * Contributor: Dan Dennedy <dan@dennedy.org>
+/**
+ * \file mlt_repository.c
+ * \brief provides a map between service and shared objects
+ *
+ * Copyright (C) 2003-2008 Ushodaya Enterprises Limited
+ * \author Charles Yates <charles.yates@pandora.be>
+ * Dan Dennedy <dan@dennedy.org>
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
#include "mlt_repository.h"
#include "mlt_properties.h"
#include "mlt_tokeniser.h"
+#include "mlt_log.h"
#include <stdio.h>
#include <stdlib.h>
#include <dlfcn.h>
#include <string.h>
+/** \brief Repository class
+ *
+ * \extends mlt_properties_s
+ */
+
struct mlt_repository_s
{
struct mlt_properties_s parent; // a list of object files
// Safety check
if ( directory == NULL || strcmp( directory, "" ) == 0 )
return NULL;
-
+
// Construct the repository
mlt_repository this = calloc( sizeof( struct mlt_repository_s ), 1 );
mlt_properties_init( &this->parent, this );
mlt_properties dir = mlt_properties_new();
int count = mlt_properties_dir_list( dir, directory, NULL, 0 );
int i;
-
+
// Iterate over files
for ( i = 0; i < count; i++ )
{
flags |= RTLD_GLOBAL;
// Open the shared object
- void *object = dlopen( object_name, flags );
+ void *object = dlopen( object_name, flags );
if ( object != NULL )
{
// Get the registration function
mlt_repository_callback symbol_ptr = dlsym( object, "mlt_register" );
-
+
// Call the registration function
if ( symbol_ptr != NULL )
{
symbol_ptr( this );
-
+
// Register the object file for closure
mlt_properties_set_data( &this->parent, object_name, object, 0, ( mlt_destructor )dlclose, NULL );
}
}
else if ( strstr( object_name, "libmlt" ) )
{
- fprintf( stderr, "%s, %s: failed to dlopen %s\n", __FILE__, __FUNCTION__, object_name );
+ mlt_log( NULL, MLT_LOG_WARNING, "%s: failed to dlopen %s\n (%s)\n", __FUNCTION__, object_name, dlerror() );
}
}
-
+
+ mlt_properties_close( dir );
+
return this;
}
if ( properties != NULL )
{
mlt_register_callback symbol_ptr = mlt_properties_get_data( properties, "symbol", NULL );
-
+
// Construct the service
return ( symbol_ptr != NULL ) ? symbol_ptr( profile, type, service, input ) : NULL;
}
{
mlt_properties metadata = NULL;
mlt_properties properties = get_service_properties( self, type, service );
-
+
// If this is a valid service
if ( properties )
{
{
// Fetch the callback data arg
void *data = mlt_properties_get_data( properties, "metadata_cb_data", NULL );
-
+
// Fetch the metadata through the callback
metadata = callback( type, service, data );
-
+
// Cache the metadata
if ( metadata )
// Include dellocation and serialisation
}
/** Return a list of user-preferred language codes taken from environment variables.
-*/
+*/
mlt_properties mlt_repository_languages( mlt_repository self )
{
mlt_properties languages = mlt_properties_get_data( &self->parent, "languages", NULL );
if ( languages )
return languages;
-
- const char *locale = getenv_locale();
+
languages = mlt_properties_new();
+ char *locale = getenv_locale();
if ( locale )
{
+ locale = strdup( locale );
mlt_tokeniser tokeniser = mlt_tokeniser_init();
int count = mlt_tokeniser_parse_new( tokeniser, locale, ":" );
if ( count )
{
mlt_properties_set( languages, "0", "en" );
}
+ free( locale );
mlt_tokeniser_close( tokeniser );
}
else