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 /** Construct a new repository
41 mlt_repository
mlt_repository_init( const char *directory
)
44 if ( directory
== NULL
|| strcmp( directory
, "" ) == 0 )
47 // Construct the repository
48 mlt_repository
this = calloc( sizeof( struct mlt_repository_s
), 1 );
49 mlt_properties_init( &this->parent
, this );
50 this->consumers
= mlt_properties_new();
51 this->filters
= mlt_properties_new();
52 this->producers
= mlt_properties_new();
53 this->transitions
= mlt_properties_new();
55 // Get the directory list
56 mlt_properties dir
= mlt_properties_new();
57 int count
= mlt_properties_dir_list( dir
, directory
, NULL
, 0 );
61 for ( i
= 0; i
< count
; i
++ )
64 const char *object_name
= mlt_properties_get_value( dir
, i
);
66 // Very temporary hack to allow the quicktime plugins to work
67 // TODO: extend repository to allow this to be used on a case by case basis
68 if ( strstr( object_name
, "libmltkino" ) )
71 // Open the shared object
72 void *object
= dlopen( object_name
, flags
);
75 // Get the registration function
76 int ( *symbol_ptr
)( mlt_repository
) = dlsym( object
, "mlt_register" );
78 // Call the registration function
79 if ( symbol_ptr
!= NULL
)
83 // Register the object file for closure
84 mlt_properties_set_data( &this->parent
, object_name
, object
, 0, ( mlt_destructor
)dlclose
, NULL
);
96 static mlt_properties
new_service( void *symbol
)
98 mlt_properties properties
= mlt_properties_new();
99 mlt_properties_set_data( properties
, "symbol", symbol
, 0, NULL
, NULL
);
103 /** Register a service with the repository
104 Typically, this is invoked by a module within its mlt_register().
107 void mlt_repository_register( mlt_repository
this, mlt_service_type service_type
, const char *service
, void *symbol
)
109 // Add the entry point to the corresponding service list
110 switch ( service_type
)
113 mlt_properties_set_data( this->consumers
, service
, new_service( symbol
), 0, ( mlt_destructor
)mlt_properties_close
, NULL
);
116 mlt_properties_set_data( this->filters
, service
, new_service( symbol
), 0, ( mlt_destructor
)mlt_properties_close
, NULL
);
119 mlt_properties_set_data( this->producers
, service
, new_service( symbol
), 0, ( mlt_destructor
)mlt_properties_close
, NULL
);
121 case transition_type
:
122 mlt_properties_set_data( this->transitions
, service
, new_service( symbol
), 0, ( mlt_destructor
)mlt_properties_close
, NULL
);
129 static mlt_properties
get_service_properties( mlt_repository
this, mlt_service_type type
, const char *service
)
131 mlt_properties service_properties
= NULL
;
133 // Get the entry point from the corresponding service list
137 service_properties
= mlt_properties_get_data( this->consumers
, service
, NULL
);
140 service_properties
= mlt_properties_get_data( this->filters
, service
, NULL
);
143 service_properties
= mlt_properties_get_data( this->producers
, service
, NULL
);
145 case transition_type
:
146 service_properties
= mlt_properties_get_data( this->transitions
, service
, NULL
);
151 return service_properties
;
154 /** Construct a new instance of a service
157 void *mlt_repository_create( mlt_repository
this, mlt_profile profile
, mlt_service_type type
, const char *service
, void *input
)
159 mlt_properties properties
= get_service_properties( this, type
, service
);
160 if ( properties
!= NULL
)
162 void *( *symbol_ptr
)( mlt_profile
, mlt_service_type
, const char *, void * ) =
163 mlt_properties_get_data( properties
, "symbol", NULL
);
165 // Construct the service
166 return ( symbol_ptr
!= NULL
) ?
symbol_ptr( profile
, type
, service
, input
) : NULL
;
171 /** Destroy a repository
174 void mlt_repository_close( mlt_repository
this )
176 mlt_properties_close( this->consumers
);
177 mlt_properties_close( this->filters
);
178 mlt_properties_close( this->producers
);
179 mlt_properties_close( this->transitions
);
180 mlt_properties_close( &this->parent
);
184 /** Get the list of registered consumers
187 mlt_properties
mlt_repository_consumers( mlt_repository self
)
189 return self
->consumers
;
192 /** Get the list of registered filters
195 mlt_properties
mlt_repository_filters( mlt_repository self
)
197 return self
->filters
;
200 /** Get the list of registered producers
203 mlt_properties
mlt_repository_producers( mlt_repository self
)
205 return self
->producers
;
208 /** Get the list of registered transitions
211 mlt_properties
mlt_repository_transitions( mlt_repository self
)
213 return self
->transitions
;
216 /** Register the metadata for a service
217 IMPORTANT: mlt_repository will take responsibility for deallocating the metadata properties that you supply!
219 void mlt_repository_register_metadata( mlt_repository self
, mlt_service_type type
, const char *service
, mlt_properties metadata
)
221 mlt_properties service_properties
= get_service_properties( self
, type
, service
);
222 mlt_properties_set_data( service_properties
, "metadata", metadata
, 0, ( mlt_destructor
)mlt_properties_close
, NULL
);
225 /** Get the metadata about a service
228 mlt_properties
mlt_repository_metadata( mlt_repository self
, mlt_service_type type
, const char *service
)
230 mlt_properties properties
= get_service_properties( self
, type
, service
);
231 return mlt_properties_get_data( properties
, "metadata", NULL
);