plptools
Loading...
Searching...
No Matches
ncp_session.h
Go to the documentation of this file.
1/*
2 * This file is part of plptools.
3 *
4 * Copyright (C) 1999 Philip Proudman <philip.proudman@btinternet.com>
5 * Copyright (C) 1999-2001 Fritz Elfert <felfert@to.com>
6 * Copyright (C) 2026 Jason Morley <hello@jbmorley.co.uk>
7 *
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation; either version 2 of the License, or
11 * (at your option) any later version.
12 *
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
17 *
18 * You should have received a copy of the GNU General Public License along
19 * along with this program; if not, see <https://www.gnu.org/licenses/>.
20 *
21 */
22#pragma once
23
24#include "config.h"
25
26#include <mutex>
27#include <string>
28#include <bufferstore.h>
29#include <tcpsocket.h>
30#include <iowatch.h>
31
32#include "ncp.h"
33#include "socketchannel.h"
34
42public:
43
44 NCPSession(int portNumber,
45 int baudRate,
46 std::string host,
47 std::string serialDevice,
48 bool autoexit,
49 unsigned short nverbose)
50 : portNumber_(portNumber)
51 , baudRate_(baudRate)
52 , host_(host)
53 , serialDevice_(serialDevice)
54 , autoexit_(autoexit)
55 , nverbose_(nverbose) {}
56
58
66 int start();
67
74 void cancel();
75
82 void wait();
83
84private:
85
86 // Thread entry points and helpers.
87
88 friend void *ncp_session_main_thread(void *arg);
89 friend void *link_thread(void *arg);
90 friend void *socket_connection_polling_thread(void *arg);
91 friend void check_for_new_socket_connection(NCPSession *session);
92
93 bool isCancelled();
94
95 // Configuration.
96
99 std::string host_;
100 std::string serialDevice_;
102 unsigned short nverbose_;
103
104 // State.
105
106 pthread_t sessionMainThreadId_ = 0;
107
111 NCP *ncp_ = nullptr;
112
117
120 std::vector<SocketChannel *>socketChannels_;
121 int cancellationPipe_[2] = { -1, -1 };
122};
A simple thread-safe wrapper for select()
Definition: iowatch.h:34
Responsible for orchestrating the high-level life cycle of a daemon-side NCP server and multiplexing ...
Definition: ncp_session.h:41
IOWatch socketChannelWatch_
Used to watch all active SocketChannel instances (stored in socketChannels_) to see if they're readab...
Definition: ncp_session.h:116
int baudRate_
Definition: ncp_session.h:98
TCPSocket skt_
Definition: ncp_session.h:118
int cancellationPipe_[2]
Definition: ncp_session.h:121
std::string host_
Definition: ncp_session.h:99
bool isCancelled()
Definition: ncp_session.cc:234
void cancel()
Mark the session as cancelled.
Definition: ncp_session.cc:229
std::string serialDevice_
Definition: ncp_session.h:100
int portNumber_
Definition: ncp_session.h:97
NCP * ncp_
NCP instance.
Definition: ncp_session.h:111
bool autoexit_
Definition: ncp_session.h:101
std::mutex socketChannelLock_
Definition: ncp_session.h:119
unsigned short nverbose_
Definition: ncp_session.h:102
pthread_t sessionMainThreadId_
Definition: ncp_session.h:106
void wait()
Wait for the session to terminate.
Definition: ncp_session.cc:245
friend void check_for_new_socket_connection(NCPSession *session)
Definition: ncp_session.cc:123
NCPSession(int portNumber, int baudRate, std::string host, std::string serialDevice, bool autoexit, unsigned short nverbose)
Definition: ncp_session.h:44
friend void * link_thread(void *arg)
Definition: ncp_session.cc:51
std::vector< SocketChannel * > socketChannels_
Definition: ncp_session.h:120
int start()
Creates and manages all the threads necessary to run a full session for communicating with a Psion an...
Definition: ncp_session.cc:219
friend void * socket_connection_polling_thread(void *arg)
Responsible for driving the SocketChannel instances (incoming TCP connections) by means of SocketChan...
Definition: ncp_session.cc:78
friend void * ncp_session_main_thread(void *arg)
Definition: ncp_session.cc:171
Definition: ncp.h:54
A class for dealing with sockets.
Definition: tcpsocket.h:38