Buran Motion Planning Framework
base_server.h
1 #pragma once
2 
3 #include <sys/socket.h>
4 #include <netinet/in.h>
5 #include "log.h"
6 #include "base/path_finder.h"
7 #include "continuous_path_finder.h"
8 #include <netinet/in.h>
9 #include "iostream"
10 #include <sys/socket.h>
11 #include <unistd.h>
12 #include <chrono>
13 #include <thread>
14 #include "base/path_finder.h"
15 #include "continuous_path_finder.h"
16 #include <json/value.h>
17 #include <json/reader.h>
18 #include <semaphore.h>
19 #include <csignal>
20 
26 class BaseServer {
27 public:
28 
32  static void initLinuxServerSocket();
33 
37  void mainLoop();
38 
45  virtual void init(int port, int maxClients, int delay);
46 
53  virtual void processCommand(int clientSocket, int command, Json::Value jsonData) = 0;
54 
59  virtual void onSocketConnected(int clientSocket) = 0;
60 
65  void processRequests(int clientSocket);
66 
70  void stop() { _terminated = true; }
71 
77  return accept(_serverFD, (struct sockaddr *) &_address, (socklen_t *) &_addrLen);
78  }
79 
84  int getServerFd() const { return _serverFD; }
85 
90  const sockaddr_in &getAddress() const { return _address; }
91 
92 protected:
96  sem_t _sem;
97 
98 private:
99 
103  struct sockaddr_in _address;
107  int _port;
111  int _addrLen;
115  int _serverFD;
119  int _delay;
123  bool _terminated;
127  std::string _commandBuf;
128 
129 };
BaseServer
Базовый класс для всех серверов Для реализации сервера, необходимо переопределить две чисто виртуальн...
Definition: base_server.h:26
BaseServer::getServerFd
int getServerFd() const
Definition: base_server.h:84
BaseServer::processRequests
void processRequests(int clientSocket)
Definition: base_server.cpp:77
BaseServer::initLinuxServerSocket
static void initLinuxServerSocket()
Definition: base_server.cpp:6
BaseServer::onSocketConnected
virtual void onSocketConnected(int clientSocket)=0
BaseServer::mainLoop
void mainLoop()
Definition: base_server.cpp:17
BaseServer::getAddress
const sockaddr_in & getAddress() const
Definition: base_server.h:90
BaseServer::stop
void stop()
Definition: base_server.h:70
BaseServer::init
virtual void init(int port, int maxClients, int delay)
Definition: base_server.cpp:37
BaseServer::_sem
sem_t _sem
Definition: base_server.h:96
BaseServer::acceptNewSocket
int acceptNewSocket()
Definition: base_server.h:76
BaseServer::processCommand
virtual void processCommand(int clientSocket, int command, Json::Value jsonData)=0