9#include "helpers/uint32_to_binary.h"
28 printf(
" Decimal : %u\n", number);
38 printf(
" Hexadecimal: 0X%08X\n", number);
48 char buffer[(
sizeof(uint32_t) * 8) + 1];
50 printf(
" Binary : %s\n", buffer);
76 printf(
"\nObserver_Exercise\n");
100 for (
int index = 0; index < 10; ++index)
102 printf(
" Update %d on number producer. Results from observers:\n", index);
static void ObserverForDecimal_NumberChanged(uint32_t number)
Represents an observer that prints out the specified number from the Subject in decimal.
static void ObserverForHexadecimal_NumberChanged(uint32_t number)
Represents an observer that prints out the specified number from the Subject in hexadecimal.
static void ObserverForBinary_NumberChanged(uint32_t number)
Represents an observer that prints out the specified number from the Subject in binary.
void Observer_Exercise(void)
Example of using the Observer Pattern.
bool NumberProducer_SubscribeToNumberChanged(NumberProducer *producer, NumberChangedFunction observer)
Subscribe to the given NumberProducer to received changes to that producer's number....
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()...
Declaration of the Observer_Exercise() function as used in the Observer Pattern.
Represents the Subject in this example. In this case, a structure that contains a list of observers a...
void uint32_to_binary(uint32_t number, char *buffer, size_t bufferSize)
Function to convert a 32-bit unsigned integer into a string representation containing all 32 bits.