2 * Copyright (C) 2011 Data Differential, http://datadifferential.com/
3 * Copyright (C) 2006-2009 Brian Aker
6 * Use and distribution licensed under the BSD license. See
7 * the COPYING file in the parent directory for full text.
16 #include <netinet/in.h>
27 std::string _pid_file
;
28 std::string _log_file
;
29 std::string _base_command
; // executable command which include libtool, valgrind, gdb, etc
30 std::string _running
; // Current string being used for system()
35 std::string _hostname
;
36 std::string _extra_args
;
39 Server(const std::string
& hostname
, const in_port_t port_arg
, const bool is_socket_arg
= false);
43 virtual const char *name()= 0;
44 virtual const char *executable()= 0;
45 virtual const char *port_option()= 0;
46 virtual const char *pid_file_option()= 0;
47 virtual const char *daemon_file_option()= 0;
48 virtual const char *log_file_option()= 0;
49 virtual bool is_libtool()= 0;
51 virtual const char *socket_file_option() const
56 virtual bool broken_pid_file()
61 const std::string
& pid_file() const
66 const std::string
& base_command() const
71 const std::string
& log_file() const
76 const std::string
& hostname() const
81 const std::string
& socket() const
86 bool has_socket() const
93 virtual bool ping()= 0;
95 virtual pid_t
get_pid(bool error_is_ok
= true)= 0;
97 virtual bool build(int argc
, const char *argv
[])= 0;
99 in_port_t
port() const
104 bool has_port() const
109 // Reset a server if another process has killed the server
117 void set_extra_args(const std::string
&arg
);
119 bool args(std::string
& options
);
133 bool is_socket() const
135 return _hostname
[0] == '/';
138 const std::string
running() const
143 std::string
log_and_pid();
147 bool command(std::string
& command_arg
);
153 bool is_valgrind() const;
154 bool is_debug() const;
157 bool set_socket_file();
158 void rebuild_base_command();
162 std::ostream
& operator<<(std::ostream
& output
, const libtest::Server
&arg
);
164 class server_startup_st
167 std::string server_list
;
172 std::vector
<Server
*> servers
;
174 server_startup_st() :
178 bool start_socket_server(const std::string
& server_type
, const in_port_t try_port
, int argc
, const char *argv
[]);
180 std::string
option_string() const;
184 return servers
.size();
187 bool is_debug() const;
188 bool is_valgrind() const;
190 void shutdown(bool remove
= false);
191 void push_server(Server
*);
192 Server
*pop_server();
194 ~server_startup_st();
197 bool server_startup(server_startup_st
&, const std::string
&, in_port_t try_port
, int argc
, const char *argv
[]);
199 } // namespace libtest