This commit was manufactured by cvs2svn to create branch 'uc'.
[gnokii.git] / gnokiid / gnokiid.c
1 /*
2
3   G N O K I I
4
5   A Linux/Unix toolset and driver for Nokia mobile phones.
6
7   Released under the terms of the GNU GPL, see file COPYING for more details.
8
9   Mainline code for gnokiid daemon. Handles command line parsing and
10   various daemon functions.
11
12 */
13
14 #include <stdio.h>
15 #include <stdlib.h>
16 #include <unistd.h>
17 #include <termios.h>
18 #include <fcntl.h>
19 #include <signal.h>
20 #include <sys/types.h>
21 #include <sys/time.h>
22 #include <string.h>
23
24 #include "misc.h"
25 #include "files/cfgreader.h"
26 #include "gsm-common.h"
27 #include "gsm-api.h"
28 #include "data/virtmodem.h"
29
30 /* Global variables */
31 bool            DebugMode;      /* When true, run in debug mode */
32 char            *Model;         /* Model from .gnokiirc file. */
33 char            *Port;          /* Port from .gnokiirc file */
34 char            *Initlength;    /* Init length from .gnokiirc file */
35 char            *Connection;    /* Connection type from .gnokiirc file */
36 char            *SynchronizeTime;
37 char            *BinDir;        /* Directory of the mgnokiidev command */
38
39 bool  TerminateThread;
40
41 void version(void)
42 {
43
44   fprintf(stdout, _("gnokiid Version %s\n"
45 "Copyright (C) Hugh Blemings <hugh@linuxcare.com>, 1999\n"
46 "Copyright (C) Pavel Janík ml. <Pavel.Janik@linux.cz>, 1999\n"
47 "Built %s %s for %s on %s \n"), VERSION, __TIME__, __DATE__, Model, Port);
48 }
49
50 /* The function usage is only informative - it prints this program's usage and
51    command-line options.*/
52
53 void usage(void)
54 {
55
56   fprintf(stdout, _("   usage: gnokiid {--help|--version}\n"
57 "          --help            display usage information."
58 "          --version         displays version and copyright information."
59 "          --debug           uses stdin/stdout for virtual modem comms.\n"));
60 }
61
62 /* Main function - handles command line arguments, passes them to separate
63    functions accordingly. */
64
65 int main(int argc, char *argv[])
66 {
67
68     GSM_ConnectionType connection;
69
70                 /* For GNU gettext */
71
72         #ifdef USE_NLS
73                 textdomain("gnokii");
74         #endif
75
76 #ifndef WIN32
77         if (strcmp(GetMygnokiiVersion(),VERSION)!=0)
78           fprintf(stderr,_("WARNING: version of installed libmygnokii.so (%s) is different to version of gnokiid (%s)\n"),GetMygnokiiVersion(),VERSION);
79 #endif
80
81         if (CFG_ReadConfig(&Model, &Port, &Initlength, &Connection, &BinDir, &SynchronizeTime,true) < 0) {
82                 exit(-1);
83         }
84
85                 /* Handle command line arguments. */
86
87         if (argc >= 2 && strcmp(argv[1], "--help") == 0) {
88                 usage();
89         exit(0);
90         }
91
92                 /* Display version, copyright and build information. */
93
94         if (argc >= 2 && strcmp(argv[1], "--version") == 0) {
95         version();
96             exit(0);
97         }
98
99         if (argc >= 2 && strcmp(argv[1], "--debug") == 0) {
100                 DebugMode = true;       
101         }
102         else {
103                 DebugMode = false;      
104         }
105
106         connection=GetConnectionTypeFromString(Connection);
107         
108         /* MBUS wasn't tested */
109         if (connection!=GCT_FBUS && connection!=GCT_MBUS &&
110             connection!=GCT_Infrared && connection!=GCT_Tekram) {
111           fprintf(stdout,_("Incorrect connection type!\n"));    
112           exit(0);
113         }
114         
115         TerminateThread=false;
116
117         if (VM_Initialise(Model, Port, Initlength, connection, BinDir, DebugMode, true, SynchronizeTime) == false) 
118           exit (-1);
119
120         while (1) {
121           if (TerminateThread==true) {
122             VM_Terminate();
123             exit(1);
124           }
125           sleep (1);
126         }
127         exit (0);
128 }