Property Change Listeners
When using TW_SET_PROPERTY() and twExt_GenericPropertyHandler(), which is a C SDK edge extension, for your property handler, you can take advantage of the Observer pattern. You can declare C functions that will be notified when the value of a property has changed, either on the server or locally as the result of a TW_SET_PROPERTY() command. To do this, use the following set of C SDK functions:
void twExt_AddPropertyChangeListener(char* entityName, char* propertyName,
propertyChangeListenerFunction PropertyChangeListenerFunction);
void twExt_RemovePropertyChangeListener
(propertyChangeListenerFunction PropertyChangeListenerFunction);
By calling twExt_AddPropertyChangeListener(), you can designate a function with the parameters shown below. This function is called when a property on the Thing specified in the entityName parameter changes. If propertyName is set to NULL or the constant TW_OBSERVE_ALL_PROPERTIES, this function is notified on all property changes. If a specific property is passed in the propertyName field, the function is called only if that property changes. Here is an example:
void simplePropertyObserver(const char * entityName,
const char * thingName,twPrimitive* newValue){
printf("My Value has changed\n");

void test_simplePropertyChangeListener() {

twExt_AddPropertyChangeListener() can be called multiple times, allowing multiple observers to be attached to a single Thing. twRemovePropertyChangeListener() removes a function as a change listener.
Was this helpful?