Added the option to specify the old value to observers so that they can determine if the announcement should be sent out quicklier than otherwise
This commit is contained in:
parent
b746b7fc06
commit
a4d9d6651b
@ -33,7 +33,7 @@
|
||||
*
|
||||
* This file is part of the Contiki operating system.
|
||||
*
|
||||
* $Id: announcement.c,v 1.2 2009/11/08 19:40:17 adamdunkels Exp $
|
||||
* $Id: announcement.c,v 1.3 2010/02/23 18:32:44 adamdunkels Exp $
|
||||
*/
|
||||
|
||||
/**
|
||||
@ -50,7 +50,7 @@
|
||||
LIST(announcements);
|
||||
|
||||
static void (* listen_callback)(int time);
|
||||
static void (* observer_callback)(uint16_t id, uint16_t val);
|
||||
static void (* observer_callback)(uint16_t id, uint16_t newval, uint16_t oldval);
|
||||
|
||||
/*---------------------------------------------------------------------------*/
|
||||
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);
|
||||
observer_callback(a->id, a->value, 0);
|
||||
}
|
||||
}
|
||||
/*---------------------------------------------------------------------------*/
|
||||
@ -81,9 +81,10 @@ announcement_remove(struct announcement *a)
|
||||
void
|
||||
announcement_set_value(struct announcement *a, uint16_t value)
|
||||
{
|
||||
uint16_t oldvalue = a->value;
|
||||
a->value = value;
|
||||
if(observer_callback) {
|
||||
observer_callback(a->id, a->value);
|
||||
observer_callback(a->id, value, oldvalue);
|
||||
}
|
||||
}
|
||||
/*---------------------------------------------------------------------------*/
|
||||
@ -92,7 +93,7 @@ announcement_set_id(struct announcement *a, uint16_t id)
|
||||
{
|
||||
a->id = id;
|
||||
if(observer_callback) {
|
||||
observer_callback(a->id, a->value);
|
||||
observer_callback(a->id, a->value, a->value);
|
||||
}
|
||||
}
|
||||
/*---------------------------------------------------------------------------*/
|
||||
@ -111,7 +112,7 @@ announcement_register_listen_callback(void (*callback)(int time))
|
||||
}
|
||||
/*---------------------------------------------------------------------------*/
|
||||
void
|
||||
announcement_register_observer_callback(void (*callback)(uint16_t id, uint16_t value))
|
||||
announcement_register_observer_callback(void (*callback)(uint16_t, uint16_t, uint16_t))
|
||||
{
|
||||
observer_callback = callback;
|
||||
}
|
||||
|
@ -54,7 +54,7 @@
|
||||
*
|
||||
* This file is part of the Contiki operating system.
|
||||
*
|
||||
* $Id: announcement.h,v 1.5 2009/11/08 19:40:17 adamdunkels Exp $
|
||||
* $Id: announcement.h,v 1.6 2010/02/23 18:32:44 adamdunkels Exp $
|
||||
*/
|
||||
|
||||
/**
|
||||
@ -240,7 +240,8 @@ void announcement_register_listen_callback(void (*callback)(int time));
|
||||
*
|
||||
*/
|
||||
void announcement_register_observer_callback(void (*observer)(uint16_t id,
|
||||
uint16_t value));
|
||||
uint16_t newvalue,
|
||||
uint16_t oldvalue));
|
||||
|
||||
/**
|
||||
* @}
|
||||
|
@ -33,7 +33,7 @@
|
||||
*
|
||||
* This file is part of the Contiki operating system.
|
||||
*
|
||||
* $Id: polite-announcement.c,v 1.10 2010/01/26 10:18:55 adamdunkels Exp $
|
||||
* $Id: polite-announcement.c,v 1.11 2010/02/23 18:32:44 adamdunkels Exp $
|
||||
*/
|
||||
|
||||
/**
|
||||
@ -158,10 +158,12 @@ send_timer(void *ptr)
|
||||
}
|
||||
/*---------------------------------------------------------------------------*/
|
||||
static void
|
||||
new_announcement(uint16_t id, uint16_t val)
|
||||
new_announcement(uint16_t id, uint16_t newval, uint16_t oldval)
|
||||
{
|
||||
if(newval != oldval) {
|
||||
c.interval = c.min_interval;
|
||||
send_timer(&c);
|
||||
}
|
||||
}
|
||||
/*---------------------------------------------------------------------------*/
|
||||
static const struct ipolite_callbacks ipolite_callbacks =
|
||||
|
Loading…
Reference in New Issue
Block a user