-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
switch call context to function argument
- Loading branch information
1 parent
d99361b
commit 74afe94
Showing
14 changed files
with
332 additions
and
174 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,40 @@ | ||
use std::{cell::RefCell, rc::Rc}; | ||
|
||
use crate::ContextRequest; | ||
|
||
use super::ArmaCallContext; | ||
|
||
/// Manages requesting and replacing the ArmaCallContext | ||
pub struct ArmaContextManager { | ||
pub(crate) request: RefCell<ContextRequest>, | ||
state: Rc<RefCell<Option<ArmaCallContext>>>, | ||
} | ||
|
||
impl ArmaContextManager { | ||
/// Create a new ArmaContextManager | ||
pub fn new(request: ContextRequest) -> Self { | ||
Self { | ||
request: RefCell::new(request), | ||
state: Rc::new(RefCell::new(None)), | ||
} | ||
} | ||
|
||
/// Request a new ArmaCallContext from Arma | ||
pub fn request(&self) -> ArmaCallContext { | ||
// When the request is called, Arma will send the request to the extension | ||
// The extension will set the state to the request it just received | ||
unsafe { | ||
(self.request.borrow())(); | ||
} | ||
// When the request function returns, the state has been set by Arma | ||
// It can now be taken and sent to the Context | ||
self.state | ||
.replace(None) | ||
.expect("Arma should've set the state") | ||
} | ||
|
||
/// Replace the current ArmaCallContext with a new one | ||
pub fn replace(&self, value: Option<ArmaCallContext>) { | ||
*self.state.borrow_mut() = value; | ||
} | ||
} |
Oops, something went wrong.