Go Back   ZeroC Forums > Help Center

Reply
 
LinkBack Thread Tools Rate Thread Display Modes
  #1 (permalink)  
Old 11-26-2005
fengxb's Avatar
fengxb fengxb is offline
Registered User
 
Name: feng xuebin
Organization: jiexin tech
Project: scientific calculation
 
Join Date: Aug 2003
Location: R.P.China
Posts: 78
a question about Classes as Unions

Hi,

I define some classes as below:

/////////////////////////////////////////////////////
enum VARTYPE { VTNULL, VTBOOL, VTBYTE, VTSHORT, VTINT, VTLONG, VTFLOAT, VTDOUBLE, VTSTRING, VTBLOB, VTSTRINGBLOB };

class Variant{
string toString();
int fromString(string s);
VARTYPE getType();
};

class VariantBoolean extends Variant { bool value; };

class VariantByte extends Variant { byte value; };

class ComplexObj{
int i;
Variant value;
};

interface MyOp{
int submit(ComplexObj obj);
};
//////////////////////////////////////////////////////////////////

In the client side, member "value" of ComplexObj object is instantiated as VariantBooleanI object.
After client invoke submit() of MyOp, the server throws an exception as below:

//////////////////////////////////////////////////////////////////
infoprocmgt: warning: dispatch exception: g:\def.
cpp:1521: Ice::NoObjectFactoryException:
protocol error: no suitable object factory found for `Variant'
identity: MyOp.submit
facet:
operation: submit

//////////////////////////////////////////////////////

do Ice support the semantics?

Thanks in advance.

FengXB
__________________
Fengxb
Reply With Quote
  #2 (permalink)  
Old 11-26-2005
matthew's Avatar
matthew matthew is online now
ZeroC Staff
 
Name: Matthew Newhook
Organization: ZeroC, Inc.
Project: Internet Communications Engine
 
Join Date: Feb 2003
Location: NL, Canada
Posts: 1,060
Yes. But you have to install an object factory for the types you expect to use in your application. See the Ice manual for more information.
Reply With Quote
  #3 (permalink)  
Old 11-27-2005
fengxb's Avatar
fengxb fengxb is offline
Registered User
 
Name: feng xuebin
Organization: jiexin tech
Project: scientific calculation
 
Join Date: Aug 2003
Location: R.P.China
Posts: 78
Thanks a lot. It works.
__________________
Fengxb
Reply With Quote
  #4 (permalink)  
Old 04-05-2007
mmongu mmongu is offline
Registered User
 
Name: Marco Monguzzi
Organization: SITEK s.p.a.
Project: developing test case for ICE-E
 
Join Date: Apr 2007
Location: Verona, Italy
Posts: 4
Hello,

I am a newbie and looking at ice-e now as 1st time.

I am basically in the same need: defining a variant type to serialize/deserialize
over the wire.
In SOAP I use anytype for that. With slice (ICE-E),
how I define a variant that can hold a sequence of bytes?

class VariantBINARY extends Variant { sequence<byte> value; };
would pops a syntax error.

Thanks in advance,
Marco Monguzzi

Last edited by mmongu : 04-05-2007 at 06:36 AM.
Reply With Quote
  #5 (permalink)  
Old 04-05-2007
matthew's Avatar
matthew matthew is online now
ZeroC Staff
 
Name: Matthew Newhook
Organization: ZeroC, Inc.
Project: Internet Communications Engine
 
Join Date: Feb 2003
Location: NL, Canada
Posts: 1,060
You cannot directly use a sequence like that. You must first typedef it and use the resulting type. sequence<byte> is pre-defined in slice/Ice/BuiltinSequences.ice. So you can do something like:

#include <Ice/BuiltinSequences.ice>

class VariantBINARY extends Variant { Ice::ByteSeq value; };

Also note that with Ice-E you cannot send a class by-value over the wire.
Reply With Quote
  #6 (permalink)  
Old 04-05-2007
mmongu mmongu is offline
Registered User
 
Name: Marco Monguzzi
Organization: SITEK s.p.a.
Project: developing test case for ICE-E
 
Join Date: Apr 2007
Location: Verona, Italy
Posts: 4
Hi Matthew,

thanks for your reply.

Quote:
Originally Posted by matthew View Post
Also note that with Ice-E you cannot send a class by-value over the wire.
what options I have in ICE-E to transfer instances of TRV defined below:

enum VTYPE
{
VTEMPTY,
VTBIT,
VTBYTE,
VTSHORT,
VTINT,
VTUBYTE,
VTUSHORT,
VTUINT,
VTFLOAT,
VTDOUBLE,
VTSTRING,
VTBINARY,
VTTIME
};

struct Timestamp
{
long utc;
short msec;
};

//FIXME: need support for UBYTE, USHORT, UINT
class Variant { VTYPE type; };
class VariantBIT extends Variant { bool value; };
class VariantBYTE extends Variant { byte value; };
class VariantSHORT extends Variant { short value; };
class VariantINT extends Variant { int value; };
class VariantFLOAT extends Variant { float value; };
class VariantDOUBLE extends Variant { double value; };
class VariantSTRING extends Variant { string value; };
class VariantTIME extends Variant { Timestamp value; };
//FIXME: binary as seq of bytes?
class VariantBINARY extends Variant { Ice::ByteSeq value; };

struct TRV
{
int ec;
Timestamp ts;
byte qual;
Variant value;
};

I see I can compile with slice2cpp for ICE but not for ICE-E. As you mentioned
slice for ICE-E warns that 'struct data member 'value' cannot be a value object'. Should I consider the full blown ICE?


Thanks
Marco
Reply With Quote
  #7 (permalink)  
Old 04-10-2007
michi's Avatar
michi michi is offline
ZeroC Staff
 
Name: Michi Henning
Organization: ZeroC
Project: Ice
 
Join Date: Feb 2003
Location: Brisbane, Australia
Posts: 912
One way to emulate a union with Ice-E is to do the following:

Code:
enum Discriminator { A, B, C };
sequence<TypeA> ASeq;
sequence<TypeB> BSeq;
sequence<TypeB> CSeq;

struct Variant {
    Discriminator activeType;
    ASeq a;
    BSeq b;
    CSeq c;
};
Basically, you have a sequence for each possible type and the struct contains one member of each sequence type, plus the discriminator that tells you which type is conceptually active. The sequences are all empty, except for the one indicated by the discriminator, which contains only a single element.

This is not quite as convenient as using derived classes but, in practice, it's workable, and it is quite efficient: the empty sequences consume only a single byte each on the wire.

Cheers,

Michi.
Reply With Quote
  #8 (permalink)  
Old 04-10-2007
bernard's Avatar
bernard bernard is online now
ZeroC Staff
 
Name: Bernard Normier
Organization: ZeroC, Inc.
Project: Ice
 
Join Date: Feb 2003
Location: Palm Beach Gardens, FL
Posts: 816
Hi Marco,

Quote:
Originally Posted by mmongu View Post
Should I consider the full blown ICE?
This very much depends on your target platform. If you have just a few MBs of flash and RAM, then you should probably use Ice-E. Otherwise, you can use Ice.

In particular, if your target is a regular Intel/AMD Linux/Windows system, there is no compelling reason to use Ice-E instead of Ice.

Best regards,
Bernard
__________________
Bernard Normier
ZeroC, Inc.
Reply With Quote
  #9 (permalink)  
Old 04-11-2007
mmongu mmongu is offline
Registered User
 
Name: Marco Monguzzi
Organization: SITEK s.p.a.
Project: developing test case for ICE-E
 
Join Date: Apr 2007
Location: Verona, Italy
Posts: 4
Hi Michi,
thanks for the hint. I will try that way.
Marco
Reply With Quote
  #10 (permalink)  
Old 04-11-2007
mmongu mmongu is offline
Registered User
 
Name: Marco Monguzzi
Organization: SITEK s.p.a.
Project: developing test case for ICE-E
 
Join Date: Apr 2007
Location: Verona, Italy
Posts: 4
Quote:
Originally Posted by bernard View Post
Hi Marco,



This very much depends on your target platform. If you have just a few MBs of flash and RAM, then you should probably use Ice-E. Otherwise, you can use Ice.

In particular, if your target is a regular Intel/AMD Linux/Windows system, there is no compelling reason to use Ice-E instead of Ice.

Best regards,
Bernard
Hi Bernard,

thanks for your reply. My test case would target custom embedded platforms as servers (MIPS vr4131@200MHz/wce4.2/64MB RAM/128MB flash) and commercial PDA/mobiles as clients (WCE5 and symbian). Even thought the work behind the full ICE is amazing, I am afraid it wouldn't fit my needs. The idea is comparing against rtcorba, embedded soap and custom protocols.

Marco
Reply With Quote
Reply



Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Similar Threads
Thread Thread Starter Forum Replies Last Post
Deprecating Classes in ICE kamran Help Center 1 09-07-2006 06:57 PM
C# classes semerich Comments 3 02-08-2006 09:23 AM
Sequence of 'unions'? dwolfe5272 Help Center 6 10-18-2004 05:38 PM
About Classes as Unions level Help Center 2 04-09-2004 02:45 AM
Why operations on classes? bernard Comments 1 02-21-2003 11:36 AM


All times are GMT -4. The time now is 10:23 PM.


Powered by vBulletin® Version 3.6.4
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.0.0
(c) 2008 ZeroC, Inc.