45#include "ignore-value.h"
65 linf <<
_(
"Got SIGTERM") << endl;
73 linf <<
_(
"Got SIGINT") << endl;
82 "Usage: ncpd [OPTIONS]...\n"
84 "Supported options:\n"
86 " -d, --dontfork Run in foreground, don't fork\n"
87 " -h, --help Display this text.\n"
88 " -V, --version Print version and exit.\n"
89 " -e, --autoexit Exit after device is disconnected.\n"
90 " -v, --verbose=LOGCLASS Enable logging of LOGCLASS events\n"
91 " Valid log classes are:\n"
93 " nl - NCP protocol log\n"
94 " nd - NCP protocol data dump\n"
95 " ll - PLP protocol log\n"
96 " ld - PLP protocol data dump\n"
97 " pl - physical I/O log\n"
98 " ph - physical I/O handshake\n"
99 " pd - physical I/O data dump\n"
100 " all - All of the above\n"
101 " -s, --serial=DEV Use serial device DEV.\n"
102 " -b, --baudrate=RATE Set serial speed to BAUD.\n"
106#define SPEEDSTR(x) #x
107 _(
" Default: ") << DSPEED <<
".\n";
109 _(
" Default: Autocycle 115.2k, 57.6k 38.4k, 19.2k\n");
112 " -p, --port=[HOST:]PORT Listen on host HOST, port PORT.\n"
113 " Default for HOST: 127.0.0.1\n"
114 " Default for PORT: "
115 ) << DPORT <<
"\n\n";
120 cerr <<
_(
"Try `ncpd --help' for more information") << endl;
124 {
"dontfork", no_argument, 0,
'd'},
125 {
"autoexit", no_argument, 0,
'e'},
126 {
"help", no_argument, 0,
'h'},
127 {
"version", no_argument, 0,
'V'},
128 {
"verbose", required_argument, 0,
'v'},
129 {
"port", required_argument, 0,
'p'},
130 {
"serial", required_argument, 0,
's'},
131 {
"baudrate", required_argument, 0,
'b'},
142 int baudRate = DSPEED;
143 string host =
"127.0.0.1";
144 const char *serialDevice = NULL;
145 unsigned short nverbose = 0;
146 bool autoexit =
false;
153 int c = getopt_long(argc, argv,
"hdeVb:s:p:v:",
opts, NULL);
161 cout <<
_(
"ncpd Version ") << VERSION << endl;
167 if (!strcmp(optarg,
"nl"))
169 if (!strcmp(optarg,
"nd"))
171 if (!strcmp(optarg,
"ll"))
173 if (!strcmp(optarg,
"ld"))
175 if (!strcmp(optarg,
"pl"))
177 if (!strcmp(optarg,
"pd"))
179 if (!strcmp(optarg,
"ph"))
181 if (!strcmp(optarg,
"m"))
183 if (!strcmp(optarg,
"all")) {
197 if (!strcmp(optarg,
"auto"))
200 baudRate = atoi(optarg);
203 serialDevice = optarg;
207 cout <<
_(
"Invalid port definition.") << endl;
218 if (serialDevice == NULL)
233 openlog(
"ncpd", LOG_CONS|LOG_PID, LOG_DAEMON);
238 ignore_value(chdir(
"/"));
239 int devnull = open(
"/dev/null", O_RDWR, 0);
241 dup2(devnull, STDIN_FILENO);
242 dup2(devnull, STDOUT_FILENO);
243 dup2(devnull, STDERR_FILENO);
264 lerr <<
"fork: " << strerror(errno) << endl;
269 linf <<
_(
"normal exit") << endl;
Responsible for orchestrating the high-level life cycle of a daemon-side NCP server and multiplexing ...
void cancel()
Mark the session as cancelled.
void wait()
Wait for the session to terminate.
int start()
Creates and manages all the threads necessary to run a full session for communicating with a Psion an...
void useFileDescriptor()
Write logs to the file descriptor passed in the constructor.
void useSyslog()
Write logs using syslog.
bool parse_port(const std::string &arg, std::string *host, int *port)
int lookup_default_port()
logbuf dlog(LOG_DEBUG, STDOUT_FILENO)
logbuf elog(LOG_ERR, STDERR_FILENO)
logbuf ilog(LOG_INFO, STDOUT_FILENO)
#define PKT_DEBUG_HANDSHAKE
static void term_handler(int)
static void int_handler(int)
int main(int argc, char **argv)
static struct option opts[]
static NCPSession * sharedSession