Fang-Robotics-MCB
Fang Robotics Team Codebase
Loading...
Searching...
No Matches
tcp_server.hpp
Go to the documentation of this file.
1/*****************************************************************************/
2/********** !!! WARNING: CODE GENERATED BY TAPROOT. DO NOT EDIT !!! **********/
3/*****************************************************************************/
4
5/*
6 * Copyright (c) 2020-2021 Advanced Robotics at the University of Washington <robomstr@uw.edu>
7 *
8 * This file is part of Taproot.
9 *
10 * Taproot is free software: you can redistribute it and/or modify
11 * it under the terms of the GNU General Public License as published by
12 * the Free Software Foundation, either version 3 of the License, or
13 * (at your option) any later version.
14 *
15 * Taproot is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU General Public License for more details.
19 *
20 * You should have received a copy of the GNU General Public License
21 * along with Taproot. If not, see <https://www.gnu.org/licenses/>.
22 */
23
24#ifndef TAPROOT_TCP_SERVER_HPP_
25#define TAPROOT_TCP_SERVER_HPP_
26
27#ifdef PLATFORM_HOSTED
28
29#ifdef __linux__
30#include <netinet/in.h>
31#endif
32
33#include <atomic>
34#include <cstdint>
35
36namespace tap
37{
38namespace communication
39{
44class TCPServer
45{
46// Make constructor and destructor public if in unit tests environment.
47#ifdef ENV_UNIT_TESTS
48public:
49#endif
55 TCPServer(int portnumber);
56
60 ~TCPServer();
61
62public:
63 /* PortNumber which the server will try to open on. This seems finicky
64 * as it's possible that port is in use, but I don't know how to do
65 * better (Tenzin)*/
66 static const int16_t PORT_NUMBER = 8888;
67 static const uint8_t LISTEN_QUEUE_SIZE = 5; // 5 is max on most systems
68
72 static TCPServer* MainServer();
73
77 void getConnection();
78
82 void closeConnection();
83
87 uint16_t getPortNumber();
88
93 void writeToClient(const char* message, int32_t messageLength);
94
95private:
96#ifdef __linux__
97 bool socketOpened;
98 bool clientConnected;
99 int16_t listenFileDescriptor; // File descriptor which server gets connection requests
100 int16_t mainClientDescriptor; // File Descriptor which we communciate with
101 sockaddr_in serverAddress;
102 int16_t portNumber; // portNumber the server is bound to
103#endif // __linux__
104
105 // Singleton server.
106 static TCPServer mainServer;
107}; // TCPServer
108
109#ifdef __linux__
118void readMessage(int16_t fileDescriptor, char* readBuffer, uint16_t messageLength);
119
125void writeMessage(int16_t fileDescriptor, const char* message, uint16_t bytes);
126
131int32_t readInt32(int16_t fileDescriptor);
132#endif // __linux__
133
134} // namespace communication
135
136} // namespace tap
137
138#endif // PLATFORM_HOSTED
139
140#endif // TAPROOT_TCP_SERVER_HPP_
Definition ballistics.cpp:29