Skip to content
This repository has been archived by the owner on Jul 17, 2020. It is now read-only.

Injection failed #168

Open
wants to merge 6 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions hermes-ffi-test/src/json_round_trips.rs
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,16 @@ round_trip_json!(
hermes::InjectionResetCompleteMessage
);

round_trip_json!(
hermes_ffi_test_round_trip_injection_failed_json,
hermes::InjectionFailedMessage
);

round_trip_json!(
hermes_ffi_test_round_trip_injection_reset_failed_json,
hermes::InjectionResetFailedMessage
);

round_trip_json!(
hermes_ffi_test_round_trip_register_sound_json,
hermes::RegisterSoundMessage
Expand Down
16 changes: 16 additions & 0 deletions hermes-ffi-test/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,22 @@ pub extern "C" fn hermes_ffi_test_round_trip_injection_reset_complete(
wrap!(round_trip(input, output))
}

#[no_mangle]
pub extern "C" fn hermes_ffi_test_round_trip_injection_failed(
input: *const hermes_ffi::CInjectionFailedMessage,
output: *mut *const hermes_ffi::CInjectionFailedMessage,
) -> ffi_utils::SNIPS_RESULT {
wrap!(round_trip(input, output))
}

#[no_mangle]
pub extern "C" fn hermes_ffi_test_round_trip_injection_reset_failed(
input: *const hermes_ffi::CInjectionResetFailedMessage,
output: *mut *const hermes_ffi::CInjectionResetFailedMessage,
) -> ffi_utils::SNIPS_RESULT {
wrap!(round_trip(input, output))
}

#[no_mangle]
pub extern "C" fn hermes_ffi_test_round_trip_map_string_to_string_array(
input: *const hermes_ffi::CMapStringToStringArray,
Expand Down
78 changes: 78 additions & 0 deletions hermes-ffi/src/ontology/injection.rs
Original file line number Diff line number Diff line change
Expand Up @@ -386,6 +386,72 @@ impl AsRust<hermes::InjectionResetCompleteMessage> for CInjectionResetCompleteMe
}
}

#[repr(C)]
#[derive(Debug)]
pub struct CInjectionFailedMessage {
pub request_id: *const libc::c_char,
nebuto marked this conversation as resolved.
Show resolved Hide resolved
pub context: *const libc::c_char,
}

unsafe impl Sync for CInjectionFailedMessage {}

impl Drop for CInjectionFailedMessage {
fn drop(&mut self) {
take_back_nullable_c_string!(self.request_id);
take_back_nullable_c_string!(self.context);
}
}

impl CReprOf<hermes::InjectionFailedMessage> for CInjectionFailedMessage {
fn c_repr_of(message: hermes::InjectionFailedMessage) -> Fallible<Self> {
Ok(Self {
request_id: convert_to_nullable_c_string!(message.request_id),
context: convert_to_nullable_c_string!(message.context),
})
}
}

impl AsRust<hermes::InjectionFailedMessage> for CInjectionFailedMessage {
fn as_rust(&self) -> Fallible<hermes::InjectionFailedMessage> {
let request_id = create_optional_rust_string_from!(self.request_id);
let context = create_optional_rust_string_from!(self.context);
Ok(hermes::InjectionFailedMessage { request_id, context })
}
}

#[repr(C)]
#[derive(Debug)]
pub struct CInjectionResetFailedMessage {
pub request_id: *const libc::c_char,
nebuto marked this conversation as resolved.
Show resolved Hide resolved
pub context: *const libc::c_char,
}

unsafe impl Sync for CInjectionResetFailedMessage {}

impl Drop for CInjectionResetFailedMessage {
fn drop(&mut self) {
take_back_nullable_c_string!(self.request_id);
take_back_nullable_c_string!(self.context);
}
}

impl CReprOf<hermes::InjectionResetFailedMessage> for CInjectionResetFailedMessage {
fn c_repr_of(message: hermes::InjectionResetFailedMessage) -> Fallible<Self> {
Ok(Self {
request_id: convert_to_nullable_c_string!(message.request_id),
context: convert_to_nullable_c_string!(message.context),
})
}
}

impl AsRust<hermes::InjectionResetFailedMessage> for CInjectionResetFailedMessage {
fn as_rust(&self) -> Fallible<hermes::InjectionResetFailedMessage> {
let request_id = create_optional_rust_string_from!(self.request_id);
let context = create_optional_rust_string_from!(self.context);
Ok(hermes::InjectionResetFailedMessage { request_id, context })
}
}

#[cfg(test)]
mod tests {
use super::super::tests::round_trip_test;
Expand Down Expand Up @@ -536,4 +602,16 @@ mod tests {
round_trip_test::<_, CInjectionResetCompleteMessage>(hermes::InjectionResetCompleteMessage::minimal_example());
round_trip_test::<_, CInjectionResetCompleteMessage>(hermes::InjectionResetCompleteMessage::full_example());
}

#[test]
fn round_trip_injection_failed() {
round_trip_test::<_, CInjectionFailedMessage>(hermes::InjectionFailedMessage::minimal_example());
round_trip_test::<_, CInjectionFailedMessage>(hermes::InjectionFailedMessage::full_example());
}

#[test]
fn round_trip_injection_reset_failed() {
round_trip_test::<_, CInjectionResetFailedMessage>(hermes::InjectionResetFailedMessage::minimal_example());
round_trip_test::<_, CInjectionResetFailedMessage>(hermes::InjectionResetFailedMessage::full_example());
}
}
2 changes: 2 additions & 0 deletions hermes-ffi/src/protocol_handler/json.rs
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,8 @@ macro_rules! generate_json_c_symbols {
$crate::generate_facade_subscribe_json!(hermes_injection_subscribe_injection_status_json = CInjectionFacade: subscribe_injection_status());
$crate::generate_facade_subscribe_json!(hermes_injection_subscribe_injection_complete_json = CInjectionFacade: subscribe_injection_complete());
$crate::generate_facade_subscribe_json!(hermes_injection_subscribe_injection_reset_complete_json = CInjectionFacade: subscribe_injection_reset_complete());
$crate::generate_facade_subscribe_json!(hermes_injection_subscribe_injection_failed_json = CInjectionFacade: subscribe_injection_failed());
$crate::generate_facade_subscribe_json!(hermes_injection_subscribe_injection_reset_failed_json = CInjectionFacade: subscribe_injection_reset_failed());

#[cfg(feature = "full_bindings")]
pub mod full_bindings {
Expand Down
4 changes: 4 additions & 0 deletions hermes-ffi/src/protocol_handler/structures.rs
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,8 @@ macro_rules! generate_structures_c_symbols {
$crate::generate_facade_subscribe!(hermes_injection_subscribe_injection_status = CInjectionFacade: subscribe_injection_status(|CInjectionStatusMessage|));
$crate::generate_facade_subscribe!(hermes_injection_subscribe_injection_complete = CInjectionFacade: subscribe_injection_complete(|CInjectionCompleteMessage|));
$crate::generate_facade_subscribe!(hermes_injection_subscribe_injection_reset_complete = CInjectionFacade: subscribe_injection_reset_complete(|CInjectionResetCompleteMessage|));
$crate::generate_facade_subscribe!(hermes_injection_subscribe_injection_failed = CInjectionFacade: subscribe_injection_failed(|CInjectionFailedMessage|));
$crate::generate_facade_subscribe!(hermes_injection_subscribe_injection_reset_failed = CInjectionFacade: subscribe_injection_reset_failed(|CInjectionResetFailedMessage|));

$crate::generate_facade_publish!(hermes_tts_publish_register_sound = CTtsFacade: publish_register_sound(CRegisterSoundMessage));

Expand All @@ -122,6 +124,8 @@ macro_rules! generate_structures_c_symbols {
$crate::generate_destroy!(hermes_drop_injection_status_message for CInjectionStatusMessage);
$crate::generate_destroy!(hermes_drop_injection_complete_message for CInjectionCompleteMessage);
$crate::generate_destroy!(hermes_drop_injection_reset_complete_message for CInjectionResetCompleteMessage);
$crate::generate_destroy!(hermes_drop_injection_failed_message for CInjectionFailedMessage);
$crate::generate_destroy!(hermes_drop_injection_reset_failed_message for CInjectionResetFailedMessage);

#[cfg(feature = "full_bindings")]
pub mod full_bindings {
Expand Down
26 changes: 26 additions & 0 deletions hermes-inprocess/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1067,6 +1067,16 @@ struct InjectionResetComplete {
message: InjectionResetCompleteMessage,
}

#[derive(Debug)]
struct InjectionFailed {
message: InjectionFailedMessage,
}

#[derive(Debug)]
struct InjectionResetFailed {
message: InjectionResetFailedMessage,
}

impl InjectionFacade for InProcessComponent<Injection> {
fn publish_injection_request(&self, request: InjectionRequestMessage) -> Fallible<()> {
self.publish(InjectionPerform { request })
Expand All @@ -1091,6 +1101,14 @@ impl InjectionFacade for InProcessComponent<Injection> {
fn subscribe_injection_reset_complete(&self, handler: Callback<InjectionResetCompleteMessage>) -> Fallible<()> {
subscribe!(self, InjectionResetComplete { message }, handler)
}

fn subscribe_injection_failed(&self, handler: Callback<InjectionFailedMessage>) -> Fallible<()> {
subscribe!(self, InjectionFailed { message }, handler)
}

fn subscribe_injection_reset_failed(&self, handler: Callback<InjectionResetFailedMessage>) -> Fallible<()> {
subscribe!(self, InjectionResetFailed { message }, handler)
}
}

impl InjectionBackendFacade for InProcessComponent<Injection> {
Expand All @@ -1117,6 +1135,14 @@ impl InjectionBackendFacade for InProcessComponent<Injection> {
fn publish_injection_reset_complete(&self, message: InjectionResetCompleteMessage) -> Fallible<()> {
self.publish(InjectionResetComplete { message })
}

fn publish_injection_failed(&self, message: InjectionFailedMessage) -> Fallible<()> {
self.publish(InjectionFailed { message })
}

fn publish_injection_reset_failed(&self, message: InjectionResetFailedMessage) -> Fallible<()> {
self.publish(InjectionResetFailed { message })
}
}

#[cfg(test)]
Expand Down
4 changes: 4 additions & 0 deletions hermes-mqtt/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -720,6 +720,8 @@ impl InjectionFacade for MqttComponentFacade {
s!(subscribe_injection_status<InjectionStatusMessage> &HermesTopic::Injection(InjectionCommand::Status););
s!(subscribe_injection_complete<InjectionCompleteMessage> &HermesTopic::Injection(InjectionCommand::Complete););
s!(subscribe_injection_reset_complete<InjectionResetCompleteMessage> &HermesTopic::Injection(InjectionCommand::ResetComplete););
s!(subscribe_injection_failed<InjectionFailedMessage> &HermesTopic::Injection(InjectionCommand::Failed););
s!(subscribe_injection_reset_failed<InjectionResetFailedMessage> &HermesTopic::Injection(InjectionCommand::ResetFailed););
}

impl InjectionBackendFacade for MqttComponentFacade {
Expand All @@ -729,6 +731,8 @@ impl InjectionBackendFacade for MqttComponentFacade {
p!(publish_injection_status<InjectionStatusMessage> &HermesTopic::Injection(InjectionCommand::Status););
p!(publish_injection_complete<InjectionCompleteMessage> &HermesTopic::Injection(InjectionCommand::Complete););
p!(publish_injection_reset_complete<InjectionResetCompleteMessage> &HermesTopic::Injection(InjectionCommand::ResetComplete););
p!(publish_injection_failed<InjectionFailedMessage> &HermesTopic::Injection(InjectionCommand::Failed););
p!(publish_injection_reset_failed<InjectionResetFailedMessage> &HermesTopic::Injection(InjectionCommand::ResetFailed););
}

impl MqttHermesProtocolHandler {
Expand Down
13 changes: 13 additions & 0 deletions hermes-mqtt/src/topics.rs
Original file line number Diff line number Diff line change
Expand Up @@ -280,6 +280,7 @@ impl HermesTopic {
ComponentCommand::VersionRequest,
)),
Some("complete") => Some(Injection(Complete)),
Some("failed") => Some(Injection(Failed)),
Some("version") => Some(HermesTopic::Component(
None,
Component::Injection,
Expand All @@ -298,6 +299,7 @@ impl HermesTopic {
Some("reset") => match comps.next() {
Some("perform") => Some(Injection(ResetRequest)),
Some("complete") => Some(Injection(ResetComplete)),
Some("failed") => Some(Injection(ResetFailed)),
_ => None,
},
_ => None,
Expand Down Expand Up @@ -533,13 +535,16 @@ pub enum InjectionCommand {
Complete,
ResetRequest,
ResetComplete,
Failed,
ResetFailed,
}

impl ToPath for InjectionCommand {
fn as_path(&self) -> String {
match &self {
InjectionCommand::ResetRequest => "reset/perform".into(),
InjectionCommand::ResetComplete => "reset/complete".into(),
InjectionCommand::ResetFailed => "reset/failed".into(),
_ => self.as_path_default(),
}
}
Expand Down Expand Up @@ -831,6 +836,14 @@ mod tests {
HermesTopic::Injection(InjectionCommand::ResetComplete),
"hermes/injection/reset/complete",
),
(
HermesTopic::Injection(InjectionCommand::Failed),
"hermes/injection/failed",
),
(
HermesTopic::Injection(InjectionCommand::ResetFailed),
"hermes/injection/reset/failed",
),
(
HermesTopic::Component(None, Component::Injection, ComponentCommand::VersionRequest),
"hermes/injection/versionRequest",
Expand Down
4 changes: 4 additions & 0 deletions hermes-test-suite/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -257,5 +257,9 @@ macro_rules! test_suite {
injection_backend.subscribe_injection_reset_request <= InjectionResetRequestMessage | injection.publish_injection_reset_request);
t!(injection_reset_complete:
injection.subscribe_injection_reset_complete <= InjectionResetCompleteMessage | injection_backend.publish_injection_reset_complete);
t!(injection_failed:
injection.subscribe_injection_failed <= InjectionFailedMessage | injection_backend.publish_injection_failed);
t!(injection_reset_failed:
injection.subscribe_injection_reset_failed <= InjectionResetFailedMessage | injection_backend.publish_injection_reset_failed);
};
}
4 changes: 4 additions & 0 deletions hermes/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -271,6 +271,8 @@ pub trait InjectionFacade: ComponentFacade {
fn subscribe_injection_status(&self, handler: Callback<InjectionStatusMessage>) -> Fallible<()>;
fn subscribe_injection_complete(&self, handler: Callback<InjectionCompleteMessage>) -> Fallible<()>;
fn subscribe_injection_reset_complete(&self, handler: Callback<InjectionResetCompleteMessage>) -> Fallible<()>;
fn subscribe_injection_failed(&self, handler: Callback<InjectionFailedMessage>) -> Fallible<()>;
fn subscribe_injection_reset_failed(&self, handler: Callback<InjectionResetFailedMessage>) -> Fallible<()>;
}

/// The facade the injecter must use to receive its orders and advertise when it has finished
Expand All @@ -281,6 +283,8 @@ pub trait InjectionBackendFacade: ComponentBackendFacade {
fn publish_injection_status(&self, status: InjectionStatusMessage) -> Fallible<()>;
fn publish_injection_complete(&self, message: InjectionCompleteMessage) -> Fallible<()>;
fn publish_injection_reset_complete(&self, message: InjectionResetCompleteMessage) -> Fallible<()>;
fn publish_injection_failed(&self, message: InjectionFailedMessage) -> Fallible<()>;
fn publish_injection_reset_failed(&self, message: InjectionResetFailedMessage) -> Fallible<()>;
}

pub trait HermesProtocolHandler: Send + Sync + std::fmt::Display {
Expand Down
22 changes: 22 additions & 0 deletions hermes/src/ontology/injection.rs
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,17 @@ pub struct InjectionCompleteMessage {

impl<'de> HermesMessage<'de> for InjectionCompleteMessage {}

#[derive(Debug, Clone, PartialEq, Serialize, Deserialize, Example)]
#[serde(rename_all = "camelCase")]
pub struct InjectionFailedMessage {
/// The id of the `InjectionFailedMessage`
pub request_id: Option<String>,
/// The context of the failure
pub context: Option<String>,
nebuto marked this conversation as resolved.
Show resolved Hide resolved
}

impl<'de> HermesMessage<'de> for InjectionFailedMessage {}

#[derive(Debug, Clone, PartialEq, Serialize, Deserialize, Example)]
#[serde(rename_all = "camelCase")]
pub struct InjectionResetRequestMessage {
Expand All @@ -115,6 +126,17 @@ pub struct InjectionResetCompleteMessage {

impl<'de> HermesMessage<'de> for InjectionResetCompleteMessage {}

#[derive(Debug, Clone, PartialEq, Serialize, Deserialize, Example)]
#[serde(rename_all = "camelCase")]
pub struct InjectionResetFailedMessage {
/// The id of the `InjectionResetFailedMessage`
pub request_id: Option<String>,
/// The context of the failure
pub context: Option<String>,
nebuto marked this conversation as resolved.
Show resolved Hide resolved
}

impl<'de> HermesMessage<'de> for InjectionResetFailedMessage {}

#[cfg(test)]
mod test {
use serde_json;
Expand Down
20 changes: 20 additions & 0 deletions platforms/c/libsnips_hermes.h
Original file line number Diff line number Diff line change
Expand Up @@ -631,10 +631,20 @@ typedef struct {
void *user_data;
} CInjectionFacade;

typedef struct {
const char *request_id;
const char *context;
} CInjectionFailedMessage;

typedef struct {
const char *request_id;
} CInjectionResetCompleteMessage;

typedef struct {
const char *request_id;
const char *context;
} CInjectionResetFailedMessage;

typedef struct {
const char *last_injection_date;
} CInjectionStatusMessage;
Expand Down Expand Up @@ -933,8 +943,12 @@ SNIPS_RESULT hermes_drop_injection_complete_message(const CInjectionCompleteMess

SNIPS_RESULT hermes_drop_injection_facade(const CInjectionFacade *cstruct);

SNIPS_RESULT hermes_drop_injection_failed_message(const CInjectionFailedMessage *cstruct);

SNIPS_RESULT hermes_drop_injection_reset_complete_message(const CInjectionResetCompleteMessage *cstruct);

SNIPS_RESULT hermes_drop_injection_reset_failed_message(const CInjectionResetFailedMessage *cstruct);

SNIPS_RESULT hermes_drop_injection_status_message(const CInjectionStatusMessage *cstruct);

SNIPS_RESULT hermes_drop_intent_message(const CIntentMessage *cstruct);
Expand Down Expand Up @@ -972,9 +986,15 @@ SNIPS_RESULT hermes_injection_publish_injection_status_request(const CInjectionF
SNIPS_RESULT hermes_injection_subscribe_injection_complete(const CInjectionFacade *facade,
void (*handler)(const CInjectionCompleteMessage*, void*));

SNIPS_RESULT hermes_injection_subscribe_injection_failed(const CInjectionFacade *facade,
void (*handler)(const CInjectionFailedMessage*, void*));

SNIPS_RESULT hermes_injection_subscribe_injection_reset_complete(const CInjectionFacade *facade,
void (*handler)(const CInjectionResetCompleteMessage*, void*));

SNIPS_RESULT hermes_injection_subscribe_injection_reset_failed(const CInjectionFacade *facade,
void (*handler)(const CInjectionResetFailedMessage*, void*));

SNIPS_RESULT hermes_injection_subscribe_injection_status(const CInjectionFacade *facade,
void (*handler)(const CInjectionStatusMessage*, void*));

Expand Down
Loading