-
Notifications
You must be signed in to change notification settings - Fork 52
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added a generic backend monitor for the event loop to monitor user-sp…
…ecific events
- Loading branch information
Showing
12 changed files
with
398 additions
and
25 deletions.
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,98 @@ | ||
/*********************************************************************** | ||
* backend_monitor.cpp - Monitoring general objects * | ||
* * | ||
* This file is part of the FINAL CUT widget toolkit * | ||
* * | ||
* Copyright 2023 Markus Gans * | ||
* * | ||
* FINAL CUT is free software; you can redistribute it and/or modify * | ||
* it under the terms of the GNU Lesser General Public License as * | ||
* published by the Free Software Foundation; either version 3 of * | ||
* the License, or (at your option) any later version. * | ||
* * | ||
* FINAL CUT is distributed in the hope that it will be useful, but * | ||
* WITHOUT ANY WARRANTY; without even the implied warranty of * | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * | ||
* GNU Lesser General Public License for more details. * | ||
* * | ||
* You should have received a copy of the GNU Lesser General Public * | ||
* License along with this program. If not, see * | ||
* <http://www.gnu.org/licenses/>. * | ||
***********************************************************************/ | ||
|
||
#include <unistd.h> | ||
|
||
#include "final/eventloop/eventloop_functions.h" | ||
#include "final/eventloop/eventloop.h" | ||
#include "final/eventloop/backend_monitor.h" | ||
#include "final/util/fsystem.h" | ||
|
||
namespace finalcut | ||
{ | ||
|
||
//---------------------------------------------------------------------- | ||
// class BackendMonitor | ||
//---------------------------------------------------------------------- | ||
|
||
// constructors and destructor | ||
//---------------------------------------------------------------------- | ||
BackendMonitor::BackendMonitor (EventLoop* eloop) | ||
: Monitor(eloop) | ||
{ } | ||
|
||
//---------------------------------------------------------------------- | ||
BackendMonitor::~BackendMonitor() noexcept // destructor | ||
{ | ||
// Close pipe file descriptors | ||
static const auto& fsystem = FSystem::getInstance(); | ||
(void)fsystem->close(self_pipe.getReadFd()); | ||
(void)fsystem->close(self_pipe.getWriteFd()); | ||
} | ||
|
||
// public methods of BackendMonitor | ||
//---------------------------------------------------------------------- | ||
void BackendMonitor::setEvent() noexcept | ||
{ | ||
// The event loop is notified by write access to the pipe | ||
uint64_t buffer{1U}; | ||
auto successful = ::write ( self_pipe.getWriteFd() | ||
, &buffer, sizeof(buffer) ) > 0; | ||
|
||
if ( ! successful ) | ||
{ | ||
// Possible error handling | ||
} | ||
} | ||
|
||
//---------------------------------------------------------------------- | ||
void BackendMonitor::clearEvent() noexcept | ||
{ | ||
drainPipe(getFileDescriptor()); | ||
} | ||
|
||
//---------------------------------------------------------------------- | ||
void BackendMonitor::trigger (short return_events) | ||
{ | ||
clearEvent(); | ||
Monitor::trigger(return_events); | ||
} | ||
|
||
|
||
// private methods of BackendMonitor | ||
//---------------------------------------------------------------------- | ||
void BackendMonitor::init() | ||
{ | ||
static const auto& fsystem = FSystem::getInstance(); | ||
setEvents (POLLIN); | ||
|
||
// Set up pipe for notification | ||
if ( fsystem->pipe(self_pipe) != 0 ) | ||
{ | ||
throw monitor_error{"No pipe could be set up for the signal monitor."}; | ||
} | ||
|
||
setFileDescriptor(self_pipe.getReadFd()); // Read end of pipe | ||
setInitialized(); | ||
} | ||
|
||
} // namespace finalcut |
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,114 @@ | ||
/*********************************************************************** | ||
* backend_monitor.h - Monitoring general objects * | ||
* * | ||
* This file is part of the FINAL CUT widget toolkit * | ||
* * | ||
* Copyright 2023 Markus Gans * | ||
* * | ||
* FINAL CUT is free software; you can redistribute it and/or modify * | ||
* it under the terms of the GNU Lesser General Public License as * | ||
* published by the Free Software Foundation; either version 3 of * | ||
* the License, or (at your option) any later version. * | ||
* * | ||
* FINAL CUT is distributed in the hope that it will be useful, but * | ||
* WITHOUT ANY WARRANTY; without even the implied warranty of * | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * | ||
* GNU Lesser General Public License for more details. * | ||
* * | ||
* You should have received a copy of the GNU Lesser General Public * | ||
* License along with this program. If not, see * | ||
* <http://www.gnu.org/licenses/>. * | ||
***********************************************************************/ | ||
|
||
/* Inheritance diagram | ||
* ═══════════════════ | ||
* | ||
* ▕▔▔▔▔▔▔▔▔▔▏ | ||
* ▕ Monitor ▏ | ||
* ▕▁▁▁▁▁▁▁▁▁▏ | ||
* ▲ | ||
* │ | ||
* ▕▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▏1 1▕▔▔▔▔▔▔▔▔▔▔▏ | ||
* ▕ BackendMonitor ▏- - - - -▕ PipeData ▏ | ||
* ▕▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▏ ▕▁▁▁▁▁▁▁▁▁▁▏ | ||
*/ | ||
|
||
#ifndef BACKEND_MONITOR_H | ||
#define BACKEND_MONITOR_H | ||
|
||
#include "final/eventloop/monitor.h" | ||
#include "final/eventloop/pipedata.h" | ||
#include "final/util/fstring.h" | ||
|
||
namespace finalcut | ||
{ | ||
|
||
//---------------------------------------------------------------------- | ||
// class BackendMonitor | ||
//---------------------------------------------------------------------- | ||
|
||
class BackendMonitor final : public Monitor | ||
{ | ||
public: | ||
explicit BackendMonitor (EventLoop*); | ||
|
||
// Disable default constructor | ||
BackendMonitor() = delete; | ||
|
||
// Disable copy constructor | ||
BackendMonitor(const BackendMonitor&) = delete; | ||
|
||
// Disable move constructor | ||
BackendMonitor(const BackendMonitor&&) = delete; | ||
|
||
// Destructor | ||
~BackendMonitor() noexcept override; | ||
|
||
// Accessor | ||
auto getClassName() const -> FString override; | ||
|
||
// Mutator | ||
void setEvent() noexcept; | ||
|
||
// Methods | ||
template <typename T> | ||
void init (handler_t, T&&); | ||
void trigger (short) override; | ||
|
||
private: | ||
// Disable copy assignment operator (=) | ||
auto operator = (const BackendMonitor&) -> BackendMonitor& = delete; | ||
|
||
// Disable move assignment operator (=) | ||
auto operator = (BackendMonitor&&) noexcept -> BackendMonitor& = delete; | ||
|
||
// Mutator | ||
void clearEvent() noexcept; | ||
|
||
// Methods | ||
void init(); | ||
|
||
// Data members | ||
PipeData self_pipe{NO_FILE_DESCRIPTOR, NO_FILE_DESCRIPTOR}; | ||
}; | ||
|
||
// BackendMonitor inline functions | ||
//---------------------------------------------------------------------- | ||
inline auto BackendMonitor::getClassName() const -> FString | ||
{ return "BackendMonitor"; } | ||
|
||
//---------------------------------------------------------------------- | ||
template <typename T> | ||
inline void BackendMonitor::init (handler_t hdl, T&& uc) | ||
{ | ||
if ( isInitialized() ) | ||
throw monitor_error{"This instance has already been initialised."}; | ||
|
||
setHandler (std::move(hdl)); | ||
setUserContext (std::forward<T>(uc)); | ||
init(); | ||
} | ||
|
||
} // namespace finalcut | ||
|
||
#endif // BACKEND_MONITOR_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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -36,7 +36,6 @@ | |
#ifndef SIGNAL_MONITOR_H | ||
#define SIGNAL_MONITOR_H | ||
|
||
#include <array> | ||
#include <map> | ||
#include <memory> | ||
|
||
|
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
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
Oops, something went wrong.