pub struct Plugin<State> { /* private fields */ }
Implementations§
Source§impl<State> Plugin<State>
impl<State> Plugin<State>
Sourcepub fn new(state: State, fullpath: &str) -> Box<Plugin<State>>
pub fn new(state: State, fullpath: &str) -> Box<Plugin<State>>
Examples found in repository?
examples/basic_host.rs (line 18)
12fn main() {
13 let mut plugin_name = env::current_exe().expect("Failed to get current path");
14 println!("Path of this executable is: {}", plugin_name.display());
15 plugin_name.set_file_name("libbasic_guest.so");
16 // build the libbasic_guest.so file from the samples of cr.h
17 println!("Call cr_plugin_load(ctx, {:?})", plugin_name);
18 let mut plugin = BasicPlugin::new(BasicState { counter: 0 }, plugin_name.to_str().unwrap());
19
20 let mut err_cnt = 0;
21 loop {
22 println!("Run Update:");
23 let rc = plugin.update(true);
24 println!("cr_plugin_update(ctx, true) = {}", rc);
25 if rc != 0 {
26 println!("Plugin error: {:?}", plugin.get_failure());
27 err_cnt += 1;
28 if err_cnt > 10 {
29 break;
30 }
31 }
32 thread::sleep(Duration::from_millis(200));
33 }
34 println!("Call cr_plugin_close(ctx)");
35 drop(plugin);
36 println!("exit");
37}
More examples
examples/basic_guest.rs (line 21)
15pub fn plugin_main(ctx: &mut BasicPlugin, cr_op: cr::cr_op) -> i32 {
16 // Test "guest" feature.
17 #[cfg(not(feature = "guest"))]
18 {
19 println!("Guest compiled with host-side code.");
20 // This code will only run if the "guest" feature is not used.
21 let plugin = BasicPlugin::new(BasicState { counter: 0 }, "test");
22 println!("- plugin = {:?}", plugin);
23 }
24
25 println!("test recompile. test1");
26 //panic!("test");
27 // Test crash.
28 // Rollback to the previous version seems to work once.
29 // Then on the next reload it gets stuck in a setjmp/longjmp loop?
30 /*
31 unsafe {
32 let ptr
33 = std::ptr::null_mut() as *mut std::os::raw::c_int;
34 // invalid read.
35 println!("Read from null pointer: {:?}", *ptr);
36 // invalid write.
37 *ptr = 0x1234;
38 }
39 // */
40 match cr_op {
41 CR_LOAD => {
42 println!("Plugin load. version = {}", ctx.get_version());
43 }
44 CR_STEP => {
45 let version = ctx.get_version();
46 let state = ctx.state_mut();
47 state.counter += 1;
48 println!(
49 "Plugin step. count = {}. version = {}",
50 state.counter, version
51 );
52
53 // slow down the printing.
54 thread::sleep(Duration::from_millis(200));
55 }
56 CR_UNLOAD => {
57 println!("Plugin unload. version = {}", ctx.get_version());
58 }
59 CR_CLOSE => {
60 println!("Plugin close. version = {}", ctx.get_version());
61 }
62 }
63
64 return 0;
65}
pub fn from_ctx(ctx: &mut cr_plugin) -> &mut Plugin<State>
pub fn set_temporary_path(&mut self, path: &str)
Sourcepub fn update(&mut self, reload_check: bool) -> i32
pub fn update(&mut self, reload_check: bool) -> i32
Examples found in repository?
examples/basic_host.rs (line 23)
12fn main() {
13 let mut plugin_name = env::current_exe().expect("Failed to get current path");
14 println!("Path of this executable is: {}", plugin_name.display());
15 plugin_name.set_file_name("libbasic_guest.so");
16 // build the libbasic_guest.so file from the samples of cr.h
17 println!("Call cr_plugin_load(ctx, {:?})", plugin_name);
18 let mut plugin = BasicPlugin::new(BasicState { counter: 0 }, plugin_name.to_str().unwrap());
19
20 let mut err_cnt = 0;
21 loop {
22 println!("Run Update:");
23 let rc = plugin.update(true);
24 println!("cr_plugin_update(ctx, true) = {}", rc);
25 if rc != 0 {
26 println!("Plugin error: {:?}", plugin.get_failure());
27 err_cnt += 1;
28 if err_cnt > 10 {
29 break;
30 }
31 }
32 thread::sleep(Duration::from_millis(200));
33 }
34 println!("Call cr_plugin_close(ctx)");
35 drop(plugin);
36 println!("exit");
37}
Sourcepub fn get_version(&self) -> u32
pub fn get_version(&self) -> u32
Examples found in repository?
examples/basic_guest.rs (line 42)
15pub fn plugin_main(ctx: &mut BasicPlugin, cr_op: cr::cr_op) -> i32 {
16 // Test "guest" feature.
17 #[cfg(not(feature = "guest"))]
18 {
19 println!("Guest compiled with host-side code.");
20 // This code will only run if the "guest" feature is not used.
21 let plugin = BasicPlugin::new(BasicState { counter: 0 }, "test");
22 println!("- plugin = {:?}", plugin);
23 }
24
25 println!("test recompile. test1");
26 //panic!("test");
27 // Test crash.
28 // Rollback to the previous version seems to work once.
29 // Then on the next reload it gets stuck in a setjmp/longjmp loop?
30 /*
31 unsafe {
32 let ptr
33 = std::ptr::null_mut() as *mut std::os::raw::c_int;
34 // invalid read.
35 println!("Read from null pointer: {:?}", *ptr);
36 // invalid write.
37 *ptr = 0x1234;
38 }
39 // */
40 match cr_op {
41 CR_LOAD => {
42 println!("Plugin load. version = {}", ctx.get_version());
43 }
44 CR_STEP => {
45 let version = ctx.get_version();
46 let state = ctx.state_mut();
47 state.counter += 1;
48 println!(
49 "Plugin step. count = {}. version = {}",
50 state.counter, version
51 );
52
53 // slow down the printing.
54 thread::sleep(Duration::from_millis(200));
55 }
56 CR_UNLOAD => {
57 println!("Plugin unload. version = {}", ctx.get_version());
58 }
59 CR_CLOSE => {
60 println!("Plugin close. version = {}", ctx.get_version());
61 }
62 }
63
64 return 0;
65}
Sourcepub fn get_failure(&self) -> cr_failure
pub fn get_failure(&self) -> cr_failure
Examples found in repository?
examples/basic_host.rs (line 26)
12fn main() {
13 let mut plugin_name = env::current_exe().expect("Failed to get current path");
14 println!("Path of this executable is: {}", plugin_name.display());
15 plugin_name.set_file_name("libbasic_guest.so");
16 // build the libbasic_guest.so file from the samples of cr.h
17 println!("Call cr_plugin_load(ctx, {:?})", plugin_name);
18 let mut plugin = BasicPlugin::new(BasicState { counter: 0 }, plugin_name.to_str().unwrap());
19
20 let mut err_cnt = 0;
21 loop {
22 println!("Run Update:");
23 let rc = plugin.update(true);
24 println!("cr_plugin_update(ctx, true) = {}", rc);
25 if rc != 0 {
26 println!("Plugin error: {:?}", plugin.get_failure());
27 err_cnt += 1;
28 if err_cnt > 10 {
29 break;
30 }
31 }
32 thread::sleep(Duration::from_millis(200));
33 }
34 println!("Call cr_plugin_close(ctx)");
35 drop(plugin);
36 println!("exit");
37}
pub fn state(&self) -> &State
Sourcepub fn state_mut(&mut self) -> &mut State
pub fn state_mut(&mut self) -> &mut State
Examples found in repository?
examples/basic_guest.rs (line 46)
15pub fn plugin_main(ctx: &mut BasicPlugin, cr_op: cr::cr_op) -> i32 {
16 // Test "guest" feature.
17 #[cfg(not(feature = "guest"))]
18 {
19 println!("Guest compiled with host-side code.");
20 // This code will only run if the "guest" feature is not used.
21 let plugin = BasicPlugin::new(BasicState { counter: 0 }, "test");
22 println!("- plugin = {:?}", plugin);
23 }
24
25 println!("test recompile. test1");
26 //panic!("test");
27 // Test crash.
28 // Rollback to the previous version seems to work once.
29 // Then on the next reload it gets stuck in a setjmp/longjmp loop?
30 /*
31 unsafe {
32 let ptr
33 = std::ptr::null_mut() as *mut std::os::raw::c_int;
34 // invalid read.
35 println!("Read from null pointer: {:?}", *ptr);
36 // invalid write.
37 *ptr = 0x1234;
38 }
39 // */
40 match cr_op {
41 CR_LOAD => {
42 println!("Plugin load. version = {}", ctx.get_version());
43 }
44 CR_STEP => {
45 let version = ctx.get_version();
46 let state = ctx.state_mut();
47 state.counter += 1;
48 println!(
49 "Plugin step. count = {}. version = {}",
50 state.counter, version
51 );
52
53 // slow down the printing.
54 thread::sleep(Duration::from_millis(200));
55 }
56 CR_UNLOAD => {
57 println!("Plugin unload. version = {}", ctx.get_version());
58 }
59 CR_CLOSE => {
60 println!("Plugin close. version = {}", ctx.get_version());
61 }
62 }
63
64 return 0;
65}
Trait Implementations§
Auto Trait Implementations§
impl<State> Freeze for Plugin<State>where
State: Freeze,
impl<State> RefUnwindSafe for Plugin<State>where
State: RefUnwindSafe,
impl<State> !Send for Plugin<State>
impl<State> !Sync for Plugin<State>
impl<State> Unpin for Plugin<State>where
State: Unpin,
impl<State> UnwindSafe for Plugin<State>where
State: UnwindSafe,
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more