2 * repository.c -- provides a map between service and shared objects
3 * Copyright (C) 2003-2004 Ushodaya Enterprises Limited
4 * Author: Charles Yates <charles.yates@pandora.be>
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 2.1 of the License, or (at your option) any later version.
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with this library; if not, write to the Free Software
18 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
21 #include "mlt_repository.h"
22 #include "mlt_properties.h"
29 struct mlt_repository_s
31 struct mlt_properties_s parent; // a list of object files
32 mlt_properties consumers; // lists of entry points
33 mlt_properties filters;
34 mlt_properties producers;
35 mlt_properties transitions;
38 mlt_repository mlt_repository_init( const char *prefix )
40 // Construct the repository
41 mlt_repository this = calloc( sizeof( struct mlt_repository_s ), 1 );
42 mlt_properties_init( &this->parent, this );
43 this->consumers = mlt_properties_new();
44 this->filters = mlt_properties_new();
45 this->producers = mlt_properties_new();
46 this->transitions = mlt_properties_new();
48 // Get the directory list
49 mlt_properties dir = mlt_properties_new();
50 int count = mlt_properties_dir_list( dir, prefix, NULL, 0 );
54 for ( i = 0; i < count; i++ )
57 const char *object_name = mlt_properties_get_value( dir, i);
59 // Very temporary hack to allow the quicktime plugins to work
60 // TODO: extend repository to allow this to be used on a case by case basis
61 if ( strstr( object_name, "libmltkino" ) )
64 // Open the shared object
65 void *object = dlopen( object_name, flags );
68 // Get the registration function
69 int ( *symbol_ptr )( mlt_repository ) = dlsym( object, "mlt_register" );
71 // Call the registration function
72 if ( symbol_ptr != NULL )
76 // Register the object file for closure
77 mlt_properties_set_data( &this->parent, object_name, object, 0, ( mlt_destructor )dlclose, NULL );
89 void mlt_repository_register( mlt_repository this, mlt_service_type service_type, const char *service, void *symbol )
91 // Add the entry point to the corresponding service list
92 switch ( service_type )
95 mlt_properties_set_data( this->consumers, service, symbol, 0, NULL, NULL );
98 mlt_properties_set_data( this->filters, service, symbol, 0, NULL, NULL );
101 mlt_properties_set_data( this->producers, service, symbol, 0, NULL, NULL );
103 case transition_type:
104 mlt_properties_set_data( this->transitions, service, symbol, 0, NULL, NULL );
111 void *mlt_repository_fetch( mlt_repository this, mlt_profile profile, mlt_service_type type, const char *service, void *input )
113 void *( *symbol_ptr )( mlt_profile, mlt_service_type, const char *, void * ) = NULL;
115 // Get the entry point from the corresponding service list
119 symbol_ptr = mlt_properties_get_data( this->consumers, service, NULL );
122 symbol_ptr = mlt_properties_get_data( this->filters, service, NULL );
125 symbol_ptr = mlt_properties_get_data( this->producers, service, NULL );
127 case transition_type:
128 symbol_ptr = mlt_properties_get_data( this->transitions, service, NULL );
134 // Construct the service
135 return ( symbol_ptr != NULL ) ? symbol_ptr( profile, type, service, input ) : NULL;
138 void mlt_repository_close( mlt_repository this )
140 mlt_properties_close( this->consumers );
141 mlt_properties_close( this->filters );
142 mlt_properties_close( this->producers );
143 mlt_properties_close( this->transitions );
144 mlt_properties_close( &this->parent );