Missing files for SWo
git-svn-id: https://svn.vbchaos.nl/svn/hsb/trunk@236 05563f52-14a8-4384-a975-3d1654cca0fa
This commit is contained in:
@@ -0,0 +1,131 @@
|
||||
/* -----------------------------------------------------------------------------
|
||||
* Observable.h (c) 2013 Micro-Key bv
|
||||
* -----------------------------------------------------------------------------
|
||||
* Micro-Key bv
|
||||
* Industrieweg 28, 9804 TG Noordhorn
|
||||
* Postbus 92, 9800 AB Zuidhorn
|
||||
* The Netherlands
|
||||
* Tel: +31 594 503020
|
||||
* Fax: +31 594 505825
|
||||
* Email: support@microkey.nl
|
||||
* Web: www.microkey.nl
|
||||
* -----------------------------------------------------------------------------
|
||||
* Description: Observer design pattern
|
||||
* -----------------------------------------------------------------------------
|
||||
* $Id$
|
||||
* -----------------------------------------------------------------------------
|
||||
*/
|
||||
|
||||
#ifndef _OBSERVABLE_H_
|
||||
#define _OBSERVABLE_H_
|
||||
|
||||
/* --------------*
|
||||
* Include files *
|
||||
* --------------*
|
||||
*/
|
||||
|
||||
#include "stm32f10x.h"
|
||||
|
||||
#include "Class.h"
|
||||
#include "Observer.h"
|
||||
|
||||
/* -------------------------------*
|
||||
* Constant and macro definitions *
|
||||
* -------------------------------*
|
||||
*/
|
||||
|
||||
/**
|
||||
* Maximal number of Observers for one Observable.
|
||||
*/
|
||||
#define OBSERVABLE_MAX_OBSERVERS (32)
|
||||
|
||||
/**
|
||||
* Static initializer for the Observable class.
|
||||
* Typical usage: struct Observable observable = OBSERVABLE_INITIALIZER;
|
||||
*/
|
||||
#ifdef CLASS_INTERNAL_INCLUDE
|
||||
#define OBSERVABLE_INITIALIZER { .nrOfObservers = 0, .observers = { 0, } }
|
||||
#else
|
||||
#define OBSERVABLE_INITIALIZER { .DONOTUSEnrOfObservers = 0, .DONOTUSEobservers = { 0, } }
|
||||
#endif
|
||||
|
||||
/* ------------------*
|
||||
* Type definitions. *
|
||||
* ------------------*
|
||||
*/
|
||||
|
||||
/**
|
||||
* The Observable class.
|
||||
*/
|
||||
struct Observable
|
||||
{
|
||||
int PRIVATE(nrOfObservers);
|
||||
Observer PRIVATE(observers)[OBSERVABLE_MAX_OBSERVERS];
|
||||
};
|
||||
|
||||
/* ----------------------*
|
||||
* Function declarations *
|
||||
* ----------------------*
|
||||
*/
|
||||
|
||||
/**
|
||||
* Initializes the Observable class.
|
||||
* This is not needed if the Observable has been statically initialized by "struct Observable observable = OBSERVABLE_INITIALIZER".
|
||||
* @param self: address of the Observable struct.
|
||||
* @retval none.
|
||||
*/
|
||||
void Observable_initialize(struct Observable* self);
|
||||
|
||||
/**
|
||||
* Terminates the Observable class. All Observers are removed.
|
||||
* @param self: address of the Observable struct.
|
||||
* @retval none.
|
||||
*/
|
||||
void Observable_terminate(struct Observable* self);
|
||||
|
||||
/**
|
||||
* Adds one Observer to the Observable.
|
||||
* @param self: address of the Observable struct.
|
||||
* @param observer: Observer to be added.
|
||||
* @retval ErrorStatus: returns an error in case the maximum number of Observers have been added.
|
||||
*/
|
||||
ErrorStatus Observable_addObserver(struct Observable* self, const Observer observer);
|
||||
|
||||
/**
|
||||
* Adds one Observer to the Observable at the front of the list.
|
||||
* This ensures that this Observer is notified before Observers added by Observable_addObserver.
|
||||
* @param self: address of the Observable struct.
|
||||
* @param observer: Observer to be added.
|
||||
* @retval ErrorStatus: returns an error in case the maximum number of Observers have been added.
|
||||
*/
|
||||
ErrorStatus Observable_addObserverAtFront(struct Observable* self, const Observer observer);
|
||||
|
||||
/**
|
||||
* Notifies all Observers by calling the Observer callback function. The parameter void* data will be
|
||||
* passed as parameter to the Observer.
|
||||
* @param self: address of the Observable struct.
|
||||
* @param data: void pointer data to be passed as parameter to the Observer.
|
||||
* @retval ErrorStatus: returns an error in case one or more of the Observers returned an error.
|
||||
*/
|
||||
ErrorStatus Observable_notifyObservers(const struct Observable* self, const void* const data);
|
||||
|
||||
/**
|
||||
* Deletes one specific Observer added before. If the Observer cannot be found, no action is taken.
|
||||
* @param self: address of the Observable struct.
|
||||
* @param observer: Observer to be deleted.
|
||||
*/
|
||||
void Observable_deleteObserver(struct Observable* self, const Observer observer);
|
||||
|
||||
/**
|
||||
* Deletes all Observers added.
|
||||
* @param self: address of the Observable struct.
|
||||
*/
|
||||
void Observable_deleteObservers(struct Observable* self);
|
||||
|
||||
/**
|
||||
* Returns the number of Observers currently subscribed to an Observable.
|
||||
* @param self: address of the Observable struct.
|
||||
*/
|
||||
int Observable_nrOfObservers(struct Observable* self);
|
||||
|
||||
#endif
|
||||
Reference in New Issue
Block a user