Merge working tree with build tree.
[awesomized/libmemcached] / libtest / server_container.h
1 /* vim:expandtab:shiftwidth=2:tabstop=2:smarttab:
2 *
3 * libtest
4 *
5 * Copyright (C) 2011 Data Differential, http://datadifferential.com/
6 *
7 * This library is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU Lesser General Public
9 * License as published by the Free Software Foundation; either
10 * version 3 of the License, or (at your option) any later version.
11 *
12 * This library is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * Lesser General Public License for more details.
16 *
17 * You should have received a copy of the GNU Lesser General Public
18 * License along with this library; if not, write to the Free Software
19 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
20 */
21
22 #pragma once
23
24 #include <cassert>
25 #include <cstdio>
26 #include <cstring>
27 #include <netdb.h>
28 #include <netinet/in.h>
29 #include <string>
30 #include <unistd.h>
31 #include <vector>
32
33 namespace libtest {
34
35 class server_startup_st
36 {
37 private:
38 uint64_t _magic;
39 std::string server_list;
40 bool _socket;
41 bool _sasl;
42 uint32_t _count;
43 std::string _username;
44 std::string _password;
45
46 public:
47
48 uint8_t udp;
49 std::vector<Server *> servers;
50
51 server_startup_st();
52 ~server_startup_st();
53
54 bool validate();
55
56 bool start_socket_server(const std::string& server_type, const in_port_t try_port, int argc, const char *argv[]);
57
58 uint32_t count() const
59 {
60 return servers.size();
61 }
62
63 void restart();
64
65 std::string option_string() const;
66
67 const std::string& password() const
68 {
69 return _password;
70 }
71
72 const std::string& username() const
73 {
74 return _username;
75 }
76
77 bool socket()
78 {
79 return _socket;
80 }
81
82 bool sasl()
83 {
84 return _sasl;
85 }
86
87 void set_socket()
88 {
89 _socket= true;
90 }
91
92 void set_sasl(const std::string& username_arg, const std::string& password_arg)
93 {
94 _sasl= true;
95 _username= username_arg;
96 _password= password_arg;
97 }
98
99
100 void shutdown_and_remove();
101 bool shutdown();
102 bool shutdown(uint32_t number_of_host);
103
104 bool check() const;
105
106 void push_server(Server *);
107 Server *pop_server();
108
109 unsigned long int servers_to_run() const
110 {
111 return _servers_to_run;
112 }
113
114 void set_servers_to_run(unsigned long int arg)
115 {
116 _servers_to_run= arg;
117 }
118
119 private:
120 unsigned long int _servers_to_run;
121 };
122
123 bool server_startup(server_startup_st&, const std::string&, in_port_t try_port, int argc, const char *argv[], const bool opt_startup_message= true);
124
125 } // namespace libtest