flo_scene_guest/errors/connection_error.rs
1use super::scene_send_error::*;
2
3use serde::*;
4
5use alloc::string::*;
6
7///
8/// The name of the message type that is accepted by a subprogram
9///
10/// Output streams from subprograms must be connected to the input of a program that accepts that message type
11///
12#[derive(Clone, PartialEq, Eq, Hash, Debug)]
13#[derive(Serialize, Deserialize)]
14pub struct TargetInputMessageType(pub String);
15
16///
17/// The name of the message type that is being connected to a target
18///
19#[derive(Clone, PartialEq, Eq, Hash, Debug)]
20#[derive(Serialize, Deserialize)]
21pub struct SourceStreamMessageType(pub String);
22
23///
24/// Errors that can occur when trying to connect two subprograms in a scene
25///
26#[derive(Clone, PartialEq, Eq, Hash, Debug)]
27#[derive(Serialize, Deserialize)]
28pub enum ConnectionError {
29 // Something cancelled the connection
30 Cancelled,
31
32 /// The subprogram a context belongs to is no longer running
33 SubProgramNotRunning,
34
35 /// The input type of the target of a connection does not match the source
36 WrongInputType(SourceStreamMessageType, TargetInputMessageType),
37
38 /// The requested stream is not available
39 StreamNotKnown,
40
41 /// The target subprogram of a connection is not in the scene (has not been started, or has finished)
42 TargetNotInScene,
43
44 /// The target input stream is not available
45 TargetNotAvailable,
46
47 /// The target cannot accept a message because it's not ready
48 TargetNotReady,
49
50 /// The input to a filter does not match what was expected
51 FilterInputDoesNotMatch,
52
53 /// The output to a filter does not match what was expected
54 FilterOutputDoesNotMatch,
55
56 /// The filter handle was not found
57 FilterHandleNotFound,
58
59 /// A filter to map from one stream to another was expected to be defined but could not be found
60 FilterMappingMissing,
61
62 /// The input for the filter to a filter source must match the stream ID being connected
63 FilterSourceInputMustMatchStream,
64
65 /// The input for the filter to a filter target must match the stream ID being connected
66 FilterTargetInputMustMatchStream,
67
68 /// The filter supplied is not supported
69 FilterNotSupported,
70
71 /// A stream target had an unexpected value
72 UnexpectedConnectionType,
73
74 /// The `OUTSIDE_SCENE_PROGRAM` subprogram is not running and a sink for sending messages into the scene was requested
75 NoOutsideSceneSubProgram,
76
77 /// An attempt was made to 'steal' the current thread to expedite a message, which could not be completed (for example, because the subprogram was already running on the current thread)
78 CannotStealThread,
79
80 /// The connection is denied due to a permissions error
81 TargetPermissionRefused,
82
83 /// The target refused the connection
84 TargetConnectionRefused,
85
86 /// The target doesn't support serializing this message type
87 TargetCannotSerialize,
88
89 /// The target doesn't support receiving serialized messages
90 TargetCannotDeserialize,
91
92 /// An operation could not be completed because of an I/O problem
93 IoError(String),
94}
95
96impl<TMessage> From<SceneSendError<TMessage>> for ConnectionError {
97 fn from(err: SceneSendError<TMessage>) -> ConnectionError {
98 match err {
99 SceneSendError::CouldNotConnect(err) => err,
100 SceneSendError::TargetProgramEndedBeforeReady => ConnectionError::TargetNotInScene,
101 SceneSendError::StreamClosed(_) => ConnectionError::TargetNotAvailable,
102 SceneSendError::TargetProgramEnded(_) => ConnectionError::TargetNotInScene,
103 SceneSendError::StreamDisconnected(_) => ConnectionError::TargetNotAvailable,
104 SceneSendError::CannotReEnterTargetProgram => ConnectionError::CannotStealThread,
105 SceneSendError::CannotAcceptMoreInputUntilSceneIsIdle(_) => ConnectionError::TargetNotReady,
106 SceneSendError::CannotSerialize(_, _) => ConnectionError::TargetCannotSerialize,
107 SceneSendError::CannotDeserialize(_, _) => ConnectionError::TargetCannotDeserialize,
108 SceneSendError::ErrorAfterDeserialization => ConnectionError::TargetCannotDeserialize,
109 SceneSendError::NoConnection(_) => ConnectionError::TargetCannotDeserialize,
110 }
111 }
112}