#include <apievent.h>
Public Types | |
using | ArgumentConstIterator = utility::UniquePtrConstVectorWrapper< APIArgumentList, APIArgument * > |
Public Member Functions | |
APIEvent (const std::string &name) | |
APIEvent (std::string &&name) | |
APIEvent (const std::string &name, const std::string &id) | |
APIEvent (std::string &&name, std::string &&id) | |
const std::string & | getName () const |
const std::string & | getID () const |
template<typename T , typename... Args> | |
APIArgument * | addArgument (const std::string &name, Args &&... args) |
APIArgument * | addArgument (std::unique_ptr< APIBaseValue > value) |
int | getCount () const |
const ArgumentConstIterator | getArguments () const |
const APIArgument * | getArgument (int index) const |
APIArgument * | getArgument (int index) |
const APIArgument * | getArgumentByName (std::string &&name) const |
APIArgument * | getArgumentByName (std::string &&name) |
bool | matches (const nap::APISignature &signature) const |
template<typename T > | |
const T & | to () const |
template<typename T > | |
T & | to () |
APIArgument & | operator[] (std::size_t idx) |
const APIArgument & | operator[] (std::size_t idx) const |
![]() | |
virtual | ~Event ()=default |
Event ()=default | |
Event (const Event &)=delete | |
Event & | operator= (const Event &)=delete |
Input / Output message that is used at run-time to describe an api message. Contains a list of API arguments. Every api argument carries a single value or list of values. This event is created and given to the application by the APIService when an external request is made. To dispatch an event to an external environment call APIService::dispatchEvent after construction of this event.
Example:
// Create the event APIEventPtr progress_event = std::make_unique<APIEvent>("CacheProgress"); // Add an argument progress_event->addArgument<APIInt>("Percentage", ++curr_pro); // Dispatch to possible listeners mAPIService->dispatchEvent(std::move(progress_event));
APIEvent | ( | const std::string & | name | ) |
Construct a new api event with the given name. A unique id is generated.
name | name of this call |
APIEvent | ( | std::string && | name | ) |
Construct a new api event with the given name. A unique id is generated.
name | name of this call |
APIEvent | ( | const std::string & | name, |
const std::string & | id | ||
) |
Construct a new api event with the given name and unique id. Use this constructor to form a reply based on a previously received client request. The uuid should match the uuid of the request. This allows the client to match call id's.
name | name of this call |
id | unique identifier of this call |
APIEvent | ( | std::string && | name, |
std::string && | id | ||
) |
Construct a new api event with the given name and unique id. Use this constructor to form a reply based on a previously received client request. The uuid should match the uuid of the request. This allows the client to match call id's.
name | identifier of this call |
id | unique identifier of this call |
APIArgument * addArgument | ( | const std::string & | name, |
Args &&... | args | ||
) |
Adds an api argument with an id to this event where T is of type APIValue and 'args' the actual value, for example: 0.0f etc. To add a float as an argument call: addArgument<APIFloat>("drag", 1.0f).
name | the name of the newly created api value. |
args | the template arguments used for constructing the argument. In case of an APIFloat the argument could be 1.0f etc. |
APIArgument* addArgument | ( | std::unique_ptr< APIBaseValue > | value | ) |
Adds an api argument to this event based on the given api value.
value | the api value to add as an argument. |
APIArgument* getArgument | ( | int | index | ) |
index | the index of the argument |
const APIArgument* getArgument | ( | int | index | ) | const |
index | the index of the argument |
APIArgument* getArgumentByName | ( | std::string && | name | ) |
name | the name of the argument |
const APIArgument* getArgumentByName | ( | std::string && | name | ) | const |
name | the name of the argument |
const ArgumentConstIterator getArguments | ( | ) | const |
int getCount | ( | ) | const |
const std::string& getID | ( | ) | const |
const std::string& getName | ( | ) | const |
bool matches | ( | const nap::APISignature & | signature | ) | const |
If the api arguments and order of arguments matches the given api signature.
signature | the method signature to validate |
APIArgument& operator[] | ( | std::size_t | idx | ) |
Array [] subscript operator
const APIArgument& operator[] | ( | std::size_t | idx | ) | const |
Array [] subscript operator
T & to |
Returns this event as an event of type T. Example: ws_event = api_event.to<APIWebSocketEvent>(); For this to work this event must be an event of type T. Asserts if the event isn't of type T.
const T & to |
Returns this event as an event of type T. Example: ws_event = api_event.to<APIWebSocketEvent>(); For this to work this event must be an event of type T. Asserts if the event isn't of type T.