Added a bump method that tells the announcement module that a value has changed sufficiently much for it to be pushed out quicker

This commit is contained in:
adamdunkels 2010-03-19 13:16:11 +00:00
parent 17db783fb0
commit 137e02baac
2 changed files with 38 additions and 10 deletions

View file

@ -33,7 +33,7 @@
*
* This file is part of the Contiki operating system.
*
* $Id: announcement.c,v 1.3 2010/02/23 18:32:44 adamdunkels Exp $
* $Id: announcement.c,v 1.4 2010/03/19 13:16:11 adamdunkels Exp $
*/
/**
@ -50,7 +50,7 @@
LIST(announcements);
static void (* listen_callback)(int time);
static void (* observer_callback)(uint16_t id, uint16_t newval, uint16_t oldval);
static announcement_observer observer_callback;
/*---------------------------------------------------------------------------*/
void
@ -68,7 +68,7 @@ announcement_register(struct announcement *a, uint16_t id, uint16_t value,
a->callback = callback;
list_add(announcements, a);
if(observer_callback) {
observer_callback(a->id, a->value, 0);
observer_callback(a->id, a->value, 0, ANNOUNCEMENT_BUMP);
}
}
/*---------------------------------------------------------------------------*/
@ -84,7 +84,7 @@ announcement_set_value(struct announcement *a, uint16_t value)
uint16_t oldvalue = a->value;
a->value = value;
if(observer_callback) {
observer_callback(a->id, value, oldvalue);
observer_callback(a->id, value, oldvalue, ANNOUNCEMENT_NOBUMP);
}
}
/*---------------------------------------------------------------------------*/
@ -93,7 +93,15 @@ announcement_set_id(struct announcement *a, uint16_t id)
{
a->id = id;
if(observer_callback) {
observer_callback(a->id, a->value, a->value);
observer_callback(a->id, a->value, a->value, ANNOUNCEMENT_NOBUMP);
}
}
/*---------------------------------------------------------------------------*/
void
announcement_bump(struct announcement *a)
{
if(observer_callback) {
observer_callback(a->id, a->value, a->value, ANNOUNCEMENT_BUMP);
}
}
/*---------------------------------------------------------------------------*/
@ -112,7 +120,7 @@ announcement_register_listen_callback(void (*callback)(int time))
}
/*---------------------------------------------------------------------------*/
void
announcement_register_observer_callback(void (*callback)(uint16_t, uint16_t, uint16_t))
announcement_register_observer_callback(announcement_observer callback)
{
observer_callback = callback;
}

View file

@ -54,7 +54,7 @@
*
* This file is part of the Contiki operating system.
*
* $Id: announcement.h,v 1.6 2010/02/23 18:32:44 adamdunkels Exp $
* $Id: announcement.h,v 1.7 2010/03/19 13:16:11 adamdunkels Exp $
*/
/**
@ -153,6 +153,20 @@ void announcement_set_value(struct announcement *a, uint16_t value);
*/
void announcement_set_id(struct announcement *a, uint16_t id);
/**
* \brief Bump an announcement
* \param a A pointer to a struct announcement that has
* previously been registered
*
* This function is called to inform the announcement
* module that a particular announcement has changed in a
* way that it should be bumped. When an announcement is
* bumped, the announcement back-end may send out a new
* announcement to neighbors.
*
*/
void announcement_bump(struct announcement *a);
/**
* \brief Listen for announcements for a specific amount of
* announcement periods
@ -225,6 +239,14 @@ void announcement_heard(const rimeaddr_t *from, uint16_t id, uint16_t value);
*/
void announcement_register_listen_callback(void (*callback)(int time));
enum {
ANNOUNCEMENT_NOBUMP,
ANNOUNCEMENT_BUMP,
};
typedef void (* announcement_observer)(uint16_t id, uint16_t newvalue,
uint16_t oldvalue, uint8_t bump);
/**
* \brief Register an observer callback with the announcement module
* \param observer A pointer to an observer function
@ -239,9 +261,7 @@ void announcement_register_listen_callback(void (*callback)(int time));
* message with the updated values.
*
*/
void announcement_register_observer_callback(void (*observer)(uint16_t id,
uint16_t newvalue,
uint16_t oldvalue));
void announcement_register_observer_callback(announcement_observer observer);
/**
* @}