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
);
91 else if ( strstr( object_name
, "libmlt" ) )
93 fprintf( stderr
, "%s:%s: failed to dlopen %s\n", __FILE__
, __FUNCTION__
, object_name
);
100 static mlt_properties
new_service( void *symbol
)
102 mlt_properties properties
= mlt_properties_new();
103 mlt_properties_set_data( properties
, "symbol", symbol
, 0, NULL
, NULL
);
107 /** Register a service with the repository
108 Typically, this is invoked by a module within its mlt_register().
111 void mlt_repository_register( mlt_repository
this, mlt_service_type service_type
, const char *service
, void *symbol
)
113 // Add the entry point to the corresponding service list
114 switch ( service_type
)
117 mlt_properties_set_data( this->consumers
, service
, new_service( symbol
), 0, ( mlt_destructor
)mlt_properties_close
, NULL
);
120 mlt_properties_set_data( this->filters
, service
, new_service( symbol
), 0, ( mlt_destructor
)mlt_properties_close
, NULL
);
123 mlt_properties_set_data( this->producers
, service
, new_service( symbol
), 0, ( mlt_destructor
)mlt_properties_close
, NULL
);
125 case transition_type
:
126 mlt_properties_set_data( this->transitions
, service
, new_service( symbol
), 0, ( mlt_destructor
)mlt_properties_close
, NULL
);
133 static mlt_properties
get_service_properties( mlt_repository
this, mlt_service_type type
, const char *service
)
135 mlt_properties service_properties
= NULL
;
137 // Get the entry point from the corresponding service list
141 service_properties
= mlt_properties_get_data( this->consumers
, service
, NULL
);
144 service_properties
= mlt_properties_get_data( this->filters
, service
, NULL
);
147 service_properties
= mlt_properties_get_data( this->producers
, service
, NULL
);
149 case transition_type
:
150 service_properties
= mlt_properties_get_data( this->transitions
, service
, NULL
);
155 return service_properties
;
158 /** Construct a new instance of a service
161 void *mlt_repository_create( mlt_repository
this, mlt_profile profile
, mlt_service_type type
, const char *service
, void *input
)
163 mlt_properties properties
= get_service_properties( this, type
, service
);
164 if ( properties
!= NULL
)
166 void *( *symbol_ptr
)( mlt_profile
, mlt_service_type
, const char *, void * ) =
167 mlt_properties_get_data( properties
, "symbol", NULL
);
169 // Construct the service
170 return ( symbol_ptr
!= NULL
) ?
symbol_ptr( profile
, type
, service
, input
) : NULL
;
175 /** Destroy a repository
178 void mlt_repository_close( mlt_repository
this )
180 mlt_properties_close( this->consumers
);
181 mlt_properties_close( this->filters
);
182 mlt_properties_close( this->producers
);
183 mlt_properties_close( this->transitions
);
184 mlt_properties_close( &this->parent
);
188 /** Get the list of registered consumers
191 mlt_properties
mlt_repository_consumers( mlt_repository self
)
193 return self
->consumers
;
196 /** Get the list of registered filters
199 mlt_properties
mlt_repository_filters( mlt_repository self
)
201 return self
->filters
;
204 /** Get the list of registered producers
207 mlt_properties
mlt_repository_producers( mlt_repository self
)
209 return self
->producers
;
212 /** Get the list of registered transitions
215 mlt_properties
mlt_repository_transitions( mlt_repository self
)
217 return self
->transitions
;
220 /** Register the metadata for a service
221 IMPORTANT: mlt_repository will take responsibility for deallocating the metadata properties that you supply!
223 void mlt_repository_register_metadata( mlt_repository self
, mlt_service_type type
, const char *service
, mlt_properties metadata
)
225 mlt_properties service_properties
= get_service_properties( self
, type
, service
);
226 mlt_properties_set_data( service_properties
, "metadata", metadata
, 0, ( mlt_destructor
)mlt_properties_close
, NULL
);
229 /** Get the metadata about a service
232 mlt_properties
mlt_repository_metadata( mlt_repository self
, mlt_service_type type
, const char *service
)
234 mlt_properties properties
= get_service_properties( self
, type
, service
);
235 return mlt_properties_get_data( properties
, "metadata", NULL
);