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()
54 std::string _hostname
;
55 std::string _extra_args
;
58 Server(const std::string
& hostname
, const in_port_t port_arg
, const bool is_socket_arg
= false);
62 virtual const char *name()= 0;
63 virtual const char *executable()= 0;
64 virtual const char *daemon_file_option()= 0;
65 virtual bool is_libtool()= 0;
67 virtual bool has_socket_file_option() const
72 virtual void socket_file_option(Application
& app
, const std::string
& socket_arg
)
74 if (socket_arg
.empty() == false)
76 std::string
buffer("--socket=");
78 app
.add_option(buffer
);
82 virtual bool has_log_file_option() const
87 virtual void log_file_option(Application
& app
, const std::string
& arg
)
89 if (arg
.empty() == false)
91 std::string
buffer("--log-file=");
93 app
.add_option(buffer
);
97 virtual void pid_file_option(Application
& app
, const std::string
& arg
)
99 if (arg
.empty() == false)
101 std::string
buffer("--pid-file=");
103 app
.add_option(buffer
);
107 virtual bool has_port_option() const
112 virtual void port_option(Application
& app
, in_port_t arg
)
117 snprintf(buffer
, sizeof(buffer
), "--port=%d", int(arg
));
118 app
.add_option(buffer
);
122 virtual bool broken_socket_cleanup()
127 virtual bool broken_pid_file()
132 const std::string
& pid_file() const
137 const std::string
& base_command() const
139 return _base_command
;
142 const std::string
& log_file() const
147 const std::string
& hostname() const
152 const std::string
& socket() const
157 bool has_socket() const
164 virtual bool ping()= 0;
166 virtual pid_t
get_pid(bool error_is_ok
= false)= 0;
168 virtual bool build(size_t argc
, const char *argv
[])= 0;
170 void add_option(const std::string
&);
171 void add_option(const std::string
&, const std::string
&);
173 in_port_t
port() const
178 bool has_port() const
183 virtual bool has_syslog() const
188 // Reset a server if another process has killed the server
196 bool args(Application
&);
210 bool wait_for_pidfile() const;
212 bool check_pid(pid_t pid_arg
) const
214 return (pid_arg
> 1);
217 bool is_socket() const
219 return _hostname
[0] == '/';
222 const std::string
running() const
227 std::string
log_and_pid();
229 bool kill(pid_t pid_arg
);
231 bool command(libtest::Application
& app
);
240 bool is_helgrind() const;
241 bool is_valgrind() const;
242 bool is_debug() const;
244 bool set_socket_file();
248 std::ostream
& operator<<(std::ostream
& output
, const libtest::Server
&arg
);
250 } // namespace libtest