forked from indilib/indi
-
Notifications
You must be signed in to change notification settings - Fork 0
/
indidrivermain.c
114 lines (91 loc) · 2.93 KB
/
indidrivermain.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
#if 0
INDI
Copyright (C) 2003-2006 Elwood C. Downey
Updated by Jasem Mutlaq (2003-2010)
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2.1 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with this library; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
#endif
/* main() for one INDI driver process.
* Drivers define IS*() functions we call to deliver INDI XML arriving on stdin.
* Drivers call ID*() functions to send INDI XML commands to stdout.
* Drivers call IE*() functions to build an event-driver program.
* Drivers call IU*() functions to perform various common utility tasks.
* Troubles are reported on stderr then we exit.
*
* This requires liblilxml.
*/
#include "base64.h"
#include "eventloop.h"
#include "indicom.h"
#include "indidevapi.h"
#include "indidriver.h"
#include "lilxml.h"
#include <errno.h>
#include <stdarg.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <time.h>
#include <unistd.h>
#include <sys/types.h>
#include <sys/stat.h>
#define MAXRBUF 2048
ROSC *propCache;
int nPropCache; /* # of elements in roCheck */
int verbose; /* chatty */
char *me; /* a.out name */
LilXML *clixml; /* XML parser context */
static void usage(void);
int main(int ac, char *av[])
{
#ifndef _WIN32
int ret = setgid(getgid());
ret = setuid(getuid());
if (geteuid() != getuid())
exit(255);
#endif
/* save handy pointer to our base name */
for (me = av[0]; av[0][0]; av[0]++)
if (av[0][0] == '/')
me = &av[0][1];
/* crack args */
while (--ac && (*++av)[0] == '-')
while (*++(*av))
switch (*(*av))
{
case 'v': /* verbose */
verbose++;
break;
default:
usage();
}
/* ac remaining args starting at av[0] */
if (ac > 0)
usage();
/* init */
clixml = newLilXML();
addCallback(0, clientMsgCB, NULL);
/* service client */
eventLoop();
/* eh?? */
fprintf(stderr, "%s: inf loop ended\n", me);
return (1);
}
/* print usage message and exit (1) */
static void usage(void)
{
fprintf(stderr, "Usage: %s [options]\n", me);
fprintf(stderr, "Purpose: INDI Device driver framework.\n");
fprintf(stderr, "Options:\n");
fprintf(stderr, " -v : more verbose to stderr\n");
exit(1);
}