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
|
#-----------------------------------------------------------------------
# Copyright (C) 2005-2015 by Jörn Reder <joern AT zyn.de>.
# All Rights Reserved. See file COPYRIGHT for details.
#
# This module is part of Event::RPC, which is free software; you can
# redistribute it and/or modify it under the same terms as Perl itself.
#-----------------------------------------------------------------------
package Event_RPC_Test;
use Event_RPC_Test2;
use strict;
use utf8;
sub get_data { shift->{data} }
sub get_object2 { shift->{object2} }
sub set_data { shift->{data} = $_[1] }
sub set_object2 { shift->{object2} = $_[1] }
sub new {
my $class = shift;
my %par = @_;
my ($data) = $par{'data'};
my $self = bless {
data => $data,
object2 => Event_RPC_Test2->new("foo"),
}, $class;
return $self;
}
my $SINGLETON;
sub singleton {
my $class = shift;
return $SINGLETON if $SINGLETON;
return $SINGLETON = $class->new(data => "singleton"),
}
sub hello {
my $self = shift;
return "I hold this data: '".$self->get_data."'";
}
sub quit {
my $self = shift;
my $rpc_server = Event::RPC::Server->instance;
$rpc_server->get_loop->add_timer (
after => 1,
cb => sub { $rpc_server->stop },
);
return "Server stops in one second";
}
sub clone {
my $self = shift;
my $clone = (ref $self)->new (
data => $self->get_data
);
return $clone;
}
sub multi {
my $self = shift;
my ($num) = @_;
my (@list, %hash);
while ($num) {
push @list, $hash{$num} = (ref $self)->new ( data => $num );
--$num;
}
return (\@list, \%hash);
}
sub echo {
my $self = shift;
my (@params) = @_;
return @params;
}
sub get_cid {
my $self = shift;
my $connection = Event::RPC::Server->instance->get_active_connection;
my $cid = $connection->get_cid;
return $cid;
}
sub get_object_cnt {
my $self = shift;
my $connection = Event::RPC::Server->instance->get_active_connection;
my $client_oids = $connection->get_client_oids;
my $cnt = keys %{$client_oids};
return $cnt;
}
sub get_undef_object {
return undef;
}
sub new_object2 {
my $class = shift;
my ($data) = @_;
return Event_RPC_Test2->new($data);
}
sub get_big_data_struct {
my @records;
for (0..100) {
push @records, {
a => 123,
b => 456789,
c => "ABCD ABCD ABCD ABCD ABCD ABCD ABCD ABCD\n",
d => ("ABCD ABCD ABCD ABCD ABCD ABCD ABCD ABCD\n" x 20),
e => ("ABCD ABCD ABCD ABCD ABCD ABCD ABCD ABCD\n" x 20),
f => ("ABCD ABCD ABCD ABCD ABCD ABCD ABCD ABCD\n" x 50),
g => ("ABCD ABCD ABCD ABCD ABCD ABCD ABCD ABCD\n" x 50),
x => $_,
h => {
a => 123,
b => 456789,
c => "ABCD ABCD ABCD ABCD ABCD ABCD ABCD ABCD\n",
d => ("ABCD ABCD ABCD ABCD ABCD ABCD ABCD ABCD\n" x 20),
e => ("ABCD ABCD ABCD ABCD ABCD ABCD ABCD ABCD\n" x 20),
f => ("ABCD ABCD ABCD ABCD ABCD ABCD ABCD ABCD\n" x 50),
g => ("ABCD ABCD ABCD ABCD ABCD ABCD ABCD ABCD\n" x 50),
x => $_,
},
};
}
return \@records;
}
1;
|