114 for (
size_t index = 0; index < localList.
length; index++)
116 if (windowId == -1 || windowId == (
int)localList.
data[index])
128 printf(
" Error! Out of memory condition copying the handler chain list in HandlerChain_SendMessage()!\n'");
138 bool success =
false;
142 if (foundIndex == -1)
147 printf(
" Error! Out of memory condition adding window handle to handler chain in HandlerChain_AddWindow()!\n");
152 printf(
" Error! Unable to find window handle %d in HandlerChain_AddWindow()!\n", windowId);
166 if (foundIndex != -1)
178 bool success =
false;
210 printf(
" Error! Out of memory condition converting handler chain to a string!\n");
217 printf(
" Error! Out of memory condition copying the handler chain in HandlerChain_ToString()!\n");
bool HandlerChain_AddWindow(int windowId)
Add an instance of a MessageWindow to end of the list of windows, protected by a multi-threading lock...
static void _DestroyMutex(void)
An atexit() handler to destroy the mutex on program exit.
static bool _mutex_initialized
A flag to indicate whether the mutex has been initialized and is ready for use.
static void _LockMutex(void)
Helper function to lock the mutex.
bool HandlerChain_ToString(DynamicString *output)
Convert the Handler Chain to a string, protected by a multi-threading lock.
static bool _CreateMutex(void)
Helper function to create the mutex, if not already created.
static UIntArray _handleList
List of IDs of MessageWindow objects that can be sent messages.
static void _UnlockMutex(void)
Helper function to unlock the mutex.
static Mutex _mutex
A mutex used to protect the handler list from cross-thread corruption.
void HandlerChain_RemoveWindow(int windowId)
Remove an instance of a MessageWindow from the list, protected by a multi-threading lock.
void HandlerChain_SendMessage(int windowId, Message *message)
Send a message to each of the handlers in the list, protected by a multi-threading lock.
Declaration of the Handler Chain functions, HandlerChain_SendMessage(), HandlerChain_AddWindow(),...
bool MessageWindow_ProcessMessage(int windowId, Message *message)
Pass a Message object to a window for processing.
bool MessageWindow_ToString(int windowId, DynamicString *output)
Convert the specified window to a string representation.
Declaration of the MessageWindow support functions, MessageWindow_Create(), MessageWindow_Destroy(),...
void DynamicString_Clear(DynamicString *string)
Clear a DynamicString object, releasing any allocated memory. Resets to an empty string.
bool DynamicString_Append(DynamicString *string, const char *s)
Append the specified string to the DynamicString object.
bool mutex_destroy(Mutex *mutex)
Destroy a previously created mutex.
bool mutex_unlock(Mutex *mutex)
Unlock a previously locked mutex.
bool mutex_create(Mutex *mutex)
Create a new mutex, which is initially not owned.
bool mutex_lock(Mutex *mutex)
Lock a previously created and unlocked mutex. This will block if the mutex is already locked by some ...
Declaration of the Mutex structure and supporting functions for working with mutexes.
Represents a string that can be grown dynamically.
char * string
The string that can grow.
Represents a message sent to the windows. A message contains a type and a position.
Represents a handle to a mutex. Call mutex_create() to create the mutex and mutex_destroy() to destro...
Represents an array of 32-bit unsigned integers. The data field points to a block of memory allocated...
uint32_t * data
Pointer to array of 32-bit unsigned integers.
size_t length
Number of 32-bit unsigned integers actually in the data array.
int UIntArray_Find(UIntArray *array, uint32_t value)
Search the given UIntArray object for the specified value and return the index of that found value.
bool UIntArray_Copy(UIntArray *sourceArray, UIntArray *destinationArray)
Copy the source UIntArray to the destination UIntArray. The destination UIntArray is erased before ge...
void UIntArray_Clear(UIntArray *array)
Clear the given UIntArray object so it can be reused again. Releases the list of integers.
bool UIntArray_AddInt(UIntArray *array, uint32_t value)
Add an unsigned 32-bit integer to the given UIntArray object.
void UIntArray_RemoveInt(UIntArray *array, int removeIndex)
Remove the unsigned 32-bit integer from the given UIntArray object at the given index....
Declaration of the UIntArray structure and the supporting functions that represents an array of 32-bi...