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