S2OPC OPCUA Toolkit
Data Structures | Typedefs | Functions
sopc_event_handler.h File Reference
#include <stdint.h>
#include "sopc_enums.h"

Go to the source code of this file.

Data Structures

struct  SOPC_LooperEvent
 Struct describing the various parts of an event. More...
 

Typedefs

typedef struct _SOPC_EventHandler SOPC_EventHandler
 Processes messages from a queue. More...
 
typedef struct _SOPC_Looper SOPC_Looper
 Manages the processing of events on a given thread. More...
 
typedef void SOPC_SetListenerFunc(SOPC_EventHandler *handler)
 Function prototype for connecting an event emitter to a listener. More...
 
typedef void SOPC_EventHandler_Callback(SOPC_EventHandler *handler, int32_t event, uint32_t eltId, uintptr_t params, uintptr_t auxParam)
 Function prototype for message processing callbacks. More...
 

Functions

SOPC_EventHandlerSOPC_EventHandler_Create (SOPC_Looper *looper, SOPC_EventHandler_Callback *callback)
 Creates a new event handler and attaches it to an existing looper. More...
 
SOPC_ReturnStatus SOPC_EventHandler_Post (SOPC_EventHandler *handler, int32_t event, uint32_t eltId, uintptr_t params, uintptr_t auxParam)
 Posts an event to the back of the event handler's message queue. More...
 
SOPC_ReturnStatus SOPC_EventHandler_PostAsNext (SOPC_EventHandler *handler, int32_t event, uint32_t eltId, uintptr_t params, uintptr_t auxParam)
 Posts an event to the front of the event handler's message queue. More...
 
SOPC_LooperSOPC_Looper_Create (const char *threadName)
 Creates a new looper and attaches it to a new thread. More...
 
void SOPC_Looper_Delete (SOPC_Looper *looper)
 Stops a looper and releases all resources allocated to it. More...
 

Typedef Documentation

◆ SOPC_EventHandler

typedef struct _SOPC_EventHandler SOPC_EventHandler

Processes messages from a queue.

An SOPC_EventHandler processes the messages from its queue with a callback function. That callback function is called in the thread of the looper to which the event handler is attached. Posting event is safe to do from other threads.

◆ SOPC_Looper

typedef struct _SOPC_Looper SOPC_Looper

Manages the processing of events on a given thread.

A SOPC_Looper owns a thread on which the callbacks from one or more event handlers will be processed.

◆ SOPC_SetListenerFunc

typedef void SOPC_SetListenerFunc(SOPC_EventHandler *handler)

Function prototype for connecting an event emitter to a listener.

◆ SOPC_EventHandler_Callback

typedef void SOPC_EventHandler_Callback(SOPC_EventHandler *handler, int32_t event, uint32_t eltId, uintptr_t params, uintptr_t auxParam)

Function prototype for message processing callbacks.

handler is a pointer to the SOPC_EventHandler invoking this callback, the other parameters (and their lifetime) are specific to the event invoked.

Function Documentation

◆ SOPC_EventHandler_Create()

SOPC_EventHandler* SOPC_EventHandler_Create ( SOPC_Looper looper,
SOPC_EventHandler_Callback callback 
)

Creates a new event handler and attaches it to an existing looper.

Parameters
looperthe looper to attach the event handler to
callbackthe callback to call to process incoming messages

The returned handler belongs to the looper, and will be freed with it.

Returns
The created event handler, or NULL on memory allocation failure.

◆ SOPC_EventHandler_Post()

SOPC_ReturnStatus SOPC_EventHandler_Post ( SOPC_EventHandler handler,
int32_t  event,
uint32_t  eltId,
uintptr_t  params,
uintptr_t  auxParam 
)

Posts an event to the back of the event handler's message queue.

Parameters
handlerthe event handler
eventthe event code
eltIdevent specific data
paramsevent specific data
auxParamevent specific data
Returns
SOPC_STATUS_OK on success, or an error code on failure.

◆ SOPC_EventHandler_PostAsNext()

SOPC_ReturnStatus SOPC_EventHandler_PostAsNext ( SOPC_EventHandler handler,
int32_t  event,
uint32_t  eltId,
uintptr_t  params,
uintptr_t  auxParam 
)

Posts an event to the front of the event handler's message queue.

Parameters
handlerthe event handler
eventthe event code
eltIdevent specific data
paramsevent specific data
auxParamevent specific data
Returns
SOPC_STATUS_OK on success, or an error code on failure.

◆ SOPC_Looper_Create()

SOPC_Looper* SOPC_Looper_Create ( const char *  threadName)

Creates a new looper and attaches it to a new thread.

Parameters
threadNamename of the thread
Returns
The created looper, or NULL in case or error.

◆ SOPC_Looper_Delete()

void SOPC_Looper_Delete ( SOPC_Looper looper)

Stops a looper and releases all resources allocated to it.

Parameters
looperthe looper

The queues of the attached handlers will be processed before the thread of the looper is stopped.