Aktualizr
C++ SOTA Client
All Classes Namespaces Files Functions Variables Enumerations Enumerator Pages
secondary_tcp_server.h
1 #ifndef AKTUALIZR_SECONDARY_TCP_SERVER_H_
2 #define AKTUALIZR_SECONDARY_TCP_SERVER_H_
3 
4 #include <atomic>
5 #include <condition_variable>
6 #include <mutex>
7 
8 #include "utilities/utils.h"
9 
10 class MsgHandler;
11 
12 /**
13  * Listens on a socket, decodes calls (ASN.1) and forwards them to an Uptane Secondary
14  * implementation
15  */
17  public:
18  enum class ExitReason {
19  kNotApplicable,
20  kRebootNeeded,
21  kUnkown,
22  };
23 
24  SecondaryTcpServer(MsgHandler& msg_handler, const std::string& primary_ip, in_port_t primary_port, in_port_t port = 0,
25  bool reboot_after_install = false);
26 
27  SecondaryTcpServer(const SecondaryTcpServer&) = delete;
28  SecondaryTcpServer& operator=(const SecondaryTcpServer&) = delete;
29 
30  public:
31  /**
32  * Accept connections on the socket, decode requests and respond using the secondary implementation
33  */
34  void run();
35  void stop();
36 
37  void wait_until_running(int timeout = 10);
38 
39  in_port_t port() const;
40  ExitReason exit_reason() const;
41 
42  private:
43  bool HandleOneConnection(int socket);
44 
45  private:
46  MsgHandler& msg_handler_;
47  ListenSocket listen_socket_;
48  std::atomic<bool> keep_running_;
49  bool reboot_after_install_;
50  ExitReason exit_reason_{ExitReason::kNotApplicable};
51 
52  bool is_running_;
53  std::mutex running_condition_mutex_;
54  std::condition_variable running_condition_;
55 };
56 
57 #endif // AKTUALIZR_SECONDARY_TCP_SERVER_H_
MsgHandler
Definition: msg_handler.h:10
SecondaryTcpServer
Listens on a socket, decodes calls (ASN.1) and forwards them to an Uptane Secondary implementation.
Definition: secondary_tcp_server.h:16
SecondaryTcpServer::run
void run()
Accept connections on the socket, decode requests and respond using the secondary implementation.
Definition: secondary_tcp_server.cc:32
ListenSocket
Definition: utils.h:136