Contiki 2.5
announcement.h
Go to the documentation of this file.
1 /**
2  * \addtogroup rime
3  * @{
4  */
5 
6 /**
7  * \defgroup rimeannouncement Announcements
8  * @{
9  *
10  * The Announcement primitive does local area announcements. An
11  * announcement is an (ID, value) tuple that is disseminated to local
12  * area neighbors. An application or protocol can explicitly listen to
13  * announcements from neighbors. When an announcement is heard, a
14  * callback is invoked.
15  *
16  * Announcements can be used for a variety of network mechanisms such
17  * as neighbor discovery, node-level service discovery, or routing
18  * metric dissemination.
19  *
20  * Application programs and protocols register announcements with the
21  * announcement module. An announcement back-end, implemented by the
22  * system, takes care of sending out announcements over the radio, as
23  * well as collecting announcements heard from neighbors.
24  *
25  */
26 
27 /*
28  * Copyright (c) 2008, Swedish Institute of Computer Science.
29  * All rights reserved.
30  *
31  * Redistribution and use in source and binary forms, with or without
32  * modification, are permitted provided that the following conditions
33  * are met:
34  * 1. Redistributions of source code must retain the above copyright
35  * notice, this list of conditions and the following disclaimer.
36  * 2. Redistributions in binary form must reproduce the above copyright
37  * notice, this list of conditions and the following disclaimer in the
38  * documentation and/or other materials provided with the distribution.
39  * 3. Neither the name of the Institute nor the names of its contributors
40  * may be used to endorse or promote products derived from this software
41  * without specific prior written permission.
42  *
43  * THIS SOFTWARE IS PROVIDED BY THE INSTITUTE AND CONTRIBUTORS ``AS IS'' AND
44  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
45  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
46  * ARE DISCLAIMED. IN NO EVENT SHALL THE INSTITUTE OR CONTRIBUTORS BE LIABLE
47  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
48  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
49  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
50  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
51  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
52  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
53  * SUCH DAMAGE.
54  *
55  * This file is part of the Contiki operating system.
56  *
57  * $Id: announcement.h,v 1.8 2010/03/25 08:49:56 adamdunkels Exp $
58  */
59 
60 /**
61  * \file
62  * Header file for the announcement primitive
63  * \author
64  * Adam Dunkels <adam@sics.se>
65  */
66 
67 #ifndef __ANNOUNCEMENT_H__
68 #define __ANNOUNCEMENT_H__
69 
70 #include "net/rime/rimeaddr.h"
71 
72 struct announcement;
73 
74 typedef void (*announcement_callback_t)(struct announcement *a,
75  const rimeaddr_t *from,
76  uint16_t id, uint16_t val);
77 
78 /**
79  * \brief Representation of an announcement.
80  *
81  * This structure holds the state of an announcement. It
82  * is an opaque structure with no user-visible elements.
83  */
84 struct announcement {
85  struct announcement *next;
86  uint16_t id;
87  uint16_t value;
88  announcement_callback_t callback;
89  uint8_t has_value;
90 };
91 
92 /**
93  * \name Application API
94  * @{
95  */
96 /**
97  * \brief Register an announcement
98  * \param a A pointer to a struct announcement
99  * \param id The identifying number of the announcement
100  * \param callback A pointer to a callback function that is called
101  * when an announcement is heard
102  *
103  * This function registers an announcement with the
104  * announcement module. The state of the announcement is
105  * held in a struct announcement variable, which is passed
106  * as an argument to this function. This variable must be
107  * allocated by the caller. An announcement is identified
108  * with a 16-bit number, which is passed as a parameter to
109  * the function. The announcement also has an initial
110  * value, that can later be changed with
111  * announcement_set_value().
112  *
113  */
114 void announcement_register(struct announcement *a,
115  uint16_t id,
116  announcement_callback_t callback);
117 
118 /**
119  * \brief Remove a previously registered announcement
120  * \param a A pointer to a struct announcement that has
121  * previously been registered
122  *
123  * This function removes an announcement that has
124  * previously been registered with
125  * announcement_register().
126  *
127  */
128 void announcement_remove(struct announcement *a);
129 
130 
131 /**
132  * \brief Set the value of an announcement
133  * \param a A pointer to a struct announcement that has
134  * previously been registered
135  *
136  * This function sets the value of an announcement that
137  * has previously been registered with
138  * announcement_register().
139  *
140  */
141 void announcement_set_value(struct announcement *a, uint16_t value);
142 
143 /**
144  * \brief Remove the value of an announcement
145  * \param a A pointer to a struct announcement that has
146  * previously been registered
147  *
148  * This function removes the value of an announcement that
149  * has previously been registered with
150  * announcement_register().
151  *
152  */
154 
155 
156 /**
157  * \brief Bump an announcement
158  * \param a A pointer to a struct announcement that has
159  * previously been registered
160  *
161  * This function is called to inform the announcement
162  * module that a particular announcement has changed in a
163  * way that it should be bumped. When an announcement is
164  * bumped, the announcement back-end may send out a new
165  * announcement to neighbors.
166  *
167  */
168 void announcement_bump(struct announcement *a);
169 
170 /**
171  * \brief Listen for announcements for a specific amount of
172  * announcement periods
173  * \param periods The number of periods to listen for announcement
174  *
175  * This function starts to listen for announcements for
176  * the specified amount of announcement periods. This
177  * function is called to ensure that the announcement
178  * module hears announcements from neighbors. The
179  * announcement module may hear announcements even if
180  * listening is not explicitly enabled, but with listening
181  * enabled, more announcements will be heard.
182  *
183  */
184 void announcement_listen(int periods);
185 /**
186  * @}
187  */
188 
189 /**
190  * \name System API
191  * @{
192  */
193 
194 /**
195  * \brief Initialize the announcement module
196  *
197  * This function initializes the announcement module, and
198  * is called by the system at boot up.
199  */
200 void announcement_init(void);
201 
202 /**
203  * \brief Get the list of registered announcements
204  * \return The list of registered announcements
205  *
206  * This function returns the list of registered
207  * announcements. This function is used by the back-end to
208  * compile announcement packets from the registered
209  * announcements.
210  *
211  * The announcement list is an ordinary Contiki list, as
212  * defined by the \ref list "list module".
213  *
214  */
215 struct announcement *announcement_list(void);
216 
217 /**
218  * \brief Inform the announcement module of an incoming announcement
219  * \param from The address of the sender of the announcement
220  * \param id The identifier of the announcement
221  * \param value The value of the announcement
222  *
223  * This function is called by the back-end to inform the
224  * announcement module that an announcement from a
225  * neighbor has been heard.
226  *
227  */
228 void announcement_heard(const rimeaddr_t *from, uint16_t id, uint16_t value);
229 
230 /**
231  * \brief Register a listen callback with the announcement module
232  * \param callback A pointer to a callback function
233  *
234  * This function is called by the back-end to register a
235  * listen callback with the announcement module. The
236  * listen callback function is called by the announcement
237  * module as part of the announcement_listen() function.
238  *
239  */
240 void announcement_register_listen_callback(void (*callback)(int time));
241 
242 enum {
243  ANNOUNCEMENT_NOBUMP,
244  ANNOUNCEMENT_BUMP,
245 };
246 
247 typedef void (* announcement_observer)(uint16_t id, uint8_t has_value,
248  uint16_t newvalue, uint16_t oldvalue,
249  uint8_t bump);
250 
251 /**
252  * \brief Register an observer callback with the announcement module
253  * \param observer A pointer to an observer function
254  *
255  * This function is callback by the back-end to register
256  * an observer callback with the announcement module. The
257  * observer callback is called by the announcement module
258  * when an announcement is registered, removed, or have
259  * its identifier or value updated.
260  *
261  * The back-end may chose to send out a new announcement
262  * message with the updated values.
263  *
264  */
265 void announcement_register_observer_callback(announcement_observer observer);
266 
267 /**
268  * @}
269  */
270 
271 #endif /* __ANNOUNCE_H__ */
272 
273 /** @} */
274 /** @} */