opensurgsim
FileDescriptor.h
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 
105  int m_descriptor;
106  bool m_canRead;
107  bool m_canWrite;
108 };
109 
110 }; // namespace Devices
111 }; // namespace SurgSim
112 
113 #endif // SURGSIM_DEVICES_MULTIAXIS_LINUX_FILEDESCRIPTOR_H
Wraps glewInit() to separate the glew opengl definitions from the osg opengl definitions only imgui n...
Definition: AddRandomSphereBehavior.cpp:36
bool openForReading(const std::string &path)
Attempts to open the file descriptor for reading only.
Definition: FileDescriptor.cpp:93
bool openForWriting(const std::string &path)
Attempts to open the file descriptor for writing only.
Definition: FileDescriptor.cpp:102
void reset()
Resets the file descriptor back to an invalid state.
Definition: FileDescriptor.cpp:123
bool isValid() const
Checks if the file descriptor is valid, i.e.
Definition: FileDescriptor.cpp:63
bool openForReadingAndWriting(const std::string &path)
Attempts to open the file descriptor for reading and writing.
Definition: FileDescriptor.cpp:84
FileDescriptor & operator=(FileDescriptor &&other)
Move assignment operator.
Definition: FileDescriptor.cpp:49
~FileDescriptor()
Destructor.
Definition: FileDescriptor.cpp:58
bool canRead() const
Determines if the file descriptor can be read from.
Definition: FileDescriptor.cpp:68
FileDescriptor()
Default constructor.
Definition: FileDescriptor.cpp:34
A wrapper for an UNIX-style integer file descriptor.
Definition: FileDescriptor.h:29
bool readBytes(void *dataBuffer, size_t bytesToRead, size_t *bytesActuallyRead)
Reads bytes from the file descriptor.
Definition: FileDescriptor.cpp:149
bool openForReadingAndMaybeWriting(const std::string &path)
Attempts to open the file descriptor for reading and (if permissions allow it) writing.
Definition: FileDescriptor.cpp:111
bool hasDataToRead() const
Checks whether this object has data available to be read.
Definition: FileDescriptor.cpp:132
bool canWrite() const
Determines if the file descriptor can be written to.
Definition: FileDescriptor.cpp:73