[gmpi] Re: low level API - Abstract Factory summary

  • From: "Angus F. Hewlett" <angus@xxxxxxxxxxxxx>
  • To: gmpi@xxxxxxxxxxxxx
  • Date: Mon, 07 Feb 2005 20:02:57 +0000

OK, a couple of problems there IMHO...
-- passing IN a struct to get a metadata struct OUT means that the struct will have to be versioned on in and out, so that both parties know the size of the struct. If we're following an object-ish model, why not instead:-


GMPI_RESULT GetMetaData(int index, void** gmpi_descriptor, GMPI_IID descriptor_interface);

If index is out of range, the factory sets *gmpi_descriptor to null, and returns an error code.

descriptor_interface is an interface identifier, so that if the metadata spec is expanded at some point along the line, the host can try and get the new and expanded interface.

Assuming we're using ref-counting, the host should call Release() on the meta-data object when it's done with it. Otherwise, our base interface class needs to provide a Free() method so that objects can be safely released across language and compiler boundaries.

As a general point of coding conventions, I'd prefer to see all functions having a result-code return type equivalent to unsigned long (equivalent to COM's HRESULT), unless a particular function needs to return a value in an absolutely speed-critical way.

When we're dealing with code from different vendors, it makes sense to have bulletproofing at every point - at least in debug builds. You can do stuff like
ASSERT_SUCCESS(gmpiIntfPtr->DoSomething())
which will print log messages if it fails.


Best regards,
      Angus.






Jeff McClintock wrote:


Re the dll Abstract Factory.

Cheers to Tim and Angus, here's a possible implementation.. please rip this to pieces ( constructively criticize )

Angus said:
The single entry point should return a master object which provides functions for, at a minimum:-
- Enumerating the plugin-classes this DLL can instantiate. Could be as simple as passing in an index, the enumerate function returns either a class-id, or null to mean "no more".
- Instantiating a specific plug-in (pass the class-identifier as an argument, returns an interface-pointer to the newly created instance)



let's call it:

class GMPI_Plugin_Factory
{
  void GetMetaData( int index, gmpi_descriptor *gd );
  GMPI_Plugin *Instantiate( int index );
};

..where gmpi_descriptor describes the plugin...

struct gmpi_descriptor
{
  char *unique_identifier;
  char *name;
  //etc
};

Notes: I've modified Tim's idea a little to separate metadata from instantiation. This is a nod to the external metadata camp, and at least makes it easy to switch to external metadata later, or for the plugin to read it from an external file if nesc.


..So the dll has a single exported function..

extern "C" {
__declspec (dllexport)

IGMPI_Plugin_Factory *GetPluginFactory(void)
{
  static GMPI_Plugin_Factory factory;
  return &factory;
}
}

Notes: factory is implemented as a Meyer's singleton. I've assumed we're using a COM-like technique whereby we can deal in C++ objects without worrying too much about the underlying plain C binary interface.

and finally,

GMPI_Plugin's 'interface' is defined as a pure abstract base class. This is all the host ever 'sees' to hide the internal details..

class IGMPI_Plugin
{
  virtual void placeholder1(void) = 0;
  virtual void placeholder2(void) = 0;
};

...and the 'real' concrete plugin base class that we base our plugins on..

class GMPI_Plugin : public IGMPI_Plugin
{
  virtual void placeholder1(void){};
  virtual void placeholder2(void){};
};

Notes: IGMPI_Plugin should probably include the standard 'COM stuff' too..

have at it...

Jeff


---------------------------------------------------------------------- Generalized Music Plugin Interface (GMPI) public discussion list Participation in this list is contingent upon your abiding by the following rules: Please stay on topic. You are responsible for your own words. Please respect your fellow subscribers. Please do not redistribute anyone else's words without their permission.

Archive: //www.freelists.org/archives/gmpi
Email gmpi-request@xxxxxxxxxxxxx w/ subject "unsubscribe" to unsubscribe





--
=========================================================
Angus F. Hewlett, Managing Director (CEO)
FXpansion Audio UK Ltd - http://www.fxpansion.com
Registered in the UK - #4455834 - VAT: GB 798 7782 33
=========================================================



---------------------------------------------------------------------- Generalized Music Plugin Interface (GMPI) public discussion list Participation in this list is contingent upon your abiding by the following rules: Please stay on topic. You are responsible for your own words. Please respect your fellow subscribers. Please do not redistribute anyone else's words without their permission.

Archive: //www.freelists.org/archives/gmpi
Email gmpi-request@xxxxxxxxxxxxx w/ subject "unsubscribe" to unsubscribe

Other related posts: