Template Class EntityWatchdog

Inheritance Relationships

Base Types

  • public axr::sdk::utils::IEntityWatchdog (Class IEntityWatchdog)

  • public std::enable_shared_from_this< EntityWatchdog< T > >

Template Parameter Order

  1. class T

Class Documentation

template<class T>
class EntityWatchdog : public axr::sdk::utils::IEntityWatchdog, public std::enable_shared_from_this<EntityWatchdog<T>>

EntityWatchdog is a utility service that provides a simple way to retrieve automatic updates for a registered EntityBase object. When registering a callback function for a given entity object the service will begin monitoring the backend service for changes to the object. If a change has been detected the callback function that was registered will be called containing the newly modified entity object. Note that it will not modify the existing object instance used to register the callback. It is the responsibility of the implementor to merge any changes from the new instance to the old one if desired.

Also note that the registered callback function will be executed from a different thread where safety is not guaranteed. It is the responsibility of the implementor to enforce any thread-safety needed for the data in question.

WARNING: This class should never be instantiated directly. Use the EntityWatchdogFactory class instead. If creating an instance manually, never do so using the local stack or via the new operator without assigning to a std::shared_ptr.

Author

Jean-Philippe Steinmetz info@acceleratxr.com

Public Types

typedef std::function<void(std::shared_ptr<T> oldObj, std::shared_ptr<T> newObj)> EntityCallback

Callback function when a watched entity has a new version.

Param oldObj

The old version of the entity.

Param newObj

The new version of the entity.

Public Functions

inline EntityWatchdog(std::shared_ptr<Configuration> inConfig, std::shared_ptr<net::IApiClient> inApiClient)
inline virtual ~EntityWatchdog()
inline virtual void SetPushSocket(std::shared_ptr<net::IWebSocket> inSocket) override

Sets the currently active push notification websocket connection.

inline virtual bool NotifyEntityUpdate(Object &message) override

Notifies the watchdog that an entity has been updated.

Parameters

message – The message object containing the entity update.

Returns

Returns true if the entity update was handled by this watchdog instance, otherwise returns false.

inline virtual void Shutdown() override

Stops watching all entity objects and cleans up the service.

inline void Start()

Starts the process.

inline size_t Watch(const std::map<utility::string_t, utility::string_t> searchParams, const uint16_t startIndex, const uint16_t maxResults, const utility::string_t &sortBy, std::function<void(std::shared_ptr<T> obj)> callback)

Registers the provided callback function to be notified whenever changes occur for the specified search query. Note that the callback function will be notified from a different thread of execution. It is recommended that thread-safe handling of the provided data is implemented in the callback function itself.

Parameters
  • searchParams – A map of property names to values to search for.

  • startIndex – The index of the first object to include in the result.

  • maxResults – The maximum number of objects to evaluate during the search.

  • sortBy – The property name and order direction to sort the results using. (e.g. “MyProperty=ASC” to sort by MyProperty in ascending order, “MyProperty=DESC” to sort by MyProperty in descending order).

  • callback – The function call call when an update to the entity object is detected.

Returns

An identifier for the registered callback. Use this to unregister the callback to stop watching the object.

inline size_t Watch(std::shared_ptr<T> entity, EntityCallback callback)

Registers the provided callback function to be notified whenever an update is detected for the specified entity object. Note that the callback function will be notified from a different thread of execution. It is recommended that thread-safe handling of the provided data is implemented in the callback function itself.

Parameters
  • entity – The pointer to the entity object to watch.

  • callback – The function call call when an update to the entity object is detected. If nullptr is passed in as the argument then the object was deleted on the back-end.

Throws

Throws – if the entity does not exist or have a valid remoteUrl.

Returns

An identifier for the registered callback. Use this to unregister the callback to stop watching the object.

inline void Unwatch(std::shared_ptr<T> entity, size_t id)

Removes the registered callback with the given id for the specified entity object.

Parameters
  • entity – The entity object to stop watching.

  • id – The id of the callback function to unregister (e.g. the value that was returned from RegisterCallback).