NAP
Public Member Functions | Public Attributes | List of all members
APIComponentInstance Class Reference

#include <apicomponent.h>

Public Member Functions

 APIComponentInstance (EntityInstance &entity, Component &resource)
 
virtual ~APIComponentInstance () override
 
virtual bool init (utility::ErrorState &errorState) override
 
const APISignaturefindSignature (const std::string &id) const
 
bool accepts (const APIEvent &apiEvent) const
 
void registerCallback (const APISignature &signature, nap::Slot< const APIEvent & > &slot)
 
- Public Member Functions inherited from ComponentInstance
 ComponentInstance (EntityInstance &entity, Component &resource)
 
virtual void update (double deltaTime)
 
nap::EntityInstancegetEntityInstance () const
 
nap::ComponentgetComponent () const
 
template<typename T >
T * getComponent () const
 
virtual bool init (utility::ErrorState &errorState)
 
- Public Member Functions inherited from Object
 Object ()
 
virtual ~Object ()
 
virtual void onDestroy ()
 
 Object (Object &)=delete
 
Objectoperator= (const Object &)=delete
 
 Object (Object &&)=delete
 
Objectoperator= (Object &&)=delete
 

Public Attributes

Signal< const APIEvent & > messageReceived
 Triggered when the component receives an api event. More...
 
- Public Attributes inherited from Object
std::string mID
 Property: 'mID' unique name of the object. Used as an identifier by the system. More...
 

Additional Inherited Members

- Static Public Member Functions inherited from Object
static bool isIDProperty (rtti::Instance &object, const rtti::Property &property)
 

Description

Receives APIEvents from the APIService and forwards the event to all registered callbacks. An event is received when an external application calls into to API service to perform a specific task. Only events with a matching signature are accepted and forwarded.

To receive api events listen to the 'messageReceived' signal, which is triggered when a new api event is received. When received, you know for sure the values of the events precisely match that of the registered signature. For a more specific handling of api events you can create a callback for a given API signature and listen to it's messageReceived signal.

Inheritance diagram for APIComponentInstance:
[legend]
Collaboration diagram for APIComponentInstance:
[legend]

Constructor & Destructor Documentation

◆ APIComponentInstance()

APIComponentInstance ( EntityInstance entity,
Component resource 
)

Constructor

◆ ~APIComponentInstance()

virtual ~APIComponentInstance ( )
overridevirtual

Destructor, removes itself as a listener from the API service.

Member Function Documentation

◆ accepts()

bool accepts ( const APIEvent apiEvent) const

Checks to see if a specific API call is accepted by this component.

Parameters
apiEventthe api event to accept
Returns
if a specific API call is accepted by this component

◆ findSignature()

const APISignature* findSignature ( const std::string &  id) const

Tries to find a method signature with the given name.

Parameters
idname of the signature.
Returns
found signature, nullptr if not found.

◆ init()

virtual bool init ( utility::ErrorState errorState)
overridevirtual
Parameters
errorStateshould hold the error message when initialization fails
Returns
if the component initialized successfully

Reimplemented from ComponentInstance.

◆ registerCallback()

void registerCallback ( const APISignature signature,
nap::Slot< const APIEvent & > &  slot 
)

Registers a specific callback that is called after receiving a specific api event. This is a convenience function that takes a slot and binds it to a new or existing callback. The signature needs to be acquired using findSignature(). A new callback is created if it doesn't exist already.

Parameters
signaturethe signature to register a callback for, must be acquired using findSignature()
slotthe function that is called when receiving an event that matches the given signature.

Member Data Documentation

◆ messageReceived

Signal<const APIEvent&> messageReceived

Triggered when the component receives an api event.