switching licenses
[lwes-perl.git] / lwes.i
blob9626511bebb55f0a9c0504357fc986e68f0a283a
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 Portions Copyright (c) 2008, Yahoo! Inc. All rights reserved.
284 Portions Copyright (c) 2010, OpenX Inc. All rights reserved.
286 Licensed under the New BSD License (the "License"); you may not use
287 this file except in compliance with the License. Unless required
288 by applicable law or agreed to in writing, software distributed
289 under the License is distributed on an "AS IS" BASIS, WITHOUT
290 WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
291 See the License for the specific language governing permissions and
292 limitations under the License. See accompanying LICENSE file.
294 =cut