1 /*
2  * The olsr.org Optimized Link-State Routing daemon (olsrd)
3  *
4  * (c) by the OLSR project
5  *
6  * See our Git repository to find out who worked on this file
7  * and thus is a copyright holder on it.
8  *
9  * All rights reserved.
10  *
11  * Redistribution and use in source and binary forms, with or without
12  * modification, are permitted provided that the following conditions
13  * are met:
14  *
15  * * Redistributions of source code must retain the above copyright
16  *   notice, this list of conditions and the following disclaimer.
17  * * Redistributions in binary form must reproduce the above copyright
18  *   notice, this list of conditions and the following disclaimer in
19  *   the documentation and/or other materials provided with the
20  *   distribution.
21  * * Neither the name of olsr.org, olsrd nor the names of its
22  *   contributors may be used to endorse or promote products derived
23  *   from this software without specific prior written permission.
24  *
25  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
26  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
27  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
28  * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
29  * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
30  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
31  * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
32  * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
33  * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
34  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
35  * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
36  * POSSIBILITY OF SUCH DAMAGE.
37  *
38  * Visit http://www.olsr.org for more information.
39  *
40  * If you find this software useful feel free to make a donation
41  * to the project. For more information see the website or contact
42  * the copyright holders.
43  *
44  */
45 
46 #include "olsrdPlugin.h"
47 
48 /* Plugin includes */
49 #include "sgwDynSpeed.h"
50 
51 /* OLSRD includes */
52 #include "olsr.h"
53 #include "builddata.h"
54 
55 /* System includes */
56 #include <stdbool.h>
57 
58 /*
59  * OLSR Entrypoints
60  */
61 
62 /**
63  OLSR entrypoint to initialise the plugin.
64 
65  @return
66  - 0 on fail
67  - 1 on success
68  */
olsrd_plugin_init(void)69 int olsrd_plugin_init(void) {
70 	bool retval = initSgwDynSpeed();
71 	return (retval ? 1 : 0);
72 }
73 
74 /**
75  OLSR entrypoint to retrieve the interface version supported by the plugin.
76 
77  @return
78  the supported interface version
79  */
olsrd_plugin_interface_version(void)80 int olsrd_plugin_interface_version(void) {
81 	return SGWDYNSPEED_PLUGIN_INTERFACE_VERSION;
82 }
83 
84 /**
85  OLSR entrypoint to retrieve the plugin parameter configuration.
86 
87  @param params
88  a pointer to a variable in which the function stores a pointer to the
89  plugin parameter configuration
90  @param size
91  a pointer to a variable in which the function stores the number of rows of the
92  plugin parameter configuration
93  */
olsrd_get_plugin_parameters(const struct olsrd_plugin_parameters ** params,int * size)94 void olsrd_get_plugin_parameters(const struct olsrd_plugin_parameters **params, int *size) {
95 	*params = &plugin_parameters[0];
96 	*size = ARRAYSIZE(plugin_parameters);
97 }
98 
99 /*
100  * Shared Library Entrypoints
101  */
102 
103 /**
104  Shared library entrypoint declaration for initialisation
105  */
106 static void __attribute__ ((constructor)) sgwDynSpeed_init(void);
107 
108 /**
109  Shared library entrypoint declaration for destruction
110  */
111 static void __attribute__ ((destructor)) sgwDynSpeed_fini(void);
112 
113 /**
114  Shared library entrypoint for initialisation
115  */
sgwDynSpeed_init(void)116 static void sgwDynSpeed_init(void) {
117   /* Print plugin info to stdout */
118   olsr_printf(0, "%s (%s)\n", SGWDYNSPEED_PLUGIN_NAME_LONG, git_descriptor);
119 }
120 
121 /**
122  Shared library entrypoint for destruction
123  */
sgwDynSpeed_fini(void)124 static void sgwDynSpeed_fini(void) {
125 	stopSgwDynSpeed();
126 }
127