| line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
|
1
|
|
|
|
|
|
|
# $Id: Proxy.pm 1247 2014-07-07 09:06:34Z fil $ |
|
2
|
|
|
|
|
|
|
package POE::Component::IKC::Proxy; |
|
3
|
|
|
|
|
|
|
|
|
4
|
|
|
|
|
|
|
############################################################################## |
|
5
|
|
|
|
|
|
|
# $Id: Proxy.pm 1247 2014-07-07 09:06:34Z fil $ |
|
6
|
|
|
|
|
|
|
# Copyright 1999-2014 Philip Gwyn. All rights reserved. |
|
7
|
|
|
|
|
|
|
# This program is free software; you can redistribute it and/or modify |
|
8
|
|
|
|
|
|
|
# it under the same terms as Perl itself. |
|
9
|
|
|
|
|
|
|
# |
|
10
|
|
|
|
|
|
|
# Contributed portions of IKC may be copyright by their respective |
|
11
|
|
|
|
|
|
|
# contributors. |
|
12
|
|
|
|
|
|
|
|
|
13
|
1
|
|
|
1
|
|
1168
|
use strict; |
|
|
1
|
|
|
|
|
2
|
|
|
|
1
|
|
|
|
|
36
|
|
|
14
|
1
|
|
|
1
|
|
5
|
use vars qw($VERSION @ISA @EXPORT @EXPORT_OK $ikc_kernel); |
|
|
1
|
|
|
|
|
1
|
|
|
|
1
|
|
|
|
|
83
|
|
|
15
|
1
|
|
|
1
|
|
5
|
use Carp; |
|
|
1
|
|
|
|
|
2
|
|
|
|
1
|
|
|
|
|
60
|
|
|
16
|
1
|
|
|
1
|
|
7
|
use Data::Dumper; |
|
|
1
|
|
|
|
|
1
|
|
|
|
1
|
|
|
|
|
56
|
|
|
17
|
|
|
|
|
|
|
|
|
18
|
1
|
|
|
1
|
|
496
|
use POE qw(Session); |
|
|
0
|
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
19
|
|
|
|
|
|
|
use POE::Component::IKC::Specifier; |
|
20
|
|
|
|
|
|
|
|
|
21
|
|
|
|
|
|
|
require Exporter; |
|
22
|
|
|
|
|
|
|
@ISA = qw(Exporter); |
|
23
|
|
|
|
|
|
|
@EXPORT = qw(create_ikc_proxy); |
|
24
|
|
|
|
|
|
|
$VERSION = '0.2402'; |
|
25
|
|
|
|
|
|
|
|
|
26
|
|
|
|
|
|
|
sub DEBUG { 0 } |
|
27
|
|
|
|
|
|
|
|
|
28
|
|
|
|
|
|
|
sub create_ikc_proxy |
|
29
|
|
|
|
|
|
|
{ |
|
30
|
|
|
|
|
|
|
__PACKAGE__->spawn(@_); |
|
31
|
|
|
|
|
|
|
} |
|
32
|
|
|
|
|
|
|
|
|
33
|
|
|
|
|
|
|
sub spawn |
|
34
|
|
|
|
|
|
|
{ |
|
35
|
|
|
|
|
|
|
my($package, $r_kernel, $r_session, $monitor_start, $monitor_stop)=@_; |
|
36
|
|
|
|
|
|
|
|
|
37
|
|
|
|
|
|
|
my $name=specifier_name({kernel=>$r_kernel, session=>$r_session}); |
|
38
|
|
|
|
|
|
|
my $t=$poe_kernel->alias_resolve($name); |
|
39
|
|
|
|
|
|
|
|
|
40
|
|
|
|
|
|
|
if($t) { |
|
41
|
|
|
|
|
|
|
# why is this commented out? |
|
42
|
|
|
|
|
|
|
# $poe_kernel->call($t, '_add_callback', $r_kernel, $r_session); |
|
43
|
|
|
|
|
|
|
} |
|
44
|
|
|
|
|
|
|
else { |
|
45
|
|
|
|
|
|
|
POE::Session->create( |
|
46
|
|
|
|
|
|
|
package_states => [ |
|
47
|
|
|
|
|
|
|
$package => |
|
48
|
|
|
|
|
|
|
[qw( |
|
49
|
|
|
|
|
|
|
_start _stop _delete _default |
|
50
|
|
|
|
|
|
|
_shutdown _add_callback |
|
51
|
|
|
|
|
|
|
)], |
|
52
|
|
|
|
|
|
|
], |
|
53
|
|
|
|
|
|
|
args=> [$name, $r_kernel, $r_session, |
|
54
|
|
|
|
|
|
|
$monitor_start, $monitor_stop] |
|
55
|
|
|
|
|
|
|
); |
|
56
|
|
|
|
|
|
|
} |
|
57
|
|
|
|
|
|
|
} |
|
58
|
|
|
|
|
|
|
|
|
59
|
|
|
|
|
|
|
sub _start |
|
60
|
|
|
|
|
|
|
{ |
|
61
|
|
|
|
|
|
|
my($kernel, $heap, $name, $r_kernel, $r_session, $monitor_start, |
|
62
|
|
|
|
|
|
|
$monitor_stop)= |
|
63
|
|
|
|
|
|
|
@_[KERNEL, HEAP, ARG0, ARG1, ARG2, ARG3, ARG4]; |
|
64
|
|
|
|
|
|
|
|
|
65
|
|
|
|
|
|
|
$heap->{name}=$name; |
|
66
|
|
|
|
|
|
|
$heap->{monitor_stop}=$monitor_stop; |
|
67
|
|
|
|
|
|
|
$heap->{callback}=[]; |
|
68
|
|
|
|
|
|
|
_add_callback($heap, $r_kernel, $r_session); |
|
69
|
|
|
|
|
|
|
|
|
70
|
|
|
|
|
|
|
DEBUG && warn "$$: Proxy for $name ($r_session) created\n"; |
|
71
|
|
|
|
|
|
|
$kernel->alias_set($name); |
|
72
|
|
|
|
|
|
|
$kernel->alias_set($r_session) |
|
73
|
|
|
|
|
|
|
unless $kernel->alias_resolve( $r_session ); |
|
74
|
|
|
|
|
|
|
|
|
75
|
|
|
|
|
|
|
# monitor for shutdown events. |
|
76
|
|
|
|
|
|
|
# this is the best way to get IKC::Responder to tell us about the |
|
77
|
|
|
|
|
|
|
# shutdown |
|
78
|
|
|
|
|
|
|
$kernel->post(IKC=>'monitor', '*', {shutdown=>'_shutdown'}); |
|
79
|
|
|
|
|
|
|
|
|
80
|
|
|
|
|
|
|
&$monitor_start; |
|
81
|
|
|
|
|
|
|
} |
|
82
|
|
|
|
|
|
|
|
|
83
|
|
|
|
|
|
|
sub _shutdown |
|
84
|
|
|
|
|
|
|
{ |
|
85
|
|
|
|
|
|
|
my($kernel, $heap)=@_[KERNEL, HEAP]; |
|
86
|
|
|
|
|
|
|
$kernel->alias_remove($heap->{name}); |
|
87
|
|
|
|
|
|
|
my $spec=specifier_parse($heap->{name}); |
|
88
|
|
|
|
|
|
|
$kernel->alias_remove($spec->{session}) if $spec; |
|
89
|
|
|
|
|
|
|
} |
|
90
|
|
|
|
|
|
|
|
|
91
|
|
|
|
|
|
|
sub _add_callback |
|
92
|
|
|
|
|
|
|
{ |
|
93
|
|
|
|
|
|
|
my($heap, $r_k, $r_s)=@_[HEAP, ARG0, ARG1]; |
|
94
|
|
|
|
|
|
|
($heap, $r_k, $r_s)=@_ if not $heap; |
|
95
|
|
|
|
|
|
|
|
|
96
|
|
|
|
|
|
|
push @{$heap->{callback}}, { kernel=>$r_k, |
|
97
|
|
|
|
|
|
|
session=>$r_s, |
|
98
|
|
|
|
|
|
|
state=>'IKC:proxy' |
|
99
|
|
|
|
|
|
|
}; |
|
100
|
|
|
|
|
|
|
} |
|
101
|
|
|
|
|
|
|
|
|
102
|
|
|
|
|
|
|
sub _delete |
|
103
|
|
|
|
|
|
|
{ |
|
104
|
|
|
|
|
|
|
my($kernel, $heap)=@_[KERNEL, HEAP]; |
|
105
|
|
|
|
|
|
|
$kernel->alias_remove($heap->{name}); |
|
106
|
|
|
|
|
|
|
} |
|
107
|
|
|
|
|
|
|
|
|
108
|
|
|
|
|
|
|
sub _stop |
|
109
|
|
|
|
|
|
|
{ |
|
110
|
|
|
|
|
|
|
my($kernel, $heap)=@_[KERNEL, HEAP]; |
|
111
|
|
|
|
|
|
|
DEBUG && warn "$$: Proxy for $heap->{name} deleted\n"; |
|
112
|
|
|
|
|
|
|
&{$heap->{monitor_stop}}; |
|
113
|
|
|
|
|
|
|
} |
|
114
|
|
|
|
|
|
|
|
|
115
|
|
|
|
|
|
|
|
|
116
|
|
|
|
|
|
|
|
|
117
|
|
|
|
|
|
|
sub _default |
|
118
|
|
|
|
|
|
|
{ |
|
119
|
|
|
|
|
|
|
my($kernel, $heap, $state, $args, $sender)= |
|
120
|
|
|
|
|
|
|
@_[KERNEL, HEAP, ARG0, ARG1, SENDER]; |
|
121
|
|
|
|
|
|
|
return if $state =~ /^_/; |
|
122
|
|
|
|
|
|
|
|
|
123
|
|
|
|
|
|
|
# use Data::Dumper; |
|
124
|
|
|
|
|
|
|
# warn "$$: _default args=", Dumper $args; |
|
125
|
|
|
|
|
|
|
if(not $heap->{callback}) |
|
126
|
|
|
|
|
|
|
{ |
|
127
|
|
|
|
|
|
|
warn "$$: Attempt to respond to a callback with $state\n"; |
|
128
|
|
|
|
|
|
|
return; |
|
129
|
|
|
|
|
|
|
} |
|
130
|
|
|
|
|
|
|
|
|
131
|
|
|
|
|
|
|
DEBUG && warn "$$: Proxy $heap->{name}/$state posted.\n"; |
|
132
|
|
|
|
|
|
|
# use Data::Dumper; |
|
133
|
|
|
|
|
|
|
# warn "$$: _default args=", Dumper $args; |
|
134
|
|
|
|
|
|
|
my $ARG = [$state, [@$args]]; |
|
135
|
|
|
|
|
|
|
foreach my $r_state (@{$heap->{callback}}) { |
|
136
|
|
|
|
|
|
|
# warn "$$: _default ARG=", Dumper $ARG; |
|
137
|
|
|
|
|
|
|
$kernel->call('IKC', 'post2', $r_state, $sender, $ARG); |
|
138
|
|
|
|
|
|
|
} |
|
139
|
|
|
|
|
|
|
return; |
|
140
|
|
|
|
|
|
|
} |
|
141
|
|
|
|
|
|
|
|
|
142
|
|
|
|
|
|
|
1; |
|
143
|
|
|
|
|
|
|
|
|
144
|
|
|
|
|
|
|
__END__ |