use std::{
future::{Future, IntoFuture},
pin::Pin,
};
use time::OffsetDateTime;
use crate::{
hgtp::*, taxonomy::*, CallError, Entity, Session, SessionAsync, SessionTrait, String255, Token,
Value,
};
use super::macros::*;
pub(crate) async fn send_recv(msg: HGTPMessage, pool: &HGTPPool) -> Result<HGTPMessage, CallError> {
let mut msg = msg;
let mut s = pool.get().await.expect("socket_pool.get()"); s.send(&msg).await?;
s.recv(&mut msg).await?;
Ok(msg)
}
decl_call_atapi! {
InvokeEntity(entity: Entity, method: Method, authorization: Token) -> Value,
{
auxiliary: Entity,
ancillary: Entity,
attribute: Attribute,
instance: i32,
offset: i32,
name: String255,
key: String255,
value: &Value,
parameter: i64,
resultant: i64,
index: i64,
count: i64,
aspect: Aspect,
context: Context,
category: Category,
class: Class,
event: Event,
mode: Mode,
state: State,
condition: Condition,
precedence: u16,
time: OffsetDateTime,
timeout: i64,
authority: Token,
}
}
impl<T: SessionTrait> InvokeEntity<T> {
async fn call_async(mut self) -> Result<Value, CallError> {
self.msg.pack_command(Command::Invoke);
let msg = send_recv(self.msg, self.session.get_socket_pool()).await?;
Ok(msg.unpack_value()?)
}
}
decl_call_atapi! {
CreateEntity(name: String255, authorization: Token) -> Entity,
{
outlet: Entity,
ancillary: Entity as with_server(),
key: String255,
context: Context,
category: Category,
class: Class,
method: Method,
attribute: Attribute,
event: Event,
precedence: u16,
timeout: i64,
}
}
impl<T: SessionTrait> CreateEntity<T> {
async fn call_async(mut self) -> Result<Entity, CallError> {
self.msg.pack_command(Command::Create);
let msg = send_recv(self.msg, self.session.get_socket_pool()).await?;
Ok(msg.unpack_entity())
}
}
decl_call_atapi! {
DeleteEntity(entity: Entity, authorization: Token) -> (),
{
}
}
impl<T: SessionTrait> DeleteEntity<T> {
async fn call_async(mut self) -> Result<(), CallError> {
self.msg.pack_command(Command::Delete);
let _ = send_recv(self.msg, self.session.get_socket_pool()).await?;
Ok(())
}
}
decl_call_atapi! {
InquireEntity(entity: Entity, attribute: Attribute, authorization: Token) -> Value,
{
auxiliary: Entity,
ancillary: Entity,
instance: i32,
offset: i32,
name: String255,
key: String255,
parameter: i64,
resultant: i64,
index: i64,
count: i64,
aspect: Aspect,
context: Context,
category: Category,
class: Class,
event: Event,
mode: Mode,
state: State,
condition: Condition,
precedence: u16,
value: &Value,
time: OffsetDateTime,
timeout: i64,
authority: Token,
}
}
impl<T: SessionTrait> InquireEntity<T> {
async fn call_async(mut self) -> Result<Value, CallError> {
self.msg.pack_command(Command::Inquire);
let msg = send_recv(self.msg, self.session.get_socket_pool()).await?;
Ok(msg.unpack_value()?)
}
}
decl_call_atapi! {
ReferenceEntity(entity: Entity, authorization: Token) -> (),
{
count: i64,
}
}
impl<T: SessionTrait> ReferenceEntity<T> {
async fn call_async(mut self) -> Result<(), CallError> {
self.msg.pack_command(Command::Reference);
let _ = send_recv(self.msg, self.session.get_socket_pool()).await?;
Ok(())
}
}
decl_call_atapi! {
DereferenceEntity(entity: Entity, authorization: Token) -> (),
{
count: i64,
}
}
impl<T: SessionTrait> DereferenceEntity<T> {
async fn call_async(mut self) -> Result<(), CallError> {
self.msg.pack_command(Command::Dereference);
let _ = send_recv(self.msg, self.session.get_socket_pool()).await?;
Ok(())
}
}
decl_call_atapi! {
ConnectMethod(entity: Entity, outlet: Entity, authorization: Token) -> (),
{
method: Method,
precedence: u16,
timeout: i64,
}
}
impl<T: SessionTrait> ConnectMethod<T> {
async fn call_async(mut self) -> Result<(), CallError> {
self.msg.pack_command(Command::Connect);
let _ = send_recv(self.msg, self.session.get_socket_pool()).await?;
Ok(())
}
}
decl_call_atapi! {
DisconnectMethod(entity: Entity, outlet: Entity, method: Method, authorization: Token) -> (),
{
precedence: u16,
}
}
impl<T: SessionTrait> DisconnectMethod<T> {
async fn call_async(mut self) -> Result<(), CallError> {
self.msg.pack_command(Command::Disconnect);
let _ = send_recv(self.msg, self.session.get_socket_pool()).await?;
Ok(())
}
}
#[derive(Debug, Clone, Copy)]
pub struct Connection {
pub outlet: Entity,
pub method: Method,
pub precedence: u16,
}
decl_call_atapi! {
EntityConnection(entity: Entity, index: i64, authorization: Token) -> Connection,
{
}
}
impl<T: SessionTrait> EntityConnection<T> {
async fn call_async(mut self) -> Result<Connection, CallError> {
self.msg.pack_command(Command::Connection);
let msg = send_recv(self.msg, self.session.get_socket_pool()).await?;
Ok(Connection {
outlet: msg.unpack_outlet(),
method: msg.unpack_method()?,
precedence: msg.unpack_precedence(),
})
}
}
decl_call_atapi! {
AttachAttribute(entity: Entity, outlet: Entity, authorization: Token) -> (),
{
attribute: Attribute,
precedence: u16,
timeout: i64,
}
}
impl<T: SessionTrait> AttachAttribute<T> {
async fn call_async(mut self) -> Result<(), CallError> {
self.msg.pack_command(Command::Attach);
let _ = send_recv(self.msg, self.session.get_socket_pool()).await?;
Ok(())
}
}
decl_call_atapi! {
DetachAttribute(entity: Entity, outlet: Entity, attribute: Attribute, authorization: Token) -> (),
{
attribute: Attribute,
precedence: u16,
}
}
impl<T: SessionTrait> DetachAttribute<T> {
async fn call_async(mut self) -> Result<(), CallError> {
self.msg.pack_command(Command::Detach);
let _ = send_recv(self.msg, self.session.get_socket_pool()).await?;
Ok(())
}
}
#[derive(Debug, Clone, Copy)]
pub struct Attachment {
pub outlet: Entity,
pub attribute: Attribute,
pub precedence: u16,
}
decl_call_atapi! {
EntityAttachment(entity: Entity, index: i64, authorization: Token) -> Attachment,
{
}
}
impl<T: SessionTrait> EntityAttachment<T> {
async fn call_async(mut self) -> Result<Attachment, CallError> {
self.msg.pack_command(Command::Attachment);
let msg = send_recv(self.msg, self.session.get_socket_pool()).await?;
Ok(Attachment {
outlet: msg.unpack_outlet(),
attribute: msg.unpack_attribute()?,
precedence: msg.unpack_precedence(),
})
}
}
decl_call_atapi! {
ActivateOutlet(outlet: Entity, authorization: Token) -> (),
{
}
}
impl<T: SessionTrait> ActivateOutlet<T> {
async fn call_async(mut self) -> Result<(), CallError> {
self.msg.pack_command(Command::Activate);
let _ = send_recv(self.msg, self.session.get_socket_pool()).await?;
Ok(())
}
}
decl_call_atapi! {
DeactivateOutlet(outlet: Entity, authorization: Token) -> (),
{
}
}
impl<T: SessionTrait> DeactivateOutlet<T> {
async fn call_async(mut self) -> Result<(), CallError> {
self.msg.pack_command(Command::Deactivate);
let _ = send_recv(self.msg, self.session.get_socket_pool()).await?;
Ok(())
}
}
decl_call_atapi! {
ResetOutlet(outlet: Entity, authorization: Token) -> (),
{
}
}
impl<T: SessionTrait> ResetOutlet<T> {
async fn call_async(mut self) -> Result<(), CallError> {
self.msg.pack_command(Command::Reset);
let _ = send_recv(self.msg, self.session.get_socket_pool()).await?;
Ok(())
}
}
decl_call_atapi! {
PublishEvent(entity: Entity, event: Event, authorization: Token) -> (),
{
auxiliary: Entity,
ancillary: Entity,
method: Method,
attribute: Attribute,
instance: i32,
offset: i32,
name: String255,
key: String255,
parameter: i64,
resultant: i64,
index: i64,
count: i64,
aspect: Aspect,
context: Context,
category: Category,
class: Class,
mode: Mode,
state: State,
condition: Condition,
precedence: u16,
value: &Value,
time: OffsetDateTime,
timeout: i64,
authority: Token,
}
}
impl<T: SessionTrait> PublishEvent<T> {
async fn call_async(mut self) -> Result<(), CallError> {
self.msg.pack_command(Command::Publish);
let _ = send_recv(self.msg, self.session.get_socket_pool()).await?;
Ok(())
}
}
decl_call_atapi! {
SubscribeEvent(entity: Entity, outlet: Entity, authorization: Token) -> (),
{
event: Event,
precedence: u16,
timeout: i64,
}
}
impl<T: SessionTrait> SubscribeEvent<T> {
async fn call_async(mut self) -> Result<(), CallError> {
self.msg.pack_command(Command::Subscribe);
let _ = send_recv(self.msg, self.session.get_socket_pool()).await?;
Ok(())
}
}
decl_call_atapi! {
UnsubscribeEvent(entity: Entity, outlet: Entity, event: Event, authorization: Token) -> (),
{
precedence: u16,
}
}
impl<T: SessionTrait> UnsubscribeEvent<T> {
async fn call_async(mut self) -> Result<(), CallError> {
self.msg.pack_command(Command::Unsubscribe);
let _ = send_recv(self.msg, self.session.get_socket_pool()).await?;
Ok(())
}
}
#[derive(Debug, Clone)]
pub struct WaiterEvent {
pub entity: Entity,
pub outlet: Entity,
pub method: Method,
pub auxiliary: Entity,
pub attribute: Attribute,
pub ancillary: Entity,
pub instance: i32,
pub offset: i32,
pub name: String255,
pub key: String255,
pub parameter: i64,
pub resultant: i64,
pub index: i64,
pub count: i64,
pub aspect: Aspect,
pub context: Context,
pub category: Category,
pub class: Class,
pub event: Event,
pub mode: Mode,
pub state: State,
pub condition: Condition,
pub precedence: u16,
pub time: OffsetDateTime,
pub value: Value,
pub timeout: i64,
pub authority: Token,
pub authorization: Token,
}
impl TryFrom<&HGTPMessage> for WaiterEvent {
type Error = UnpackError;
#[rustfmt::skip]
fn try_from(msg: &HGTPMessage) -> Result<Self, Self::Error> {
Ok(Self {
entity : msg.unpack_entity(),
outlet : msg.unpack_outlet(),
method : msg.unpack_method()?,
auxiliary : msg.unpack_auxiliary(),
attribute : msg.unpack_attribute()?,
ancillary : msg.unpack_ancillary(),
instance : msg.unpack_instance(),
offset : msg.unpack_offset(),
name : msg.unpack_name()?,
key : msg.unpack_key()?,
parameter : msg.unpack_parameter(),
resultant : msg.unpack_resultant(),
index : msg.unpack_index(),
count : msg.unpack_count(),
aspect : msg.unpack_aspect()?,
context : msg.unpack_context()?,
category : msg.unpack_category()?,
class : msg.unpack_class()?,
event : msg.unpack_event()?,
mode : msg.unpack_mode()?,
state : msg.unpack_state()?,
condition : msg.unpack_condition()?,
precedence : msg.unpack_precedence(),
time : msg.unpack_time()?,
value : msg.unpack_value()?,
timeout : msg.unpack_timeout(),
authority : msg.unpack_authority(),
authorization: msg.unpack_authorization(),
})
}
}
decl_call_atapi! {
WaitEvent(outlet: Entity, authorization: Token) -> WaiterEvent,
{
}
}
impl<T: SessionTrait> WaitEvent<T> {
async fn call_async(mut self) -> Result<WaiterEvent, CallError> {
self.msg.pack_command(Command::Wait);
let msg = send_recv(self.msg, self.session.get_socket_pool()).await?;
Ok(WaiterEvent::try_from(&msg)?)
}
}
decl_call_atapi! {
SubscribeEntity(entity: Entity, outlet: Entity, event: Event, authorization: Token) -> (),
{
precedence: u16,
timeout: i64,
}
}
impl<T: SessionTrait> SubscribeEntity<T> {
async fn call_async(mut self) -> Result<(), CallError> {
self.msg.pack_command(Command::Subscribe);
let _ = send_recv(self.msg, self.session.get_socket_pool()).await?;
Ok(())
}
}
decl_call_atapi! {
LockOutlet(outlet: Entity, authorization: Token) -> (),
{
timeout: i64,
}
}
impl<T: SessionTrait> LockOutlet<T> {
async fn call_async(mut self) -> Result<(), CallError> {
self.msg.pack_command(Command::Lock);
let _ = send_recv(self.msg, self.session.get_socket_pool()).await?;
Ok(())
}
}
decl_call_atapi! {
UnlockOutlet(outlet: Entity, authorization: Token) -> (),
{
}
}
impl<T: SessionTrait> UnlockOutlet<T> {
async fn call_async(mut self) -> Result<(), CallError> {
self.msg.pack_command(Command::Unlock);
let _ = send_recv(self.msg, self.session.get_socket_pool()).await?;
Ok(())
}
}
decl_call_atapi! {
AuthorizeEntity(entity: Entity, authority: Token, authorization: Token) -> (),
{
parameter: i64 as with_restriction(),
}
}
impl<T: SessionTrait> AuthorizeEntity<T> {
async fn call_async(mut self) -> Result<(), CallError> {
self.msg.pack_command(Command::Authorize);
let _ = send_recv(self.msg, self.session.get_socket_pool()).await?;
Ok(())
}
}
decl_call_atapi! {
DeauthorizeEntity(entity: Entity, authority: Token, authorization: Token) -> (),
{
}
}
impl<T: SessionTrait> DeauthorizeEntity<T> {
async fn call_async(mut self) -> Result<(), CallError> {
self.msg.pack_command(Command::Deauthorize);
let _ = send_recv(self.msg, self.session.get_socket_pool()).await?;
Ok(())
}
}
decl_call_atapi! {
EntityAuthorized(entity: Entity, authority: Token, authorization: Token) -> bool,
{
}
}
impl<T: SessionTrait> EntityAuthorized<T> {
async fn call_async(mut self) -> Result<bool, CallError> {
self.msg.pack_command(Command::Authorized);
let msg = send_recv(self.msg, self.session.get_socket_pool()).await?;
Ok(msg.unpack_resultant() != 0)
}
}
decl_call_atapi! {
EntityAuthority(entity: Entity, authorization: Token) -> Token,
{
}
}
impl<T: SessionTrait> EntityAuthority<T> {
async fn call_async(mut self) -> Result<Token, CallError> {
self.msg.pack_command(Command::Report);
self.msg.pack_report(Report::Authority);
let msg = send_recv(self.msg, self.session.get_socket_pool()).await?;
Ok(msg.unpack_authority())
}
}
decl_call_atapi! {
EntityName(entity: Entity, authorization: Token) -> String255,
{
}
}
impl<T: SessionTrait> EntityName<T> {
async fn call_async(mut self) -> Result<String255, CallError> {
self.msg.pack_command(Command::Report);
self.msg.pack_report(Report::Name);
let msg = send_recv(self.msg, self.session.get_socket_pool()).await?;
Ok(msg.unpack_name()?)
}
}
decl_call_atapi! {
EntityClass(entity: Entity, authorization: Token) -> Class,
{
}
}
impl<T: SessionTrait> EntityClass<T> {
async fn call_async(mut self) -> Result<Class, CallError> {
self.msg.pack_command(Command::Report);
self.msg.pack_report(Report::Class);
let msg = send_recv(self.msg, self.session.get_socket_pool()).await?;
Ok(msg.unpack_class()?)
}
}
decl_call_atapi! {
EntityCategory(entity: Entity, authorization: Token) -> Category,
{
}
}
impl<T: SessionTrait> EntityCategory<T> {
async fn call_async(mut self) -> Result<Category, CallError> {
self.msg.pack_command(Command::Report);
self.msg.pack_report(Report::Category);
let msg = send_recv(self.msg, self.session.get_socket_pool()).await?;
Ok(msg.unpack_category()?)
}
}
decl_call_atapi! {
LocalServer(authorization: Token) -> Entity,
{
}
}
impl<T: SessionTrait> LocalServer<T> {
async fn call_async(mut self) -> Result<Entity, CallError> {
self.msg.pack_command(Command::Report);
self.msg.pack_report(Report::Local);
let msg = send_recv(self.msg, self.session.get_socket_pool()).await?;
Ok(msg.unpack_entity())
}
}
decl_call_atapi! {
LocalVersion() -> String,
{}
}
impl<T: SessionTrait> LocalVersion<T> {
async fn call_async(mut self) -> Result<String, CallError> {
self.msg.pack_command(Command::Report);
self.msg.pack_report(Report::Version);
let msg = send_recv(self.msg, self.session.get_socket_pool()).await?;
Ok(String::from_utf8_lossy(msg.unpack_bytes()).into_owned())
}
}
decl_call_atapi! {
EntityRedirection(entity: Entity, authorization: Token) -> Entity,
{
}
}
impl<T: SessionTrait> EntityRedirection<T> {
async fn call_async(mut self) -> Result<Entity, CallError> {
self.msg.pack_command(Command::Report);
self.msg.pack_report(Report::Redirection);
let msg = send_recv(self.msg, self.session.get_socket_pool()).await?;
Ok(msg.unpack_entity())
}
}
decl_call_atapi! {
EntityRedirect(auxiliary: Entity,ancillary: Entity, authorization: Token) -> (),
{
entity: Entity as with_server(),
}
}
impl<T: SessionTrait> EntityRedirect<T> {
async fn call_async(mut self) -> Result<(), CallError> {
self.msg.pack_command(Command::Redirect);
send_recv(self.msg, self.session.get_socket_pool()).await?;
Ok(())
}
}
decl_call_atapi! {
ChangeEntity(entity: Entity, authorization: Token) -> (),
{
name: String255,
key: String255,
context: Context,
category: Category,
class: Class,
state: State,
authority: Token,
}
}
impl<T: SessionTrait> ChangeEntity<T> {
async fn call_async(mut self) -> Result<(), CallError> {
self.msg.pack_command(Command::Change);
let _ = send_recv(self.msg, self.session.get_socket_pool()).await?;
Ok(())
}
}
decl_call_atapi! {
EntityTimestamp(entity: Entity, authorization: Token) -> OffsetDateTime,
{
}
}
impl<T: SessionTrait> EntityTimestamp<T> {
async fn call_async(mut self) -> Result<OffsetDateTime, CallError> {
self.msg.pack_command(Command::Report);
self.msg.pack_report(Report::Timestamp);
let msg = send_recv(self.msg, self.session.get_socket_pool()).await?;
msg.unpack_time().map_err(CallError::from)
}
}
decl_call_atapi! {
EntityAvailable(entity: Entity, authorization: Token) -> bool,
{
}
}
impl<T: SessionTrait> EntityAvailable<T> {
async fn call_async(mut self) -> Result<bool, CallError> {
self.msg.pack_command(Command::Report);
self.msg.pack_report(Report::Available);
let msg = send_recv(self.msg, self.session.get_socket_pool()).await?;
Ok(msg.unpack_resultant() != 0)
}
}
decl_call_atapi! {
EntityExtinct(entity: Entity, authorization: Token) -> bool,
{
}
}
impl<T: SessionTrait> EntityExtinct<T> {
async fn call_async(mut self) -> Result<bool, CallError> {
self.msg.pack_command(Command::Report);
self.msg.pack_report(Report::Extinct);
let msg = send_recv(self.msg, self.session.get_socket_pool()).await?;
Ok(msg.unpack_resultant() != 0)
}
}
decl_call_atapi! {
EntityActivated(entity: Entity, authorization: Token) -> bool,
{
}
}
impl<T: SessionTrait> EntityActivated<T> {
async fn call_async(mut self) -> Result<bool, CallError> {
self.msg.pack_command(Command::Report);
self.msg.pack_report(Report::Activated);
let msg = send_recv(self.msg, self.session.get_socket_pool()).await?;
Ok(msg.unpack_resultant() != 0)
}
}
decl_call_atapi! {
EntityLocked(entity: Entity, authorization: Token) -> bool,
{
}
}
impl<T: SessionTrait> EntityLocked<T> {
async fn call_async(mut self) -> Result<bool, CallError> {
self.msg.pack_command(Command::Report);
self.msg.pack_report(Report::Locked);
let msg = send_recv(self.msg, self.session.get_socket_pool()).await?;
Ok(msg.unpack_resultant() != 0)
}
}
decl_call_atapi! {
Pending(entity: Entity, authorization: Token) -> i64,
{
}
}
impl<T: SessionTrait> Pending<T> {
async fn call_async(mut self) -> Result<i64, CallError> {
self.msg.pack_command(Command::Report);
self.msg.pack_report(Report::Pending);
let msg = send_recv(self.msg, self.session.get_socket_pool()).await?;
Ok(msg.unpack_count())
}
}
decl_call_atapi! {
EntityRendezvous(entity: Entity, authorization: Token) -> String,
{
}
}
impl<T: SessionTrait> EntityRendezvous<T> {
async fn call_async(mut self) -> Result<String, CallError> {
self.msg.pack_command(Command::Report);
self.msg.pack_report(Report::Rendezvous);
let msg = send_recv(self.msg, self.session.get_socket_pool()).await?;
Ok(String::from_utf8_lossy(msg.unpack_bytes()).into_owned())
}
}
decl_call_atapi! {
EntityReferences(entity: Entity, authorization: Token) -> i64,
{
}
}
impl<T: SessionTrait> EntityReferences<T> {
async fn call_async(mut self) -> Result<i64, CallError> {
self.msg.pack_command(Command::Report);
self.msg.pack_report(Report::References);
let msg = send_recv(self.msg, self.session.get_socket_pool()).await?;
Ok(msg.unpack_count())
}
}
decl_call_atapi! {
ConnectionCount(entity: Entity, authorization: Token) -> i64,
{
}
}
impl<T: SessionTrait> ConnectionCount<T> {
async fn call_async(mut self) -> Result<i64, CallError> {
self.msg.pack_command(Command::Report);
self.msg.pack_report(Report::Connections);
let msg = send_recv(self.msg, self.session.get_socket_pool()).await?;
Ok(msg.unpack_count())
}
}
decl_call_atapi! {
AttachmentCount(entity: Entity, authorization: Token) -> i64,
{
}
}
impl<T: SessionTrait> AttachmentCount<T> {
async fn call_async(mut self) -> Result<i64, CallError> {
self.msg.pack_command(Command::Report);
self.msg.pack_report(Report::Attachments);
let msg = send_recv(self.msg, self.session.get_socket_pool()).await?;
Ok(msg.unpack_count())
}
}
decl_call_atapi! {
SubscriptionCount(entity: Entity, authorization: Token) -> i64,
{
}
}
impl<T: SessionTrait> SubscriptionCount<T> {
async fn call_async(mut self) -> Result<i64, CallError> {
self.msg.pack_command(Command::Report);
self.msg.pack_report(Report::Subscriptions);
let msg = send_recv(self.msg, self.session.get_socket_pool()).await?;
Ok(msg.unpack_count())
}
}
decl_call_atapi! {
EntityAuthorizations(entity: Entity, authorization: Token) -> i64,
{
}
}
impl<T: SessionTrait> EntityAuthorizations<T> {
async fn call_async(mut self) -> Result<i64, CallError> {
self.msg.pack_command(Command::Report);
self.msg.pack_report(Report::Authorizations);
let msg = send_recv(self.msg, self.session.get_socket_pool()).await?;
Ok(msg.unpack_count())
}
}
decl_call_atapi! {
FetchEntity(entity: Entity, authorization: Token) -> Value,
{
name: String255,
}
}
impl<T: SessionTrait> FetchEntity<T> {
async fn call_async(mut self) -> Result<Value, CallError> {
self.msg.pack_command(Command::Fetch);
let msg = send_recv(self.msg, self.session.get_socket_pool()).await?;
Ok(msg.unpack_value()?)
}
}
decl_call_atapi! {
InsertElement(entity: Entity, value: &Value, index: i64, authorization: Token) -> (),
{}
}
impl<T: SessionTrait> InsertElement<T> {
async fn call_async(mut self) -> Result<(), CallError> {
self.msg.pack_command(Command::Insert);
send_recv(self.msg, self.session.get_socket_pool()).await?;
Ok(())
}
}
decl_call_atapi! {
RemoveElement(entity: Entity, index: i64, authorization: Token) -> (),
{}
}
impl<T: SessionTrait> RemoveElement<T> {
async fn call_async(mut self) -> Result<(), CallError> {
self.msg.pack_command(Command::Remove);
send_recv(self.msg, self.session.get_socket_pool()).await?;
Ok(())
}
}
decl_call_atapi! {
ReplaceElement(entity: Entity, value: &Value, index: i64, authorization: Token) -> (),
{}
}
impl<T: SessionTrait> ReplaceElement<T> {
async fn call_async(mut self) -> Result<(), CallError> {
self.msg.pack_command(Command::Replace);
send_recv(self.msg, self.session.get_socket_pool()).await?;
Ok(())
}
}
decl_call_atapi! {
EraseElement(entity: Entity, authorization: Token) -> (),
{}
}
impl<T: SessionTrait> EraseElement<T> {
async fn call_async(mut self) -> Result<(), CallError> {
self.msg.pack_command(Command::Erase);
send_recv(self.msg, self.session.get_socket_pool()).await?;
Ok(())
}
}
decl_call_atapi! {
FindElement(entity: Entity, value: &Value, index: i64, authorization: Token) -> i64,
{}
}
impl<T: SessionTrait> FindElement<T> {
async fn call_async(mut self) -> Result<i64, CallError> {
self.msg.pack_command(Command::Find);
let msg = send_recv(self.msg, self.session.get_socket_pool()).await?;
Ok(msg.unpack_index())
}
}
decl_call_atapi! {
EntityElement(entity: Entity, authorization: Token) -> Value,
{}
}
impl<T: SessionTrait> EntityElement<T> {
async fn call_async(mut self) -> Result<Value, CallError> {
self.msg.pack_command(Command::Element);
let msg = send_recv(self.msg, self.session.get_socket_pool()).await?;
Ok(msg.unpack_value()?)
}
}
decl_call_atapi! {
ElementCount(entity: Entity, authorization: Token) -> i64,
{}
}
impl<T: SessionTrait> ElementCount<T> {
async fn call_async(mut self) -> Result<i64, CallError> {
self.msg.pack_command(Command::Length);
let msg = send_recv(self.msg, self.session.get_socket_pool()).await?;
Ok(msg.unpack_count())
}
}