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.11 by root, Sat Jul 21 18:01:26 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);
125 my $id = ++$self->{id}; 127 my $id = ++$self->{id};
126 128
127 my $ws = bless { 129 my $ws = bless {
128 id => $id, 130 id => $id,
129 ns => $self, 131 ns => $self,
130 w => {}, 132 _w => {},
131 }, "ext::widget::set"; 133 }, "ext::widget::set";
132 134
133 $ws->msg (ws_n => id => $id); 135 $ws->msg (ws_n => id => $id);
134 136
135 $ws 137 $ws
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) {
178 push @{$proxy->{ev}{$ev}}, $args{$ev}; 182 push @{$proxy->{ev}{$ev}}, $args{$ev};
179 $args{$ev} = 0; 183 $args{$ev} = 0;
180 } 184 }
181 185
182 $self->msg (ws_c => 186 $self->msg (ws_c =>
183 ws => $self->{w}{id}, 187 ws => $proxy->{id},
184 id => $id, 188 id => $id,
185 class => $class, 189 class => $class,
186 args => \%args, 190 args => \%args,
187 ); 191 );
188 192
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 if (my $ws = $self->{ws}) { 205 if (my $ws = $self->{ws}) {
202 delete $ws->{w}{$self->{id}};
203 $self->msg (w_c => name => "destroy"); 206 $self->msg (w_c => name => "destroy");
207 delete $ws->{_w}{$self->{id}};
204 } 208 }
205} 209}
206 210
207sub msg { 211sub msg {
208 my ($self, $type, %msg) = @_; 212 my ($self, $type, %msg) = @_;
243 247
244 () 248 ()
245} 249}
246 250
247sub set { 251sub set {
248 my ($self, $member, $value) = @_; 252 my ($self, @kv) = @_;
249 253
250 $self->msg (w_s => attr => [ [$member, $value] ]); 254 $self->msg (w_s => attr => \@kv);
251} 255}
252 256
253sub get { 257sub get {
254 my ($self, $member, $cb) = @_; 258 my ($self, $member, $cb) = @_;
255 259

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines