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 *directory
)
41 if ( directory
== NULL
|| strcmp( directory
, "" ) == 0 )
44 // Construct the repository
45 mlt_repository
this = calloc( sizeof( struct mlt_repository_s
), 1 );
46 mlt_properties_init( &this->parent
, this );
47 this->consumers
= mlt_properties_new();
48 this->filters
= mlt_properties_new();
49 this->producers
= mlt_properties_new();
50 this->transitions
= mlt_properties_new();
52 // Get the directory list
53 mlt_properties dir
= mlt_properties_new();
54 int count
= mlt_properties_dir_list( dir
, directory
, NULL
, 0 );
58 for ( i
= 0; i
< count
; i
++ )
61 const char *object_name
= mlt_properties_get_value( dir
, i
);
63 // Very temporary hack to allow the quicktime plugins to work
64 // TODO: extend repository to allow this to be used on a case by case basis
65 if ( strstr( object_name
, "libmltkino" ) )
68 // Open the shared object
69 void *object
= dlopen( object_name
, flags
);
72 // Get the registration function
73 int ( *symbol_ptr
)( mlt_repository
) = dlsym( object
, "mlt_register" );
75 // Call the registration function
76 if ( symbol_ptr
!= NULL
)
80 // Register the object file for closure
81 mlt_properties_set_data( &this->parent
, object_name
, object
, 0, ( mlt_destructor
)dlclose
, NULL
);
93 void mlt_repository_register( mlt_repository
this, mlt_service_type service_type
, const char *service
, void *symbol
)
95 // Add the entry point to the corresponding service list
96 switch ( service_type
)
99 mlt_properties_set_data( this->consumers
, service
, symbol
, 0, NULL
, NULL
);
102 mlt_properties_set_data( this->filters
, service
, symbol
, 0, NULL
, NULL
);
105 mlt_properties_set_data( this->producers
, service
, symbol
, 0, NULL
, NULL
);
107 case transition_type
:
108 mlt_properties_set_data( this->transitions
, service
, symbol
, 0, NULL
, NULL
);
115 void *mlt_repository_create( mlt_repository
this, mlt_profile profile
, mlt_service_type type
, const char *service
, void *input
)
117 void *( *symbol_ptr
)( mlt_profile
, mlt_service_type
, const char *, void * ) = NULL
;
119 // Get the entry point from the corresponding service list
123 symbol_ptr
= mlt_properties_get_data( this->consumers
, service
, NULL
);
126 symbol_ptr
= mlt_properties_get_data( this->filters
, service
, NULL
);
129 symbol_ptr
= mlt_properties_get_data( this->producers
, service
, NULL
);
131 case transition_type
:
132 symbol_ptr
= mlt_properties_get_data( this->transitions
, service
, NULL
);
138 // Construct the service
139 return ( symbol_ptr
!= NULL
) ?
symbol_ptr( profile
, type
, service
, input
) : NULL
;
142 void mlt_repository_close( mlt_repository
this )
144 mlt_properties_close( this->consumers
);
145 mlt_properties_close( this->filters
);
146 mlt_properties_close( this->producers
);
147 mlt_properties_close( this->transitions
);
148 mlt_properties_close( &this->parent
);