2 * MltMiracle.cpp - MLT Wrapper
3 * Copyright (C) 2004-2005 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 "MltMiracle.h"
22 #include "MltService.h"
27 static valerie_response
mlt_miracle_execute( void *arg
, char *command
)
29 Miracle
*miracle
= ( Miracle
* )arg
;
30 if ( miracle
!= NULL
)
32 return miracle
->execute( command
);
36 valerie_response response
= valerie_response_init( );
37 valerie_response_set_error( response
, 500, "Invalid server" );
42 static valerie_response
mlt_miracle_push( void *arg
, char *command
, mlt_service service
)
44 Miracle
*miracle
= ( Miracle
* )arg
;
45 if ( miracle
!= NULL
)
47 Service
input( service
);
48 return miracle
->push( command
, &input
);
52 valerie_response response
= valerie_response_init( );
53 valerie_response_set_error( response
, 500, "Invalid server" );
58 Miracle
::Miracle( char *name
, int port
, char *config
)
60 server
= miracle_server_init( name
);
61 miracle_server_set_port( server
, port
);
62 miracle_server_set_config( server
, config
);
67 miracle_server_shutdown( server
);
70 bool Miracle
::start( )
72 miracle_server_execute( server
);
73 _real
= server
->parser
->real
;
74 _execute
= server
->parser
->execute
;
75 _push
= server
->parser
->push
;
76 server
->parser
->real
= this;
77 server
->parser
->execute
= mlt_miracle_execute
;
78 server
->parser
->push
= mlt_miracle_push
;
79 return server
->shutdown
== 0;
82 bool Miracle
::is_running( )
84 return server
->shutdown
== 0;
87 valerie_response Miracle
::execute( char *command
)
89 return _execute( _real
, command
);
92 valerie_response Miracle
::push( char *command
, Service
*service
)
94 return _push( _real
, command
, service
->get_service( ) );
97 void Miracle
::wait_for_shutdown( )
99 struct timespec tm
= { 1, 0 };
100 while ( !server
->shutdown
)
101 nanosleep( &tm
, NULL
);