-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
resman_rustabi: Add Rust ABI for resman
- Loading branch information
Showing
13 changed files
with
809 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
[package] | ||
name = "resman_rustabi" | ||
version = "0.0.1" | ||
edition = "2021" | ||
|
||
[lib] | ||
name = "resman_rustabi" | ||
crate-type = ["rlib"] | ||
|
||
[dependencies] | ||
libc = "0.2" | ||
num_enum = "0.7" | ||
core_rustabi = { path = "../core_rustabi" } | ||
lowlevel_rustabi = { path = "../lowlevel_rustabi" } |
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,5 @@ | ||
name = resman_rustabi | ||
type = aux | ||
languages = RUST | ||
engine_module_deps = wm | ||
engine_aux_deps = lowlevel_rustabi,core_rustabi |
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,19 @@ | ||
/* | ||
* This file is a part of Argus. | ||
* Copyright (c) 2019-2024, Max Roncace <[email protected]> | ||
* | ||
* This program is free software: you can redistribute it and/or modify | ||
* it under the terms of the GNU Lesser General Public License as published by | ||
* the Free Software Foundation, either version 3 of the License, or | ||
* (at your option) any later version. | ||
* | ||
* This program is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
* GNU Lesser General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU Lesser General Public License | ||
* along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
*/ | ||
|
||
pub mod resman; |
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,27 @@ | ||
/* | ||
* This file is a part of Argus. | ||
* Copyright (c) 2019-2024, Max Roncace <[email protected]> | ||
* | ||
* This program is free software: you can redistribute it and/or modify | ||
* it under the terms of the GNU Lesser General Public License as published by | ||
* the Free Software Foundation, either version 3 of the License, or | ||
* (at your option) any later version. | ||
* | ||
* This program is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
* GNU Lesser General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU Lesser General Public License | ||
* along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
*/ | ||
|
||
pub mod resource; | ||
pub mod resource_event; | ||
pub mod resource_loader; | ||
pub mod resource_manager; | ||
|
||
pub use self::resource::*; | ||
pub use self::resource_event::*; | ||
pub use self::resource_loader::*; | ||
pub use self::resource_manager::*; |
122 changes: 122 additions & 0 deletions
122
engine/auxiliary/resman_rustabi/src/argus/resman/resource.rs
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,122 @@ | ||
/* | ||
* This file is a part of Argus. | ||
* Copyright (c) 2019-2024, Max Roncace <[email protected]> | ||
* | ||
* This program is free software: you can redistribute it and/or modify | ||
* it under the terms of the GNU Lesser General Public License as published by | ||
* the Free Software Foundation, either version 3 of the License, or | ||
* (at your option) any later version. | ||
* | ||
* This program is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
* GNU Lesser General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU Lesser General Public License | ||
* along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
*/ | ||
|
||
use lowlevel_rustabi::util::*; | ||
use num_enum::{IntoPrimitive, TryFromPrimitive}; | ||
use std::path::PathBuf; | ||
|
||
use crate::resman_cabi::*; | ||
|
||
pub struct Resource { | ||
handle: argus_resource_const_t, | ||
} | ||
|
||
pub struct ResourcePrototype { | ||
pub uid: String, | ||
pub media_type: String, | ||
pub fs_path: PathBuf, | ||
} | ||
|
||
pub(crate) unsafe fn unwrap_resource_prototype( | ||
proto: &argus_resource_prototype_t, | ||
) -> ResourcePrototype { | ||
ResourcePrototype { | ||
uid: cstr_to_string(proto.uid), | ||
media_type: cstr_to_string(proto.media_type), | ||
fs_path: PathBuf::from(cstr_to_str(proto.fs_path)), | ||
} | ||
} | ||
|
||
impl Resource { | ||
#[allow(dead_code)] | ||
pub(crate) fn get_handle(&self) -> argus_resource_const_t { | ||
self.handle | ||
} | ||
|
||
pub fn of(handle: argus_resource_const_t) -> Self { | ||
Self { handle } | ||
} | ||
|
||
pub fn get_prototype(&self) -> ResourcePrototype { | ||
unsafe { unwrap_resource_prototype(&argus_resource_get_prototype(self.handle)) } | ||
} | ||
|
||
pub fn release(&self) -> () { | ||
unsafe { argus_resource_release(self.handle) } | ||
} | ||
|
||
pub fn get_data_ptr(&self) -> *const u8 { | ||
unsafe { argus_resource_get_data_ptr(self.handle).cast() } | ||
} | ||
} | ||
|
||
#[derive(Eq, Ord, PartialEq, PartialOrd, IntoPrimitive, TryFromPrimitive)] | ||
#[repr(u32)] | ||
pub enum ResourceErrorReason { | ||
Generic = RESOURCE_ERROR_REASON_GENERIC, | ||
NotFound = RESOURCE_ERROR_REASON_NOT_FOUND, | ||
NotLoaded = RESOURCE_ERROR_REASON_NOT_LOADED, | ||
AlreadyLoaded = RESOURCE_ERROR_REASON_ALREADY_LOADED, | ||
NoLoader = RESOURCE_ERROR_REASON_NO_LOADER, | ||
LoadFailed = RESOURCE_ERROR_REASON_LOAD_FAILED, | ||
MalformedContent = RESOURCE_ERROR_REASON_MALFORMED_CONTENT, | ||
InvalidContent = RESOURCE_ERROR_REASON_INVALID_CONTENT, | ||
UnsupportedContent = RESOURCE_ERROR_REASON_UNSUPPORTED_CONTENT, | ||
UnexpectedReferenceType = RESOURCE_ERROR_REASON_UNEXPECTED_REFERENCE_TYPE, | ||
} | ||
|
||
pub struct ResourceError { | ||
pub reason: ResourceErrorReason, | ||
pub uid: String, | ||
pub info: String, | ||
} | ||
|
||
impl ResourceError { | ||
pub fn new(reason: ResourceErrorReason, uid: &str, info: &str) -> Self { | ||
Self { | ||
reason, | ||
uid: uid.to_string(), | ||
info: info.to_string(), | ||
} | ||
} | ||
} | ||
|
||
impl From<argus_resource_error_t> for ResourceError { | ||
fn from(value: argus_resource_error_t) -> Self { | ||
unsafe { | ||
Self { | ||
reason: ResourceErrorReason::try_from(argus_resource_error_get_reason(value)) | ||
.expect("Invalid ResourceErrorReason ordinal"), | ||
uid: cstr_to_string(argus_resource_error_get_uid(value)), | ||
info: cstr_to_string(argus_resource_error_get_info(value)), | ||
} | ||
} | ||
} | ||
} | ||
|
||
impl Into<argus_resource_error_t> for ResourceError { | ||
fn into(self) -> argus_resource_error_t { | ||
unsafe { | ||
argus_resource_error_new( | ||
self.reason.into(), | ||
string_to_cstring(&self.uid).as_ptr(), | ||
string_to_cstring(&self.info).as_ptr(), | ||
) | ||
} | ||
} | ||
} |
54 changes: 54 additions & 0 deletions
54
engine/auxiliary/resman_rustabi/src/argus/resman/resource_event.rs
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,54 @@ | ||
/* | ||
* This file is a part of Argus. | ||
* Copyright (c) 2019-2024, Max Roncace <[email protected]> | ||
* | ||
* This program is free software: you can redistribute it and/or modify | ||
* it under the terms of the GNU Lesser General Public License as published by | ||
* the Free Software Foundation, either version 3 of the License, or | ||
* (at your option) any later version. | ||
* | ||
* This program is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
* GNU Lesser General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU Lesser General Public License | ||
* along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
*/ | ||
|
||
use num_enum::{IntoPrimitive, TryFromPrimitive}; | ||
|
||
use crate::argus::resman::{unwrap_resource_prototype, Resource, ResourcePrototype}; | ||
use crate::resman_cabi::*; | ||
|
||
#[derive(Eq, Ord, PartialEq, PartialOrd, IntoPrimitive, TryFromPrimitive)] | ||
#[repr(u32)] | ||
pub enum ResourceEventType { | ||
Load = RESOURCE_EVENT_TYPE_LOAD, | ||
Unload = RESOURCE_EVENT_TYPE_UNLOAD, | ||
} | ||
|
||
pub struct ResourceEvent { | ||
handle: argus_resource_event_t, | ||
} | ||
|
||
impl ResourceEvent { | ||
pub fn of(handle: argus_resource_event_t) -> Self { | ||
Self { handle } | ||
} | ||
|
||
pub fn get_subtype(&self) -> ResourceEventType { | ||
unsafe { | ||
ResourceEventType::try_from(argus_resource_event_get_subtype(self.handle)) | ||
.expect("Invalid ResourceEventType ordinal") | ||
} | ||
} | ||
|
||
pub fn get_prototype(&self) -> ResourcePrototype { | ||
unsafe { unwrap_resource_prototype(&argus_resource_event_get_prototype(self.handle)) } | ||
} | ||
|
||
pub fn get_resource(&mut self) -> Resource { | ||
unsafe { Resource::of(argus_resource_event_get_resource(self.handle)) } | ||
} | ||
} |
Oops, something went wrong.