Legacy Class, implementation with class A in class B parameter...

Legacy Class, implementation with class A in class B parameter...

Post by Eric » Tue, 28 Aug 2001 22:04:01



Hello,

Hello, I have some questions about implementing CORBA with legacy class
inC++(which was not develooped for this...).

I have 2 legacy class:

//------------------
Classe LcDatabase
//------------------
 bool Open( const char* szPathname);
 bool Close();
...}

//------------------
Classe LcAdmLookup
//------------------
 long Count(const LcDatabase& Database, const char* CountryName);
...}

IDL

module Napi
 {
 interface Database
  {
  boolean Open(in string szPathname);
  void Close();
  };
 interface AdmLookup
  {
  long Count(in Database Db, in string CountryName);
  };
 };

IMPLEMENTATION

class DatabaseImpl: public POA_Napi::Database
{
protected:
    LcDatabase Db;   //Legacy class
public:
    CORBA::Boolean Open(const char * szPathname)
        {
         CORBA::Boolean res = Db.Open(szPathname);
         return res;
        };
    void Close()
        {
         Db.Close();
        };

Quote:};

class AdmLookupImpl: public POA_Napi::AdmLookup
{
public:
 virtual CORBA::Long Count(Napi::Database_ptr DbI)
    {
     LcAdmLookup Count( Db, "Test" );
    }

Quote:};

Here, the problem, is that 'Db' should be a reference of LcDatabase and not
DatabaseImpl
How can I use an get the LcDatabase instance from DatabaseImpl instance in
AdmLookupImpl..., could you give me the exemple.

Thanks for your HELP.

 
 
 

Legacy Class, implementation with class A in class B parameter...

Post by Steve Vinosk » Wed, 29 Aug 2001 04:55:36


First, note that trying to mirror legacy classes directly into IDL usually
fails, because those legacy classes were not designed with CORBA or
distributed systems in mind.

The AdmLookup class shows the classic problem of "operations *about*
objects" instead of "operations *on* objects." Specifically, the Count()
function should be an operation on the Database object, not on the AdmLookup
object.

My advice is as follows:

1) Move the lookup operations from the AdmLookup class into your IDL
Database interface. That's where they logically belong.

2) Having an open() call in the Database interface is strange, because it
implies that you first create the database object in some null state and
then you use open() to attach it to a real datastore. Instead, use a factory
CORBA object to create your Database objects. The factory interface would
look like this:

interface DatabaseFactory {
    exception NoSuchDatastore {};
    Database open(in string name) raises(NoSuchDatastore);

Quote:};

This way, the Database object is ready to use immediately on creation. Keep
the close() operation on the Database interface. Note that this also allows
your factory to create a Database servant containing an LcDatabase class
object, and an LcAdmLookup class object if necessary, and that way the
Database servant has access to those underlying C++ classes as necessary.

3) If you really want a separate Adm interface, add an operation to the
Database interface to return it:

interface Database {
    AdmLookup get_admin();

Quote:};

This way, the Database servant can create the AdmLookup servant and pass its
LcDatabase C++ class object to it upon creation.

The most important lesson to take away from all this is not to try to carry
your C++ application designs directly into CORBA. C++ designs are C++
designs, and CORBA designs are CORBA designs, and they're largely different
from each other.

--steve

--
Steve Vinoski                      vinoski at iona.com
Chief Architect & Vice President Platform Technologies
IONA Technologies  http://www.iona.com/hyplan/vinoski/
200 West St.                     Waltham, MA USA 02451


Quote:> Hello,

> Hello, I have some questions about implementing CORBA with legacy class
> inC++(which was not develooped for this...).

> I have 2 legacy class:

> //------------------
> Classe LcDatabase
> //------------------
>  bool Open( const char* szPathname);
>  bool Close();
> ...}

> //------------------
> Classe LcAdmLookup
> //------------------
>  long Count(const LcDatabase& Database, const char* CountryName);
> ...}

> IDL

> module Napi
>  {
>  interface Database
>   {
>   boolean Open(in string szPathname);
>   void Close();
>   };
>  interface AdmLookup
>   {
>   long Count(in Database Db, in string CountryName);
>   };
>  };

> IMPLEMENTATION

> class DatabaseImpl: public POA_Napi::Database
> {
> protected:
>     LcDatabase Db;   //Legacy class
> public:
>     CORBA::Boolean Open(const char * szPathname)
>         {
>          CORBA::Boolean res = Db.Open(szPathname);
>          return res;
>         };
>     void Close()
>         {
>          Db.Close();
>         };
> };

> class AdmLookupImpl: public POA_Napi::AdmLookup
> {
> public:
>  virtual CORBA::Long Count(Napi::Database_ptr DbI)
>     {
>      LcAdmLookup Count( Db, "Test" );
>     }
> };

> Here, the problem, is that 'Db' should be a reference of LcDatabase and
not
> DatabaseImpl
> How can I use an get the LcDatabase instance from DatabaseImpl instance in
> AdmLookupImpl..., could you give me the exemple.

> Thanks for your HELP.


 
 
 

1. What are legacy classes, wat zijn legacy classes?

Reading a course I see something that I have not seen before. Can anyone
tell me what legacy classes are?

This is the text, it is about when to use the tie approach in Corba.. Do you
understand it? It refers to a Corba/Visibroker course I am self studying.

"When legacy C++ classes already exist, and they must be made accessible
through the ORB with minimal surgery.

It is rather unlikely that legacy C++ class methods can be represented in
IDL, so that the reverse mapping matches the original method definitions"

Marc

2. zone alarm

3. class inherit class A _and_ class B

4. Disabling Tools:Password

5. xbox console Class A and Class B

6. A1000 2meg memory

7. MNP Protocol Specifications - Class 4 & Class 5

8. Review of NETGEAR Web Safe Router

9. Class C subnet mask on class B network

10. Type case from base class to children class.

11. Debugging C++ classes using library String class

12. Range Class / Spinner class/ numeric data type