-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathLWES.pm
166 lines (123 loc) · 4.17 KB
/
LWES.pm
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
# This file was automatically generated by SWIG
package LWES;
require Exporter;
require DynaLoader;
@ISA = qw(Exporter DynaLoader);
package LWESc;
bootstrap LWES;
package LWES;
@EXPORT = qw( );
# ---------- BASE METHODS -------------
package LWES;
sub TIEHASH {
my ($classname,$obj) = @_;
return bless $obj, $classname;
}
sub CLEAR { }
sub FIRSTKEY { }
sub NEXTKEY { }
sub FETCH {
my ($self,$field) = @_;
my $member_func = "swig_${field}_get";
$self->$member_func();
}
sub STORE {
my ($self,$field,$newval) = @_;
my $member_func = "swig_${field}_set";
$self->$member_func($newval);
}
sub this {
my $ptr = shift;
return tied(%$ptr);
}
# ------- FUNCTION WRAPPERS --------
package LWES;
*create_db = *LWESc::create_db;
*destroy_db = *LWESc::destroy_db;
*create_emitter = *LWESc::create_emitter;
*create_emitter_with_ttl = *LWESc::create_emitter_with_ttl;
*emit = *LWESc::emit;
*emitto = *LWESc::emitto;
*destroy_emitter = *LWESc::destroy_emitter;
*create_event = *LWESc::create_event;
*create_event_with_encoding = *LWESc::create_event_with_encoding;
*set_uint16 = *LWESc::set_uint16;
*get_uint16 = *LWESc::get_uint16;
*set_int16 = *LWESc::set_int16;
*get_int16 = *LWESc::get_int16;
*set_uint32 = *LWESc::set_uint32;
*get_uint32 = *LWESc::get_uint32;
*set_int32 = *LWESc::set_int32;
*get_int32 = *LWESc::get_int32;
*set_uint64 = *LWESc::set_uint64;
*get_uint64 = *LWESc::get_uint64;
*set_int64 = *LWESc::set_int64;
*get_int64 = *LWESc::get_int64;
*set_string = *LWESc::set_string;
*get_string = *LWESc::get_string;
*set_ip_addr = *LWESc::set_ip_addr;
*get_ip_addr = *LWESc::get_ip_addr;
*set_boolean = *LWESc::set_boolean;
*get_boolean = *LWESc::get_boolean;
*destroy_event = *LWESc::destroy_event;
*current_time_millis = *LWESc::current_time_millis;
# ------- VARIABLE STUBS --------
package LWES;
=head1 NAME
LWES - Perl extension for the Light Weight Event System
=head1 SYNOPSIS
use LWES;
use LWES::EventParser;
use IO::Socket::Multicast;
my $LWES_ADDRESS = "224.1.1.1";
my $LWES_PORT = 9000;
# load an event schema from a file to validate events
my $event_db = LWES::create_db("eventTypes.esf");
# create an emitter for sending events
my $emitter = LWES::create_emitter($LWES_ADDRESS, 0, $LWES_PORT, 0, 60);
# create an event and validate it against the DB
my $event = LWES::create_event($event_db, "MyEvent");
# or create an unvalidated event
my $event2 = LWES::create_event(undef, "MyOtherEvent");
# set some fields
LWES::set_string($event, "MyField", "MyValue");
LWES::set_int32($event2, "MyNumber", 123);
# emit the events
LWES::emit($emitter, $event);
LWES::emit($emitter, $event2);
# listen to some events on the network
my $socket = IO::Socket::Multicast->new(LocalPort => $LWES_PORT,
Reuse => 1);
$socket->mcast_add($LWES_ADDRESS);
my ($message, $peer);
$peer = recv($socket, $message, 65535, 0);
my ($port, $peeraddr) = sockaddr_in($peer);
# deserialize the event into a perl hash
my $event = bytesToEvent($message);
# access the various event fields
my $data = $event->{'MyField'};
# cleanup
LWES::destroy_event($event);
LWES::destroy_emitter($emitter);
LWES::destroy_db($event_db);
=head1 DESCRIPTION
This is the Perl interface to the Light Weight Event System. The
Light Weight Event System is a UDP-based communication toolkit with
built-in serialization, formatting, and type-checking.
=head1 EXPORT
None by default.
=head1 AUTHOR
Anthony Molinaro, E<lt>[email protected]<gt>
Michael P. Lum, E<lt>[email protected]<gt>
=head1 COPYRIGHT AND LICENSE
Portions Copyright (c) 2008, Yahoo! Inc. All rights reserved.
Portions Copyright (c) 2010, OpenX Inc. All rights reserved.
Licensed under the New BSD License (the "License"); you may not use
this file except in compliance with the License. Unless required
by applicable law or agreed to in writing, software distributed
under the License is distributed on an "AS IS" BASIS, WITHOUT
WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License. See accompanying LICENSE file.
=cut
1;