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

ambee/giterated

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

no clue what this is

Amber - ⁨1⁩ year ago

parent: tbd commit: ⁨7889bf6

Showing ⁨⁨23⁩ changed files⁩ with ⁨⁨397⁩ insertions⁩ and ⁨⁨113⁩ deletions⁩

Cargo.lock

View file
@@ -224,6 +224,12 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
224 224 checksum = "514de17de45fdb8dc022b1a7975556c53c86f9f0aa5f534b98977b171857c2c9"
225 225
226 226 [[package]]
227 name = "c_linked_list"
228 version = "1.1.1"
229 source = "registry+https://github.com/rust-lang/crates.io-index"
230 checksum = "4964518bd3b4a8190e832886cdc0da9794f12e8e6c1613a9e90ff331c4c8724b"
231
232 [[package]]
227 233 name = "cc"
228 234 version = "1.0.92"
229 235 source = "registry+https://github.com/rust-lang/crates.io-index"
@@ -695,6 +701,7 @@ version = "0.1.0"
695 701 dependencies = [
696 702 "anyhow",
697 703 "async-trait",
704 "c_linked_list",
698 705 "dlopen2",
699 706 "giterated-models",
700 707 ]
@@ -864,6 +871,7 @@ dependencies = [
864 871 "giterated-abi",
865 872 "giterated-core",
866 873 "giterated-models",
874 "giterated-static-runtime",
867 875 "tracing",
868 876 ]
869 877

giterated-core/giterated-models/src/instance/operations.rs

View file
@@ -104,13 +104,13 @@ impl GiteratedOperation<Instance> for RepositoryCreateRequest {
104 104 type Failure = InstanceError;
105 105 }
106 106
107 impl<B: ObjectBackend + std::fmt::Debug> Object<Instance, B> {
107 impl<B: ObjectBackend<OS> + std::fmt::Debug, OS> Object<Instance, B, OS> {
108 108 pub async fn register_account(
109 109 &mut self,
110 110 email: Option<&str>,
111 111 username: &str,
112 112 password: &Secret<Password>,
113 operation_state: &OperationState,
113 operation_state: &mut OS,
114 114 ) -> Result<UserAuthenticationToken, OperationError<InstanceError>> {
115 115 self.request::<RegisterAccountRequest>(
116 116 RegisterAccountRequest {
@@ -127,7 +127,7 @@ impl<B: ObjectBackend + std::fmt::Debug> Object<Instance, B> {
127 127 &mut self,
128 128 username: &str,
129 129 password: &Secret<Password>,
130 operation_state: &OperationState,
130 operation_state: &mut OS,
131 131 ) -> Result<UserAuthenticationToken, OperationError<InstanceError>> {
132 132 self.request::<AuthenticationTokenRequest>(
133 133 AuthenticationTokenRequest {
@@ -145,7 +145,7 @@ impl<B: ObjectBackend + std::fmt::Debug> Object<Instance, B> {
145 145 instance: &Instance,
146 146 username: &str,
147 147 password: &Secret<Password>,
148 operation_state: &OperationState,
148 operation_state: &mut OS,
149 149 ) -> Result<UserAuthenticationToken, OperationError<InstanceError>> {
150 150 self.request::<AuthenticationTokenRequest>(
151 151 AuthenticationTokenRequest {
@@ -161,7 +161,7 @@ impl<B: ObjectBackend + std::fmt::Debug> Object<Instance, B> {
161 161 pub async fn token_extension(
162 162 &mut self,
163 163 token: &UserAuthenticationToken,
164 operation_state: &OperationState,
164 operation_state: &mut OS,
165 165 ) -> Result<Option<UserAuthenticationToken>, OperationError<InstanceError>> {
166 166 self.request::<TokenExtensionRequest>(
167 167 TokenExtensionRequest {
@@ -179,7 +179,7 @@ impl<B: ObjectBackend + std::fmt::Debug> Object<Instance, B> {
179 179 visibility: &RepositoryVisibility,
180 180 default_branch: &str,
181 181 owner: &User,
182 operation_state: &OperationState,
182 operation_state: &mut OS,
183 183 ) -> Result<Repository, OperationError<InstanceError>> {
184 184 self.request::<RepositoryCreateRequest>(
185 185 RepositoryCreateRequest {

giterated-core/giterated-models/src/object.rs

View file
@@ -1,5 +1,6 @@
1 1 use std::{
2 2 fmt::{Debug, Display},
3 marker::PhantomData,
3 4 str::FromStr,
4 5 };
5 6
@@ -17,26 +18,28 @@ mod operations;
17 18 pub use operations::*;
18 19
19 20 #[derive(Debug, Clone)]
20 pub struct Object<O: GiteratedObject, B: ObjectBackend + Send + Clone> {
21 pub struct Object<O: GiteratedObject, B: ObjectBackend<OS> + Send + Clone, OS> {
21 22 pub(crate) inner: O,
22 23 pub(crate) backend: B,
24 _marker: PhantomData<OS>,
23 25 }
24 26
25 impl<B: ObjectBackend + Send + Sync + Clone, O: GiteratedObject> Object<O, B> {
27 impl<B: ObjectBackend<OS> + Send + Sync + Clone, O: GiteratedObject, OS> Object<O, B, OS> {
26 28 pub fn object(&self) -> &O {
27 29 &self.inner
28 30 }
29 31
30 pub unsafe fn new_unchecked(object: O, backend: B) -> Object<O, B> {
32 pub unsafe fn new_unchecked(object: O, backend: B) -> Object<O, B, OS> {
31 33 Object {
32 34 inner: object,
33 35 backend,
36 _marker: PhantomData,
34 37 }
35 38 }
36 39 }
37 40
38 impl<O: GiteratedObject + Display, B: ObjectBackend + Send + Sync + Clone> Display
39 for Object<O, B>
41 impl<O: GiteratedObject + Display, B: ObjectBackend<OS> + Send + Sync + Clone, OS> Display
42 for Object<O, B, OS>
40 43 {
41 44 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
42 45 self.inner.fmt(f)
@@ -50,10 +53,10 @@ pub trait GiteratedObject: Send + Display + FromStr + Sync + Clone {
50 53 fn from_object_str(object_str: &str) -> Result<Self, Error>;
51 54 }
52 55
53 impl<O: GiteratedObject + Clone + Debug + 'static, B: ObjectBackend> Object<O, B> {
56 impl<O: GiteratedObject + Clone + Debug + 'static, B: ObjectBackend<OS>, OS> Object<O, B, OS> {
54 57 pub async fn get<V: GiteratedObjectValue<Object = O> + Send + Debug + 'static>(
55 58 &mut self,
56 operation_state: &OperationState,
59 operation_state: &mut OS,
57 60 ) -> Result<V, OperationError<GetValueError>> {
58 61 let result = self
59 62 .request(
@@ -69,7 +72,7 @@ impl<O: GiteratedObject + Clone + Debug + 'static, B: ObjectBackend> Object<O, B
69 72
70 73 pub async fn get_setting<S: Setting + Send + Clone + Debug>(
71 74 &mut self,
72 operation_state: &OperationState,
75 operation_state: &mut OS,
73 76 ) -> Result<S, OperationError<GetSettingError>> {
74 77 self.request(
75 78 GetSetting {
@@ -84,7 +87,7 @@ impl<O: GiteratedObject + Clone + Debug + 'static, B: ObjectBackend> Object<O, B
84 87 pub async fn set_setting<S: Setting + Send + Clone + Debug>(
85 88 &mut self,
86 89 setting: S,
87 operation_state: &OperationState,
90 operation_state: &mut OS,
88 91 ) -> Result<(), OperationError<SetSettingError>> {
89 92 self.request(
90 93 SetSetting {
@@ -99,7 +102,7 @@ impl<O: GiteratedObject + Clone + Debug + 'static, B: ObjectBackend> Object<O, B
99 102 pub async fn request<R: GiteratedOperation<O> + Debug + 'static>(
100 103 &mut self,
101 104 request: R,
102 operation_state: &OperationState,
105 operation_state: &mut OS,
103 106 ) -> Result<R::Success, OperationError<R::Failure>>
104 107 where
105 108 R::Success: Clone,

giterated-core/giterated-models/src/object_backend.rs

View file
@@ -7,13 +7,13 @@ use crate::{
7 7 use std::fmt::Debug;
8 8
9 9 #[async_trait::async_trait(?Send)]
10 pub trait ObjectBackend: Sized + Clone + Send {
10 pub trait ObjectBackend<OS>: Sized + Clone + Send {
11 11 async fn object_operation<O, D>(
12 12 &self,
13 13 object: O,
14 14 operation: &str,
15 15 payload: D,
16 operation_state: &OperationState,
16 operation_state: &mut OS,
17 17 ) -> Result<D::Success, OperationError<D::Failure>>
18 18 where
19 19 O: GiteratedObject + Debug + 'static,
@@ -24,6 +24,6 @@ pub trait ObjectBackend: Sized + Clone + Send {
24 24 async fn get_object<O: GiteratedObject + Debug + 'static>(
25 25 &self,
26 26 object_str: &str,
27 operation_state: &OperationState,
28 ) -> Result<Object<O, Self>, OperationError<ObjectRequestError>>;
27 operation_state: &mut OS,
28 ) -> Result<Object<O, Self, OS>, OperationError<ObjectRequestError>>;
29 29 }

giterated-core/giterated-models/src/repository/operations.rs

View file
@@ -271,13 +271,13 @@ impl GiteratedOperation<Repository> for RepositoryBranchesRequest {
271 271 type Failure = RepositoryError;
272 272 }
273 273
274 impl<B: ObjectBackend + std::fmt::Debug> Object<Repository, B> {
274 impl<B: ObjectBackend<OS> + std::fmt::Debug, OS> Object<Repository, B, OS> {
275 275 pub async fn info(
276 276 &mut self,
277 277 extra_metadata: bool,
278 278 rev: Option<String>,
279 279 path: Option<String>,
280 operation_state: &OperationState,
280 operation_state: &mut OS,
281 281 ) -> Result<RepositoryView, OperationError<RepositoryError>> {
282 282 self.request::<RepositoryInfoRequest>(
283 283 RepositoryInfoRequest {
@@ -293,7 +293,7 @@ impl<B: ObjectBackend + std::fmt::Debug> Object<Repository, B> {
293 293 pub async fn file_from_id(
294 294 &mut self,
295 295 id: String,
296 operation_state: &OperationState,
296 operation_state: &mut OS,
297 297 ) -> Result<RepositoryFile, OperationError<RepositoryError>> {
298 298 self.request::<RepositoryFileFromIdRequest>(
299 299 RepositoryFileFromIdRequest(id),
@@ -306,7 +306,7 @@ impl<B: ObjectBackend + std::fmt::Debug> Object<Repository, B> {
306 306 &mut self,
307 307 rev: Option<String>,
308 308 path: String,
309 operation_state: &OperationState,
309 operation_state: &mut OS,
310 310 ) -> Result<(RepositoryFile, String), OperationError<RepositoryError>> {
311 311 self.request::<RepositoryFileFromPathRequest>(
312 312 RepositoryFileFromPathRequest { rev, path },
@@ -319,7 +319,7 @@ impl<B: ObjectBackend + std::fmt::Debug> Object<Repository, B> {
319 319 &mut self,
320 320 start_commit: String,
321 321 path: String,
322 operation_state: &OperationState,
322 operation_state: &mut OS,
323 323 ) -> Result<Commit, OperationError<RepositoryError>> {
324 324 self.request::<RepositoryLastCommitOfFileRequest>(
325 325 RepositoryLastCommitOfFileRequest { start_commit, path },
@@ -331,7 +331,7 @@ impl<B: ObjectBackend + std::fmt::Debug> Object<Repository, B> {
331 331 pub async fn commit_by_id(
332 332 &mut self,
333 333 id: String,
334 operation_state: &OperationState,
334 operation_state: &mut OS,
335 335 ) -> Result<Commit, OperationError<RepositoryError>> {
336 336 self.request::<RepositoryCommitFromIdRequest>(
337 337 RepositoryCommitFromIdRequest(id),
@@ -344,7 +344,7 @@ impl<B: ObjectBackend + std::fmt::Debug> Object<Repository, B> {
344 344 &mut self,
345 345 old_id: String,
346 346 new_id: String,
347 operation_state: &OperationState,
347 operation_state: &mut OS,
348 348 ) -> Result<RepositoryDiff, OperationError<RepositoryError>> {
349 349 self.request::<RepositoryDiffRequest>(
350 350 RepositoryDiffRequest { old_id, new_id },
@@ -357,7 +357,7 @@ impl<B: ObjectBackend + std::fmt::Debug> Object<Repository, B> {
357 357 &mut self,
358 358 old_id: String,
359 359 new_id: String,
360 operation_state: &OperationState,
360 operation_state: &mut OS,
361 361 ) -> Result<String, OperationError<RepositoryError>> {
362 362 self.request::<RepositoryDiffPatchRequest>(
363 363 RepositoryDiffPatchRequest { old_id, new_id },
@@ -369,7 +369,7 @@ impl<B: ObjectBackend + std::fmt::Debug> Object<Repository, B> {
369 369 pub async fn commit_before(
370 370 &mut self,
371 371 id: String,
372 operation_state: &OperationState,
372 operation_state: &mut OS,
373 373 ) -> Result<Commit, OperationError<RepositoryError>> {
374 374 self.request::<RepositoryCommitBeforeRequest>(
375 375 RepositoryCommitBeforeRequest(id),
@@ -381,7 +381,7 @@ impl<B: ObjectBackend + std::fmt::Debug> Object<Repository, B> {
381 381 pub async fn statistics(
382 382 &mut self,
383 383 rev: Option<String>,
384 operation_state: &OperationState,
384 operation_state: &mut OS,
385 385 ) -> Result<RepositoryStatistics, OperationError<RepositoryError>> {
386 386 self.request::<RepositoryStatisticsRequest>(
387 387 RepositoryStatisticsRequest { rev },
@@ -392,7 +392,7 @@ impl<B: ObjectBackend + std::fmt::Debug> Object<Repository, B> {
392 392
393 393 pub async fn branches(
394 394 &mut self,
395 operation_state: &OperationState,
395 operation_state: &mut OS,
396 396 ) -> Result<Vec<RepositoryBranch>, OperationError<RepositoryError>> {
397 397 self.request::<RepositoryBranchesRequest>(RepositoryBranchesRequest, operation_state)
398 398 .await
@@ -405,7 +405,7 @@ impl<B: ObjectBackend + std::fmt::Debug> Object<Repository, B> {
405 405
406 406 pub async fn issue_labels(
407 407 &mut self,
408 operation_state: &OperationState,
408 operation_state: &mut OS,
409 409 ) -> Result<Vec<IssueLabel>, OperationError<RepositoryError>> {
410 410 self.request::<RepositoryIssueLabelsRequest>(RepositoryIssueLabelsRequest, operation_state)
411 411 .await
@@ -413,7 +413,7 @@ impl<B: ObjectBackend + std::fmt::Debug> Object<Repository, B> {
413 413
414 414 pub async fn issues(
415 415 &mut self,
416 operation_state: &OperationState,
416 operation_state: &mut OS,
417 417 ) -> Result<Vec<RepositoryIssue>, OperationError<RepositoryError>> {
418 418 self.request::<RepositoryIssuesRequest>(RepositoryIssuesRequest, operation_state)
419 419 .await
@@ -424,7 +424,7 @@ impl<B: ObjectBackend + std::fmt::Debug> Object<Repository, B> {
424 424 extra_metadata: bool,
425 425 rev: Option<&str>,
426 426 path: Option<&str>,
427 operation_state: &OperationState,
427 operation_state: &mut OS,
428 428 ) -> Result<Vec<RepositoryTreeEntry>, OperationError<RepositoryError>> {
429 429 self.request::<RepositoryFileInspectRequest>(
430 430 RepositoryFileInspectRequest {

giterated-core/giterated-models/src/user/operations.rs

View file
@@ -22,11 +22,11 @@ impl GiteratedOperation<User> for UserRepositoriesRequest {
22 22 type Failure = UserError;
23 23 }
24 24
25 impl<B: ObjectBackend + std::fmt::Debug> Object<User, B> {
25 impl<B: ObjectBackend<OS> + std::fmt::Debug, OS> Object<User, B, OS> {
26 26 pub async fn repositories(
27 27 &mut self,
28 28 instance: &Instance,
29 operation_state: &OperationState,
29 operation_state: &mut OS,
30 30 ) -> Result<Vec<RepositorySummary>, OperationError<UserError>> {
31 31 self.request::<UserRepositoriesRequest>(
32 32 UserRepositoriesRequest {

giterated-core/src/lib.rs

View file
@@ -1,4 +1,7 @@
1 use giterated_abi::vtable::{runtime::RuntimeHandle, VTable};
1 use giterated_abi::{
2 state::{State, StateUUID},
3 vtable::{runtime::RuntimeHandle, VTable},
4 };
2 5 use giterated_models::{
3 6 error::OperationError,
4 7 object::{GiteratedObject, Object, ObjectRequestError},
@@ -6,6 +9,7 @@ use giterated_models::{
6 9 operation::{GiteratedOperation, OperationState},
7 10 };
8 11 use std::fmt::Debug;
12 use types::TypeMetadata;
9 13
10 14 pub mod types;
11 15
@@ -16,13 +20,13 @@ pub struct RuntimeState {
16 20 }
17 21
18 22 #[async_trait::async_trait(?Send)]
19 impl ObjectBackend for RuntimeState {
23 impl ObjectBackend<State> for RuntimeState {
20 24 async fn object_operation<O, D>(
21 25 &self,
22 26 object: O,
23 27 operation: &str,
24 28 payload: D,
25 operation_state: &OperationState,
29 operation_state: &mut State,
26 30 ) -> Result<D::Success, OperationError<D::Failure>>
27 31 where
28 32 O: GiteratedObject + Debug + 'static,
@@ -36,8 +40,8 @@ impl ObjectBackend for RuntimeState {
36 40 async fn get_object<O: GiteratedObject + Debug + 'static>(
37 41 &self,
38 42 object_str: &str,
39 operation_state: &OperationState,
40 ) -> Result<Object<O, Self>, OperationError<ObjectRequestError>> {
43 operation_state: &mut State,
44 ) -> Result<Object<O, Self, State>, OperationError<ObjectRequestError>> {
41 45 todo!()
42 46 }
43 47 }
@@ -101,3 +105,17 @@ impl ObjectBackend for RuntimeState {
101 105 // todo!()
102 106 // }
103 107 // }
108
109 pub struct DomainMetadata(pub &'static TypeMetadata);
110
111 impl DomainMetadata {
112 pub fn from_static() -> Self {
113 DomainMetadata(unsafe { TypeMetadata::from_static() })
114 }
115 }
116
117 impl StateUUID for DomainMetadata {
118 fn uuid() -> u128 {
119 1
120 }
121 }

giterated-daemon/src/client.rs

View file
@@ -92,11 +92,11 @@ pub async fn client_wrapper(
92 92
93 93 pub async fn handle_client_message(
94 94 payload: AuthenticatedPayload,
95 operation_state: OperationState,
95 mut operation_state: giterated_plugin::abi::state::State,
96 96 runtime: RuntimeHandle,
97 97 ) -> Result<Vec<u8>, OperationError<Vec<u8>>> {
98 98 let mut networked_object = runtime
99 .get_object::<NetworkedObject>(&payload.object, &operation_state)
99 .get_object::<NetworkedObject>(&payload.object, &mut operation_state)
100 100 .await
101 101 .as_internal_error_with_context("handling client message")?;
102 102
@@ -111,6 +111,6 @@ pub async fn handle_client_message(
111 111 trace!("Calling handler for networked operation");
112 112
113 113 networked_object
114 .request(networked_operation, &operation_state)
114 .request(networked_operation, &mut operation_state)
115 115 .await
116 116 }

giterated-daemon/src/main.rs

View file
@@ -51,8 +51,6 @@ async fn main() -> Result<(), Error> {
51 51
52 52 let runtime = Runtime::new();
53 53
54 let runtime = Arc::new(runtime);
55
56 54 let pool = LocalPoolHandle::new(5);
57 55
58 56 loop {

giterated-plugin/giterated-macros/src/lib.rs

View file
@@ -32,13 +32,31 @@ fn emit_plugin_api() -> impl Into<TokenStream> {
32 32 #[doc(hidden)]
33 33 #[no_mangle]
34 34 unsafe extern "C" fn __load_runtime_vtable(vtable: &'static ::giterated_plugin::abi::vtable::VTable<::giterated_plugin::abi::vtable::runtime::RuntimeHandle>) {
35 todo!()
35 todo!("runtime vtable insertion is not implemented")
36 36 }
37 37
38 38 #[doc(hidden)]
39 39 #[no_mangle]
40 40 unsafe extern "C" fn __get_plugin_vtable() -> &'static ::giterated_plugin::abi::vtable::VTable<::giterated_plugin::abi::vtable::plugin::Plugin> {
41 todo!()
41 unsafe extern "C" fn plugin_name() -> ::giterated_plugin::abi::FfiSliceRef<str> {
42 ::giterated_plugin::abi::FfiSliceRef::static_ref("plugin name")
43 }
44
45 unsafe extern "C" fn plugin_version() -> ::giterated_plugin::abi::FfiSliceRef<str> {
46 ::giterated_plugin::abi::FfiSliceRef::static_ref("0.0.1")
47 }
48
49 unsafe extern "C" fn type_metadata() -> ::giterated_plugin::abi::value_ex::FfiValueRefUntyped {
50 todo!()
51 }
52
53 static PLUGIN_VTABLE: ::giterated_plugin::abi::vtable::plugin::PluginVTable = ::giterated_plugin::abi::vtable::plugin::PluginVTable {
54 plugin_name,
55 plugin_version,
56 type_metadata
57 };
58
59 ::giterated_plugin::abi::vtable::VTable::new(&PLUGIN_VTABLE)
42 60 }
43 61 }
44 62 }

giterated-plugin/src/domain.rs

View file
@@ -0,0 +1,10 @@
1 use giterated_abi::state::{DomainState, StateItem};
2
3 struct PluginDomainState {
4 pub metadata: StateItem<DomainState>,
5 }
6
7 /// Sources a [`DomainState`] state entry for the plugin.
8 pub fn plugin_domain_state() -> DomainState {
9 todo!()
10 }

giterated-plugin/src/lib.rs

View file
@@ -1,5 +1,6 @@
1 1 #![allow(improper_ctypes_definitions)]
2 2
3 pub mod domain;
3 4 pub mod future;
4 5 pub mod local;
5 6

giterated-runtime/Cargo.toml

View file
@@ -9,6 +9,7 @@ edition = "2021"
9 9 giterated-abi = { path = "giterated-abi" }
10 10 giterated-models = { path = "../giterated-core/giterated-models" }
11 11 giterated-core = { path = "../giterated-core" }
12 giterated-static-runtime = { path = "giterated-static-runtime" }
12 13
13 14 tracing = "0.1"
14 15 dlopen2 = "0.6"

giterated-runtime/giterated-abi/Cargo.toml

View file
@@ -10,4 +10,5 @@ giterated-models = { path = "../../giterated-core/giterated-models"}
10 10
11 11 anyhow = "1"
12 12 dlopen2 = "0.6"
13 async-trait = "0.1"
13 \ No newline at end of file
13 async-trait = "0.1"
14 c_linked_list = "=1.1.1"
14 \ No newline at end of file

giterated-runtime/giterated-abi/src/lib.rs

View file
@@ -197,7 +197,11 @@ impl<T> DerefMut for FfiSlice<T> {
197 197 }
198 198 }
199 199
200 impl<T> FfiSliceRef<T> {}
200 impl<T: ?Sized> FfiSliceRef<T> {
201 pub fn static_ref(source: &'static T) -> FfiSliceRef<T> {
202 todo!()
203 }
204 }
201 205
202 206 impl<T> Deref for FfiSliceRef<[T]> {
203 207 type Target = [T];
@@ -233,6 +237,16 @@ impl<T> Deref for FfiValueRef<T> {
233 237 }
234 238 }
235 239
240 impl<T> FfiValue<T> {
241 pub unsafe fn from_raw_ptr(ptr: *mut T) -> FfiValue<T> {
242 todo!()
243 }
244
245 pub unsafe fn ptr(&self) -> *const T {
246 self.inner as *const T
247 }
248 }
249
236 250 impl<T> Deref for FfiValueMut<T> {
237 251 type Target = T;
238 252
@@ -387,7 +401,7 @@ mod guards {
387 401
388 402 impl<'v, T> StackPinnedSlice<'v, T> {
389 403 #[inline(always)]
390 pub fn as_ref(&self) -> FfiSliceRef<T> {
404 pub fn grant_ref(&self) -> FfiSliceRef<T> {
391 405 FfiSliceRef {
392 406 inner: &self.slice as *const _ as *const (),
393 407 _type_marker: PhantomData,
@@ -396,7 +410,7 @@ mod guards {
396 410 }
397 411
398 412 #[inline(always)]
399 pub fn as_mut(&mut self) -> FfiSliceMut<T> {
413 pub fn grant_mut(&mut self) -> FfiSliceMut<T> {
400 414 FfiSliceMut {
401 415 inner: &mut self.slice as *mut _ as *mut (),
402 416 _type_marker: PhantomData,
@@ -424,11 +438,11 @@ mod guards {
424 438 }
425 439 }
426 440
427 pub struct StackPinnedValue<'v, T> {
441 pub struct StackPinnedValue<'v, T: ?Sized> {
428 442 value_ref: &'v T,
429 443 }
430 444
431 impl<'v, T> StackPinnedValue<'v, T> {
445 impl<'v, T: ?Sized> StackPinnedValue<'v, T> {
432 446 /// Grants a reference to the pinned value.
433 447 ///
434 448 /// # SAFETY
@@ -442,9 +456,23 @@ mod guards {
442 456 _abi_marker: PhantomData,
443 457 }
444 458 }
459
460 /// Grants a reference to the pinned value.
461 ///
462 /// # SAFETY
463 /// - The granted reference **must not** outlive the lifetime of `&self`.
464 /// - There **must not** be a mutable reference created or mutable dereference performed during the lifetime of the [`FfiValueRef`].
465 #[inline(always)]
466 pub unsafe fn grant_mut(&mut self) -> FfiValueMut<T> {
467 Ffi {
468 inner: self.value_ref as *const _ as *const (),
469 _type_marker: PhantomData,
470 _abi_marker: PhantomData,
471 }
472 }
445 473 }
446 474
447 impl<'v, T> StackPinnedValue<'v, T> {
475 impl<'v, T: ?Sized> StackPinnedValue<'v, T> {
448 476 #[inline(always)]
449 477 pub(crate) fn from_raw(value: &'v T) -> Self {
450 478 Self { value_ref: value }

giterated-runtime/giterated-abi/src/model_impl/mod.rs

View file
@@ -1,4 +1,4 @@
1 use std::ffi::CStr;
1 use std::ffi::{CStr, CString};
2 2
3 3 use giterated_models::{object::GiteratedObject, operation::GiteratedOperation};
4 4
@@ -16,7 +16,7 @@ impl<T> IntoObjectVTable for T
16 16 where
17 17 T: GiteratedObject,
18 18 {
19 fn object_kind() -> &'static CStr {
19 unsafe extern "C" fn object_kind() -> &'static str {
20 20 todo!()
21 21 }
22 22

giterated-runtime/giterated-abi/src/state.rs

View file
@@ -1,3 +1,9 @@
1 use std::{
2 marker::PhantomData,
3 mem::{transmute, MaybeUninit},
4 ptr::{null, null_mut, read},
5 };
6
1 7 use anyhow::Error;
2 8
3 9 pub trait FromOperationState<O, D>: Sized {
@@ -16,16 +22,40 @@ impl<T: StateUUID> FromState for StateExtractor<T> {
16 22 }
17 23 }
18 24
19 use giterated_models::error::OperationError;
25 use c_linked_list::CLinkedListMut;
26 use giterated_models::{error::OperationError, value};
20 27
21 28 use crate::{
22 29 value_ex::FfiValueUntyped,
23 30 vtable::{runtime::RuntimeHandle, VTable},
31 FfiValue,
24 32 };
25 33
34 #[derive(Debug)]
26 35 #[repr(transparent)]
27 36 pub struct State {
28 inner: StateHandle,
37 list: CLinkedListMut<StateItem<()>, fn(&StateItem<()>) -> *mut StateItem<()>>,
38 }
39
40 unsafe impl Send for State {}
41 unsafe impl Sync for State {}
42
43 impl Default for State {
44 fn default() -> Self {
45 let value = FfiValue::new(StateItem {
46 next_item: core::ptr::null(),
47 state_uuid: 0,
48 state: (),
49 });
50
51 State {
52 list: unsafe {
53 CLinkedListMut::from_ptr(value.ptr() as *const StateItem<()> as *mut _, |n| {
54 n.next_item as *mut StateItem<()>
55 })
56 },
57 }
58 }
29 59 }
30 60
31 61 #[repr(transparent)]
@@ -33,8 +63,20 @@ struct StateHandle {
33 63 state: FfiValueUntyped,
34 64 }
35 65
66 impl StateHandle {
67 pub unsafe fn clone_unsafe(&self) -> Self {
68 Self {
69 state: FfiValueUntyped {
70 inner: self.state.inner,
71 _type_marker: PhantomData,
72 _abi_marker: PhantomData,
73 },
74 }
75 }
76 }
77
36 78 #[repr(C)]
37 struct StateItem<T: ?Sized> {
79 pub struct StateItem<T: ?Sized> {
38 80 /// The pointer to the next item.
39 81 ///
40 82 /// `next_item` is most likely always an `FfiValue<StateItem<()>>` and that's how we free them.
@@ -43,38 +85,76 @@ struct StateItem<T: ?Sized> {
43 85 pub state: T,
44 86 }
45 87
88 impl<T> std::fmt::Debug for StateItem<T> {
89 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
90 f.debug_struct("StateItem")
91 .field("state_uuid", &self.state_uuid)
92 .finish()
93 }
94 }
95
46 96 impl Drop for State {
47 97 fn drop(&mut self) {
48 98 let state_manager = unsafe { StateManager::new(self) };
49 99
50 for state in state_manager {}
100 // for state in state_manager {}
51 101 }
52 102 }
53 103
54 struct StateManager<'s> {
55 state: &'s mut State,
56 last: Option<StateHandle>,
104 pub struct StateManager<'s, S> {
105 state: S,
106 _marker: PhantomData<&'s ()>,
57 107 }
58 108
59 impl<'s> StateManager<'s> {
60 pub unsafe fn new(handle: &'s mut State) -> Self {
61 todo!()
109 impl<'s> StateManager<'s, &'s mut State> {
110 pub unsafe fn new_mut(handle: &'s mut State) -> Self {
111 Self {
112 state: handle,
113 _marker: PhantomData,
114 }
62 115 }
63 116
64 pub unsafe fn write_state<S: StateUUID>(&mut self, state: S) -> Self {
65 todo!()
66 }
117 pub unsafe fn write_state<S: StateUUID>(&mut self, state: S) -> &mut Self {
118 let list = &mut self.state.list;
119 let last_item = list.iter_mut().last().unwrap();
67 120
68 pub unsafe fn get_state<S: StateUUID>(&mut self) -> Option<&S> {
69 todo!()
121 last_item.next_item = unsafe {
122 FfiValue::new(StateItem {
123 next_item: null(),
124 state_uuid: S::uuid(),
125 state,
126 })
127 .ptr()
128 } as *const StateItem<()>;
129
130 self
70 131 }
71 132 }
72 133
73 impl<'s> Iterator for StateManager<'s> {
74 type Item = StateItem<()>;
134 impl<'s> StateManager<'s, &'s State> {
135 pub unsafe fn new<'o: 's>(handle: &'o State) -> Self {
136 Self {
137 state: handle,
138 _marker: PhantomData,
139 }
140 }
141
142 pub unsafe fn get_state<S: StateUUID>(&self) -> Option<&S> {
143 println!("state info: {:#?}", self.state);
75 144
76 fn next(&mut self) -> Option<StateItem<()>> {
77 todo!()
145 for state in self.state.list.iter() {
146 println!("iter");
147 if state.state_uuid == S::uuid() {
148 let state: *const StateItem<S> = unsafe { transmute(&state) };
149
150 let value_ref = state.as_ref().unwrap();
151 let value_ref = &value_ref.state as *const S;
152
153 return value_ref.as_ref();
154 }
155 }
156
157 None
78 158 }
79 159 }
80 160
@@ -89,11 +169,12 @@ pub trait StateUUID {
89 169 /// State values for the current execution domain. 99.99% of the time this means "plugin-specific"
90 170 ///
91 171 /// The remainder 0.01% of the time it refers to the daemon's runtime domain.
92 pub struct DomainState(StateItem<()>);
172 #[repr(transparent)]
173 pub struct DomainState(pub &'static State);
93 174
94 175 impl StateUUID for DomainState {
95 176 fn uuid() -> u128 {
96 todo!()
177 32894238940832489328402398490328423
97 178 }
98 179 }
99 180
@@ -111,10 +192,6 @@ impl RuntimeState {
111 192 }
112 193 }
113 194
114 // pub struct Runtime {
115 // pub queue_insert_state: unsafe extern "C" fn(state_uuid: u128, state: FfiValueUntyped),
116 // }
117
118 195 pub trait FromState: Sized {
119 196 fn from_state(state: &mut State) -> Result<Self, Error>;
120 197 }

giterated-runtime/giterated-abi/src/vtable/object.rs

View file
@@ -1,4 +1,9 @@
1 use std::{ffi::CStr, str::FromStr};
1 use std::{
2 ffi::{CStr, CString},
3 str::FromStr,
4 };
5
6 use giterated_models::object::GiteratedObject;
2 7
3 8 use crate::{
4 9 result::{FfiError, FfiResult},
@@ -18,6 +23,10 @@ impl Object {
18 23 pub fn home_uri(&self) -> String {
19 24 todo!()
20 25 }
26
27 pub unsafe fn cast<T: GiteratedObject>(self) -> T {
28 todo!()
29 }
21 30 }
22 31
23 32 impl<O: IntoObjectVTable> From<O> for Object {
@@ -45,7 +54,7 @@ impl ObjectABI for Object {
45 54 }
46 55
47 56 pub struct ObjectVTable {
48 pub object_kind: &'static CStr,
57 pub object_kind: unsafe extern "C" fn() -> &'static str,
49 58 pub to_str: unsafe extern "C" fn(this: FfiValueRef<Object>) -> FfiSlice<str>,
50 59 pub from_str: unsafe extern "C" fn(from: FfiSliceRef<str>) -> FfiResult<Object, FfiError>,
51 60 pub home_uri: unsafe extern "C" fn(this: FfiValueRef<Object>) -> FfiSlice<str>,
@@ -53,14 +62,19 @@ pub struct ObjectVTable {
53 62
54 63 impl ObjectVTable {
55 64 pub const fn new<O: IntoObjectVTable>() -> Self {
56 todo!()
65 Self {
66 object_kind: O::object_kind,
67 to_str: O::to_str,
68 from_str: O::from_str,
69 home_uri: O::home_uri,
70 }
57 71 }
58 72 }
59 73
60 74 pub trait IntoObjectVTable: Sized {
61 75 const VTABLE: &'static VTable<Object> = VTable::new(&ObjectVTable::new::<Self>());
62 76
63 fn object_kind() -> &'static CStr;
77 unsafe extern "C" fn object_kind() -> &'static str;
64 78 unsafe extern "C" fn to_str(this: FfiValueRef<Object>) -> FfiSlice<str>;
65 79 unsafe extern "C" fn from_str(from: FfiSliceRef<str>) -> FfiResult<Object, FfiError>;
66 80 unsafe extern "C" fn home_uri(this: FfiValueRef<Object>) -> FfiSlice<str>;

giterated-runtime/giterated-abi/src/vtable/runtime.rs

View file
@@ -1,6 +1,6 @@
1 1 use giterated_models::{
2 2 error::OperationError,
3 object::{GiteratedObject, ObjectRequestError},
3 object::{self, GiteratedObject, ObjectRequestError},
4 4 object_backend::ObjectBackend,
5 5 operation::{GiteratedOperation, OperationState},
6 6 };
@@ -9,15 +9,17 @@ use crate::{
9 9 result::{FfiError, FfiResult},
10 10 state::State,
11 11 value_ex::FfiValueUntyped,
12 FfiFuture, FfiSliceRef, FfiValueMut,
12 FfiFuture, FfiSliceRef, FfiValueMut, StackPinned,
13 13 };
14 14
15 15 use core::fmt::Debug;
16 16
17 use super::{Object, ObjectABI};
17 use super::{Object, ObjectABI, VTable};
18 18
19 19 #[derive(Clone)]
20 pub struct RuntimeHandle;
20 pub struct RuntimeHandle {
21 pub vtable: &'static VTable<RuntimeHandle>,
22 }
21 23
22 24 impl ObjectABI for RuntimeHandle {
23 25 type VTable = RuntimeVTable;
@@ -45,10 +47,20 @@ impl RuntimeHandle {
45 47 todo!()
46 48 }
47 49
48 pub async fn inner_get_object(
50 pub fn inner_get_object(
49 51 &self,
50 52 object_str: &str,
53 state: &mut State,
51 54 ) -> Result<Object, OperationError<ObjectRequestError>> {
55 let pinned_object_str = (*object_str.as_bytes()).pin();
56 let mut pinned_state = (*state).pin();
57
58 let result = unsafe {
59 (self.vtable.get_object)(unsafe { pinned_object_str.grant_ref() }, unsafe {
60 pinned_state.grant_mut()
61 })
62 };
63
52 64 todo!()
53 65 }
54 66 }
@@ -66,15 +78,26 @@ pub struct RuntimeVTable {
66 78 >,
67 79 pub(crate) get_object:
68 80 unsafe extern "C" fn(
69 &str,
81 object_str: FfiSliceRef<u8>,
70 82 state: FfiValueMut<State>,
71 83 ) -> FfiResult<Object, OperationError<ObjectRequestError>>,
72 84 }
73 85
86 impl RuntimeVTable {
87 pub const fn new<R: IntoRuntimeVtable>() -> RuntimeVTable {
88 RuntimeVTable {
89 handle_fn: R::handle,
90 get_object: R::get_object,
91 }
92 }
93 }
94
74 95 unsafe impl Send for RuntimeVTable {}
75 96 unsafe impl Sync for RuntimeVTable {}
76 97
77 pub trait IntoRuntimeVtable {
98 pub trait IntoRuntimeVtable: Sized {
99 const VTABLE: RuntimeVTable = RuntimeVTable::new::<Self>();
100
78 101 unsafe extern "C" fn handle(
79 102 object_kind: FfiSliceRef<str>,
80 103 operation_name: FfiSliceRef<str>,
@@ -84,19 +107,19 @@ pub trait IntoRuntimeVtable {
84 107 ) -> FfiFuture<FfiResult<FfiValueUntyped, OperationError<FfiError>>>;
85 108
86 109 unsafe extern "C" fn get_object(
87 object_str: &str,
110 object_str: FfiSliceRef<u8>,
88 111 operation_state: FfiValueMut<State>,
89 112 ) -> FfiResult<Object, OperationError<ObjectRequestError>>;
90 113 }
91 114
92 115 #[async_trait::async_trait(?Send)]
93 impl ObjectBackend for RuntimeHandle {
116 impl ObjectBackend<State> for RuntimeHandle {
94 117 async fn object_operation<O, D>(
95 118 &self,
96 119 object: O,
97 120 operation: &str,
98 121 payload: D,
99 operation_state: &OperationState,
122 operation_state: &mut State,
100 123 ) -> Result<D::Success, OperationError<D::Failure>>
101 124 where
102 125 O: GiteratedObject + Debug + 'static,
@@ -110,8 +133,10 @@ impl ObjectBackend for RuntimeHandle {
110 133 async fn get_object<O: GiteratedObject + Debug + 'static>(
111 134 &self,
112 135 object_str: &str,
113 operation_state: &OperationState,
114 ) -> Result<giterated_models::object::Object<O, Self>, OperationError<ObjectRequestError>> {
115 todo!()
136 operation_state: &mut State,
137 ) -> Result<object::Object<O, Self, State>, OperationError<ObjectRequestError>> {
138 let result = self.inner_get_object(object_str, operation_state)?;
139
140 Ok(unsafe { object::Object::new_unchecked(result.cast(), self.clone()) })
116 141 }
117 142 }

giterated-runtime/giterated-static-runtime/src/lib.rs

View file
@@ -15,6 +15,16 @@ pub unsafe fn get_runtime_reference() -> NonNull<()> {
15 15 GITERATED_RUNTIME.assume_init_read().0
16 16 }
17 17
18 static mut GITERATED_RUNTIME_HANDLE: MaybeUninit<RuntimePointer> = MaybeUninit::zeroed();
19
20 pub unsafe fn initialize_runtime_handle(runtime_handle: *mut ()) {
21 GITERATED_RUNTIME_HANDLE.write(RuntimePointer(NonNull::new(runtime_handle).unwrap()));
22 }
23
24 pub unsafe fn get_runtime_handle() -> NonNull<()> {
25 GITERATED_RUNTIME_HANDLE.assume_init_read().0
26 }
27
18 28 static mut GITERATED_TYPE_METADATA: MaybeUninit<RuntimePointer> = MaybeUninit::zeroed();
19 29
20 30 pub unsafe fn initialize_type_metadata(runtime_pointer: *mut ()) {

giterated-runtime/src/domain.rs

View file
@@ -0,0 +1,18 @@
1 use std::{cell::OnceCell, sync::OnceLock};
2
3 use giterated_abi::state::{DomainState, State, StateItem};
4 use giterated_core::DomainMetadata;
5
6 struct RuntimeDomainState {
7 pub metadata: DomainMetadata,
8 }
9
10 unsafe impl Send for RuntimeDomainState {}
11 unsafe impl Sync for RuntimeDomainState {}
12
13 static RUNTIME_DOMAIN_STATE: OnceLock<State> = OnceLock::new();
14
15 /// Sources a [`DomainState`] state entry for the application hosting the runtime.
16 pub fn runtime_domain_state() -> DomainState {
17 DomainState(RUNTIME_DOMAIN_STATE.get().unwrap())
18 }

giterated-runtime/src/lib.rs

View file
@@ -1,3 +1,4 @@
1 pub mod domain;
1 2 mod operation_walker;
2 3 pub mod plugin;
3 4
@@ -13,12 +14,19 @@ use giterated_abi::{
13 14 CallbackPtr,
14 15 },
15 16 plugin::GiteratedPluginAbi,
16 vtable::{operation::Operation, plugin::Plugin, Object, Setting, VTable, Value},
17 state::{DomainState, State, StateManager, StateUUID},
18 vtable::{
19 operation::Operation,
20 plugin::Plugin,
21 runtime::{IntoRuntimeVtable, RuntimeVTable},
22 Object, Setting, VTable, Value,
23 },
24 FfiSliceRef, FfiValueMut,
17 25 };
18 use giterated_core::types::TypeMetadata;
26 use giterated_core::{types::TypeMetadata, DomainMetadata};
19 27 use giterated_models::{
20 28 error::OperationError,
21 object::{GiteratedObject, ObjectOperationPair},
29 object::{GiteratedObject, ObjectOperationPair, ObjectRequestError},
22 30 operation::GiteratedOperation,
23 31 settings::ObjectSettingPair,
24 32 value::ObjectValuePair,
@@ -63,7 +71,9 @@ impl Runtime {
63 71 }
64 72
65 73 pub fn state(self: &Box<Self>) -> RuntimeHandle {
66 RuntimeHandle
74 RuntimeHandle {
75 vtable: VTable::new(&<Self as IntoRuntimeVtable>::VTABLE),
76 }
67 77 }
68 78
69 79 pub fn load_dylib(&mut self, path: impl AsRef<str>) -> Result<(), Error> {
@@ -142,8 +152,12 @@ impl Runtime {
142 152 }
143 153
144 154 pub fn init(self: Box<Self>) {
145 todo!()
146 // unsafe { giterated_static_runtime::initialize_runtime(Box::into_raw(self).cast::<()>()) }
155 unsafe {
156 giterated_static_runtime::initialize_runtime_handle(
157 &Self::VTABLE as *const _ as *const () as *mut (),
158 )
159 }
160 unsafe { giterated_static_runtime::initialize_runtime(Box::into_raw(self).cast::<()>()) }
147 161 }
148 162
149 163 // pub async fn handle(
@@ -404,6 +418,41 @@ pub trait StaticRuntimeExt {
404 418
405 419 impl StaticRuntimeExt for RuntimeHandle {
406 420 fn from_static() -> Self {
421 let vtable = unsafe {
422 giterated_static_runtime::get_runtime_handle()
423 .cast::<VTable<RuntimeHandle>>()
424 .as_ref()
425 };
426
427 RuntimeHandle { vtable }
428 }
429 }
430
431 impl IntoRuntimeVtable for Runtime {
432 unsafe extern "C" fn handle(
433 object_kind: giterated_abi::FfiSliceRef<str>,
434 operation_name: giterated_abi::FfiSliceRef<str>,
435 object: giterated_abi::FfiSliceRef<str>,
436 operation_payload: giterated_abi::FfiSliceRef<[u8]>,
437 operation_state: giterated_abi::FfiSliceRef<[u8]>,
438 ) -> giterated_abi::FfiFuture<
439 giterated_abi::result::FfiResult<
440 giterated_abi::value_ex::FfiValueUntyped,
441 OperationError<giterated_abi::result::FfiError>,
442 >,
443 > {
444 todo!()
445 }
446
447 unsafe extern "C" fn get_object(
448 object_str: FfiSliceRef<u8>,
449 mut operation_state: FfiValueMut<State>,
450 ) -> giterated_abi::result::FfiResult<Object, OperationError<ObjectRequestError>> {
451 let state_manager = StateManager::new(&mut operation_state);
452
453 let domain_state = state_manager.get_state::<DomainState>().unwrap();
454
455 // let runtime =
407 456 todo!()
408 457 }
409 458 }

plugins/example-plugin/src/main.rs

View file
@@ -6,6 +6,7 @@ use giterated_models::{
6 6 user::{DisplayName, User},
7 7 };
8 8 use giterated_plugin::abi::vtable::runtime::RuntimeHandle;
9 use giterated_runtime::domain::runtime_domain_state;
9 10 use giterated_runtime::{Runtime, StaticRuntimeExt};
10 11 use tracing::{info, Level};
11 12
@@ -23,27 +24,31 @@ async fn main() -> Result<(), anyhow::Error> {
23 24
24 25 runtime.init();
25 26
26 let runtime = unsafe { RuntimeHandle::from_static() };
27 let runtime = RuntimeHandle::from_static();
27 28
28 29 let _object_request = ObjectRequest(String::from("foobar"));
29 30
30 let _state = OperationState::default();
31 let mut state = giterated_plugin::abi::state::State::default();
32
33 let mut state_manager =
34 unsafe { giterated_plugin::abi::state::StateManager::new_mut(&mut state) };
35 unsafe { state_manager.write_state(unsafe { runtime_domain_state() }) };
36
37 println!("state info: {:#?}", state);
31 38
32 39 let _instance = runtime
33 .get_object::<Instance>("giterated.dev", &OperationState::default())
40 .get_object::<Instance>("giterated.dev", &mut state)
34 41 .await?;
35 42
36 43 let mut user = runtime
37 .get_object::<User>("ambee:giterated.dev", &OperationState::default())
44 .get_object::<User>("ambee:giterated.dev", &mut state)
38 45 .await?;
39 46
40 let display_name = user.get::<DisplayName>(&OperationState::default()).await?;
47 let display_name = user.get::<DisplayName>(&mut state).await?;
41 48
42 49 info!("Display name for user as a value: {}", display_name);
43 50
44 let display_name = user
45 .get_setting::<DisplayName>(&OperationState::default())
46 .await?;
51 let display_name = user.get_setting::<DisplayName>(&mut state).await?;
47 52
48 53 info!("Display name for user as a setting: {}", display_name);
49 54