orchestra_toolkit/session/api/
atapi.rs

1/* Copyright 2024-2025 LEDR Technologies Inc.
2* This file is part of the Orchestra library, which helps developer use our Orchestra technology which is based on AvesTerra, owned and developped by Georgetown University, under license agreement with LEDR Technologies Inc.
3*
4* The Orchestra library is a free software: you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation, either version 3 of the License, or any later version.
5*
6* The Orchestra library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.
7*
8* You should have received a copy of the GNU Lesser General Public License along with the Orchestra library. If not, see <https://www.gnu.org/licenses/>.
9*
10* If you have any questions, feedback or issues about the Orchestra library, you can contact us at support@ledr.io.
11*/
12
13use std::{
14    future::{Future, IntoFuture},
15    pin::Pin,
16};
17
18use time::OffsetDateTime;
19
20use crate::{
21    hgtp::*, taxonomy::*, CallError, Entity, Session, SessionAsync, SessionTrait, String255, Token,
22    Value,
23};
24
25use super::macros::*;
26
27pub(crate) async fn send_recv(msg: HGTPMessage, pool: &HGTPPool) -> Result<HGTPMessage, CallError> {
28    let mut msg = msg;
29    let mut s = pool.get().await.expect("socket_pool.get()"); // TODO: first handle connection error
30    s.send(&msg).await?;
31    s.recv(&mut msg).await?;
32    Ok(msg)
33}
34
35decl_call_atapi! {
36    InvokeEntity(entity: Entity, method: Method, authorization: Token) -> Value,
37    {
38        auxiliary: Entity,
39        ancillary: Entity,
40        attribute: Attribute,
41        instance: i32,
42        offset: i32,
43        name: String255,
44        key: String255,
45        value: &Value,
46        parameter: i64,
47        resultant: i64,
48        index: i64,
49        count: i64,
50        aspect: Aspect,
51        context: Context,
52        category: Category,
53        class: Class,
54        event: Event,
55        mode: Mode,
56        state: State,
57        condition: Condition,
58        precedence: u16,
59        time: OffsetDateTime,
60        timeout: i64,
61        authority: Token,
62    }
63}
64
65impl<T: SessionTrait> InvokeEntity<T> {
66    async fn call_async(mut self) -> Result<Value, CallError> {
67        self.msg.pack_command(Command::Invoke);
68
69        let msg = send_recv(self.msg, self.session.get_socket_pool()).await?;
70        Ok(msg.unpack_value()?)
71    }
72}
73
74decl_call_atapi! {
75    CreateEntity(name: String255, authorization: Token) -> Entity,
76    {
77        outlet: Entity,
78        ancillary: Entity as with_server(),
79        key: String255,
80        context: Context,
81        category: Category,
82        class: Class,
83        method: Method,
84        attribute: Attribute,
85        event: Event,
86        precedence: u16,
87        timeout: i64,
88    }
89}
90impl<T: SessionTrait> CreateEntity<T> {
91    async fn call_async(mut self) -> Result<Entity, CallError> {
92        self.msg.pack_command(Command::Create);
93
94        let msg = send_recv(self.msg, self.session.get_socket_pool()).await?;
95        Ok(msg.unpack_entity())
96    }
97}
98
99decl_call_atapi! {
100    DeleteEntity(entity: Entity, authorization: Token) -> (),
101    {
102    }
103}
104impl<T: SessionTrait> DeleteEntity<T> {
105    async fn call_async(mut self) -> Result<(), CallError> {
106        self.msg.pack_command(Command::Delete);
107
108        let _ = send_recv(self.msg, self.session.get_socket_pool()).await?;
109        Ok(())
110    }
111}
112
113decl_call_atapi! {
114    InquireEntity(entity: Entity, attribute: Attribute, authorization: Token) -> Value,
115    {
116        auxiliary: Entity,
117        ancillary: Entity,
118        instance: i32,
119        offset: i32,
120        name: String255,
121        key: String255,
122        parameter: i64,
123        resultant: i64,
124        index: i64,
125        count: i64,
126        aspect: Aspect,
127        context: Context,
128        category: Category,
129        class: Class,
130        event: Event,
131        mode: Mode,
132        state: State,
133        condition: Condition,
134        precedence: u16,
135        value: &Value,
136        time: OffsetDateTime,
137        timeout: i64,
138        authority: Token,
139    }
140}
141impl<T: SessionTrait> InquireEntity<T> {
142    async fn call_async(mut self) -> Result<Value, CallError> {
143        self.msg.pack_command(Command::Inquire);
144
145        let msg = send_recv(self.msg, self.session.get_socket_pool()).await?;
146        Ok(msg.unpack_value()?)
147    }
148}
149
150decl_call_atapi! {
151    ReferenceEntity(entity: Entity, authorization: Token) -> (),
152    {
153        count: i64,
154    }
155}
156impl<T: SessionTrait> ReferenceEntity<T> {
157    async fn call_async(mut self) -> Result<(), CallError> {
158        self.msg.pack_command(Command::Reference);
159
160        let _ = send_recv(self.msg, self.session.get_socket_pool()).await?;
161        Ok(())
162    }
163}
164
165decl_call_atapi! {
166    DereferenceEntity(entity: Entity, authorization: Token) -> (),
167    {
168        count: i64,
169    }
170}
171impl<T: SessionTrait> DereferenceEntity<T> {
172    async fn call_async(mut self) -> Result<(), CallError> {
173        self.msg.pack_command(Command::Dereference);
174
175        let _ = send_recv(self.msg, self.session.get_socket_pool()).await?;
176        Ok(())
177    }
178}
179
180decl_call_atapi! {
181    ConnectMethod(entity: Entity, outlet: Entity, authorization: Token) -> (),
182    {
183        method: Method,
184        precedence: u16,
185        timeout: i64,
186    }
187}
188impl<T: SessionTrait> ConnectMethod<T> {
189    async fn call_async(mut self) -> Result<(), CallError> {
190        self.msg.pack_command(Command::Connect);
191
192        let _ = send_recv(self.msg, self.session.get_socket_pool()).await?;
193        Ok(())
194    }
195}
196
197decl_call_atapi! {
198    DisconnectMethod(entity: Entity, outlet: Entity, method: Method, authorization: Token) -> (),
199    {
200        precedence: u16,
201    }
202}
203impl<T: SessionTrait> DisconnectMethod<T> {
204    async fn call_async(mut self) -> Result<(), CallError> {
205        self.msg.pack_command(Command::Disconnect);
206
207        let _ = send_recv(self.msg, self.session.get_socket_pool()).await?;
208        Ok(())
209    }
210}
211
212#[derive(Debug, Clone, Copy)]
213pub struct Connection {
214    pub outlet: Entity,
215    pub method: Method,
216    pub precedence: u16,
217}
218
219decl_call_atapi! {
220    EntityConnection(entity: Entity, index: i64, authorization: Token) -> Connection,
221    {
222    }
223}
224impl<T: SessionTrait> EntityConnection<T> {
225    async fn call_async(mut self) -> Result<Connection, CallError> {
226        self.msg.pack_command(Command::Connection);
227
228        let msg = send_recv(self.msg, self.session.get_socket_pool()).await?;
229        Ok(Connection {
230            outlet: msg.unpack_outlet(),
231            method: msg.unpack_method()?,
232            precedence: msg.unpack_precedence(),
233        })
234    }
235}
236
237decl_call_atapi! {
238    AttachAttribute(entity: Entity, outlet: Entity, authorization: Token) -> (),
239    {
240        attribute: Attribute,
241        precedence: u16,
242        timeout: i64,
243    }
244}
245impl<T: SessionTrait> AttachAttribute<T> {
246    async fn call_async(mut self) -> Result<(), CallError> {
247        self.msg.pack_command(Command::Attach);
248
249        let _ = send_recv(self.msg, self.session.get_socket_pool()).await?;
250        Ok(())
251    }
252}
253
254decl_call_atapi! {
255    DetachAttribute(entity: Entity, outlet: Entity, attribute: Attribute, authorization: Token) -> (),
256    {
257        attribute: Attribute,
258        precedence: u16,
259    }
260}
261impl<T: SessionTrait> DetachAttribute<T> {
262    async fn call_async(mut self) -> Result<(), CallError> {
263        self.msg.pack_command(Command::Detach);
264
265        let _ = send_recv(self.msg, self.session.get_socket_pool()).await?;
266        Ok(())
267    }
268}
269
270#[derive(Debug, Clone, Copy)]
271pub struct Attachment {
272    pub outlet: Entity,
273    pub attribute: Attribute,
274    pub precedence: u16,
275}
276
277decl_call_atapi! {
278    EntityAttachment(entity: Entity, index: i64, authorization: Token) -> Attachment,
279    {
280    }
281}
282impl<T: SessionTrait> EntityAttachment<T> {
283    async fn call_async(mut self) -> Result<Attachment, CallError> {
284        self.msg.pack_command(Command::Attachment);
285
286        let msg = send_recv(self.msg, self.session.get_socket_pool()).await?;
287        Ok(Attachment {
288            outlet: msg.unpack_outlet(),
289            attribute: msg.unpack_attribute()?,
290            precedence: msg.unpack_precedence(),
291        })
292    }
293}
294
295decl_call_atapi! {
296    ActivateOutlet(outlet: Entity, authorization: Token) -> (),
297    {
298    }
299}
300impl<T: SessionTrait> ActivateOutlet<T> {
301    async fn call_async(mut self) -> Result<(), CallError> {
302        self.msg.pack_command(Command::Activate);
303
304        let _ = send_recv(self.msg, self.session.get_socket_pool()).await?;
305        Ok(())
306    }
307}
308
309decl_call_atapi! {
310    DeactivateOutlet(outlet: Entity, authorization: Token) -> (),
311    {
312    }
313}
314impl<T: SessionTrait> DeactivateOutlet<T> {
315    async fn call_async(mut self) -> Result<(), CallError> {
316        self.msg.pack_command(Command::Deactivate);
317
318        let _ = send_recv(self.msg, self.session.get_socket_pool()).await?;
319        Ok(())
320    }
321}
322
323decl_call_atapi! {
324    ResetOutlet(outlet: Entity, authorization: Token) -> (),
325    {
326    }
327}
328impl<T: SessionTrait> ResetOutlet<T> {
329    async fn call_async(mut self) -> Result<(), CallError> {
330        self.msg.pack_command(Command::Reset);
331
332        let _ = send_recv(self.msg, self.session.get_socket_pool()).await?;
333        Ok(())
334    }
335}
336
337decl_call_atapi! {
338    PublishEvent(entity: Entity, event: Event, authorization: Token) -> (),
339    {
340        auxiliary: Entity,
341        ancillary: Entity,
342        method: Method,
343        attribute: Attribute,
344        instance: i32,
345        offset: i32,
346        name: String255,
347        key: String255,
348        parameter: i64,
349        resultant: i64,
350        index: i64,
351        count: i64,
352        aspect: Aspect,
353        context: Context,
354        category: Category,
355        class: Class,
356        mode: Mode,
357        state: State,
358        condition: Condition,
359        precedence: u16,
360        value: &Value,
361        time: OffsetDateTime,
362        timeout: i64,
363        authority: Token,
364    }
365}
366impl<T: SessionTrait> PublishEvent<T> {
367    async fn call_async(mut self) -> Result<(), CallError> {
368        self.msg.pack_command(Command::Publish);
369
370        let _ = send_recv(self.msg, self.session.get_socket_pool()).await?;
371        Ok(())
372    }
373}
374
375decl_call_atapi! {
376    SubscribeEvent(entity: Entity, outlet: Entity, authorization: Token) -> (),
377    {
378        event: Event,
379        precedence: u16,
380        timeout: i64,
381    }
382}
383impl<T: SessionTrait> SubscribeEvent<T> {
384    async fn call_async(mut self) -> Result<(), CallError> {
385        self.msg.pack_command(Command::Subscribe);
386
387        let _ = send_recv(self.msg, self.session.get_socket_pool()).await?;
388        Ok(())
389    }
390}
391
392decl_call_atapi! {
393    UnsubscribeEvent(entity: Entity, outlet: Entity, event: Event, authorization: Token) -> (),
394    {
395        precedence: u16,
396    }
397}
398impl<T: SessionTrait> UnsubscribeEvent<T> {
399    async fn call_async(mut self) -> Result<(), CallError> {
400        self.msg.pack_command(Command::Unsubscribe);
401
402        let _ = send_recv(self.msg, self.session.get_socket_pool()).await?;
403        Ok(())
404    }
405}
406
407#[derive(Debug, Clone)]
408pub struct WaiterEvent {
409    /// The entity the event has been published on
410    pub entity: Entity,
411    /// The outlet subscribed to the entity
412    pub outlet: Entity,
413    pub method: Method,
414    pub auxiliary: Entity,
415    pub attribute: Attribute,
416    pub ancillary: Entity,
417    pub instance: i32,
418    pub offset: i32,
419    pub name: String255,
420    pub key: String255,
421    pub parameter: i64,
422    pub resultant: i64,
423    pub index: i64,
424    pub count: i64,
425    pub aspect: Aspect,
426    pub context: Context,
427    pub category: Category,
428    pub class: Class,
429    pub event: Event,
430    pub mode: Mode,
431    pub state: State,
432    pub condition: Condition,
433    pub precedence: u16,
434    pub time: OffsetDateTime,
435    pub value: Value,
436    pub timeout: i64,
437    pub authority: Token,
438    /// The authorization the event was published with
439    pub authorization: Token,
440}
441
442impl TryFrom<&HGTPMessage> for WaiterEvent {
443    type Error = UnpackError;
444
445    #[rustfmt::skip]
446    fn try_from(msg: &HGTPMessage) -> Result<Self, Self::Error> {
447        Ok(Self {
448            entity       : msg.unpack_entity(),
449            outlet       : msg.unpack_outlet(),
450            method       : msg.unpack_method()?,
451            auxiliary    : msg.unpack_auxiliary(),
452            attribute    : msg.unpack_attribute()?,
453            ancillary    : msg.unpack_ancillary(),
454            instance     : msg.unpack_instance(),
455            offset       : msg.unpack_offset(),
456            name         : msg.unpack_name()?,
457            key          : msg.unpack_key()?,
458            parameter    : msg.unpack_parameter(),
459            resultant    : msg.unpack_resultant(),
460            index        : msg.unpack_index(),
461            count        : msg.unpack_count(),
462            aspect       : msg.unpack_aspect()?,
463            context      : msg.unpack_context()?,
464            category     : msg.unpack_category()?,
465            class        : msg.unpack_class()?,
466            event        : msg.unpack_event()?,
467            mode         : msg.unpack_mode()?,
468            state        : msg.unpack_state()?,
469            condition    : msg.unpack_condition()?,
470            precedence   : msg.unpack_precedence(),
471            time         : msg.unpack_time()?,
472            value        : msg.unpack_value()?,
473            timeout      : msg.unpack_timeout(),
474            authority    : msg.unpack_authority(),
475            authorization: msg.unpack_authorization(),
476        })
477    }
478}
479
480decl_call_atapi! {
481    WaitEvent(outlet: Entity, authorization: Token) -> WaiterEvent,
482    {
483    }
484}
485impl<T: SessionTrait> WaitEvent<T> {
486    async fn call_async(mut self) -> Result<WaiterEvent, CallError> {
487        self.msg.pack_command(Command::Wait);
488
489        let msg = send_recv(self.msg, self.session.get_socket_pool()).await?;
490        Ok(WaiterEvent::try_from(&msg)?)
491    }
492}
493
494decl_call_atapi! {
495    SubscribeEntity(entity: Entity, outlet: Entity, event: Event, authorization: Token) -> (),
496    {
497        precedence: u16,
498        timeout: i64,
499    }
500}
501impl<T: SessionTrait> SubscribeEntity<T> {
502    async fn call_async(mut self) -> Result<(), CallError> {
503        self.msg.pack_command(Command::Subscribe);
504
505        let _ = send_recv(self.msg, self.session.get_socket_pool()).await?;
506        Ok(())
507    }
508}
509
510decl_call_atapi! {
511    LockOutlet(outlet: Entity, authorization: Token) -> (),
512    {
513        timeout: i64,
514    }
515}
516impl<T: SessionTrait> LockOutlet<T> {
517    async fn call_async(mut self) -> Result<(), CallError> {
518        self.msg.pack_command(Command::Lock);
519
520        let _ = send_recv(self.msg, self.session.get_socket_pool()).await?;
521        Ok(())
522    }
523}
524
525decl_call_atapi! {
526    UnlockOutlet(outlet: Entity, authorization: Token) -> (),
527    {
528    }
529}
530impl<T: SessionTrait> UnlockOutlet<T> {
531    async fn call_async(mut self) -> Result<(), CallError> {
532        self.msg.pack_command(Command::Unlock);
533
534        let _ = send_recv(self.msg, self.session.get_socket_pool()).await?;
535        Ok(())
536    }
537}
538
539decl_call_atapi! {
540    AuthorizeEntity(entity: Entity, authority: Token, authorization: Token) -> (),
541    {
542        parameter: i64 as with_restriction(),
543    }
544}
545impl<T: SessionTrait> AuthorizeEntity<T> {
546    async fn call_async(mut self) -> Result<(), CallError> {
547        self.msg.pack_command(Command::Authorize);
548
549        let _ = send_recv(self.msg, self.session.get_socket_pool()).await?;
550        Ok(())
551    }
552}
553
554decl_call_atapi! {
555    DeauthorizeEntity(entity: Entity, authority: Token, authorization: Token) -> (),
556    {
557    }
558}
559impl<T: SessionTrait> DeauthorizeEntity<T> {
560    async fn call_async(mut self) -> Result<(), CallError> {
561        self.msg.pack_command(Command::Deauthorize);
562
563        let _ = send_recv(self.msg, self.session.get_socket_pool()).await?;
564        Ok(())
565    }
566}
567
568decl_call_atapi! {
569    EntityAuthorized(entity: Entity, authority: Token, authorization: Token) -> bool,
570    {
571    }
572}
573impl<T: SessionTrait> EntityAuthorized<T> {
574    async fn call_async(mut self) -> Result<bool, CallError> {
575        self.msg.pack_command(Command::Authorized);
576
577        let msg = send_recv(self.msg, self.session.get_socket_pool()).await?;
578        Ok(msg.unpack_resultant() != 0)
579    }
580}
581
582decl_call_atapi! {
583    EntityAuthority(entity: Entity, authorization: Token) -> Token,
584    {
585    }
586}
587impl<T: SessionTrait> EntityAuthority<T> {
588    async fn call_async(mut self) -> Result<Token, CallError> {
589        self.msg.pack_command(Command::Report);
590        self.msg.pack_report(Report::Authority);
591
592        let msg = send_recv(self.msg, self.session.get_socket_pool()).await?;
593        Ok(msg.unpack_authority())
594    }
595}
596
597decl_call_atapi! {
598    EntityName(entity: Entity, authorization: Token) -> String255,
599    {
600    }
601}
602impl<T: SessionTrait> EntityName<T> {
603    async fn call_async(mut self) -> Result<String255, CallError> {
604        self.msg.pack_command(Command::Report);
605        self.msg.pack_report(Report::Name);
606
607        let msg = send_recv(self.msg, self.session.get_socket_pool()).await?;
608        Ok(msg.unpack_name()?)
609    }
610}
611
612decl_call_atapi! {
613    EntityClass(entity: Entity, authorization: Token) -> Class,
614    {
615    }
616}
617impl<T: SessionTrait> EntityClass<T> {
618    async fn call_async(mut self) -> Result<Class, CallError> {
619        self.msg.pack_command(Command::Report);
620        self.msg.pack_report(Report::Class);
621
622        let msg = send_recv(self.msg, self.session.get_socket_pool()).await?;
623        Ok(msg.unpack_class()?)
624    }
625}
626
627decl_call_atapi! {
628    EntityCategory(entity: Entity, authorization: Token) -> Category,
629    {
630    }
631}
632impl<T: SessionTrait> EntityCategory<T> {
633    async fn call_async(mut self) -> Result<Category, CallError> {
634        self.msg.pack_command(Command::Report);
635        self.msg.pack_report(Report::Category);
636
637        let msg = send_recv(self.msg, self.session.get_socket_pool()).await?;
638        Ok(msg.unpack_category()?)
639    }
640}
641
642decl_call_atapi! {
643    LocalServer(authorization: Token) -> Entity,
644    {
645    }
646}
647impl<T: SessionTrait> LocalServer<T> {
648    async fn call_async(mut self) -> Result<Entity, CallError> {
649        self.msg.pack_command(Command::Report);
650        self.msg.pack_report(Report::Local);
651
652        let msg = send_recv(self.msg, self.session.get_socket_pool()).await?;
653        Ok(msg.unpack_entity())
654    }
655}
656
657decl_call_atapi! {
658    LocalVersion() -> String,
659    {}
660}
661impl<T: SessionTrait> LocalVersion<T> {
662    async fn call_async(mut self) -> Result<String, CallError> {
663        self.msg.pack_command(Command::Report);
664        self.msg.pack_report(Report::Version);
665
666        let msg = send_recv(self.msg, self.session.get_socket_pool()).await?;
667        Ok(String::from_utf8_lossy(msg.unpack_bytes()).into_owned())
668    }
669}
670
671decl_call_atapi! {
672    EntityRedirection(entity: Entity, authorization: Token) -> Entity,
673    {
674    }
675}
676impl<T: SessionTrait> EntityRedirection<T> {
677    async fn call_async(mut self) -> Result<Entity, CallError> {
678        self.msg.pack_command(Command::Report);
679        self.msg.pack_report(Report::Redirection);
680
681        let msg = send_recv(self.msg, self.session.get_socket_pool()).await?;
682        Ok(msg.unpack_entity())
683    }
684}
685
686decl_call_atapi! {
687    EntityRedirect(auxiliary: Entity,ancillary: Entity, authorization: Token) -> (),
688    {
689        entity: Entity as with_server(),
690    }
691}
692impl<T: SessionTrait> EntityRedirect<T> {
693    async fn call_async(mut self) -> Result<(), CallError> {
694        self.msg.pack_command(Command::Redirect);
695
696        send_recv(self.msg, self.session.get_socket_pool()).await?;
697        Ok(())
698    }
699}
700
701decl_call_atapi! {
702    ChangeEntity(entity: Entity, authorization: Token) -> (),
703    {
704        name: String255,
705        key: String255,
706        context: Context,
707        category: Category,
708        class: Class,
709        state: State,
710        authority: Token,
711    }
712}
713impl<T: SessionTrait> ChangeEntity<T> {
714    async fn call_async(mut self) -> Result<(), CallError> {
715        self.msg.pack_command(Command::Change);
716
717        let _ = send_recv(self.msg, self.session.get_socket_pool()).await?;
718        Ok(())
719    }
720}
721
722decl_call_atapi! {
723    EntityTimestamp(entity: Entity, authorization: Token) -> OffsetDateTime,
724    {
725    }
726}
727impl<T: SessionTrait> EntityTimestamp<T> {
728    async fn call_async(mut self) -> Result<OffsetDateTime, CallError> {
729        self.msg.pack_command(Command::Report);
730        self.msg.pack_report(Report::Timestamp);
731
732        let msg = send_recv(self.msg, self.session.get_socket_pool()).await?;
733        msg.unpack_time().map_err(CallError::from)
734    }
735}
736
737decl_call_atapi! {
738    EntityAvailable(entity: Entity, authorization: Token) -> bool,
739    {
740    }
741}
742impl<T: SessionTrait> EntityAvailable<T> {
743    async fn call_async(mut self) -> Result<bool, CallError> {
744        self.msg.pack_command(Command::Report);
745        self.msg.pack_report(Report::Available);
746
747        let msg = send_recv(self.msg, self.session.get_socket_pool()).await?;
748        Ok(msg.unpack_resultant() != 0)
749    }
750}
751
752decl_call_atapi! {
753    EntityExtinct(entity: Entity, authorization: Token) -> bool,
754    {
755    }
756}
757impl<T: SessionTrait> EntityExtinct<T> {
758    async fn call_async(mut self) -> Result<bool, CallError> {
759        self.msg.pack_command(Command::Report);
760        self.msg.pack_report(Report::Extinct);
761
762        let msg = send_recv(self.msg, self.session.get_socket_pool()).await?;
763        Ok(msg.unpack_resultant() != 0)
764    }
765}
766
767decl_call_atapi! {
768    EntityActivated(entity: Entity, authorization: Token) -> bool,
769    {
770    }
771}
772impl<T: SessionTrait> EntityActivated<T> {
773    async fn call_async(mut self) -> Result<bool, CallError> {
774        self.msg.pack_command(Command::Report);
775        self.msg.pack_report(Report::Activated);
776
777        let msg = send_recv(self.msg, self.session.get_socket_pool()).await?;
778        Ok(msg.unpack_resultant() != 0)
779    }
780}
781
782decl_call_atapi! {
783    EntityLocked(entity: Entity, authorization: Token) -> bool,
784    {
785    }
786}
787impl<T: SessionTrait> EntityLocked<T> {
788    async fn call_async(mut self) -> Result<bool, CallError> {
789        self.msg.pack_command(Command::Report);
790        self.msg.pack_report(Report::Locked);
791
792        let msg = send_recv(self.msg, self.session.get_socket_pool()).await?;
793        Ok(msg.unpack_resultant() != 0)
794    }
795}
796
797decl_call_atapi! {
798    Pending(entity: Entity, authorization: Token) -> i64,
799    {
800    }
801}
802impl<T: SessionTrait> Pending<T> {
803    async fn call_async(mut self) -> Result<i64, CallError> {
804        self.msg.pack_command(Command::Report);
805        self.msg.pack_report(Report::Pending);
806
807        let msg = send_recv(self.msg, self.session.get_socket_pool()).await?;
808        Ok(msg.unpack_count())
809    }
810}
811
812decl_call_atapi! {
813    EntityRendezvous(entity: Entity, authorization: Token) -> String,
814    {
815    }
816}
817impl<T: SessionTrait> EntityRendezvous<T> {
818    async fn call_async(mut self) -> Result<String, CallError> {
819        self.msg.pack_command(Command::Report);
820        self.msg.pack_report(Report::Rendezvous);
821
822        let msg = send_recv(self.msg, self.session.get_socket_pool()).await?;
823        Ok(String::from_utf8_lossy(msg.unpack_bytes()).into_owned())
824    }
825}
826
827decl_call_atapi! {
828    EntityReferences(entity: Entity, authorization: Token) -> i64,
829    {
830    }
831}
832impl<T: SessionTrait> EntityReferences<T> {
833    async fn call_async(mut self) -> Result<i64, CallError> {
834        self.msg.pack_command(Command::Report);
835        self.msg.pack_report(Report::References);
836
837        let msg = send_recv(self.msg, self.session.get_socket_pool()).await?;
838        Ok(msg.unpack_count())
839    }
840}
841
842decl_call_atapi! {
843    ConnectionCount(entity: Entity, authorization: Token) -> i64,
844    {
845    }
846}
847impl<T: SessionTrait> ConnectionCount<T> {
848    async fn call_async(mut self) -> Result<i64, CallError> {
849        self.msg.pack_command(Command::Report);
850        self.msg.pack_report(Report::Connections);
851
852        let msg = send_recv(self.msg, self.session.get_socket_pool()).await?;
853        Ok(msg.unpack_count())
854    }
855}
856
857decl_call_atapi! {
858    AttachmentCount(entity: Entity, authorization: Token) -> i64,
859    {
860    }
861}
862impl<T: SessionTrait> AttachmentCount<T> {
863    async fn call_async(mut self) -> Result<i64, CallError> {
864        self.msg.pack_command(Command::Report);
865        self.msg.pack_report(Report::Attachments);
866
867        let msg = send_recv(self.msg, self.session.get_socket_pool()).await?;
868        Ok(msg.unpack_count())
869    }
870}
871
872decl_call_atapi! {
873    SubscriptionCount(entity: Entity, authorization: Token) -> i64,
874    {
875    }
876}
877impl<T: SessionTrait> SubscriptionCount<T> {
878    async fn call_async(mut self) -> Result<i64, CallError> {
879        self.msg.pack_command(Command::Report);
880        self.msg.pack_report(Report::Subscriptions);
881
882        let msg = send_recv(self.msg, self.session.get_socket_pool()).await?;
883        Ok(msg.unpack_count())
884    }
885}
886
887decl_call_atapi! {
888    EntityAuthorizations(entity: Entity, authorization: Token) -> i64,
889    {
890    }
891}
892impl<T: SessionTrait> EntityAuthorizations<T> {
893    async fn call_async(mut self) -> Result<i64, CallError> {
894        self.msg.pack_command(Command::Report);
895        self.msg.pack_report(Report::Authorizations);
896
897        let msg = send_recv(self.msg, self.session.get_socket_pool()).await?;
898        Ok(msg.unpack_count())
899    }
900}
901
902decl_call_atapi! {
903    FetchEntity(entity: Entity, authorization: Token) -> Value,
904    {
905        name: String255,
906    }
907}
908impl<T: SessionTrait> FetchEntity<T> {
909    async fn call_async(mut self) -> Result<Value, CallError> {
910        self.msg.pack_command(Command::Fetch);
911
912        let msg = send_recv(self.msg, self.session.get_socket_pool()).await?;
913        Ok(msg.unpack_value()?)
914    }
915}
916
917decl_call_atapi! {
918    InsertElement(entity: Entity, value: &Value, index: i64, authorization: Token) -> (),
919    {}
920}
921impl<T: SessionTrait> InsertElement<T> {
922    async fn call_async(mut self) -> Result<(), CallError> {
923        self.msg.pack_command(Command::Insert);
924
925        send_recv(self.msg, self.session.get_socket_pool()).await?;
926        Ok(())
927    }
928}
929
930decl_call_atapi! {
931    RemoveElement(entity: Entity, index: i64, authorization: Token) -> (),
932    {}
933}
934impl<T: SessionTrait> RemoveElement<T> {
935    async fn call_async(mut self) -> Result<(), CallError> {
936        self.msg.pack_command(Command::Remove);
937
938        send_recv(self.msg, self.session.get_socket_pool()).await?;
939        Ok(())
940    }
941}
942
943decl_call_atapi! {
944    ReplaceElement(entity: Entity, value: &Value, index: i64, authorization: Token) -> (),
945    {}
946}
947impl<T: SessionTrait> ReplaceElement<T> {
948    async fn call_async(mut self) -> Result<(), CallError> {
949        self.msg.pack_command(Command::Replace);
950
951        send_recv(self.msg, self.session.get_socket_pool()).await?;
952        Ok(())
953    }
954}
955
956decl_call_atapi! {
957    EraseElement(entity: Entity, authorization: Token) -> (),
958    {}
959}
960impl<T: SessionTrait> EraseElement<T> {
961    async fn call_async(mut self) -> Result<(), CallError> {
962        self.msg.pack_command(Command::Erase);
963
964        send_recv(self.msg, self.session.get_socket_pool()).await?;
965        Ok(())
966    }
967}
968
969decl_call_atapi! {
970    FindElement(entity: Entity, value: &Value, index: i64, authorization: Token) -> i64,
971    {}
972}
973impl<T: SessionTrait> FindElement<T> {
974    async fn call_async(mut self) -> Result<i64, CallError> {
975        self.msg.pack_command(Command::Find);
976
977        let msg = send_recv(self.msg, self.session.get_socket_pool()).await?;
978        Ok(msg.unpack_index())
979    }
980}
981
982decl_call_atapi! {
983    EntityElement(entity: Entity, authorization: Token) -> Value,
984    {}
985}
986impl<T: SessionTrait> EntityElement<T> {
987    async fn call_async(mut self) -> Result<Value, CallError> {
988        self.msg.pack_command(Command::Element);
989
990        let msg = send_recv(self.msg, self.session.get_socket_pool()).await?;
991        Ok(msg.unpack_value()?)
992    }
993}
994
995decl_call_atapi! {
996    ElementCount(entity: Entity, authorization: Token) -> i64,
997    {}
998}
999impl<T: SessionTrait> ElementCount<T> {
1000    async fn call_async(mut self) -> Result<i64, CallError> {
1001        self.msg.pack_command(Command::Length);
1002
1003        let msg = send_recv(self.msg, self.session.get_socket_pool()).await?;
1004        Ok(msg.unpack_count())
1005    }
1006}