author | Michael Krelin <hacker@klever.net> | 2009-03-08 20:09:21 (UTC) |
---|---|---|
committer | Michael Krelin <hacker@klever.net> | 2009-03-08 20:09:21 (UTC) |
commit | aadaa8b5d7eda23e72dbded9d6437b40358353f3 (patch) (unidiff) | |
tree | 0bff6fdde1e2b9be02b48aaf7d03f095604718e1 /src/iiid.cc | |
download | iii-aadaa8b5d7eda23e72dbded9d6437b40358353f3.zip iii-aadaa8b5d7eda23e72dbded9d6437b40358353f3.tar.gz iii-aadaa8b5d7eda23e72dbded9d6437b40358353f3.tar.bz2 |
Inital commit to public repository0.0
-rw-r--r-- | src/iiid.cc | 86 |
1 files changed, 86 insertions, 0 deletions
diff --git a/src/iiid.cc b/src/iiid.cc new file mode 100644 index 0000000..6c23790 --- a/dev/null +++ b/src/iiid.cc | |||
@@ -0,0 +1,86 @@ | |||
1 | #include <syslog.h> | ||
2 | #include <getopt.h> | ||
3 | #include <iostream> | ||
4 | #include <cassert> | ||
5 | #include <stdexcept> | ||
6 | #include "eyetil.h" | ||
7 | #include "eyefiworker.h" | ||
8 | |||
9 | #include "config.h" | ||
10 | |||
11 | #include "eyefi.nsmap" | ||
12 | |||
13 | #define PHEADER \ | ||
14 | PACKAGE " Version " VERSION "\n" \ | ||
15 | "Copyright (c) 2009 Klever Group" | ||
16 | |||
17 | int main(int argc,char **argv) try { | ||
18 | |||
19 | int port = 59278; | ||
20 | |||
21 | while(true) { | ||
22 | static struct option opts[] = { | ||
23 | { "help", no_argument, 0, 'h' }, | ||
24 | { "usage", no_argument, 0, 'h' }, | ||
25 | { "version", no_argument, 0, 'V' }, | ||
26 | { "license", no_argument, 0, 'L' }, | ||
27 | { "port", required_argument, 0, 'p' }, | ||
28 | { NULL, 0, 0, 0 } | ||
29 | }; | ||
30 | int c = getopt_long(argc,argv,"hVLp:",opts,NULL); | ||
31 | if(c==-1) break; | ||
32 | switch(c) { | ||
33 | case 'h': | ||
34 | std::cerr << PHEADER << std::endl << std::endl | ||
35 | << " " << argv[0] << " [options]" << std::endl | ||
36 | << std::endl << | ||
37 | " -h, --help,\n" | ||
38 | " --usage display this text\n" | ||
39 | " -V, --version display version information\n" | ||
40 | " -L, --license show license\n" | ||
41 | " -p <port>, --port=<port> port to listen to\n" | ||
42 | " (you're not likely to ever need it)\n" | ||
43 | << std::endl << std::endl; | ||
44 | exit(0); | ||
45 | break; | ||
46 | case 'V': | ||
47 | std::cerr << VERSION << std::endl; | ||
48 | exit(0); | ||
49 | break; | ||
50 | case 'L': | ||
51 | extern const char *COPYING; | ||
52 | std::cerr << COPYING << std::endl; | ||
53 | exit(0); | ||
54 | break; | ||
55 | case 'p': | ||
56 | port = strtol(optarg,0,0); | ||
57 | if(errno) { | ||
58 | std::cerr << "Failed to parse port number" << std::endl; | ||
59 | exit(1); | ||
60 | } | ||
61 | break; | ||
62 | default: | ||
63 | std::cerr << "Huh?" << std::endl; | ||
64 | exit(1); | ||
65 | break; | ||
66 | } | ||
67 | } | ||
68 | |||
69 | const char *ident = rindex(*argv,'/'); | ||
70 | if(ident) | ||
71 | ++ident; | ||
72 | else | ||
73 | ident = *argv; | ||
74 | openlog(ident,LOG_PERROR|LOG_PID,LOG_DAEMON); | ||
75 | syslog(LOG_INFO,"Starting iii eye-fi manager"); | ||
76 | |||
77 | eyefiworker().run(port); | ||
78 | |||
79 | closelog(); | ||
80 | return 0; | ||
81 | } catch(std::exception& e) { | ||
82 | syslog(LOG_CRIT,"Exiting iii daemon, because of error condition"); | ||
83 | syslog(LOG_CRIT,"Exception: %s",e.what()); | ||
84 | return 1; | ||
85 | } | ||
86 | |||