-
Notifications
You must be signed in to change notification settings - Fork 14
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #46 from robotpy/before-after-cb
Add wrapper for HALSIM_RegisterSimPeriodic{Before,After}Callback
- Loading branch information
Showing
3 changed files
with
71 additions
and
2 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
|
||
#pragma once | ||
|
||
class SimCB { | ||
public: | ||
|
||
SimCB(std::function<void(void)> fn, std::function<void(int32_t)> cancel) : | ||
m_fn(fn), | ||
m_cancel(cancel) | ||
{} | ||
|
||
void SetUID(int32_t uid) { | ||
m_uid = uid; | ||
} | ||
|
||
~SimCB() { | ||
Cancel(); | ||
} | ||
|
||
void Cancel() { | ||
if (m_valid) { | ||
m_cancel(m_uid); | ||
m_valid = false; | ||
} | ||
} | ||
|
||
std::function<void(void)> m_fn; | ||
|
||
private: | ||
bool m_valid = true; | ||
int32_t m_uid; | ||
std::function<void(int32_t)> m_cancel; | ||
}; |