3 /// Class for passing command line arguments via fifo instead
8 Copyright (C) 2012-2013, Net Direct Inc. (http://www.netdirect.ca/)
10 This program is free software; you can redistribute it and/or modify
11 it under the terms of the GNU General Public License as published by
12 the Free Software Foundation; either version 2 of the License, or
13 (at your option) any later version.
15 This program is distributed in the hope that it will be useful,
16 but WITHOUT ANY WARRANTY; without even the implied warranty of
17 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
19 See the GNU General Public License in the COPYING file at the
20 root directory of this project for more details.
23 #ifndef __BARRY_FIFOARGS_H__
24 #define __BARRY_FIFOARGS_H__
35 /// Contains argument variables to be passed through the FIFO.
36 /// It is no coincidence that there is a close connection to this
37 /// set of arguments and the arguments given to the pppob program.
39 struct BXEXPORT FifoArgs
42 std::string m_password
;
43 std::string m_log_filename
;
44 bool m_use_serial_mode
;
48 : m_use_serial_mode(false)
53 std::ostream
& Write(std::ostream
&os
) const;
54 std::istream
& Read(std::istream
&is
);
62 /// Accepts a FifoArgs struct, and creates the necessary fifo for transfer.
63 /// To use, create the object, then execute the program (eg. pppob), and
64 /// then call Serve() with a given timeout in seconds.
66 /// This class deletes the fifo in the destructor, or explicitly, with
67 /// the Cleanup() call.
69 /// Only arguments that are valid are sent.
71 class BXEXPORT FifoServer
73 const FifoArgs
&m_args
;
77 explicit FifoServer(const FifoArgs
&args
);
80 /// Serves the given arguments through the fifo. Returns
82 bool Serve(int timeout_sec
);
84 /// Deletes the fifo. Called automatically by destructor.
91 /// Searches for a fifo and opens and reads it if available. Use
92 /// Fetch() with a given timeout to perform the read attempt.
93 /// Use GetArgs() to access the filled FifoArgs struct.
95 class BXEXPORT FifoClient
102 /// Tries to open the fifo and read the arguments from it.
103 /// If it fails in any way, or timeout, returns false.
104 bool Fetch(int timeout_sec
);
106 const FifoArgs
& GetArgs() const { return m_args
; }