1 /* vim:expandtab:shiftwidth=2:tabstop=2:smarttab:
5 * Copyright (C) 2011 Data Differential, http://datadifferential.com/
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.
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.
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
28 #include <netinet/in.h>
40 std::string _pid_file
;
41 std::string _log_file
;
42 std::string _base_command
; // executable command which include libtool, valgrind, gdb, etc
43 std::string _running
; // Current string being used for system()
48 std::string _hostname
;
49 std::string _extra_args
;
52 Server(const std::string
& hostname
, const in_port_t port_arg
, const bool is_socket_arg
= false);
56 virtual const char *name()= 0;
57 virtual const char *executable()= 0;
58 virtual const char *port_option()= 0;
59 virtual const char *pid_file_option()= 0;
60 virtual const char *daemon_file_option()= 0;
61 virtual const char *log_file_option()= 0;
62 virtual bool is_libtool()= 0;
64 virtual bool broken_socket_cleanup()
69 virtual const char *socket_file_option() const
74 virtual bool broken_pid_file()
79 const std::string
& pid_file() const
84 const std::string
& base_command() const
89 const std::string
& log_file() const
94 const std::string
& hostname() const
99 const std::string
& socket() const
104 bool has_socket() const
111 virtual bool ping()= 0;
113 virtual pid_t
get_pid(bool error_is_ok
= false)= 0;
115 virtual bool build(int argc
, const char *argv
[])= 0;
117 in_port_t
port() const
122 bool has_port() const
127 // Reset a server if another process has killed the server
135 void set_extra_args(const std::string
&arg
);
137 bool args(std::string
& options
);
151 bool check_pid(pid_t pid_arg
) const
153 return (pid_arg
> 1);
156 bool is_socket() const
158 return _hostname
[0] == '/';
161 const std::string
running() const
166 std::string
log_and_pid();
168 bool kill(pid_t pid_arg
);
170 bool command(std::string
& command_arg
);
177 bool is_helgrind() const;
178 bool is_valgrind() const;
179 bool is_debug() const;
181 bool set_socket_file();
182 void rebuild_base_command();
186 std::ostream
& operator<<(std::ostream
& output
, const libtest::Server
&arg
);
188 class server_startup_st
191 std::string server_list
;
194 std::string _username
;
195 std::string _password
;
200 std::vector
<Server
*> servers
;
202 server_startup_st() :
208 bool start_socket_server(const std::string
& server_type
, const in_port_t try_port
, int argc
, const char *argv
[]);
210 std::string
option_string() const;
214 return servers
.size();
217 const std::string
& password() const
222 const std::string
& username() const
228 bool is_debug() const;
229 bool is_helgrind() const;
230 bool is_valgrind() const;
247 void set_sasl(const std::string
& username_arg
, const std::string
& password_arg
)
250 _username
= username_arg
;
251 _password
= password_arg
;
255 void shutdown(bool remove
= false);
256 void push_server(Server
*);
257 Server
*pop_server();
259 ~server_startup_st();
262 bool server_startup(server_startup_st
&, const std::string
&, in_port_t try_port
, int argc
, const char *argv
[]);
264 } // namespace libtest