FileDescriptor.h
Go to the documentation of this file.
1 // This file is a part of the OpenSurgSim project.
2 // Copyright 2013, SimQuest Solutions Inc.
3 //
4 // Licensed under the Apache License, Version 2.0 (the "License");
5 // you may not use this file except in compliance with the License.
6 // You may obtain a copy of the License at
7 //
8 // http://www.apache.org/licenses/LICENSE-2.0
9 //
10 // Unless required by applicable law or agreed to in writing, software
11 // distributed under the License is distributed on an "AS IS" BASIS,
12 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 // See the License for the specific language governing permissions and
14 // limitations under the License.
15 
16 #ifndef SURGSIM_DEVICES_MULTIAXIS_LINUX_FILEDESCRIPTOR_H
17 #define SURGSIM_DEVICES_MULTIAXIS_LINUX_FILEDESCRIPTOR_H
18 
19 #include <string>
20 
21 
22 namespace SurgSim
23 {
24 namespace Devices
25 {
26 
30 {
31 public:
35 
39 
44 
47 
50  bool isValid() const;
51 
54  bool canRead() const;
55 
58  bool canWrite() const;
59 
62  bool hasDataToRead() const;
63 
69  bool readBytes(void* dataBuffer, size_t bytesToRead, size_t* bytesActuallyRead);
70 
73  int get() const;
74 
78  bool openForReadingAndWriting(const std::string& path);
79 
83  bool openForReading(const std::string& path);
84 
88  bool openForWriting(const std::string& path);
89 
93  bool openForReadingAndMaybeWriting(const std::string& path);
94 
97  void reset();
98 
99 private:
100  FileDescriptor(const FileDescriptor& other) = delete;
101  FileDescriptor& operator=(const FileDescriptor& other) = delete;
102 
103  static const int INVALID_VALUE = -1;
104 
106  bool m_canRead;
108 };
109 
110 }; // namespace Devices
111 }; // namespace SurgSim
112 
113 #endif // SURGSIM_DEVICES_MULTIAXIS_LINUX_FILEDESCRIPTOR_H
SurgSim::Devices::FileDescriptor::openForReadingAndMaybeWriting
bool openForReadingAndMaybeWriting(const std::string &path)
Attempts to open the file descriptor for reading and (if permissions allow it) writing.
Definition: FileDescriptor.cpp:111
SurgSim::Devices::FileDescriptor::reset
void reset()
Resets the file descriptor back to an invalid state.
Definition: FileDescriptor.cpp:123
SurgSim::Devices::FileDescriptor::FileDescriptor
FileDescriptor()
Default constructor.
Definition: FileDescriptor.cpp:34
SurgSim::Devices::FileDescriptor::hasDataToRead
bool hasDataToRead() const
Checks whether this object has data available to be read.
Definition: FileDescriptor.cpp:132
SurgSim::Devices::FileDescriptor::operator=
FileDescriptor & operator=(FileDescriptor &&other)
Move assignment operator.
Definition: FileDescriptor.cpp:49
SurgSim::Devices::FileDescriptor::m_descriptor
int m_descriptor
Definition: FileDescriptor.h:105
SurgSim
Definition: CompoundShapeToGraphics.cpp:29
SurgSim::Devices::FileDescriptor::openForWriting
bool openForWriting(const std::string &path)
Attempts to open the file descriptor for writing only.
Definition: FileDescriptor.cpp:102
SurgSim::Devices::FileDescriptor::canWrite
bool canWrite() const
Determines if the file descriptor can be written to.
Definition: FileDescriptor.cpp:73
SurgSim::Devices::FileDescriptor::canRead
bool canRead() const
Determines if the file descriptor can be read from.
Definition: FileDescriptor.cpp:68
SurgSim::Devices::FileDescriptor::readBytes
bool readBytes(void *dataBuffer, size_t bytesToRead, size_t *bytesActuallyRead)
Reads bytes from the file descriptor.
Definition: FileDescriptor.cpp:149
SurgSim::Devices::FileDescriptor::m_canWrite
bool m_canWrite
Definition: FileDescriptor.h:107
SurgSim::Devices::FileDescriptor::INVALID_VALUE
static const int INVALID_VALUE
Definition: FileDescriptor.h:103
SurgSim::Devices::FileDescriptor::m_canRead
bool m_canRead
Definition: FileDescriptor.h:106
SurgSim::Devices::FileDescriptor::~FileDescriptor
~FileDescriptor()
Destructor.
Definition: FileDescriptor.cpp:58
SurgSim::Devices::FileDescriptor::get
int get() const
Gets the raw underlying OS file descriptor.
Definition: FileDescriptor.cpp:78
SurgSim::Devices::FileDescriptor::openForReading
bool openForReading(const std::string &path)
Attempts to open the file descriptor for reading only.
Definition: FileDescriptor.cpp:93
SurgSim::Devices::FileDescriptor::openForReadingAndWriting
bool openForReadingAndWriting(const std::string &path)
Attempts to open the file descriptor for reading and writing.
Definition: FileDescriptor.cpp:84
SurgSim::Devices::FileDescriptor::isValid
bool isValid() const
Checks if the file descriptor is valid, i.e.
Definition: FileDescriptor.cpp:63
SurgSim::Devices::FileDescriptor
A wrapper for an UNIX-style integer file descriptor.
Definition: FileDescriptor.h:29