-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
15 changed files
with
365 additions
and
81 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
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,50 @@ | ||
#pragma once | ||
|
||
#include "Pads.h" | ||
|
||
#include <stdexcept> | ||
|
||
namespace ps | ||
{ | ||
class PiSample; | ||
|
||
/// Ensure only one component displays data on the pads at a given time. | ||
/// Only PiSample can grant access to the pads to other components. | ||
/// Access can be given and taken at any time, do not store states in the pads. | ||
class PadsAccess | ||
{ | ||
public: | ||
PadsAccess(Pads& pads) : _pads(pads) | ||
{ } | ||
|
||
protected: | ||
bool isAccessing() const { return _pads._access == this; } | ||
Pads& pads(); | ||
|
||
private: | ||
friend class PiSample; | ||
void receiveAccess(); | ||
|
||
virtual void onAccess() {}; | ||
Pads& _pads; | ||
}; | ||
|
||
inline void PadsAccess::receiveAccess() | ||
{ | ||
if (not isAccessing()) { | ||
_pads._access = this; | ||
onAccess(); | ||
} | ||
else { | ||
_pads._access = this; | ||
} | ||
} | ||
|
||
inline Pads& PadsAccess::pads() | ||
{ | ||
if (not isAccessing()) { | ||
throw std::logic_error("Trying to get pads without being given access"); | ||
} | ||
return _pads; | ||
} | ||
} |
Oops, something went wrong.