moosync_edk/
lib.rs

1// Moosync
2// Copyright (C) 2024, 2025  Moosync <support@moosync.app>
3//
4// This program is free software: you can redistribute it and/or modify
5// it under the terms of the GNU General Public License as published by
6// the Free Software Foundation, either version 3 of the License, or
7// (at your option) any later version.
8//
9// This program is distributed in the hope that it will be useful,
10// but WITHOUT ANY WARRANTY; without even the implied warranty of
11// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12// GNU General Public License for more details.
13//
14// You should have received a copy of the GNU General Public License
15// along with this program.  If not, see <http://www.gnu.org/licenses/>.
16
17pub use extism_pdk::{config, error, info, log, warn};
18use extism_pdk::{plugin_fn, FnResult, Prost};
19
20// Re-export generated types
21pub use extensions_proto;
22pub use songs_proto;
23pub use themes_proto;
24pub use ui_proto;
25pub use duration_proto;
26pub use prost_types;
27pub use extensions_proto::moosync::types::*;
28pub use songs_proto::moosync::types::*;
29pub use themes_proto::moosync::types::*;
30pub use ui_proto::moosync::types::*;
31
32pub mod api;
33pub mod handler;
34pub mod http;
35pub mod response_utils;
36
37pub use api::MoosyncResult;
38pub use handler::MoosyncError;
39
40unsafe extern "C" {
41    fn init();
42}
43
44#[tracing::instrument(level = "debug", skip())]
45#[plugin_fn]
46pub fn entry() -> FnResult<()> {
47    unsafe {
48        init();
49    }
50    Ok(())
51}
52
53#[tracing::instrument(level = "debug", skip())]
54#[plugin_fn]
55pub fn handle_extension_command(
56    Prost(cmd): Prost<ExtensionCommand>,
57) -> FnResult<Prost<ExtensionCommandResponse>> {
58    let res = handler::handle_command(cmd)?;
59    Ok(Prost(res))
60}
61
62/// Converts a standard Rust `Duration` into a protobuf `Duration`.
63pub fn duration_to_proto(d: std::time::Duration) -> duration_proto::google::protobuf::Duration {
64    duration_proto::google::protobuf::Duration {
65        seconds: d.as_secs() as i64,
66        nanos: d.subsec_nanos() as i32,
67    }
68}