2 * MltMelted.cpp - MLT Melted Wrapper
3 * Copyright (C) 2004-2009 Charles Yates
4 * Author: Charles Yates <charles.yates@pandora.be>
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU Lesser General Public License as published
8 * by the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
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.
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.
21 #include "MltMelted.h"
22 #include "MltService.h"
23 #include "MltResponse.h"
28 static mvcp_response
mlt_melted_execute( void *arg
, char *command
)
30 Melted
*melted
= ( Melted
* )arg
;
33 Response
*response
= melted
->execute( command
);
34 mvcp_response real
= mvcp_response_clone( response
->get_response( ) );
40 mvcp_response response
= mvcp_response_init( );
41 mvcp_response_set_error( response
, 500, "Invalid server" );
46 static mvcp_response
mlt_melted_received( void *arg
, char *command
, char *doc
)
48 Melted
*melted
= ( Melted
* )arg
;
51 Response
*response
= melted
->received( command
, doc
);
52 if ( response
!= NULL
)
54 mvcp_response real
= mvcp_response_clone( response
->get_response( ) );
62 mvcp_response response
= mvcp_response_init( );
63 mvcp_response_set_error( response
, 500, "Invalid server" );
68 static mvcp_response
mlt_melted_push( void *arg
, char *command
, mlt_service service
)
70 Melted
*melted
= ( Melted
* )arg
;
73 Service
input( service
);
74 Response
*response
= melted
->push( command
, &input
);
75 mvcp_response real
= mvcp_response_clone( response
->get_response( ) );
81 mvcp_response response
= mvcp_response_init( );
82 mvcp_response_set_error( response
, 500, "Invalid server" );
87 Melted
::Melted( char *name
, int port
, char *config
) :
90 server
= melted_server_init( name
);
91 melted_server_set_port( server
, port
);
92 melted_server_set_config( server
, config
);
97 melted_server_close( server
);
100 mlt_properties Melted
::get_properties( )
102 return &server
->parent
;
105 bool Melted
::start( )
107 if ( melted_server_execute( server
) == 0 )
109 _real
= server
->parser
->real
;
110 _execute
= server
->parser
->execute
;
111 _received
= server
->parser
->received
;
112 _push
= server
->parser
->push
;
113 server
->parser
->real
= this;
114 server
->parser
->execute
= mlt_melted_execute
;
115 server
->parser
->received
= mlt_melted_received
;
116 server
->parser
->push
= mlt_melted_push
;
118 return server
->shutdown
== 0;
121 bool Melted
::is_running( )
123 return server
->shutdown
== 0;
126 Response
*Melted
::execute( char *command
)
128 return new Response( _execute( _real
, command
) );
131 Response
*Melted
::received( char *command
, char *doc
)
133 return new Response( _received( _real
, command
, doc
) );
136 Response
*Melted
::push( char *command
, Service
*service
)
138 return new Response( _push( _real
, command
, service
->get_service( ) ) );
141 void Melted
::wait_for_shutdown( )
143 struct timespec tm
= { 1, 0 };
144 while ( !server
->shutdown
)
145 nanosleep( &tm
, NULL
);
148 void Melted
::log_level( int threshold
)
150 melted_log_init( log_stderr
, threshold
);
153 Properties
*Melted
::unit( int index
)
155 mlt_properties properties
= melted_server_fetch_unit( server
, index
);
156 return properties
!= NULL ?
new Properties( properties
) : NULL
;