| This is not quite correct (at least, it is not like COM). What is returned should be a function table, i.e. a pointer to an array of function pointers, not a single function pointer (that would be just like COM).
The beauty of COM is that if you have a C++ class with all virtual functions, the virtual function table is, exactly, a pointer to an array of function pointers, so there is a complete alias between pure virtual C++ classes and COM intefaces.
But don't be distracted by my talk about C++. The same principle is valid in C. (Even though this kind of thing is easier to program and to maintain in C++.)
Another thing is, you can only call QueryInterface in COM off an existing object. So the way this would be used in the Csound API is create an instance of Csound, then call QueryInterface off the instance to obtain the API function tables.
-----Original Message-----
From: Richard Dobson
Sent: Nov 9, 2005 11:20 AM
To: csound-devel@lists.sourceforge.net
Subject: Re: [Cs-dev] Syntactic sugar request
Istvan Varga wrote:
> Victor Lazzarini wrote:
>
>> What is "Query-Interface" ?
>
>
> I assume this function (Top/csound.c):
>
> PUBLIC int csoundQueryInterface(const char *name, void **iface, int
> *version)
> {
> if (strcmp(name, "CSOUND") != 0)
> return 1;
> *iface = csoundCreate(NULL);
> *version = csoundGetVersion();
> return 0;
> }
>
> In its current form it does not look very useful, but I think the
> intended purpose is to return a table of function pointers and the
> version of the selected interface. Of course, it now creates an
> actual instance of Csound, and returns the package (and not API)
> version, which may or may not be the intended behavior.
>
Well, not, it doesn't implement the intended bahaviour.
In very rough hand-wavy pseudo-code which is probably wrong in all sort of C
details, I envisaged something like:
/* header file */
#define CSOUND_TABLEGET_ID 0xabcd10594631ffff
typedef MYFLT (*csoundTableGetfn)(void *csound, int table, int index);
/* app file */
csoundTablegetfn *csoundTableGet = NULL;
csoundQueryinterface(csound,CSOUND_TABLEGET_ID, csoundTableGet);
/* or in COM style:
csound->QueryInterface(CSOUND_TABLEGET_ID, csoundTableGet);
*/
if(csoundTableGet){
/* get the table data, etc*/
}
else{
printf("This version of Csound does not support 'csoundTableGet'\n":
abort();
}
Of course, if something like this is not possible, we will just have to live
with an "evolving" API which may require host apps to be rebuilt each time.
Richard Dobson
-------------------------------------------------------
SF.Net email is sponsored by:
Tame your development challenges with Apache's Geronimo App Server. Download
it for free - -and be entered to win a 42" plasma tv or your very own
Sony(tm)PSP. Click here to play: http://sourceforge.net/geronimo.php
_______________________________________________
Csound-devel mailing list
Csound-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/csound-devel
-------------------------------------------------------
SF.Net email is sponsored by:
Tame your development challenges with Apache's Geronimo App Server. Download
it for free - -and be entered to win a 42" plasma tv or your very own
Sony(tm)PSP. Click here to play: http://sourceforge.net/geronimo.php
_______________________________________________
Csound-devel mailing list
Csound-devel@lists.sourceforge.net |