FileDescriptor.h
Go to the documentation of this file.
// This file is a part of the OpenSurgSim project.
// Copyright 2013, SimQuest Solutions Inc.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
#ifndef SURGSIM_DEVICES_MULTIAXIS_LINUX_FILEDESCRIPTOR_H
#define SURGSIM_DEVICES_MULTIAXIS_LINUX_FILEDESCRIPTOR_H
#include <string>
namespace SurgSim
{
namespace Devices
{
class FileDescriptor
{
public:
FileDescriptor();
FileDescriptor(FileDescriptor&& other);
FileDescriptor& operator=(FileDescriptor&& other);
~FileDescriptor();
bool isValid() const;
bool canRead() const;
bool canWrite() const;
bool hasDataToRead() const;
bool readBytes(void* dataBuffer, size_t bytesToRead, size_t* bytesActuallyRead);
int get() const;
bool openForReadingAndWriting(const std::string& path);
bool openForReading(const std::string& path);
bool openForWriting(const std::string& path);
bool openForReadingAndMaybeWriting(const std::string& path);
void reset();
private:
FileDescriptor(const FileDescriptor& other) = delete;
FileDescriptor& operator=(const FileDescriptor& other) = delete;
static const int INVALID_VALUE = -1;
int m_descriptor;
bool m_canRead;
bool m_canWrite;
};
}; // namespace Devices
}; // namespace SurgSim
#endif // SURGSIM_DEVICES_MULTIAXIS_LINUX_FILEDESCRIPTOR_H
SurgSim
Definition: CompoundShapeToGraphics.cpp:29
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::openForWriting
bool openForWriting(const std::string &path)
Attempts to open the file descriptor for writing only.
Definition: FileDescriptor.cpp:102
SurgSim::Devices::FileDescriptor::reset
void reset()
Resets the file descriptor back to an invalid state.
Definition: FileDescriptor.cpp:123
SurgSim::Devices::FileDescriptor::isValid
bool isValid() const
Checks if the file descriptor is valid, i.e.
Definition: FileDescriptor.cpp:63
SurgSim::Devices::FileDescriptor::m_descriptor
int m_descriptor
Definition: FileDescriptor.h:105
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::operator=
FileDescriptor & operator=(FileDescriptor &&other)
Move assignment operator.
Definition: FileDescriptor.cpp:49
SurgSim::Devices::FileDescriptor::~FileDescriptor
~FileDescriptor()
Destructor.
Definition: FileDescriptor.cpp:58
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::m_canWrite
bool m_canWrite
Definition: FileDescriptor.h:107
SurgSim::Devices::FileDescriptor::canRead
bool canRead() const
Determines if the file descriptor can be read from.
Definition: FileDescriptor.cpp:68
SurgSim::Devices::FileDescriptor::FileDescriptor
FileDescriptor()
Default constructor.
Definition: FileDescriptor.cpp:34
SurgSim::Devices::FileDescriptor
A wrapper for an UNIX-style integer file descriptor.
Definition: FileDescriptor.h:29
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::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::hasDataToRead
bool hasDataToRead() const
Checks whether this object has data available to be read.
Definition: FileDescriptor.cpp:132
SurgSim::Devices::FileDescriptor::canWrite
bool canWrite() const
Determines if the file descriptor can be written to.
Definition: FileDescriptor.cpp:73