1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
#![allow(clippy::transmute_ptr_to_ptr)]
use interchange::Responder;

use crate::api::{Request, Reply};
use crate::error::Error;
use crate::types::ClientId;


cfg_if::cfg_if! {

    if #[cfg(feature = "clients-12")] {
        interchange::interchange! {
            TrussedInterchange: (Request, Result<Reply, Error>, 12)
        }
    } else if #[cfg(feature = "clients-11")] {
        interchange::interchange! {
            TrussedInterchange: (Request, Result<Reply, Error>, 11)
        }
    } else if #[cfg(feature = "clients-10")] {
        interchange::interchange! {
            TrussedInterchange: (Request, Result<Reply, Error>, 10)
        }
    } else if #[cfg(feature = "clients-9")] {
        interchange::interchange! {
            TrussedInterchange: (Request, Result<Reply, Error>, 9)
        }
    } else if #[cfg(feature = "clients-8")] {
        interchange::interchange! {
            TrussedInterchange: (Request, Result<Reply, Error>, 8)
        }
    } else if #[cfg(feature = "clients-7")] {
        interchange::interchange! {
            TrussedInterchange: (Request, Result<Reply, Error>, 7)
        }
    } else if #[cfg(feature = "clients-6")] {
        interchange::interchange! {
            TrussedInterchange: (Request, Result<Reply, Error>, 6)
        }
    } else if #[cfg(feature = "clients-5")] {
        interchange::interchange! {
            TrussedInterchange: (Request, Result<Reply, Error>, 5)
        }
    } else if #[cfg(feature = "clients-4")] {
        interchange::interchange! {
            TrussedInterchange: (Request, Result<Reply, Error>, 4)
        }
    } else if #[cfg(feature = "clients-3")] {
        interchange::interchange! {
            TrussedInterchange: (Request, Result<Reply, Error>, 3)
        }
    } else if #[cfg(feature = "clients-2")] {
        interchange::interchange! {
            TrussedInterchange: (Request, Result<Reply, Error>, 2)
        }
    } else if #[cfg(feature = "clients-1")] {
        interchange::interchange! {
            TrussedInterchange: (Request, Result<Reply, Error>, 1)
        }
    }
}


// pub use interchange::TrussedInterchange;

// TODO: The request pipe should block if there is an unhandled
// previous request/reply. As a side effect, the service should always
// be able to assume that the reply pipe is "ready".

// PRIOR ART:
// https://xenomai.org/documentation/xenomai-2.4/html/api/group__native__queue.html
// https://doc.micrium.com/display/osiiidoc/Using+Message+Queues

pub struct ServiceEndpoint {
    pub interchange: Responder<TrussedInterchange>,
    // service (trusted) has this, not client (untrusted)
    // used among other things to namespace cryptographic material
    pub client_id: ClientId,
}

// pub type ClientEndpoint = Requester<TrussedInterchange>;