]> git.sesse.net Git - mlt/blob - src/framework/mlt_factory.c
Factory implementation
[mlt] / src / framework / mlt_factory.c
1 /*
2  * mlt_factory.c -- the factory method interfaces
3  * Copyright (C) 2003-2004 Ushodaya Enterprises Limited
4  * Author: Charles Yates <charles.yates@pandora.be>
5  *
6  * This program is free software; you can redistribute it and/or modify
7  * it under the terms of the GNU General Public License as published by
8  * the Free Software Foundation; either version 2 of the License, or
9  * (at your option) any later version.
10  *
11  * This program 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
14  * GNU General Public License for more details.
15  *
16  * You should have received a copy of the GNU General Public License
17  * along with this program; if not, write to the Free Software Foundation,
18  * Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
19  */
20
21 #include "config.h"
22 #include "mlt_factory.h"
23 #include "mlt_repository.h"
24 #include "mlt_properties.h"
25
26 #include <stdlib.h>
27
28 /** Singleton repositories
29 */
30
31 static mlt_properties object_list = NULL;
32 static mlt_repository producers = NULL;
33 static mlt_repository filters = NULL;
34 static mlt_repository transitions = NULL;
35 static mlt_repository consumers = NULL;
36
37 /** Construct the factories.
38 */
39
40 int mlt_factory_init( char *prefix )
41 {
42         // If no directory is specified, default to install directory
43         if ( prefix == NULL )
44                 prefix = PREFIX_DATA;
45
46         // Create the object list.
47         object_list = calloc( sizeof( struct mlt_properties_s ), 1 );
48         mlt_properties_init( object_list, NULL );
49
50         // Create a repository for each service type
51         producers = mlt_repository_init( object_list, prefix, "producers.dat", "mlt_create_producer" );
52         filters = mlt_repository_init( object_list, prefix, "filters.dat", "mlt_create_filter" );
53         transitions = mlt_repository_init( object_list, prefix, "transitions.dat", "mlt_create_transition" );
54         consumers = mlt_repository_init( object_list, prefix, "consumers.dat", "mlt_create_consumer" );
55
56         return 0;
57 }
58
59 /** Fetch a producer from the repository.
60 */
61
62 mlt_producer mlt_factory_producer( char *service, void *input )
63 {
64         return ( mlt_producer )mlt_repository_fetch( producers, service, input );
65 }
66
67 /** Fetch a filter from the repository.
68 */
69
70 mlt_filter mlt_factory_filter( char *service, void *input )
71 {
72         return ( mlt_filter )mlt_repository_fetch( filters, service, input );
73 }
74
75 /** Fetch a transition from the repository.
76 */
77
78 mlt_transition mlt_factory_transition( char *service, void *input )
79 {
80         return ( mlt_transition )mlt_repository_fetch( transitions, service, input );
81 }
82
83 /** Fetch a consumer from the repository
84 */
85
86 mlt_consumer mlt_factory_consumer( char *service, void *input )
87 {
88         return ( mlt_consumer )mlt_repository_fetch( consumers, service, input );
89 }
90
91 /** Close the factory.
92 */
93
94 void mlt_factory_close( )
95 {
96         mlt_repository_close( producers );
97         mlt_repository_close( filters );
98         mlt_repository_close( transitions );
99         mlt_repository_close( consumers );
100         mlt_properties_close( object_list );
101         free( object_list );
102 }
103