Re: Message negociation
"Toby Hudon" <[email protected]>
| Newsgroups | gmane.comp.multimedia.media-api |
|---|---|
| Message-ID | <[email protected]> |
----- Original Message ----- From: Steve Lhomme <[email protected]> Date: Thu, 08 Jan 2004 19:48:44 +0100 To: "The attempt to create a new, open standard codec API" <[email protected]> Subject: Re: [Media-api] Message negociation > Toby Hudon wrote: > > > So your call in init would look like this (pseudocode): > > > > ---------------------------- > > pNextFilter->GetSupportedFunctions(myList, listCount); > > > > listNode* head = myList; > > listNode* current = head; > > int i = 0; > > int j = 0; > > > > for(i = listCount-1; i >= 0; i--) // while we have entries > > { > > for(j = 0; j <= i; j++) // find the current end of the list > > { > > current = current->pNext; // follow list > > } // end for j > > > > switch(current->functionID) // check what function is at the end of the list > > { > > case FOO: > > fpMyFooFunction = current->fpointer; // map function to our pointer > > break; > > ... > > ... > > default: > > // we don't map functions we don't understand > > break; > > } > > } // end for i > > > > ------------------------- > > Here is my code for the vtable in one block > > enum { > CALLBACK_INIT=0, > CALLBACK_PROCESS, > CALLBACK_DUMMY, > CALLBACK_CLOSE, > ENUM_MAX > }; > > struct callback_table[ENUM_MAX]; > other_filter->AcquireCallbacks(callback_table, sizeof(callback_table)); > > // local variables to use another filter > other_filter_init = callback_table[CALLBACK_INIT]; > other_filter_close = callback_table[CALLBACK_CLOSE]; > > if (other_filter_init == NULL || other_filter_close == NULL) > return ERROR_CANT_USE_THIS_FILTER; > > // proceed now > Thank you, this is a much better approach if I'm understanding it as it is intended. I'm unfamilliar with enum, can you explain how it works? I'm assuming the idea is predefine all these CALLBACK_FOO as some kind of constant values, like the message IDs I had thought about earlier. Then we use them as a lookup in to this table of function pointers? I'm not used to function pointers but I assume that's what they are. The line "struct callback_table[ENUM_MAX]" is confusing me too. How do you have a struct without something defined in {} for it? How do we know this is going to get a table of function pointers and that they'll be the right pointer types? Also, forgive me because I'm not familliar with them, but aren't function pointers specific by return type and arguments? How do we handle mixed kinds of functions then? Does the table keep them all as something like void* and we cast them? -- ___________________________________________________________ Sign-up for Ads Free at Mail.com http://promo.mail.com/adsfreejump.htm