Re: Marshalling problem



Hi Nohl,

Change the function getInterface() in server as shown below:

# return $ifaces{$name};
  # If the object exist, simply return the old copy itself.
  return $self->{'INTERFACE_' . $name}->{'REF'}
              if (defined($self->{'INTERFACE_' . $name}) &&
                  defined($self->{'INTERFACE_' . $name}->{'REF'}));

  # Object not in cache. Create a new one, store in cache & return it.
  my $obj = $ifaces{$name};
  my $id = $self->{'POA'}->activate_object($obj);
  my $ref = $self->{'POA'}->id_to_reference($id);
  $self->{'INTERFACE_'. $name}->{'REF'} = $ref;
  return $ref;
}

Note the lines activate_object() & id_to_reference(), which is what you
have missed !
In the above you'd get the same object over and over again. If you want
new object for every getInterce(), u can do a new MyIface in
getInterface() & then activate & return the object. In that case u should
not have any cache.

HTH
Sreeji
On Mon, 3 Sep 2001, Nohl Attila Rajmund wrote:

> Hello!
> 
> When I try to return an object from one of my methods, I keep getting
> the following error message on the server:
> Value is not a rm::Iface at ./rm-server-0.pl line 64.
> Error marshalling result of call to MyRouter::getInterface at ./rm-server-0.pl line 64.
> 
> and on the client:
> Exception: CORBA::MARSHAL ('IDL:omg.org/CORBA/MARSHAL:1.0')
>     (0, COMPLETED_YES)
>    Error marshalling parameter or result
> 
> This is the IDL:
> 
> module rm {
>     interface Iface {
>     };
> 
>     interface Router {
>         Iface getInterface(in string ifaceName);
>     };
> };
> 
> This is the server:
> 
> use strict;
> use CORBA::ORBit idl => [ qw(/usr/include/ORBitservices/CosNaming.idl rm.idl) ];
> 
> package MyIface;
> 
> @MyIface::ISA = qw(POA_rm::Iface);
> 
> sub new {
> 	my $proto = shift;
>         my $class = ref($proto) || $proto;
> 
> 	my $self = {};
> 	$self->{NAME} = shift;
> 
> 	bless($self,$class);
> 	print "New interface created:",$self->{NAME},"\n";
> 	return $self;
> }
> 
> 
> package MyRouter;
> 
> @MyRouter::ISA = qw(POA_rm::Router);
> 
> sub new {
> 	my $proto = shift;
>         my $class = ref($proto) || $proto;
> 
> 	my $eth1=new MyIface("eth1");
> 	my $ppp0=new MyIface("ppp0");
> 
> 	my %interfaces=();
> 	$interfaces{"eth1"}=$eth1;
> 	$interfaces{"ppp0"}=$ppp0;
> 
> 	my $self  = {};
> 	$self->{INTERFACES} = \%interfaces;
> 	bless($self,$class);
> 	return $self;
> }
> 
> sub getInterface {
> 	my ($self,$name) = @_;
> 	my $ifacesRef=$self->{INTERFACES};
> 	my %ifaces=%$ifacesRef;
> 	return $ifaces{$name};
> }
> 
> my $orb = CORBA::ORB_init(@ARGV,"orbit-local-orb");
> 
> my $poa = $orb->resolve_initial_references("RootPOA");
> my $namingContext = $orb->resolve_initial_references("NameService");
> 
> my $servant=new MyRouter;
> my $id = $poa->activate_object ($servant);
> my $ref = $poa->id_to_reference($id);
> 
> $poa->_get_the_POAManager()->activate();
> 
> my $name = [{id => "ltpc21", kind => "server"}];
> 
> $namingContext->bind($name, $ref);
> 
> $orb->run();
> 
> 
> An this is the client:
> 
> use strict;
> use CORBA::ORBit idl => [ qw(rm.idl /usr/include/ORBitservices/CosNaming.idl)];
> 
> my $orb = CORBA::ORB_init(@ARGV, "orbit-local-orb");
> 
> my $namingContext = $orb->resolve_initial_references("NameService");
> my $name = [{ id => "ltpc21", kind => "server" }];
> my $router = $namingContext->resolve($name);
> 
> my $interface = $router->getInterface("eth1");
> 
> 
> Do you have any ideas what is the problem and how can I solve it?
> 
> 				Bye,NAR
> -- 
> "Beware of bugs in the above code; I have only proved it correct, not
>  tried it."
> 
> 
> 
> _______________________________________________
> orbit-perl-list mailing list
> orbit-perl-list gnome org
> http://mail.gnome.org/mailman/listinfo/orbit-perl-list
> 





[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]