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

  • From: Tim Hockin <thockin@xxxxxxxxxx>
  • To: gmpi@xxxxxxxxxxxxx
  • Date: Mon, 7 Feb 2005 16:03:32 -0800

On Tue, Feb 08, 2005 at 08:46:21AM +1300, Jeff McClintock wrote:


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

For the sake of consistency, let's (for now, more on this later) name
everything consistently.  GMPI_Foo.  GMPI_Bar.  struct GMPI_Thing.  The
names may well change, but for now, let's just say that
structs/classes/typedefs all start with "GMPI" and a capital letter.

> let's call it:
> 
> class GMPI_Plugin_Factory
> {
>   void GetMetaData( int index, gmpi_descriptor *gd );
>   GMPI_Plugin *Instantiate( int index );
> };
> 

Whoah.  I'd really rather not talk about how the C++ tastes until we
know how the C tastes.  I was about to propose the analog in real C,
when I had a question.  Why do we need this factory class.  Is it really
any cleaner than having the instantiate() be a method of
struct GMPI_Descriptor ?

I'd rather see the flow be simpler:

load dll
find symbol GMPI_Descriptor()
loop for each i until GMPI_Descriptor(i) == NULL

> ..So the dll has a single exported function..
> 
> extern "C" {
> __declspec (dllexport)

__declspec is not C.  I don't know what it does, but it sure isn't C.
Anything like this that is not straight C needs to be thoroughly
encapsulated.  Sigh.

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

Please make sure that *ALL* GMPI symbols that are visible are prefixed
with "GMPI".  I won't argue about UglyBumpyCaps vs nice_underscores yet,
more later.

> 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;
> };

Again, C first.  Also, why "IGMPI_Plugin"?  what does the leading "I"
mean?  Is this some convention I just don't know?


extern "C" {

struct GMPI_Descriptor {
        char *unique_identifier;
        char *name;
        struct GMPI_Plugin *instantiate(void);
        //...
};

struct GMPI_Plugin {
        //...
};

typedef struct GMPI_Descriptor *(*GMPI_Descriptor_Func)(int index);

}



----------------------------------------------------------------------
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: