mco_edge_has_space

Checks whether there is sufficient space in the ring buffer to create a new object of the specified class.

For an overview, see the Edge Client page.

Prototype

    MCO_RET mco_edge_has_space(mco_trans_h t, mco_uint2 class_code);
    

Arguments

t
Transaction handle obtained from a previous mco_edge_trans_start() call.
class_code
Internal class code identifying the object type to be created. This value is typically provided as a generated compile-time constant (e.g., CLASS_Sensor) or can be retrieved via dictionary query functions.

Description

Checks whether there is sufficient space in the edge database ring buffer to create a new object of the specified class.

The most common error during an edge transaction is insufficient buffer space for creating a new object. In such cases, the generated Class_new() function returns MCO_E_NOMEM. This error is recorded in the transaction context and will automatically trigger a rollback when mco_edge_trans_commit() is called.

To proactively avoid this situation, mco_edge_has_space() should be called before invoking Class_new(). If it returns MCO_S_OK, the creation of the object is guaranteed to succeed within the current transaction.

Buffer Management & Concurrency: The available buffer space is dynamic. Space may be freed by transmitting and clearing completed transactions via mco_edge_sync() and mco_edge_clear(). These functions can be invoked within the same transaction (if the execution model permits) or concurrently in another thread. The application is responsible for coordinating synchronization and commit operations (e.g., implementing appropriate waiting, retry, or backoff strategies).

Return Codes

MCO_S_OK
Sufficient space is available in the ring buffer. Object creation is guaranteed to succeed.
MCO_E_ILLEGAL_PARAM
One or more parameter values are invalid.
MCO_S_BUSY
insufficient space is currently available, but calling mco_edge_sync() and/or mco_edge_clear() may free the required space (i.e., the buffer is occupied by completed but not yet transmitted transactions). These functions may be invoked within the same transaction or executed concurrently in another thread. Coordination between sync() and commit() threads (e.g., waiting strategies) must be handled by the application.
MCO_E_NOMEM
The current transaction has consumed nearly the entire ring buffer, and sync()/clear() cannot free sufficient space (uncommitted transactions cannot be transmitted). The current transaction must be completed (committed or rolled back) before attempting to create more objects.

Files

Header file:
mcoedge.h
Source file:
mcoedgedb.c
Library:
libmcoiotedge.a