43 for (
size_t index = 0; index < numIds; index++)
57 prompt =
"<NO PROMPT>";
59 printf(
" %s\n", prompt);
62 printf(
"%s\n", output.
string);
90 printf(
"\nHandlerChain Exercise\n");
94 int windowIds[3] = { 0 };
101 printf(
" Select Window 2\n");
111 printf(
" Select Window 3\n");
119 printf(
" Select Window 1\n");
127 printf(
" Close Window 2\n");
135 printf(
" Removing all windows as part of clean-up.\n");
void HandlerChain_Exercise(void)
Example of using the HandlerChain Pattern or Chain of Responsibility design pattern.
static void _HandlerChain_ConstructWindowChain(int windowIds[3])
Helper function to construct a list of windows. Messages will be passed to these windows via the Hand...
static void _ShowHandlerChain(const char *prompt)
Helper function to display the current handler chain.
static void _HandleChain_DestroyWindows(int windowIds[3])
Helper function to destroy all windows that have been created.
bool HandlerChain_ToString(DynamicString *output)
Convert the Handler Chain to a string, 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(),...
void Message_Initialize(Message *message, MessageType type, int x, int y)
Initialize a Message structure.
@ ButtonUp
Take an action on the currently selected window.
@ ButtonDown
Selects a window based on position.
@ Destroy
Window is being told to destroy itself. This is sent in response to seeing the Close message.
int MessageWindow_Create(const char *title, int x, int y, int w, int h)
Create a MessageWindow object with the given properties and return the ID of the object.
Declaration of the MessageWindow support functions, MessageWindow_Create(), MessageWindow_Destroy(),...
Declaration of the HandlerChain_Exercise() function as used in the HandlerChain Pattern.
void DynamicString_Clear(DynamicString *string)
Clear a DynamicString object, releasing any allocated memory. Resets to an empty string.
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.