]> git.sesse.net Git - mlt/blob - mlt/src/miracle/miracle.c
47a645ab958048aa3a6440996fc3064b3609be55
[mlt] / mlt / src / miracle / miracle.c
1 /*
2  * dv1394d.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 #ifdef HAVE_CONFIG_H
25 #include <config.h>
26 #endif
27
28 /* System header files */
29 #include <stdio.h>
30 #include <stdlib.h>
31 #include <string.h>
32 #include <sys/types.h>
33 #include <unistd.h>
34 #include <time.h>
35
36 /* Application header files */
37 #include "dvserver.h"
38 #include "log.h"
39
40 /** Our dv server.
41 */
42
43 static dv_server server = NULL;
44
45 /** atexit shutdown handler for the server.
46 */
47
48 static void main_cleanup( )
49 {
50         dv_server_shutdown( server );
51 }
52
53 /** Report usage and exit.
54 */
55
56 void usage( char *app )
57 {
58         fprintf( stderr, "Usage: %s [-test] [-port NNNN]\n", app );
59         exit( 0 );
60 }
61
62 /** The main function.
63 */
64
65 int main( int argc, char **argv )
66 {
67         int error = 0;
68         int index = 0;
69         int background = 1;
70         struct timespec tm = { 5, 0 };
71
72         server = dv_server_init( argv[ 0 ] );
73
74         for ( index = 1; index < argc; index ++ )
75         {
76                 if ( !strcmp( argv[ index ], "-port" ) )
77                         dv_server_set_port( server, atoi( argv[ ++ index ] ) );
78                 else if ( !strcmp( argv[ index ], "-proxy" ) )
79                         dv_server_set_proxy( server, argv[ ++ index ] );
80                 else if ( !strcmp( argv[ index ], "-test" ) )
81                         background = 0;
82                 else
83                         usage( argv[ 0 ] );
84         }
85
86         /* Optionally detatch ourselves from the controlling tty */
87
88         if ( background )
89         {
90                 if ( fork() )
91                         return 0;
92                 setsid();
93                 dv1394d_log_init( log_syslog, LOG_INFO );
94         }
95         else
96         {
97                 dv1394d_log_init( log_stderr, LOG_INFO );
98         }
99
100         atexit( main_cleanup );
101
102         /* Execute the server */
103         error = dv_server_execute( server );
104
105         /* We need to wait until we're exited.. */
106         while ( !server->shutdown )
107                 nanosleep( &tm, NULL );
108
109         return error;
110 }