Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

How to Create an Object for each Session?

0 views
Skip to first unread message

Roland

unread,
May 24, 2005, 7:54:01 AM5/24/05
to
Hello,

I`d really appreciate it if somebody could help me out with this. I,m a
college student and I`ve been looking into CORBA for the past couple of
weeks as an option for a independent project. It`s my first time using
CORBA so I`m sorry if my question is too dumb...

I'm trying to implement a login routine for users with diffrent access
levels. Let's say 2 levels so I have two user classes, User1 and
User2:User1. User1 has methods that only level 1 users can access and
user2 has level 2 methods + the methods inherited from user1.

Depending on the user level, using an object factory, I'm creating an
instance of either User1 or User2 and passing on the string IOR (of
either User1 and User2) to the client which in turn can only access the
methods which are defined in the instatiated class.... Is this the
right way to think about this?

Here's how my object factory looks like. I only want to use the default
POA...

char* createUserObject(int userlevel)
{
if (userlevel == 1) {
User1_impl* user_servant = new User1_impl();
User1_var ss1= user_servant._this();
CORBA::String_var sior(orb2->object_to_string(ss1));
}

else if (userlevel == 2){
User2_impl* user_servant = new User2_impl();
User2_var ss2= user_servant._this();
CORBA::String_var sior(orb2->object_to_string(ss2));
}

return sior;

}

The factory returns a string object which in turn I pass on to the
client in the login module. Do I need reintialize the ORB and activate
poa, I already initialized in the ORB in the main? Here's I'm using the
ORB from main.
What am I doing wrong???????????????????????????????

Thanks in advance...

spano

unread,
May 24, 2005, 7:38:51 PM5/24/05
to
Roland wrote:
> Hello,
>
> I`d really appreciate it if somebody could help me out with this. I,m a
> college student and I`ve been looking into CORBA for the past couple of
> weeks as an option for a independent project. It`s my first time using
> CORBA so I`m sorry if my question is too dumb...
>
> I'm trying to implement a login routine for users with diffrent access
> levels. Let's say 2 levels so I have two user classes, User1 and
> User2:User1. User1 has methods that only level 1 users can access and
> user2 has level 2 methods + the methods inherited from user1.
>
> Depending on the user level, using an object factory, I'm creating an
> instance of either User1 or User2 and passing on the string IOR (of
> either User1 and User2) to the client which in turn can only access the
> methods which are defined in the instatiated class.... Is this the
> right way to think about this?
>

You can do it like that, or directly with this kind of IDL interface

interface my_factory
{
object create( short userlevel );
};

and in so doing, on calling side, you will not need to make
some string_to_object( ) calls.

> Here's how my object factory looks like. I only want to use the default
> POA...
>
> char* createUserObject(int userlevel)
> {
> if (userlevel == 1) {
> User1_impl* user_servant = new User1_impl();
> User1_var ss1= user_servant._this();
> CORBA::String_var sior(orb2->object_to_string(ss1));
> }
>
> else if (userlevel == 2){
> User2_impl* user_servant = new User2_impl();
> User2_var ss2= user_servant._this();
> CORBA::String_var sior(orb2->object_to_string(ss2));
> }
>
> return sior;
>
> }
>

Does this code actually compile ? or is the a global char* also
named "sior" in the global scope ?

Otherwise, if you meant:

...
{
CORBA::String_var sior( ... );
return sior;
}
...

then you have some memory leak. You'll have to do

...
{
CORBA::String_var sior( .. );
return sior._retn();
}

or simply do not use a String_var for that (the ORB will make
the cleanup of the char* returned - see C++ mapping)

Is your "createUserObject" really an IDL interface method ?

> The factory returns a string object which in turn I pass on to the
> client in the login module. Do I need reintialize the ORB and activate
> poa, I already initialized in the ORB in the main? Here's I'm using the
> ORB from main.

You need normally to call CORBA::ORB_init( ) once, obtain RootPOA
by using resolve_initial_references( ) call on the ORB, recover
the PortableServer::POAManager attached to it and activate it
in order to allow requests to be delivered to servants
activated on this POA.

> What am I doing wrong???????????????????????????????
>

... what is really your problem ?
You don't tell us really clearly.

> Thanks in advance...
>

Best regards,

Vincent.

Roland

unread,
May 25, 2005, 3:37:40 AM5/25/05
to
Hi Vincent,
Thanks for replying. My IDL looks sth like this:

module Mod1{


interface User1 {

string getSystemTime();
};

interface User2 : User1 {

int getGTC( in string Sign)
};

interface User_Factory {

string validate ( in long userLevel,
in string password);
};
};

createUserObject is not an IDL interface but the Validate function is.
I call createUserObject from the validate function after I verified the
info. I basically want to create an object type of either User1 or
User2. User2 inherits the methods from User1. I convert the object
reference to string and pass it on to the client to use after a
string_to_object( ) call. I,m only registering in the naming service
the User_Factory.

I guess the easiest question would be how to best do this. I'm totally
confused at this point...

My code almost compiles. I get an error saying "request for member
`_this' is ambiguous" when I call User1_var ss1=
user_servant._this();
Not sure why that is... Is it because of the inheritance between User1
and User2?

Any sugestions would be highly appreciated !

Thanks!

Roland

unread,
May 25, 2005, 7:34:49 AM5/25/05
to
Hello,

I figured out the problem. I'm only posting this in case somebody else
might run into the same problem. When I was implimenting the User
function I was doing it like this:

class User1_impl : public POA_Mod1::User1
{
virtual char* getSystemTime();
};

class User2_impl : public POA_Mod1::User2,
public User1_impl
{
virtual int getGTC(char* Sign);
};

The correct way to do it is:

class User1_impl : public virtual POA_Mod1::User1
{
virtual char* getSystemTime();
};

class User2_impl : public virtual POA_Mod1::User2,
public virtual User1_impl
{
virtual int getGTC(char* Sign);
};

User1_impl inherits POA_Mod1::User1 only virtually.

corba.object

unread,
May 29, 2005, 3:51:19 AM5/29/05
to
hi Roland,

The best way could be like this

First think of ior or object reference as "object" itself. Dont try to
return stringified IOR to client. return it CORBA object.

Secondly differentiate between interface (defined in IDL) to its
implementation classes.

Coming back to ur question

Basically what u want to do is that depending on what level is passed
to server (factory), it creates appropriate object and returns its
reference to client. Now u want to return objects of dif type
(belonging to diff interface type)?
If u can make this a bit clear.

If it of diff type then u need to take care of narrowing the object
refer. to correct type and should know that in prior

ur IDL may look like something like this..not exact sysntax

interface_4_user_1 : base_interface {

mthod_4_user_1();

};


interface_4_user_2 : base_interface {

mthod_4_user_2();
};


interface user_factory {
base_interface create_object (long user_level);

};

In the implementation class

user_fac_impl {

base_interface create_object (long user_level)
{

return createUserObject (user_level)

}


base_interface createUserObject (long user_level) {
//ORB_init();
//resolve root poa
//Above code must be put at more appropriate place.

if (user_level == 1) {


User1_impl* user_servant = new User1_impl();

return user_servant._this();
}

else if (use_rlevel == 2) {


User2_impl* user_servant = new User2_impl();

return user_servant._this();
}
return NULL;
}


Still better is follow style proposed by spano.

0 new messages