Flexiport  2.0.0
logwriterport.h
Go to the documentation of this file.
1 /* Flexiport
2  *
3  * Header file for the LogWriterPort class.
4  *
5  * Copyright 2008-2011 Geoffrey Biggs geoffrey.biggs@aist.go.jp
6  * RT-Synthesis Research Group
7  * Intelligent Systems Research Institute,
8  * National Institute of Advanced Industrial Science and Technology (AIST),
9  * Japan
10  * All rights reserved.
11  *
12  * This file is part of Flexiport.
13  *
14  * Flexiport is free software; you can redistribute it and/or modify it
15  * under the terms of the GNU Lesser General Public License as published
16  * by the Free Software Foundation; either version 2.1 of the License,
17  * or (at your option) any later version.
18  *
19  * Flexiport is distributed in the hope that it will be useful, but
20  * WITHOUT ANY WARRANTY; without even the implied warranty of
21  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
22  * Lesser General Public License for more details.
23  *
24  * You should have received a copy of the GNU Lesser General Public
25  * License along with Flexiport. If not, see
26  * <http://www.gnu.org/licenses/>.
27  */
28 
29 #ifndef __LOGWRITERPORT_H
30 #define __LOGWRITERPORT_H
31 
32 #include <flexiport/port.h>
33 
34 #include <map>
35 #include <string>
36 
41 namespace flexiport
42 {
43 
44 class LogFile;
45 
73 {
74  public:
75  LogWriterPort (std::map<std::string, std::string> options);
77 
79  void Open ();
81  void Close ();
83  ssize_t Read (void * const buffer, size_t count);
85  ssize_t ReadFull (void * const buffer, size_t count);
87  ssize_t Skip (size_t count);
90  ssize_t SkipUntil (uint8_t terminator, unsigned int count);
92  ssize_t BytesAvailable ();
94  ssize_t BytesAvailableWait ();
96  ssize_t Write (const void * const buffer, size_t count);
98  void Flush ();
100  void Drain ();
102  std::string GetStatus () const;
104  void SetTimeout (Timeout timeout);
106  void SetCanRead (bool canRead);
108  void SetCanWrite (bool canWrite);
110  bool IsOpen () const;
111 
112  private:
113  Port *_port;
114  LogFile *_logFile;
115  std::string _logFileName;
116 
117  void CheckPort (bool read);
118 };
119 
120 } // namespace flexiport
121 
124 #endif // __LOGWRITERPORT_H
125 
Logging implementation of the Port class.
Definition: logwriterport.h:73
void Open()
Open the port.
void SetTimeout(Timeout timeout)
Set the timeout value in milliseconds.
std::string GetStatus() const
Get the status of the port (type, device, etc).
void SetCanRead(bool canRead)
Set the read permissions of the port.
void Drain()
Drain the port's input and output buffers.
bool IsOpen() const
Check if the port is open.
void Flush()
Flush the port's input and output buffers, discarding all data.
ssize_t BytesAvailable()
Get the number of bytes waiting to be read at the port. Returns immediatly.
void Close()
Close the port.
ssize_t BytesAvailableWait()
Get the number of bytes waiting after blocking for the timeout.
ssize_t Read(void *const buffer, size_t count)
Read from the port.
ssize_t SkipUntil(uint8_t terminator, unsigned int count)
Read and dump data until the specified termination character has been seen count times.
ssize_t Write(const void *const buffer, size_t count)
Write data to the port.
void SetCanWrite(bool canWrite)
Set the write permissions of the port.
ssize_t ReadFull(void *const buffer, size_t count)
Read the requested quantity of data from the port.
ssize_t Skip(size_t count)
Dump data until the specified number of bytes have been read.
LogWriterPort(std::map< std::string, std::string > options)
Base Port class.
Definition: port.h:82
An object used to represent timeouts.
Definition: timeout.h:64
#define FLEXIPORT_EXPORT
Definition: flexiport.h:44