]> git.sesse.net Git - mlt/blob - src/miracle/miracle.c
ce0c45221c9262a62f14d5539aeba4bb0db77587
[mlt] / src / miracle / miracle.c
1 /*
2  * miracle.c -- A DV over IEEE 1394 TCP Server
3  *
4  * Copyright (C) 2002-2003 Ushodaya Enterprises Limited
5  * Authors:
6  *     Dan Dennedy <dan@dennedy.org>
7  *     Charles Yates <charles.yates@pandora.be>
8  *
9  * This program is free software; you can redistribute it and/or modify
10  * it under the terms of the GNU General Public License as published by
11  * the Free Software Foundation; either version 2 of the License, or
12  * (at your option) any later version.
13  *
14  * This program is distributed in the hope that it will be useful,
15  * but WITHOUT ANY WARRANTY; without even the implied warranty of
16  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
17  * GNU General Public License for more details.
18  *
19  * You should have received a copy of the GNU General Public License
20  * along with this program; if not, write to the Free Software Foundation,
21  * Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
22  */
23
24 /* System header files */
25 #include <stdio.h>
26 #include <stdlib.h>
27 #include <string.h>
28 #include <sys/types.h>
29 #include <unistd.h>
30 #include <time.h>
31 #include <sched.h>
32
33 #include <framework/mlt.h>
34
35 /* Application header files */
36 #include "miracle_server.h"
37 #include "miracle_log.h"
38
39 /** Our dv server.
40 */
41
42 static miracle_server server = NULL;
43
44 /** atexit shutdown handler for the server.
45 */
46
47 static void main_cleanup( )
48 {
49         miracle_server_close( server );
50 }
51
52 /** Report usage and exit.
53 */
54
55 void usage( char *app )
56 {
57         fprintf( stderr, "Usage: %s [-test] [-port NNNN]\n", app );
58         exit( 0 );
59 }
60
61 /** The main function.
62 */
63
64 int main( int argc, char **argv )
65 {
66         int error = 0;
67         int index = 0;
68         int background = 1;
69         struct timespec tm = { 5, 0 };
70         struct sched_param scp;
71
72         // Use realtime scheduling if possible
73         memset( &scp, '\0', sizeof( scp ) );
74         scp.sched_priority = sched_get_priority_max( SCHED_FIFO ) - 1;
75 #ifndef __DARWIN__
76         sched_setscheduler( 0, SCHED_FIFO, &scp );
77 #endif
78
79         mlt_factory_init( NULL );
80
81         server = miracle_server_init( argv[ 0 ] );
82
83         for ( index = 1; index < argc; index ++ )
84         {
85                 if ( !strcmp( argv[ index ], "-port" ) )
86                         miracle_server_set_port( server, atoi( argv[ ++ index ] ) );
87                 else if ( !strcmp( argv[ index ], "-proxy" ) )
88                         miracle_server_set_proxy( server, argv[ ++ index ] );
89                 else if ( !strcmp( argv[ index ], "-test" ) )
90                         background = 0;
91                 else
92                         usage( argv[ 0 ] );
93         }
94
95         /* Optionally detatch ourselves from the controlling tty */
96
97         if ( background )
98         {
99                 if ( fork() )
100                         return 0;
101                 setsid();
102                 miracle_log_init( log_syslog, LOG_INFO );
103         }
104         else
105         {
106                 miracle_log_init( log_stderr, LOG_DEBUG );
107         }
108
109         atexit( main_cleanup );
110
111         /* Set the config script */
112         miracle_server_set_config( server, "/etc/miracle.conf" );
113
114         /* Execute the server */
115         error = miracle_server_execute( server );
116
117         /* We need to wait until we're exited.. */
118         while ( !server->shutdown )
119                 nanosleep( &tm, NULL );
120
121         return error;
122 }