Merge in util update
[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 std::string server_list;
39 bool _socket;
40 bool _sasl;
41 uint32_t _count;
42 std::string _username;
43 std::string _password;
44
45 public:
46
47 uint8_t udp;
48 std::vector<Server *> servers;
49
50 server_startup_st() :
51 _socket(false),
52 _sasl(false),
53 _count(5),
54 udp(0)
55 { }
56
57 bool start_socket_server(const std::string& server_type, const in_port_t try_port, int argc, const char *argv[]);
58
59 uint32_t count() const
60 {
61 return _count;
62 }
63
64 void set_count(uint32_t arg)
65 {
66 _count= arg;
67 }
68
69 void restart();
70
71 std::string option_string() const;
72
73 const std::string& password() const
74 {
75 return _password;
76 }
77
78 const std::string& username() const
79 {
80 return _username;
81 }
82
83
84 bool is_debug() const;
85 bool is_helgrind() const;
86 bool is_valgrind() const;
87
88 bool socket()
89 {
90 return _socket;
91 }
92
93 bool sasl()
94 {
95 return _sasl;
96 }
97
98 void set_socket()
99 {
100 _socket= true;
101 }
102
103 void set_sasl(const std::string& username_arg, const std::string& password_arg)
104 {
105 _sasl= true;
106 _username= username_arg;
107 _password= password_arg;
108 }
109
110
111 void shutdown_and_remove();
112 void shutdown();
113 bool shutdown(uint32_t number_of_host);
114
115 void push_server(Server *);
116 Server *pop_server();
117
118 ~server_startup_st();
119 };
120
121 bool server_startup(server_startup_st&, const std::string&, in_port_t try_port, int argc, const char *argv[]);
122
123 } // namespace libtest