irccd  3.0.3
controller.hpp
1 /*
2  * controller.hpp -- main irccdctl interface
3  *
4  * Copyright (c) 2013-2019 David Demelier <markand@malikania.fr>
5  *
6  * Permission to use, copy, modify, and/or distribute this software for any
7  * purpose with or without fee is hereby granted, provided that the above
8  * copyright notice and this permission notice appear in all copies.
9  *
10  * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
11  * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
12  * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
13  * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
14  * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
15  * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
16  * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
17  */
18 
19 #ifndef IRCCD_CTL_CONTROLLER_HPP
20 #define IRCCD_CTL_CONTROLLER_HPP
21 
27 #include "sysconfig.hpp"
28 
29 #include <cassert>
30 
31 #include <irccd/connector.hpp>
32 #include <irccd/stream.hpp>
33 
34 namespace irccd {
35 
39 namespace ctl {
40 
53 class controller {
54 public:
62  using connect_handler = std::function<void (std::error_code, nlohmann::json)>;
63 
64 private:
65  std::unique_ptr<connector> connector_;
66  std::shared_ptr<stream> stream_;
67  std::string password_;
68 
69  void authenticate(connect_handler, nlohmann::json);
70  void verify(connect_handler);
71 
72 public:
80  controller(std::unique_ptr<connector> connector) noexcept;
81 
87  auto get_password() const noexcept -> const std::string&;
88 
97  void set_password(std::string password) noexcept;
98 
106  void connect(connect_handler handler);
107 
115  void recv(stream::recv_handler handler);
116 
126  void send(nlohmann::json message, stream::send_handler handler);
127 };
128 
129 } // !ctl
130 
131 } // !irccd
132 
133 #endif // !IRCCD_CTL_CONTROLLER_HPP
Abstract connection interface.
Definition: connector.hpp:53
Main irccdctl interface.
Definition: controller.hpp:53
controller(std::unique_ptr< connector > connector) noexcept
void recv(stream::recv_handler handler)
std::function< void(std::error_code, nlohmann::json)> connect_handler
Definition: controller.hpp:62
auto get_password() const noexcept -> const std::string &
void connect(connect_handler handler)
void set_password(std::string password) noexcept
void send(nlohmann::json message, stream::send_handler handler)
Abstract stream interface.
Definition: stream.hpp:58
Parent namespace.
Definition: acceptor.hpp:43
Definition: bot.hpp:253