Contiki 3.x
servreg-hack.h
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2010, Swedish Institute of Computer Science.
3  * All rights reserved.
4  *
5  * Redistribution and use in source and binary forms, with or without
6  * modification, are permitted provided that the following conditions
7  * are met:
8  * 1. Redistributions of source code must retain the above copyright
9  * notice, this list of conditions and the following disclaimer.
10  * 2. Redistributions in binary form must reproduce the above copyright
11  * notice, this list of conditions and the following disclaimer in the
12  * documentation and/or other materials provided with the distribution.
13  * 3. Neither the name of the Institute nor the names of its contributors
14  * may be used to endorse or promote products derived from this software
15  * without specific prior written permission.
16  *
17  * THIS SOFTWARE IS PROVIDED BY THE INSTITUTE AND CONTRIBUTORS ``AS IS'' AND
18  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
19  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
20  * ARE DISCLAIMED. IN NO EVENT SHALL THE INSTITUTE OR CONTRIBUTORS BE LIABLE
21  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
22  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
23  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
24  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
25  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
26  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
27  * SUCH DAMAGE.
28  *
29  * This file is part of the Contiki operating system.
30  *
31  */
32 
33 /**
34  * \file
35  * Header file for the servreg-hack application
36  * \author
37  * Adam Dunkels <adam@sics.se>
38  */
39 
40 /** \addtogroup apps
41  * @{ */
42 
43 /**
44  * \defgroup servreghack A service registration and diseemination hack
45  * @{
46  *
47  * This application is a quick'n'dirty hack for registering,
48  * disseminating, and looking up services. A service is identified by
49  * an 8-bit integer between 1 and 255. Integers below 128 are reserved
50  * for system services.
51  *
52  * A service is registered with the function
53  * servreg_hack_register(). Registered services will be transmitted to
54  * all neighbors that run the servreg-hack application. These will in
55  * turn resend the registration to their neighbors.
56  *
57  * Services from neighbors are stored in a local table. Services
58  * stored in the table can be looked up using a combination of the
59  * servreg_hack_list() and servreg_hack_item_match() functions.
60  *
61  */
62 
63 #ifndef SERVREG_HACK_H
64 #define SERVREG_HACK_H
65 
66 #include "contiki-conf.h"
67 #include "net/ip/uip.h"
68 
69 typedef uint8_t servreg_hack_id_t;
70 typedef void servreg_hack_item_t;
71 
72 /**
73  * \brief Initialize and start the servreg-hack application
74  *
75  * This function initializes and starts the servreg-hack
76  * application and daemon.
77  */
78 void servreg_hack_init(void);
79 
80 /**
81  * \brief Register that this node provides a service
82  * \param service_id The 8-bit ID for the service
83  * \param addr The address associated with the service
84  *
85  * This function is used to register a
86  * service. Registering a service means that other nodes
87  * in the network will become aware that this node
88  * provides this service. The servreg-hack application
89  * does not specify what this service means, nor does it
90  * provide any mechanism by which the service can be
91  * reached: this is up to the application that uses the
92  * servreg-hack application.
93  */
94 void servreg_hack_register(servreg_hack_id_t service_id, const uip_ipaddr_t *addr);
95 
96 
97 /**
98  * \brief Get the IP address of a node offering a service
99  * \param service_id The service ID of the service
100  * \return A pointer to the IP address of the node, or NULL if the service was not known
101  *
102  * This function returns the address of the node offering
103  * a specific service. If the service is not known, the
104  * function returns NULL. If there are more than one nodes
105  * offering the service, this function returns the address
106  * of the node that most recently announced its service.
107  *
108  * To get a list of all nodes offering a specific service,
109  * use the servreg_hack_list_head() function to get the
110  * full list of offered services.
111  */
112 uip_ipaddr_t * servreg_hack_lookup(servreg_hack_id_t service_id);
113 
114 
115 /**
116  * \brief Obtain the list of services provided by neighbors
117  * \return The list of services
118  *
119  * This function returns a list of services registered by
120  * other nodes. To find a specific service, the caller
121  * needs to iterate through the list and check each list
122  * item with the servreg_hack_item_match() function.
123  */
124 servreg_hack_item_t *servreg_hack_list_head(void);
125 
126 /**
127  * \brief Get the service ID for a list item
128  * \param item The list item
129  * \return The service ID for a list item
130  *
131  * This function is used when iterating through the list
132  * of registered services.
133  */
134 servreg_hack_id_t servreg_hack_item_id(servreg_hack_item_t *item);
135 
136 /**
137  * \brief Get the IP address for a list item
138  * \param item The list item
139  * \return The IP address
140  *
141  * This function is used when iterating through the list
142  * of registered services.
143  */
144 uip_ipaddr_t * servreg_hack_item_address(servreg_hack_item_t *item);
145 
146 #endif /* SERVREG_HACK_H */
147 
148 
149 /** @} */
150 /** @} */
uip_ipaddr_t * servreg_hack_lookup(servreg_hack_id_t id)
Get the IP address of a node offering a service.
Definition: servreg-hack.c:189
void servreg_hack_init(void)
Initialize and start the servreg-hack application.
Definition: servreg-hack.c:119
Header file for the uIP TCP/IP stack.
servreg_hack_id_t servreg_hack_item_id(servreg_hack_item_t *item)
Get the service ID for a list item.
Definition: servreg-hack.c:177
servreg_hack_item_t * servreg_hack_list_head(void)
Obtain the list of services provided by neighbors.
Definition: servreg-hack.c:170
uip_ipaddr_t * servreg_hack_item_address(servreg_hack_item_t *item)
Get the IP address for a list item.
Definition: servreg-hack.c:183
void servreg_hack_register(servreg_hack_id_t id, const uip_ipaddr_t *addr)
Register that this node provides a service.
Definition: servreg-hack.c:132