use std::{
future::{Future, IntoFuture},
pin::Pin,
};
use num_enum::TryFromPrimitive;
use crate::{
taxonomy::*, CallError, Entity, InvalidResponse, Session, SessionAsync, SessionTrait,
String255, Token, Value,
};
use crate::session::api::macros::*;
decl_call! {
InsertFrame(entity: Entity, attribute: Attribute, key: String255, authorization: Token) -> (),
{
index: i64,
instance: i32,
deferred: bool,
}
}
impl<T: SessionTrait> InsertFrame<T> {
async fn call_async(self) -> Result<(), CallError> {
let _ = self
.session
.get_async_session()
.invoke_entity(self.entity, Method::Insert, self.authorization)
.with_aspect(Aspect::Frame)
.with_attribute(self.attribute)
.with_key(self.key)
.with_index(self.index)
.with_instance(self.instance)
.with_parameter(self.deferred as i64)
.await?;
Ok(())
}
}
decl_call! {
RemoveFrame(entity: Entity, attribute: Attribute, index: i64, authorization: Token) -> (),
{
instance: i32,
deferred: bool,
}
}
impl<T: SessionTrait> RemoveFrame<T> {
async fn call_async(self) -> Result<(), CallError> {
let _ = self
.session
.get_async_session()
.invoke_entity(self.entity, Method::Remove, self.authorization)
.with_aspect(Aspect::Frame)
.with_attribute(self.attribute)
.with_index(self.index)
.with_instance(self.instance)
.with_parameter(self.deferred as i64)
.await?;
Ok(())
}
}
decl_call! {
ReplaceFrame(entity: Entity, attribute: Attribute, index: i64, key: String255, authorization: Token) -> (),
{
instance: i32,
deferred: bool,
}
}
impl<T: SessionTrait> ReplaceFrame<T> {
async fn call_async(self) -> Result<(), CallError> {
let _ = self
.session
.get_async_session()
.invoke_entity(self.entity, Method::Replace, self.authorization)
.with_aspect(Aspect::Frame)
.with_attribute(self.attribute)
.with_key(self.key)
.with_index(self.index)
.with_instance(self.instance)
.with_parameter(self.deferred as i64)
.await?;
Ok(())
}
}
decl_call! {
FindFrame(entity: Entity, authorization: Token) -> i64,
{
attribute: Attribute,
name: String255,
key: String255,
value: Value,
instance: i32,
index: i64,
offset: i32,
}
}
impl<T: SessionTrait> FindFrame<T> {
async fn call_async(self) -> Result<i64, CallError> {
let res = self
.session
.get_async_session()
.invoke_entity(self.entity, Method::Find, self.authorization)
.with_aspect(Aspect::Frame)
.with_attribute(self.attribute)
.with_name(self.name)
.with_key(self.key)
.with_value(&self.value)
.with_index(self.index)
.with_instance(self.instance)
.with_offset(self.offset)
.await?;
Ok(res.integer()?)
}
}
decl_call! {
IncludeFrame(entity: Entity, attribute: Attribute, key: String255, authorization: Token) -> (),
{
deferred: bool,
}
}
impl<T: SessionTrait> IncludeFrame<T> {
async fn call_async(self) -> Result<(), CallError> {
let _ = self
.session
.get_async_session()
.invoke_entity(self.entity, Method::Include, self.authorization)
.with_aspect(Aspect::Frame)
.with_attribute(self.attribute)
.with_key(self.key)
.with_parameter(self.deferred as i64)
.await?;
Ok(())
}
}
decl_call! {
ExcludeFrame(entity: Entity, attribute: Attribute, key: String255, authorization: Token) -> (),
{
deferred: bool,
}
}
impl<T: SessionTrait> ExcludeFrame<T> {
async fn call_async(self) -> Result<(), CallError> {
let _ = self
.session
.get_async_session()
.invoke_entity(self.entity, Method::Exclude, self.authorization)
.with_aspect(Aspect::Frame)
.with_attribute(self.attribute)
.with_key(self.key)
.with_parameter(self.deferred as i64)
.await?;
Ok(())
}
}
decl_call! {
SetFrame(entity: Entity, attribute: Attribute, key: String255, name: String255, value: Value, authorization: Token) -> (),
{
instance: i32,
index: i64,
offset: i32,
deferred: bool,
}
}
impl<T: SessionTrait> SetFrame<T> {
async fn call_async(self) -> Result<(), CallError> {
let _ = self
.session
.get_async_session()
.invoke_entity(self.entity, Method::Set, self.authorization)
.with_aspect(Aspect::Frame)
.with_attribute(self.attribute)
.with_name(self.name)
.with_key(self.key)
.with_value(&self.value)
.with_index(self.index)
.with_instance(self.instance)
.with_offset(self.offset)
.with_parameter(self.deferred as i64)
.await?;
Ok(())
}
}
decl_call! {
GetFrame(entity: Entity, attribute: Attribute, key: String255, name: String255, authorization: Token) -> Value,
{
instance: i32,
index: i64,
offset: i32,
}
}
impl<T: SessionTrait> GetFrame<T> {
async fn call_async(self) -> Result<Value, CallError> {
self.session
.get_async_session()
.invoke_entity(self.entity, Method::Get, self.authorization)
.with_aspect(Aspect::Frame)
.with_attribute(self.attribute)
.with_name(self.name)
.with_key(self.key)
.with_index(self.index)
.with_instance(self.instance)
.with_offset(self.offset)
.await
}
}
decl_call! {
ClearFrame(entity: Entity, attribute: Attribute, key: String255, name: String255, authorization: Token) -> (),
{
instance: i32,
index: i64,
offset: i32,
deferred: bool,
}
}
impl<T: SessionTrait> ClearFrame<T> {
async fn call_async(self) -> Result<(), CallError> {
let _ = self
.session
.get_async_session()
.invoke_entity(self.entity, Method::Clear, self.authorization)
.with_aspect(Aspect::Frame)
.with_attribute(self.attribute)
.with_name(self.name)
.with_key(self.key)
.with_index(self.index)
.with_instance(self.instance)
.with_offset(self.offset)
.with_parameter(self.deferred as i64)
.await?;
Ok(())
}
}
decl_call! {
FrameCount(entity: Entity, attribute: Attribute, authorization: Token) -> i64,
{
instance: i32,
}
}
impl<T: SessionTrait> FrameCount<T> {
async fn call_async(self) -> Result<i64, CallError> {
let res = self
.session
.get_async_session()
.invoke_entity(self.entity, Method::Count, self.authorization)
.with_aspect(Aspect::Frame)
.with_attribute(self.attribute)
.with_instance(self.instance)
.await?;
Ok(res.integer()?)
}
}
decl_call! {
FrameMember(entity: Entity, attribute: Attribute, key: String255, authorization: Token) -> bool,
{
instance: i32,
}
}
impl<T: SessionTrait> FrameMember<T> {
async fn call_async(self) -> Result<bool, CallError> {
let res = self
.session
.get_async_session()
.invoke_entity(self.entity, Method::Member, self.authorization)
.with_aspect(Aspect::Frame)
.with_attribute(self.attribute)
.with_key(self.key)
.with_instance(self.instance)
.await?;
Ok(res.boolean()?)
}
}
decl_call! {
FrameName(entity: Entity, attribute: Attribute, offset: i32, authorization: Token) -> String255,
{
instance: i32,
}
}
impl<T: SessionTrait> FrameName<T> {
async fn call_async(self) -> Result<String255, CallError> {
let res = self
.session
.get_async_session()
.invoke_entity(self.entity, Method::Name, self.authorization)
.with_aspect(Aspect::Frame)
.with_attribute(self.attribute)
.with_instance(self.instance)
.with_offset(self.offset)
.await?;
Ok(res
.string()?
.try_into()
.map_err(|e| CallError::InvalidResponse(InvalidResponse::Name(e)))?)
}
}
decl_call! {
FrameKey(entity: Entity, attribute: Attribute, index: i64, authorization: Token) -> String255,
{
instance: i32,
}
}
impl<T: SessionTrait> FrameKey<T> {
async fn call_async(self) -> Result<String255, CallError> {
let res = self
.session
.get_async_session()
.invoke_entity(self.entity, Method::Key, self.authorization)
.with_aspect(Aspect::Frame)
.with_attribute(self.attribute)
.with_index(self.index)
.with_instance(self.instance)
.await?;
Ok(res
.string()?
.try_into()
.map_err(|e| CallError::InvalidResponse(InvalidResponse::Key(e)))?)
}
}
decl_call! {
FrameValue(entity: Entity, attribute: Attribute, key: String255, name: String255, authorization: Token) -> Value,
{
instance: i32,
index: i64,
offset: i32,
}
}
impl<T: SessionTrait> FrameValue<T> {
async fn call_async(self) -> Result<Value, CallError> {
self.session
.get_async_session()
.invoke_entity(self.entity, Method::Value, self.authorization)
.with_aspect(Aspect::Frame)
.with_attribute(self.attribute)
.with_name(self.name)
.with_key(self.key)
.with_index(self.index)
.with_instance(self.instance)
.with_offset(self.offset)
.await
}
}
decl_call! {
FrameIndex(entity: Entity, attribute: Attribute, key: String255, authorization: Token) -> i64,
{
instance: i32,
}
}
impl<T: SessionTrait> FrameIndex<T> {
async fn call_async(self) -> Result<i64, CallError> {
let res = self
.session
.get_async_session()
.invoke_entity(self.entity, Method::Index, self.authorization)
.with_aspect(Aspect::Frame)
.with_attribute(self.attribute)
.with_key(self.key)
.with_instance(self.instance)
.await?;
Ok(res.integer()?)
}
}
decl_call! {
FrameAttribute(entity: Entity, authorization: Token) -> Attribute,
{
key: String255,
index: i64,
instance: i32,
}
}
impl<T: SessionTrait> FrameAttribute<T> {
async fn call_async(self) -> Result<Attribute, CallError> {
let res = self
.session
.get_async_session()
.invoke_entity(self.entity, Method::Attribute, self.authorization)
.with_aspect(Aspect::Frame)
.with_key(self.key)
.with_index(self.index)
.with_instance(self.instance)
.await?;
let num64 = res.integer()?;
let num16 = u16::try_from(num64).map_err(|_| InvalidResponse::Attribute(num64))?;
let attr =
Attribute::try_from_primitive(num16).map_err(|_| InvalidResponse::Attribute(num64))?;
Ok(attr)
}
}
decl_call! {
SortFrames(entity: Entity, attribute: Attribute, authorization: Token) -> (),
{
instance: i32,
deferred: bool,
}
}
impl<T: SessionTrait> SortFrames<T> {
async fn call_async(self) -> Result<(), CallError> {
let _ = self
.session
.get_async_session()
.invoke_entity(self.entity, Method::Sort, self.authorization)
.with_aspect(Aspect::Frame)
.with_attribute(self.attribute)
.with_instance(self.instance)
.with_parameter(self.deferred as i64)
.await?;
Ok(())
}
}
decl_call! {
PurgeFrames(entity: Entity, attribute: Attribute, authorization: Token) -> (),
{
instance: i32,
deferred: bool,
}
}
impl<T: SessionTrait> PurgeFrames<T> {
async fn call_async(self) -> Result<(), CallError> {
let _ = self
.session
.get_async_session()
.invoke_entity(self.entity, Method::Purge, self.authorization)
.with_aspect(Aspect::Frame)
.with_attribute(self.attribute)
.with_instance(self.instance)
.with_parameter(self.deferred as i64)
.await?;
Ok(())
}
}
decl_call! {
RetrieveFrames(entity: Entity, attribute: Attribute, authorization: Token) -> String,
{
instance: i32,
}
}
impl<T: SessionTrait> RetrieveFrames<T> {
async fn call_async(self) -> Result<String, CallError> {
let res = self
.session
.get_async_session()
.invoke_entity(self.entity, Method::Retrieve, self.authorization)
.with_aspect(Aspect::Frame)
.with_attribute(self.attribute)
.with_instance(self.instance)
.await?;
Ok(res.interchange()?)
}
}