11 struct lwes_event_type_db
*
12 create_db
(char
*filename
)
14 return lwes_event_type_db_create
(filename
);
18 destroy_db
(struct lwes_event_type_db
* db
)
20 return lwes_event_type_db_destroy
(db
);
24 create_emitter
(char
*address
, char
*iface
, int port
,
25 int emit_heartbeat
, short freq
)
27 return lwes_emitter_create
(address
, iface
, port
, emit_heartbeat
, freq
);
31 create_emitter_with_ttl
(char
*address
, char
*iface
, int port
,
32 int emit_heartbeat
, short freq
, int ttl
)
34 return lwes_emitter_create_with_ttl
(address
, iface
, port
, emit_heartbeat
,
39 emit
(struct lwes_emitter
*emitter
, struct lwes_event
*event
)
41 return lwes_emitter_emit
(emitter
, event
);
45 emitto
(char
*address
, char
*iface
, int port
, struct lwes_emitter
*emitter
,
46 struct lwes_event
*event
)
48 return lwes_emitter_emitto
(address
, iface
, port
, emitter
, event
);
52 destroy_emitter
(struct lwes_emitter
*emitter
)
54 return lwes_emitter_destroy
(emitter
);
58 create_event
(struct lwes_event_type_db
* db
, char
*event_name
)
60 return lwes_event_create
(db
, event_name
);
64 create_event_with_encoding
(struct lwes_event_type_db
*db
, char
*event_name
,
67 return lwes_event_create_with_encoding
(db
, event_name
, encoding
);
71 set_uint16
(struct lwes_event
*event
, char
*attribute_name
,
72 unsigned short a_uint16
)
74 return lwes_event_set_U_INT_16
(event
, attribute_name
, a_uint16
);
78 get_uint16
(struct lwes_event
* event
, char
* attribute_name
,
79 unsigned short
*a_uint16
)
81 return lwes_event_get_U_INT_16
(event
, attribute_name
, a_uint16
);
85 set_int16
(struct lwes_event
* event
, char
* attribute_name
,
88 return lwes_event_set_INT_16
(event
, attribute_name
, an_int16
);
92 get_int16
(struct lwes_event
* event
, char
* attribute_name
,
95 return lwes_event_get_INT_16
(event
, attribute_name
, an_int16
);
99 set_uint32
(struct lwes_event
* event
, char
* attribute_name
,
100 unsigned int a_uint32
)
102 return lwes_event_set_U_INT_32
(event
, attribute_name
, a_uint32
);
106 get_uint32
(struct lwes_event
* event
, char
* attribute_name
,
107 unsigned int
* a_uint32
)
109 return lwes_event_get_U_INT_32
(event
, attribute_name
, a_uint32
);
113 set_int32
(struct lwes_event
* event
, char
* attribute_name
,
116 return lwes_event_set_INT_32
(event
, attribute_name
, an_int32
);
120 get_int32
(struct lwes_event
* event
, char
* attribute_name
,
123 return lwes_event_get_INT_32
(event
, attribute_name
, an_int32
);
127 set_uint64
(struct lwes_event
* event
, char
* attribute_name
,
130 return lwes_event_set_U_INT_64_w_string
(event
, attribute_name
, a_uint64
);
134 get_uint64
(struct lwes_event
* event
, char
* attribute_name
,
135 unsigned long long
* a_uint64
)
137 return lwes_event_get_U_INT_64
(event
, attribute_name
, a_uint64
);
141 set_int64
(struct lwes_event
* event
, char
* attribute_name
,
144 return lwes_event_set_INT_64_w_string
(event
, attribute_name
, an_int64
);
148 get_int64
(struct lwes_event
* event
, char
* attribute_name
,
151 return lwes_event_get_INT_64
(event
, attribute_name
, an_int64
);
155 set_string
(struct lwes_event
* event
, char
* attribute_name
,
158 return lwes_event_set_STRING
(event
, attribute_name
, a_string
);
162 get_string
(struct lwes_event
* event
, char
* attribute_name
,
165 return lwes_event_get_STRING
(event
, attribute_name
, a_string
);
169 set_ip_addr
(struct lwes_event
* event
, char
* attribute_name
,
172 return lwes_event_set_IP_ADDR_w_string
(event
, attribute_name
, an_ip_addr
);
176 get_ip_addr
(struct lwes_event
*event
, char
*attribute_name
,
177 struct in_addr
*an_ip_addr
)
179 return lwes_event_get_IP_ADDR
(event
, attribute_name
, an_ip_addr
);
183 set_boolean
(struct lwes_event
* event
, char
* attribute_name
,
186 return lwes_event_set_BOOLEAN
(event
, attribute_name
, a_boolean
);
190 get_boolean
(struct lwes_event
*event
, char
*attribute_name
,
193 return lwes_event_get_BOOLEAN
(event
, attribute_name
, a_boolean
);
197 destroy_event
(struct lwes_event
*event
)
199 return lwes_event_destroy
(event
);
203 current_time_millis
(char
*buffer
)
205 LWES_INT_64 current_time
= 0LL;
206 current_time
= currentTimeMillisLongLong
();
207 snprintf
(buffer
,17,"%016llX",current_time
);
216 LWES
- Perl extension for the Light Weight Event System
221 use LWES
::EventParser
;
222 use IO
::Socket
::Multicast
;
224 my $LWES_ADDRESS
= "224.1.1.1";
225 my $LWES_PORT
= 9000;
227 # load an event schema from a file to validate events
228 my $event_db
= LWES
::create_db
("eventTypes.esf");
230 # create an emitter for sending events
231 my $emitter
= LWES
::create_emitter
($LWES_ADDRESS
, 0, $LWES_PORT
, 0, 60);
233 # create an event and validate it against the DB
234 my $event
= LWES
::create_event
($event_db
, "MyEvent");
236 # or create an unvalidated event
237 my $event2
= LWES
::create_event
(undef
, "MyOtherEvent");
240 LWES
::set_string
($event
, "MyField", "MyValue");
241 LWES
::set_int32
($event2
, "MyNumber", 123);
244 LWES
::emit
($emitter
, $event
);
245 LWES
::emit
($emitter
, $event2
);
247 # listen to some events on the network
248 my $socket
= IO
::Socket
::Multicast-
>new
(LocalPort
=> $LWES_PORT
,
250 $socket-
>mcast_add
($LWES_ADDRESS
);
251 my
($message
, $peer
);
252 $peer
= recv
($socket
, $message
, 65535, 0);
253 my
($port
, $peeraddr
) = sockaddr_in
($peer
);
255 # deserialize the event into a perl hash
256 my $event
= bytesToEvent
($message
);
258 # access the various event fields
259 my $data
= $event-
>{'MyField'
};
262 LWES
::destroy_event
($event
);
263 LWES
::destroy_emitter
($emitter
);
264 LWES
::destroy_db
($event_db
);
268 This is the Perl interface to the Light Weight Event System. The
269 Light Weight Event System is a UDP-based communication toolkit with
270 built-in serialization
, formatting
, and type-checking.
278 Anthony Molinaro
, E
<lt
>molinaro@users.sourceforge.netE
<gt
>
279 Michael P. Lum
, E
<lt
>mlum@users.sourceforge.netE
<gt
>
281 =head1 COPYRIGHT
AND LICENSE
283 Copyright
(C
) 2008 Light Weight Event System
286 This program is free software
: you can redistribute it and
/or modify
287 it under the terms of the GNU General Public License as published by
288 the Free Software Foundation
, either version
2 of the License
, or
289 (at your option
) any later version.
291 This program is distributed in the hope that it will be useful
,
292 but WITHOUT
ANY WARRANTY
; without even the implied warranty of
293 MERCHANTABILITY or FITNESS
FOR A PARTICULAR PURPOSE. See the
294 GNU General Public License for more details.
296 You should have received a copy of the GNU General Public License
297 along with this program. If not
, see
<http
://www.gnu.org
/licenses
/>.