Skip to content

C++11-ify virtualisation in FileHandle + Serials #12495

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Feb 25, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 15 additions & 15 deletions drivers/BufferedSerial.h
Original file line number Diff line number Diff line change
Expand Up @@ -80,14 +80,14 @@ class BufferedSerial:
int baud = MBED_CONF_PLATFORM_DEFAULT_SERIAL_BAUD_RATE
);

virtual ~BufferedSerial();
~BufferedSerial() override;

/** Equivalent to POSIX poll(). Derived from FileHandle.
* Provides a mechanism to multiplex input/output over a set of file
* handles.
* The events that can be reported are POLLIN, POLLOUT, POLLHUP.
*/
virtual short poll(short events) const;
short poll(short events) const final;

/* Resolve ambiguities versus our private SerialBase
* (for writable, spelling differs, but just in case)
Expand All @@ -107,7 +107,7 @@ class BufferedSerial:
* @param length The number of bytes to write
* @return The number of bytes written, negative error on failure
*/
virtual ssize_t write(const void *buffer, size_t length);
ssize_t write(const void *buffer, size_t length) override;

/** Read the contents of a file into a buffer
*
Expand All @@ -123,21 +123,21 @@ class BufferedSerial:
* @return The number of bytes read, 0 at end of file, negative
* error on failure
*/
virtual ssize_t read(void *buffer, size_t length);
ssize_t read(void *buffer, size_t length) override;

/** Close a file
*
* @return 0 on success, negative error code on failure
*/
virtual int close();
int close() override;

/** Check if the file in an interactive terminal device
*
* @return True if the file is a terminal
* @return False if the file is not a terminal
* @return Negative error code on failure
*/
virtual int isatty();
int isatty() override;

/** Move the file position to a given offset from from a given location
*
Expand All @@ -152,20 +152,20 @@ class BufferedSerial:
* @return The new offset of the file, negative error code on
* failure
*/
virtual off_t seek(off_t offset, int whence);
off_t seek(off_t offset, int whence) override;

/** Flush any buffers associated with the file
*
* @return 0 on success, negative error code on failure
*/
virtual int sync();
int sync() override;

/** Set blocking or non-blocking mode
* The default is blocking.
*
* @param blocking true for blocking mode, false for non-blocking mode.
*/
virtual int set_blocking(bool blocking)
int set_blocking(bool blocking) override
{
_blocking = blocking;
return 0;
Expand All @@ -175,7 +175,7 @@ class BufferedSerial:
*
* @return true for blocking mode, false for non-blocking mode.
*/
virtual bool is_blocking() const
bool is_blocking() const override
{
return _blocking;
}
Expand All @@ -193,7 +193,7 @@ class BufferedSerial:
* @return 0 on success
* @return Negative error code on failure
*/
virtual int enable_input(bool enabled);
int enable_input(bool enabled) override;

/** Enable or disable output
*
Expand All @@ -208,7 +208,7 @@ class BufferedSerial:
* @return 0 on success
* @return Negative error code on failure
*/
virtual int enable_output(bool enabled);
int enable_output(bool enabled) override;

/** Register a callback on state change of the file.
*
Expand All @@ -227,7 +227,7 @@ class BufferedSerial:
*
* @param func Function to call on state change
*/
virtual void sigio(Callback<void()> func);
void sigio(Callback<void()> func) override;

/** Setup interrupt handler for DCD line
*
Expand Down Expand Up @@ -288,11 +288,11 @@ class BufferedSerial:

/** Acquire mutex
*/
virtual void api_lock(void);
void api_lock(void);

/** Release mutex
*/
virtual void api_unlock(void);
void api_unlock(void);

/** Unbuffered write - invoked when write called from critical section
* @param buf_ptr The buffer to write from
Expand Down
14 changes: 7 additions & 7 deletions drivers/SerialWireOutput.h
Original file line number Diff line number Diff line change
Expand Up @@ -35,35 +35,35 @@ class SerialWireOutput : public FileHandle {

public:

SerialWireOutput(void);
SerialWireOutput();

virtual ssize_t write(const void *buffer, size_t size);
ssize_t write(const void *buffer, size_t size) override;

virtual ssize_t read(void *buffer, size_t size)
ssize_t read(void *buffer, size_t size) override
{
/* Reading is not supported by this file handle */
return -EBADF;
}

virtual off_t seek(off_t offset, int whence = SEEK_SET)
off_t seek(off_t offset, int whence = SEEK_SET) override
{
/* Seeking is not support by this file handler */
return -ESPIPE;
}

virtual off_t size()
off_t size() override
{
/* Size is not defined for this file handle */
return -EINVAL;
}

virtual int isatty()
int isatty() override
{
/* File handle is used for terminal output */
return true;
}

virtual int close()
int close() override
{
return 0;
}
Expand Down
14 changes: 7 additions & 7 deletions drivers/UnbufferedSerial.h
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ class UnbufferedSerial:
* @param size The number of bytes to write
* @return The number of bytes written
*/
virtual ssize_t write(const void *buffer, size_t size);
ssize_t write(const void *buffer, size_t size) override;

/** Read the contents of a file into a buffer
*
Expand All @@ -95,7 +95,7 @@ class UnbufferedSerial:
* @param size The number of bytes to read
* @return The number of bytes read
*/
virtual ssize_t read(void *buffer, size_t size);
ssize_t read(void *buffer, size_t size) override;

/** Move the file position to a given offset from from a given location
*
Expand All @@ -109,7 +109,7 @@ class UnbufferedSerial:
* SEEK_END to start from end of file
* @return The new offset of the file, negative error code on failure
*/
virtual off_t seek(off_t offset, int whence = SEEK_SET)
off_t seek(off_t offset, int whence = SEEK_SET) override
{
return -ESPIPE;
}
Expand All @@ -118,7 +118,7 @@ class UnbufferedSerial:
*
* @return Size of the file in bytes
*/
virtual off_t size()
off_t size() override
{
return -EINVAL;
}
Expand All @@ -129,7 +129,7 @@ class UnbufferedSerial:
* @return False if the file is not a terminal
* @return Negative error code on failure
*/
virtual int isatty()
int isatty() override
{
return true;
}
Expand All @@ -138,7 +138,7 @@ class UnbufferedSerial:
*
* @return 0 on success, negative error code on failure
*/
virtual int close()
int close() override
{
return 0;
}
Expand All @@ -153,7 +153,7 @@ class UnbufferedSerial:
*
* @returns bitmask of poll events that have occurred.
*/
virtual short poll(short events) const;
short poll(short events) const override;

using SerialBase::readable;
using SerialBase::writeable;
Expand Down
2 changes: 1 addition & 1 deletion drivers/source/SerialWireOutput.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@

namespace mbed {

SerialWireOutput::SerialWireOutput(void)
SerialWireOutput::SerialWireOutput()
{
/* Initialize ITM using internal init function. */
mbed_itm_init();
Expand Down
2 changes: 1 addition & 1 deletion platform/FileHandle.h
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ namespace mbed {
*/
class FileHandle : private NonCopyable<FileHandle> {
public:
virtual ~FileHandle() {}
virtual ~FileHandle() = default;

/** Read the contents of a file into a buffer
*
Expand Down