26 uint32_t localNumber = producer->
number;
36 for (
size_t index = 0; index < localObserverList.
functions_count; index++)
39 observer(localNumber);
64 printf(
" Error! Out of memory allocating space for the NumberProducer!\n");
87 bool subscribed =
false;
89 if (producer != NULL && observer != NULL)
106 if (producer != NULL && observer != NULL)
109 if (foundIndex != -1)
121 if (producer != NULL)
bool NumberChangedFunctionList_Add(NumberChangedFunctionList *functionList, NumberChangedFunction function)
Add a function pointer to the given function pointer list.
bool NumberChangedFunctionList_Copy(NumberChangedFunctionList *sourceList, NumberChangedFunctionList *destinationList)
Duplicate the given source function pointer list into the destination function pointer list.
void NumberChangedFunctionList_Remove(NumberChangedFunctionList *functionList, int functionIndex)
Removed the function pointer at the given index from the function pointer list.
int NumberChangedFunctionList_Find(NumberChangedFunctionList *functionList, NumberChangedFunction function)
Search the function list for the specified function pointer.
void NumberChangedFunctionList_Clear(NumberChangedFunctionList *functionList)
Clear the given function pointer list, releasing all associated memory. The function list can then be...
void(* NumberChangedFunction)(uint32_t)
Alias for a function that receives notifications about a number change.
bool NumberProducer_SubscribeToNumberChanged(NumberProducer *producer, NumberChangedFunction observer)
Subscribe to the given NumberProducer to received changes to that producer's number....
static void _NumberProducer_NotifyNumberChanged(NumberProducer *producer)
Helper function to notify all observers that the number has changed in the given NumberProducer objec...
void NumberProducer_UpdateNumber(NumberProducer *producer)
Update the number in the given NumberProducer object, triggering a call to all observer in the produc...
void NumberProducer_UnsubscribeFromNumberChanged(NumberProducer *producer, NumberChangedFunction observer)
Unsubscribe from the Given NumberProducer so the given observer will no longer be called when the pro...
void NumberProducer_Destroy(NumberProducer *producer)
Destroy the given instance of a NumberProducer object. After this function returns,...
NumberProducer * NumberProducer_Create(uint32_t number)
Create an instance of the NumberProducer structure and initialize the structure with the specified nu...
Declaration of the NumberProducer structure along with its support functions, NumberProducer_Create()...
Represents a dynamic list of function pointers of the type NumberChangedFunction.
size_t functions_count
Number of active function pointers in the functions array.
NumberChangedFunction * functions
Array of function pointers.
Represents the Subject in this example. In this case, a structure that contains a list of observers a...
NumberChangedFunctionList observerList
The list of observers subscribed to this class instance.
uint32_t number
The number being maintained.