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 " -n, --nodsr Disable DSR check. Use this when DSR detection is\n"
102 " poorly implemented in RS232 drivers or hardware.\n"
103 " WARNING: Could cause connection instability.\n"
104 " -s, --serial=DEV Use serial device DEV.\n"
105 " -b, --baudrate=RATE Set serial speed to BAUD.\n"
109#define SPEEDSTR(x) #x
110 _(
" Default: ") << DSPEED <<
"\n";
112 _(
" Default: Autocycle 115200, 57600, 38400, 19200, 9600\n");
115 " -p, --port=[HOST:]PORT Listen on host HOST, port PORT.\n"
116 " Default for HOST: 127.0.0.1\n"
117 " Default for PORT: "
118 ) << DPORT <<
"\n\n";
123 cerr <<
_(
"Try `ncpd --help' for more information") << endl;
127 {
"dontfork", no_argument, 0,
'd'},
128 {
"autoexit", no_argument, 0,
'e'},
129 {
"help", no_argument, 0,
'h'},
130 {
"version", no_argument, 0,
'V'},
131 {
"verbose", required_argument, 0,
'v'},
132 {
"port", required_argument, 0,
'p'},
133 {
"serial", required_argument, 0,
's'},
134 {
"baudrate", required_argument, 0,
'b'},
135 {
"nodsr", no_argument, 0,
'n'},
146 int baudRate = DSPEED;
147 string host =
"127.0.0.1";
148 const char *serialDevice = NULL;
149 unsigned short nverbose = 0;
150 bool autoexit =
false;
151 bool noDSRCheck =
false;
158 int c = getopt_long(argc, argv,
"hdeVb:s:p:v:n",
opts, NULL);
166 cout <<
_(
"ncpd Version ") << VERSION << endl;
172 if (!strcmp(optarg,
"nl"))
174 if (!strcmp(optarg,
"nd"))
176 if (!strcmp(optarg,
"ll"))
178 if (!strcmp(optarg,
"ld"))
180 if (!strcmp(optarg,
"pl"))
182 if (!strcmp(optarg,
"pd"))
184 if (!strcmp(optarg,
"ph"))
186 if (!strcmp(optarg,
"m"))
188 if (!strcmp(optarg,
"all")) {
202 if (!strcmp(optarg,
"auto"))
205 baudRate = atoi(optarg);
208 serialDevice = optarg;
212 cout <<
_(
"Invalid port definition.") << endl;
218 linf <<
"DSR check disabled" << endl;
227 if (serialDevice == NULL)
242 openlog(
"ncpd", LOG_CONS|LOG_PID, LOG_DAEMON);
247 ignore_value(chdir(
"/"));
248 int devnull = open(
"/dev/null", O_RDWR, 0);
250 dup2(devnull, STDIN_FILENO);
251 dup2(devnull, STDOUT_FILENO);
252 dup2(devnull, STDERR_FILENO);
274 lerr <<
"fork: " << strerror(errno) << endl;
279 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