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
24 #include <libtest/cmdline.h>
30 #include <netinet/in.h>
39 typedef std::vector
< std::pair
<std::string
, std::string
> > Options
;
46 std::string _pid_file
;
47 std::string _log_file
;
48 std::string _base_command
; // executable command which include libtool, valgrind, gdb, etc
49 std::string _running
; // Current string being used for system()
53 std::string _hostname
;
54 std::string _extra_args
;
57 Server(const std::string
& hostname
, const in_port_t port_arg
,
58 const std::string
& executable
, const bool _is_libtool
,
59 const bool is_socket_arg
= false);
63 virtual const char *name()= 0;
64 virtual bool is_libtool()= 0;
66 virtual bool has_socket_file_option() const
71 virtual void socket_file_option(Application
& app
, const std::string
& socket_arg
)
73 if (socket_arg
.empty() == false)
75 std::string
buffer("--socket=");
77 app
.add_option(buffer
);
81 virtual bool has_log_file_option() const
86 virtual void log_file_option(Application
& app
, const std::string
& arg
)
88 if (arg
.empty() == false)
90 std::string
buffer("--log-file=");
92 app
.add_option(buffer
);
96 virtual void pid_file_option(Application
& app
, const std::string
& arg
)
98 if (arg
.empty() == false)
100 std::string
buffer("--pid-file=");
102 app
.add_option(buffer
);
106 virtual bool has_port_option() const
111 virtual void port_option(Application
& app
, in_port_t arg
)
116 snprintf(buffer
, sizeof(buffer
), "--port=%d", int(arg
));
117 app
.add_option(buffer
);
121 virtual bool broken_socket_cleanup()
126 virtual bool broken_pid_file()
131 const std::string
& pid_file() const
136 const std::string
& base_command() const
138 return _base_command
;
141 const std::string
& log_file() const
146 const std::string
& hostname() const
151 const std::string
& socket() const
156 bool has_socket() const
163 virtual bool ping()= 0;
165 virtual bool build(size_t argc
, const char *argv
[])= 0;
167 void add_option(const std::string
&);
168 void add_option(const std::string
&, const std::string
&);
170 in_port_t
port() const
175 bool has_port() const
180 virtual bool has_syslog() const
185 // Reset a server if another process has killed the server
192 bool args(Application
&);
196 bool has_pid() const;
198 virtual bool wait_for_pidfile() const;
200 bool check_pid(pid_t pid_arg
) const
202 return (pid_arg
> 1);
205 bool is_socket() const
207 return _hostname
[0] == '/';
210 const std::string
running() const
217 std::string
log_and_pid();
221 bool command(libtest::Application
& app
);
231 bool is_helgrind() const;
232 bool is_valgrind() const;
233 bool is_debug() const;
235 bool set_socket_file();
239 std::ostream
& operator<<(std::ostream
& output
, const libtest::Server
&arg
);
241 } // namespace libtest