1 /*======================================================================*
2 * Copyright (C) 2008 Light Weight Event System *
3 * All rights reserved. *
5 * This program is free software; you can redistribute it and/or modify *
6 * it under the terms of the GNU General Public License as published by *
7 * the Free Software Foundation; either version 2 of the License, or *
8 * (at your option) any later version. *
10 * This program is distributed in the hope that it will be useful, *
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
13 * GNU General Public License for more details. *
15 * You should have received a copy of the GNU General Public License *
16 * along with this program; if not, write to the Free Software *
17 * Foundation, Inc., 51 Franklin Street, Fifth Floor, *
18 * Boston, MA 02110-1301 USA. *
19 *======================================================================*/
20 #ifndef __LWES_EMITTER_H
21 #define __LWES_EMITTER_H
23 #include "lwes_types.h"
24 #include "lwes_net_functions.h"
25 #include "lwes_event.h"
34 /*! \file lwes_emitter.h
35 * \brief Functions for emitting LWES events
38 /*! \struct lwes_emitter lwes_emitter.h
39 * \brief Emits LWES events
43 /*! multicast channel to emit to */
44 struct lwes_net_connection connection
;
45 /*! buffer for serialization of events */
47 /*! count of total events sent */
49 /*! count of events sent since last heartbeat event */
50 LWES_INT_64 count_since_last_beat
;
51 /*! sequence number of heartbeats */
53 /*! frequency in seconds of heartbeats */
54 LWES_INT_16 frequency
;
55 /*! boolean for whether or not to emit heartbeats */
56 LWES_BOOLEAN emitHeartbeat
;
57 /*! time of last heartbeat */
58 time_t last_beat_time
;
61 /*! \brief Create an Emitter
63 * \param[in] address The multicast ip address as a dotted quad string
64 * of the channel to emit to.
65 * \param[in] iface The dotted quad ip address of the interface to
66 * send messages on, can be NULL to use default.
67 * \param[in] port The port of the channel to emit to.
68 * \param[in] emit_heartbeat Set to 1 to emit heartbeats, set to 0 to not
70 * \param[in] freq Number of seconds between heartbeats.
72 * \see lwes_emitter_destroy
74 * \return A newly created emitter, use lwes_emitter_destroy to free
78 (LWES_CONST_SHORT_STRING address
,
79 LWES_CONST_SHORT_STRING iface
,
81 LWES_BOOLEAN emit_heartbeat
,
84 /*! \brief Create an Emitter with a TTL
86 * \param[in] address The multicast ip address as a dotted quad string
87 * of the channel to emit to.
88 * \param[in] iface The dotted quad ip address of the interface to
89 * send messages on, can be NULL to use default.
90 * \param[in] port The port of the channel to emit to.
91 * \param[in] emit_heartbeat Set to 1 to emit heartbeats, set to 0 to not
93 * \param[in] freq Number of seconds between heartbeats.
94 * \param[in] ttl The ttl to use for emitted events
96 * \see lwes_emitter_destroy
98 * \return A newly created emitter, use lwes_emitter_destroy to free
100 struct lwes_emitter
*
101 lwes_emitter_create_with_ttl
102 (LWES_CONST_SHORT_STRING address
,
103 LWES_CONST_SHORT_STRING iface
,
105 LWES_BOOLEAN emit_heartbeat
,
109 /*! \brief Emit an event to the multicast channel defined in the emitter
111 * \param[in] emitter The emitter to emit to
112 * \param[in] event The event to emit
114 * \return 0 on success, a negative number on failure
118 (struct lwes_emitter
*emitter
,
119 struct lwes_event
*event
);
121 /*! \brief Emit an event to a different multicast channel
123 * \param[in] address The multicast ip address as a dotted quad string
124 * of the channel to emit to.
125 * \param[in] iface The dotted quad ip address of the interface to
126 * send messages on, can be NULL to use default.
127 * \param[in] port The port of the channel to emit to.
128 * \param[in] emitter The emitter to use for holding the send buffer
129 * \param[in] event The event to emit
131 * \return 0 on success, a negative number on failure
135 (LWES_SHORT_STRING address
,
136 LWES_SHORT_STRING iface
,
138 struct lwes_emitter
*emitter
,
139 struct lwes_event
*event
);
141 /*! \brief Emit bytes to a multicast channel
143 * Use this in re-emitter's so that you don't have to deserialize and
144 * reserialize, NOTE: this will not result in statistics being incremented
146 * \param[in] emitter The emitter to emit to
147 * \param[in] bytes The bytes to emit
148 * \param[in] length The number of bytes to emit
150 * \return the number of bytes sent on success, a negative number on failure
153 lwes_emitter_emit_bytes
154 (struct lwes_emitter
*emitter
,
158 /*! \brief Destroy an Emitter
160 * \param[in] emitter The emitter to destroy by freeing all of it's used
163 * \return 0 on success, negative number on failure
167 (struct lwes_emitter
*emitter
);
173 #endif /* __LWES_EMITTER_H */