added 64 bit integer checks
[lwes-perl.git] / lwes.i
blob4537b1602aba295f6a81723f595a1056f67e52a5
1 %module LWES
3 %{
4 #include "lwes.h"
5 %}
7 %include lwes.h
9 %inline %{
11 struct lwes_event_type_db *
12 create_db(char *filename)
14 return lwes_event_type_db_create(filename);
17 int
18 destroy_db(struct lwes_event_type_db* db)
20 return lwes_event_type_db_destroy(db);
23 struct lwes_emitter *
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);
30 struct lwes_emitter *
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,
35 freq, ttl);
38 int
39 emit(struct lwes_emitter *emitter, struct lwes_event *event)
41 return lwes_emitter_emit(emitter, event);
44 int
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);
51 int
52 destroy_emitter(struct lwes_emitter *emitter)
54 return lwes_emitter_destroy(emitter);
57 struct lwes_event *
58 create_event(struct lwes_event_type_db* db, char *event_name)
60 return lwes_event_create(db, event_name);
63 struct lwes_event *
64 create_event_with_encoding(struct lwes_event_type_db *db, char *event_name,
65 short encoding)
67 return lwes_event_create_with_encoding(db, event_name, encoding);
70 int
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);
77 int
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);
84 int
85 set_int16(struct lwes_event* event, char* attribute_name,
86 short an_int16)
88 return lwes_event_set_INT_16(event, attribute_name, an_int16);
91 int
92 get_int16(struct lwes_event* event, char* attribute_name,
93 short* an_int16)
95 return lwes_event_get_INT_16(event, attribute_name, an_int16);
98 int
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,
114 int an_int32)
116 return lwes_event_set_INT_32(event, attribute_name, an_int32);
120 get_int32(struct lwes_event* event, char* attribute_name,
121 int* an_int32)
123 return lwes_event_get_INT_32(event, attribute_name, an_int32);
127 set_uint64(struct lwes_event* event, char* attribute_name,
128 char* a_uint64)
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,
142 char* an_int64)
144 return lwes_event_set_INT_64_w_string(event, attribute_name, an_int64);
148 get_int64(struct lwes_event* event, char* attribute_name,
149 long long* an_int64)
151 return lwes_event_get_INT_64(event, attribute_name, an_int64);
155 set_string(struct lwes_event* event, char* attribute_name,
156 char* a_string)
158 return lwes_event_set_STRING(event, attribute_name, a_string);
162 get_string(struct lwes_event* event, char* attribute_name,
163 char** a_string)
165 return lwes_event_get_STRING(event, attribute_name, a_string);
169 set_ip_addr(struct lwes_event* event, char* attribute_name,
170 char* an_ip_addr)
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,
184 int a_boolean)
186 return lwes_event_set_BOOLEAN(event, attribute_name, a_boolean);
190 get_boolean(struct lwes_event *event, char *attribute_name,
191 int *a_boolean)
193 return lwes_event_get_BOOLEAN(event, attribute_name, a_boolean);
197 destroy_event(struct lwes_event *event)
199 return lwes_event_destroy(event);
202 void
203 current_time_millis(char *buffer)
205 LWES_INT_64 current_time = 0LL;
206 current_time = currentTimeMillisLongLong();
207 snprintf(buffer,17,"%016llX",current_time);
212 %perlcode %{
214 =head1 NAME
216 LWES - Perl extension for the Light Weight Event System
218 =head1 SYNOPSIS
220 use LWES;
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");
239 # set some fields
240 LWES::set_string($event, "MyField", "MyValue");
241 LWES::set_int32($event2, "MyNumber", 123);
243 # emit the events
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,
249 Reuse => 1);
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'};
261 # cleanup
262 LWES::destroy_event($event);
263 LWES::destroy_emitter($emitter);
264 LWES::destroy_db($event_db);
266 =head1 DESCRIPTION
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.
272 =head1 EXPORT
274 None by default.
276 =head1 AUTHOR
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
284 All rights reserved.
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/>.
299 =cut