forked from 1b-agent/opencadstudio-upstream
Initial commit
This commit is contained in:
1 parent
125b89d8da
commit
dcfaed0182
26 files changed
+2080
-143
No files matched your search
@@ -0,0 +1,112 @@
|
||||
//! Request/response envelopes exchanged between the host and a plugin process.
|
||||
//!
|
||||
//! A single bidirectional socket is used. Each side sends either a request
|
||||
//! (expecting a response) or a response (to a previous request). This lets the
|
||||
//! host handle plugin RPCs inline while it waits for the result of a host→plugin
|
||||
//! request such as `Dispatch`, avoiding the need for two sockets or threads.
|
||||
|
||||
use serde::{Deserialize, Serialize};
|
||||
|
||||
use crate::host::CommandStep;
|
||||
use crate::manifest::ApiVersion;
|
||||
use crate::ribbon::owned::{OwnedPluginManifest, OwnedRibbonGroup};
|
||||
|
||||
pub use acadrust::{CadDocument, EntityType, Handle};
|
||||
pub use acadrust::xdata::ExtendedDataRecord;
|
||||
|
||||
/// Events the host forwards to an active plugin `InteractiveCommand`.
|
||||
#[derive(Debug, Clone, Serialize, Deserialize)]
|
||||
pub enum InteractiveEvent {
|
||||
Point([f64; 3]),
|
||||
Enter,
|
||||
ObjectPick { handle: Handle, pt: [f64; 3] },
|
||||
}
|
||||
|
||||
/// Requests the host sends to the plugin runner.
|
||||
#[derive(Debug, Serialize, Deserialize)]
|
||||
pub enum HostRequest {
|
||||
GetManifest,
|
||||
GetRibbon,
|
||||
Dispatch { cmd: String },
|
||||
InteractiveEvent { command_id: u64, event: InteractiveEvent },
|
||||
GetPrompt { command_id: u64 },
|
||||
NeedsEntityPick { command_id: u64 },
|
||||
Shutdown,
|
||||
}
|
||||
|
||||
/// Responses the plugin runner sends back for `HostRequest`.
|
||||
#[derive(Debug, Serialize, Deserialize)]
|
||||
pub enum HostResponse {
|
||||
Bool(bool),
|
||||
CommandStep(CommandStep),
|
||||
Text(String),
|
||||
Ribbon(Vec<OwnedRibbonGroup>),
|
||||
Manifest(OwnedPluginManifest),
|
||||
Error(String),
|
||||
}
|
||||
|
||||
/// Requests the plugin runner sends to the host.
|
||||
#[derive(Debug, Serialize, Deserialize)]
|
||||
pub enum PluginRequest {
|
||||
PushInfo(String),
|
||||
PushOutput(String),
|
||||
PushError(String),
|
||||
AddEntity(EntityType),
|
||||
BumpGeometry,
|
||||
ReadRecord { handle: Handle, app_name: String },
|
||||
WriteRecord { handle: Handle, record: ExtendedDataRecord },
|
||||
RemoveRecord { handle: Handle, app_name: String },
|
||||
PushUndo { label: String },
|
||||
SetDirty,
|
||||
StartInteractive { command_id: u64 },
|
||||
DocumentSnapshot,
|
||||
}
|
||||
|
||||
/// Responses the host sends back for `PluginRequest`.
|
||||
#[derive(Debug, Serialize, Deserialize)]
|
||||
pub enum PluginResponse {
|
||||
Ok,
|
||||
Bool(bool),
|
||||
Handle(Handle),
|
||||
Record(Option<ExtendedDataRecord>),
|
||||
Document(CadDocument),
|
||||
Error(String),
|
||||
}
|
||||
|
||||
/// Messages sent from the host to the plugin runner.
|
||||
#[derive(Debug, Serialize, Deserialize)]
|
||||
pub enum HostToPlugin {
|
||||
Request(HostRequest),
|
||||
Response(PluginResponse),
|
||||
}
|
||||
|
||||
/// Messages sent from the plugin runner to the host.
|
||||
#[derive(Debug, Serialize, Deserialize)]
|
||||
pub enum PluginToHost {
|
||||
Request(PluginRequest),
|
||||
Response(HostResponse),
|
||||
}
|
||||
|
||||
/// Convenience helper for manifest serialization.
|
||||
impl From<&'static crate::manifest::PluginManifest> for OwnedPluginManifest {
|
||||
fn from(m: &'static crate::manifest::PluginManifest) -> Self {
|
||||
Self {
|
||||
id: m.id.to_string(),
|
||||
name: m.name.to_string(),
|
||||
version: m.version.to_string(),
|
||||
description: m.description.to_string(),
|
||||
api_version: m.api_version.major,
|
||||
ribbon_order: m.ribbon_order,
|
||||
xdata_apps: m.xdata_apps.iter().map(|s| s.to_string()).collect(),
|
||||
command_prefixes: m.command_prefixes.iter().map(|s| s.to_string()).collect(),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl OwnedPluginManifest {
|
||||
pub fn api_version(&self) -> ApiVersion {
|
||||
ApiVersion {
|
||||
major: self.api_version,
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user