Zigbee Protocol Controller 1.6.0
zigpc_common_observable.c File Reference
#include <stddef.h>
#include <stdlib.h>
#include <stdbool.h>
#include <string.h>
#include <stdint.h>
#include "sl_status.h"
#include "zigpc_common_observable.h"

Macros

#define ZIGPC_OBSERVER_INDEX_NOT_FOUND   -1
 General value for index not found. More...
 

Functions

static int8_t zigpc_observable_get_event_index (const struct zigpc_observable *observable, const zigpc_observer_event_t event)
 return index of the registered observable event, if found More...
 
static int8_t zigpc_observable_get_event_callback_index (const struct zigpc_observable_event_entry *event_entry, const zigpc_observer_callback_t observer)
 return index of the observer callback, if found More...
 
sl_status_t zigpc_observable_notify (const struct zigpc_observable *observable, const zigpc_observer_event_t event, void *data)
 Inform Observers of observable instance of an event with data. More...
 
static sl_status_t zigpc_observable_insert_event_callback (struct zigpc_observable_event_entry *event_entry, const zigpc_observer_callback_t callback)
 Insert observer callback to be part of observable event. More...
 
sl_status_t zigpc_observable_register (struct zigpc_observable *observable, const zigpc_observer_event_t event, zigpc_observer_callback_t callback)
 Register an observer with a corresponding event to observable instance. More...
 
sl_status_t zigpc_observable_unregister (struct zigpc_observable *observable, const zigpc_observer_event_t event, const zigpc_observer_callback_t callback)
 Unregister an observer with a corresponding event from observable instance. More...
 
static bool zigpc_observable_event_list_has_duplicates (const zigpc_observer_event_t *event_list, const uint8_t event_count)
 Check if observable event list has duplicate entries. More...
 
sl_status_t zigpc_observable_init (struct zigpc_observable *observable, const zigpc_observer_event_t *event_list, const uint8_t event_count)
 Initialize observable with an approved event list. More...
 
void zigpc_observable_clear (struct zigpc_observable *observable)
 Stop all observers from being notified. More...
 

Macro Definition Documentation

◆ ZIGPC_OBSERVER_INDEX_NOT_FOUND

#define ZIGPC_OBSERVER_INDEX_NOT_FOUND   -1

General value for index not found.

Function Documentation

◆ zigpc_observable_event_list_has_duplicates()

static bool zigpc_observable_event_list_has_duplicates ( const zigpc_observer_event_t event_list,
const uint8_t  event_count 
)
inlinestatic

Check if observable event list has duplicate entries.

Parameters
event_listList to check
event_countList length
Returns
true if duplicate entries found
false if all entries are unique

◆ zigpc_observable_get_event_callback_index()

static int8_t zigpc_observable_get_event_callback_index ( const struct zigpc_observable_event_entry event_entry,
const zigpc_observer_callback_t  observer 
)
static

return index of the observer callback, if found

Parameters
event_entryObservable event entry
observerCallback to find
Returns
int8_t index of observer callback, -1 if not found

◆ zigpc_observable_get_event_index()

static int8_t zigpc_observable_get_event_index ( const struct zigpc_observable observable,
const zigpc_observer_event_t  event 
)
static

return index of the registered observable event, if found

NOTE: observable is assumed to be not NULL since this function is statically scoped and their callers should do the NULL checking

Parameters
observableObservable instance
eventevent to find
Returns
int8_t index of observer, -1 if not found

◆ zigpc_observable_insert_event_callback()

static sl_status_t zigpc_observable_insert_event_callback ( struct zigpc_observable_event_entry event_entry,
const zigpc_observer_callback_t  callback 
)
static

Insert observer callback to be part of observable event.

Parameters
event_entryObservable event instance.
callbackEvent callback to insert.
Returns
sl_status_t SL_STATUS on succes, SL_STATUS_NO_MORE_RESOURCE if the list is full. Fill callback at the first empty spot.