This repository has been archived by the owner on Sep 7, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 32
Create interface state monitor #1579
Open
mariomaz
wants to merge
7
commits into
master
Choose a base branch
from
feature/PPM-18_create_interface_state_monitor
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
39f34be
bcl: remove timeout handling from event loop
mariomaz 05dee53
bcl: remove template parameter from event loop
mariomaz 648c47f
transport: move event loop to main function
mariomaz cf17ec8
transport: move message broker to main function
mariomaz 2736c4d
bcl: add InterfaceStateManager and its dependencies
mariomaz 5140b3c
transport: use new InterfaceStateManager
mariomaz 5016b5b
transport: remove unused code
mariomaz File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
81 changes: 81 additions & 0 deletions
81
common/beerocks/bcl/include/bcl/beerocks_event_loop_impl.h
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,81 @@ | ||
/* SPDX-License-Identifier: BSD-2-Clause-Patent | ||
* | ||
* SPDX-FileCopyrightText: 2016-2020 the prplMesh contributors (see AUTHORS.md) | ||
* | ||
* This code is subject to the terms of the BSD+Patent license. | ||
* See LICENSE file for more details. | ||
*/ | ||
|
||
#ifndef _BEEROCKS_EVENT_LOOP_IMPL_H_ | ||
#define _BEEROCKS_EVENT_LOOP_IMPL_H_ | ||
|
||
#include "beerocks_event_loop.h" | ||
|
||
#include <chrono> | ||
#include <unordered_map> | ||
|
||
namespace beerocks { | ||
|
||
/** | ||
* @brief ePoll based implementation of the EventLoop interface. | ||
* @see EventLoop | ||
* | ||
* This class uses the Linux epoll APIs for monitoring the provided file descriptors for I/O | ||
* operations. | ||
*/ | ||
class EventLoopImpl : public EventLoop { | ||
public: | ||
/** | ||
* @brief Class constructor. | ||
* | ||
* Initializes an epoll file descriptor. | ||
* | ||
* @param [in] timeout Sets the master timeout (in milliseconds) for the event loop. | ||
*/ | ||
explicit EventLoopImpl(std::chrono::milliseconds timeout = std::chrono::milliseconds::min()); | ||
|
||
/** | ||
* @brief Class destructor. | ||
*/ | ||
~EventLoopImpl() override; | ||
|
||
/** | ||
* @see EventLoop::register_handlers | ||
*/ | ||
bool register_handlers(int fd, const EventHandlers &handlers) override; | ||
|
||
/** | ||
* @see EventLoop::remove_handlers | ||
*/ | ||
bool remove_handlers(int fd) override; | ||
|
||
/** | ||
* @brief Main event loop method. | ||
* @see EventLoop::run | ||
* | ||
* Executes the epoll_wait() function and processes occurred events. | ||
*/ | ||
int run() override; | ||
|
||
private: | ||
/** | ||
* epoll file descriptor. | ||
*/ | ||
int m_epoll_fd = -1; | ||
|
||
/** | ||
* Event loop master timeout (used for the epoll_wait function). | ||
*/ | ||
std::chrono::milliseconds m_timeout = std::chrono::milliseconds::min(); | ||
|
||
/** | ||
* Map of registered event handlers. | ||
* Key value is the file descriptor and value is the EventHandlers structure containing the | ||
* event handlers to deall with events occurred on that file descriptor. | ||
*/ | ||
std::unordered_map<int, EventHandlers> m_fd_to_event_handlers; | ||
}; | ||
|
||
} // namespace beerocks | ||
|
||
#endif // _BEEROCKS_EVENT_LOOP_IMPL_H_ |
108 changes: 0 additions & 108 deletions
108
common/beerocks/bcl/include/bcl/beerocks_socket_event_loop.h
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
/* SPDX-License-Identifier: BSD-2-Clause-Patent | ||
* | ||
* SPDX-FileCopyrightText: 2020 the prplMesh contributors (see AUTHORS.md) | ||
* | ||
* This code is subject to the terms of the BSD+Patent license. | ||
* See LICENSE file for more details. | ||
*/ | ||
|
||
#ifndef BCL_NETWORK_FILE_DESCRIPTOR_H_ | ||
#define BCL_NETWORK_FILE_DESCRIPTOR_H_ | ||
|
||
namespace beerocks { | ||
namespace net { | ||
|
||
/** | ||
* This interface models OS resources implementing the file descriptor interface. | ||
*/ | ||
class FileDescriptor { | ||
public: | ||
static constexpr int invalid_descriptor = -1; | ||
|
||
virtual ~FileDescriptor() = default; | ||
|
||
/** | ||
* @brief Returns the file descriptor. | ||
* | ||
* A file descriptor is a number that uniquely identifies an open file in the OS. | ||
* | ||
* @return File descriptor. | ||
*/ | ||
virtual int fd() = 0; | ||
}; | ||
|
||
} // namespace net | ||
} // namespace beerocks | ||
|
||
#endif /* BCL_NETWORK_FILE_DESCRIPTOR_H_ */ |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do we have to register all handlers at once?
Do we need ability to register/remove a single handler? Does underlying interface prevent us from doing that?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
EventHandlers
is a struct containing severalEventHandler
functions (on_read, on_write, on_error, ...). Methodregister_handlers
registers all of them at once. This way the method can check if handlers have already been installed or not.I cannot think of a situation where we would want to register/remove a single handler but that's possible by passing a
EventHandlers
struct with its members set accordingly. You can callregister_handlers
as many times as you want, provided you callremove_handlers
in between.