tzwrapper.cc: fixed use of iterator after erase
[barry.git] / src / fifoargs.h
blob242a00fdb5cf509fcd46a0c8b602a21961f44483
1 ///
2 /// \file fifoargs.h
3 /// Class for passing command line arguments via fifo instead
4 /// of command line.
5 ///
7 /*
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__
26 #include "dll.h"
27 #include "pin.h"
28 #include <iosfwd>
30 namespace Barry {
33 // FifoArgs
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.
38 ///
39 struct BXEXPORT FifoArgs
41 Pin m_pin;
42 std::string m_password;
43 std::string m_log_filename;
44 bool m_use_serial_mode;
45 bool m_verbose;
47 FifoArgs()
48 : m_use_serial_mode(false)
49 , m_verbose(false)
53 std::ostream& Write(std::ostream &os) const;
54 std::istream& Read(std::istream &is);
56 void Clear();
60 // FifoServer
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.
65 ///
66 /// This class deletes the fifo in the destructor, or explicitly, with
67 /// the Cleanup() call.
68 ///
69 /// Only arguments that are valid are sent.
70 ///
71 class BXEXPORT FifoServer
73 const FifoArgs &m_args;
74 bool m_created;
76 public:
77 explicit FifoServer(const FifoArgs &args);
78 ~FifoServer();
80 /// Serves the given arguments through the fifo. Returns
81 /// false on timeout.
82 bool Serve(int timeout_sec);
84 /// Deletes the fifo. Called automatically by destructor.
85 void Cleanup();
89 // FifoClient
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.
94 ///
95 class BXEXPORT FifoClient
97 FifoArgs m_args;
99 public:
100 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; }
109 } // Barry namespace
111 #endif