JavaScript is disabled, refresh for a better experience. ambee/giterated

ambee/giterated

Git repository hosting, collaboration, and discovery for the Fediverse.

So. Much. Work.

Amber - ⁨2⁩ years ago

parent: tbd commit: ⁨b05f964

⁨giterated-plugins/example-plugin/src/main.rs⁩ - ⁨1875⁩ bytes
Raw
1 use dlopen2::wrapper::Container;
2 use giterated_models::{
3 instance::Instance,
4 object::{GiteratedObject, ObjectRequest},
5 operation::GiteratedOperation,
6 settings::{GetSetting, Setting},
7 user::{DisplayName, User},
8 value::GetValue,
9 };
10 use giterated_plugin::{handle::PluginHandle, new_stack::Runtime, GiteratedPluginApi};
11 use tracing::{info, Level};
12
13 fn main() {
14 tracing_subscriber::fmt()
15 .pretty()
16 .with_thread_names(true)
17 .with_max_level(Level::TRACE)
18 .init();
19
20 let mut handle = PluginHandle::from_dylib("example_plugin_dylib.dll").unwrap();
21
22 let mut runtime = Runtime::default();
23
24 runtime.insert_plugin(handle);
25
26 let object_request = ObjectRequest(String::from("foobar"));
27
28 match runtime.handle(
29 Instance::object_name(),
30 ObjectRequest::operation_name(),
31 "meow",
32 &serde_json::to_vec(&object_request).unwrap(),
33 ) {
34 Ok(success) => info!("handler call success!"),
35 Err(_) => info!("handler call error"),
36 }
37
38 match runtime.handle(
39 User::object_name(),
40 <GetValue as GiteratedOperation<User>>::operation_name(),
41 "amber:giterated.dev",
42 &serde_json::to_vec(&GetValue {
43 value_name: String::from("display_name"),
44 })
45 .unwrap(),
46 ) {
47 Ok(success) => info!("get_value handler call success!"),
48 Err(_) => info!("get_value handler call error"),
49 }
50
51 match runtime.handle(
52 User::object_name(),
53 <GetSetting as GiteratedOperation<User>>::operation_name(),
54 "amber:giterated.dev",
55 &serde_json::to_vec(&GetSetting {
56 setting_name: DisplayName::name().to_string(),
57 })
58 .unwrap(),
59 ) {
60 Ok(success) => info!("get_setting handler call success!"),
61 Err(_) => info!("get_setting handler call error"),
62 }
63 }
64