ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/deliantra/server/ext/widget.ext
(Generate patch)

Comparing deliantra/server/ext/widget.ext (file contents):
Revision 1.12 by root, Sun Jul 22 20:08:38 2007 UTC vs.
Revision 1.13 by root, Mon Jul 23 21:02:50 2007 UTC

10# 10#
11# and expects the following exti message types 11# and expects the following exti message types
12# w_r rid res # widget call return 12# w_r rid res # widget call return
13# w_e id name args # widget_event 13# w_e id name args # widget_event
14 14
15our $DEBUG = 1;
16
15cf::client->attach ( 17cf::client->attach (
16 on_connect => sub { 18 on_connect => sub {
17 my ($ns) = @_; 19 my ($ns) = @_;
18 20
19 Scalar::Util::weaken (my $weakns = $ns); 21 Scalar::Util::weaken (my $weakns = $ns);
155sub msg { 157sub msg {
156 my ($self, $type, %msg) = @_; 158 my ($self, $type, %msg) = @_;
157 159
158 if (my $ns = shift->{ns}) { 160 if (my $ns = shift->{ns}) {
159 $msg{msgtype} = $type; 161 $msg{msgtype} = $type;
162 warn "msg " . $ns->{json_coder}->encode (\%msg) if $DEBUG;#d#
160 $ns->send_packet ("ext " . $ns->{json_coder}->encode (\%msg)); 163 $ns->send_packet ("ext " . $ns->{json_coder}->encode (\%msg));
161 } 164 }
162} 165}
163 166
164sub new { 167sub new {
165 my ($self, $class, %args) = @_; 168 my ($self, $class, %args) = @_;
166 169
167 my $id = ++$self->{ns}{id}; 170 my $id = ++$self->{ns}{id};
168 171
169 my $proxy = $self->{_w}{$id} = bless { 172 my $proxy = bless {
170 id => $id, 173 id => $id,
171 }, "ext::widget::proxy"; 174 }, "ext::widget::proxy";
172 175
176 Scalar::Util::weaken ($self->{_w}{$id} = $proxy);
173 Scalar::Util::weaken ($proxy->{ws} = $self); 177 Scalar::Util::weaken ($proxy->{ws} = $self);
174 Scalar::Util::weaken ($proxy->{ns} = $self->{ns}); 178 Scalar::Util::weaken ($proxy->{ns} = $self->{ns});
175 Scalar::Util::weaken ($self->{ns}{widget}{$id} = $proxy); 179 Scalar::Util::weaken ($self->{ns}{widget}{$id} = $proxy);
176 180
177 for my $ev (grep /^on_/, keys %args) { 181 for my $ev (grep /^on_/, keys %args) {
196sub DESTROY { 200sub DESTROY {
197 my ($self) = @_; 201 my ($self) = @_;
198 202
199 delete $self->{ns}{widget}{$self->{id}}; 203 delete $self->{ns}{widget}{$self->{id}};
200 204
201 #warn "DES<$self> $self->{ws}\n";#d#
202 if (my $ws = $self->{ws}) { 205 if (my $ws = $self->{ws}) {
203 $self->msg (w_c => name => "destroy"); 206 $self->msg (w_c => name => "destroy");
204 delete $ws->{_w}{$self->{id}}; 207 delete $ws->{_w}{$self->{id}};
205 } 208 }
206} 209}

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines