EdgeEventQueueRK
|
Class for managing a private queue of events on the flash file system. More...
#include <EdgeEventQueueRK.h>
Public Member Functions | |
EdgeEventQueueRK () | |
Constructor. | |
virtual | ~EdgeEventQueueRK () |
Destructor. | |
int | setup () |
Call during setup(), the main application setup function. | |
void | loop () |
Call during loop(), the main application loop function. | |
EdgeEventQueueRK & | withPriority (size_t priority) |
Sets the priority to use for publishing. Default is 0. | |
EdgeEventQueueRK & | withPublishFlags (PublishFlags flags) |
Sets the publish flags such as NO_ACK. | |
EdgeEventQueueRK & | withSizeLimit (size_t sizeLimit) |
Set the disk queue size limit (in bytes). Default is 0 (not limited). | |
EdgeEventQueueRK & | withDiskQueuePolicy (DiskQueuePolicy policy) |
Sets the disk queue policy for deleting events when the queue is full. | |
EdgeEventQueueRK & | withQueuePath (const char *path) |
Sets the queue path. Default is "/usr/privateq". Typically put in "/usr/" directory. | |
int | publish (const char *eventName, const char *eventData) |
Add an event to the publish queue on the flash file system. | |
Static Public Member Functions | |
static int | cloudServicePublish (const char *eventName, const char *eventData, PublishFlags publishFlags={}, size_t priority=0, std::function< int(CloudServiceStatus)> cb=0) |
Publishes an event using the cloud service without using the disk queue. | |
Class for managing a private queue of events on the flash file system.
The CloudService has a different prototype on Tracker Edge and Monitor Edge. These defines can be used to determine which Edge firmware you are using. This class defines a common API so you don't have to worry about it from your code.
Only available on devices using TrackerEdge or MonitorEdge, as it utilizes the DiskQueue and CloudService classes.
When metering out events to stay within the rate limit, this interleaves your private events and the system events so you won't exceed the rate limit.
A queue size limit specified in this class is independent of the one set in the cloud configuration. There is no checking done to make sure there's enough disk space available across all queues.
EdgeEventQueueRK::EdgeEventQueueRK | ( | ) |
Constructor.
Construct one of these object for each queue. Often there will only be one, but the code supports multiple queues. It is typically constructed as a global object.
|
virtual |
Destructor.
This is typically not used as the object is typically instantiated as a global object.
|
static |
Publishes an event using the cloud service without using the disk queue.
eventName | The event name, as is used in Particle.publish. |
eventData | The event data, as is used in Particle.publish |
publishFlags | Publish flags, as is used in Particle.publish. This is optional, and if omitted the default flags are used. |
priority | 0 or 1. 0 is the default queue and 1 is the low priority queue. |
cb | Callback function to be called on successful completion or error. Optional. Not called if an immediate error results in a non-zero result code; callback is only called if the return value is 0. |
The callback function has this prototype:
int callback(CloudServiceStatus status)
status
is particle::Error::NONE
(0) or an system error code on errorIt is a std::function so you can pass a lambda, which allows you to pass additional data via capture variables, or call a C++ class method and instance easily.
The eventName and eventValue are copied and do not need to remain valid until the callback is called. Once the cloudServicePublish call returns, the variables can go out of scope, so it's safe for them to be local variables on the stack.
Using cloudServicePublish interleaves your event with others in the system in a queue in RAM. The queue is finite in size (currently 8 elements per priority queue) and if the queue is full, -EBUSY (-16) is returned.
Note that this function does not use the disk queue! It's a low-level function used by the publish method in this class, or you can use it for your own purposes if you want to publish events that are not saved to disk if the device is currently offline.
void EdgeEventQueueRK::loop | ( | ) |
int EdgeEventQueueRK::publish | ( | const char * | eventName, |
const char * | eventData | ||
) |
Add an event to the publish queue on the flash file system.
eventName | The event name, as is used in Particle.publish |
eventData | The event data, as is used in Particle.publish |
The eventName and eventValue are copied and do not need to remain valid until the callback is called. Once the publish call returns, the variables can go out of scope, so it's safe for them to be local variables on the stack.
int EdgeEventQueueRK::setup | ( | ) |
|
inline |
Sets the disk queue policy for deleting events when the queue is full.
policy | DiskQueuePolicy::FifoDeleteOld (default) or DiskQueuePolicy::FifoDeleteNew |
|
inline |
Sets the priority to use for publishing. Default is 0.
priority | 0 or 1. 0 is the default queue and 1 is the low priority queue. |
|
inline |
|
inline |
Sets the queue path. Default is "/usr/privateq". Typically put in "/usr/" directory.
path | Typically put in "/usr/" directory. Does not need to exist; will be created if it does not exist. |
|
inline |
Set the disk queue size limit (in bytes). Default is 0 (not limited).