Boost logo

Boost :

From: Reece Dunn (msclrhd_at_[hidden])
Date: 2004-07-26 11:36:05


Vladimir Prus wrote:
>Reece Dunn wrote:
> >>I also wonder if it makes sense to sumbit just "dll" library, or some
> >>additional plugin support need to be developed first.
> >
> > What sort of plugin support are you looking for? Do you mean something
> > like COM/CORBA support or wrapper, e.g. something that can target both
> > (and others like them) in one implementation?
>
>I'm not CORBA expert, but I think it's entirely different beast. To use
>CORBA object you use stub generated from IDL, how it's related to plugins?
>While there are some ways to find object dynamically, it's different
>mechanism from shared libraries, isn't it?

I am not sure how CORBA works. COM generally uses a different mechanism to
load COM objects via CoCreateInstance, although DirectX exposes creation
functions that circumvent this. I was thinking about being able to use
COM/CORBA as a platform for object lifetime and dll lifetime management (as
well as things like interface extension, etc.).

>I though more about at least some kind of map<string, BasePlugin*> which is
>updated automatically when you load new DLLs.

So the dll implements some function:

   __declspec(dllexport) BasePlugin * GetMyPlugin();

so you can do something like:

   void load_plugins( map< string, BasePlugin * > & pi )
   {
      for( map< string, BasePlugin * >::iterator i = pi.begin(); i !=
pi.end(); ++i )
      {
         boost::dll plugin(( *i ).first );
         ( *i ).second = plugin.import< ... >( "GetMyPlugin" );
      }
   }

It is possible to keep the DLL in memory until all instances of a class (or
set of classes) by incrementing/decrementing a global object count variable
on construction/deconstruction as is done when using COM. You then check
this variable in the DllCanUnload function.

You may need some reference counting mechanism to keep the plugin alive, but
this is not necessary if you load all plugins on startup and release them at
the end of the run.

It should be possible to implement these facilities in a library, e.g.:

class object_counter
{
   private:
      static int objectCount = 0;
   public:
      inline int get_object_count(){ return( objectCount ); }
   public:
      inline object_counter(){ ++objectCount; } // make MT aware
      inline ~object_counter(){ --objectCount; } // make MT aware
};

class reference_counter
{
   private:
      int refCount;
   public:
      inline void add_ref(){ ++refCount; } // make MT aware
      inline void dec_ref()
      {
         if( --refCount == 0 ) // make MT aware
         {
            delete this;
         }
      }
   public:
      inline reference_counter( int rc ): refCount( rc ){}
      inline ~reference_counter(){}
};

allowing:

class plugin: public object_counter, public reference_counter, public
BasePlugin
{
   // ...
};

__declspec(dllexport) BOOL DllCanUnload()
{
   return( object_counter::get_object_count() == 0 );
}

I'm not sure what the Linux equivalent would be.

Regards,
Reece

_________________________________________________________________
Want to block unwanted pop-ups? Download the free MSN Toolbar now!
http://toolbar.msn.co.uk/


Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk