OS/2 IOCTL90 - PDD Example code
Joe Nord
This page shows example PDD source code for implementing Ioctl90 API in a device driver.
// When a mixer application changes a mixer setting, the
// device driver informs all other mixer application of
// the change by posting event semaphores for each application.
void ioctlmixCallback (PSTREAM pStreamThis)
{
PSTREAM pStream;
USHORT usRC;
ULONG ulNumPosts;
ULONG ulNumPostsLin;
ULONG ulHev;
// To post an event semaphore, we need a linear
address
// of where the kernel should place the post
count.
usRC = DevHelp_VirtToLin (_SS(),
(USHORT)(&ulNumPosts),
&ulNumPostsLin);
if (usRC != 0)
{
#ifdef CSDEBUG
ddprintf (ERROR_MONITOR,
"ioctlmixCallback VirtToLin failed\n");
DebugBreakpoint();
#endif
return;
}
// Each client mixer application creates its own
semaphore.
// The semaphore must be "shared", but it is only
shared between
// the application and this device driver.
pStream = streamGetListHead();
while (pStream != NULL)
{
// Only signal callback to
mixer applications other than
// the one that commanded the
change to the mixer.
// It already knows about the
state change.
if (pStream != pStreamThis
&&
pStream->ulCallbackSem != 0)
{
ulHev =
pStream->ulCallbackSem;
// To post
the sem, must open it from device driver.
// When post
a sem, must also reset it or it will post forever
DevHelp_OpenEventSem (ulHev);
usRC =
DevHelp_PostEventSem (ulHev);
#ifdef CSDEBUG
if (usRC != 0)
{
ddprintf (ERROR_MONITOR, "ioctlmixCallback PostEvent failed\n");
DebugBreakpoint();
}
#endif
DevHelp_ResetEventSem (ulHev, ulNumPostsLin);
DevHelp_CloseEventSem (ulHev);
}
pStream = pStream->pNext;
}
}
void ioctlmixInit (void)
{
unsigned I;
// Verify that ioctlmixCheckTable has correct
number of entries.
// That is, runtime verify that positions in
dispatch table are
// consistent with header file defines for use by
applications.
if (MaxIoctlmixFuncs != MSGBUF - 0x40)
{
#ifdef CSDEBUG
ddprintf (ERROR_MONITOR,
"ioctlmixInit Dispatch table size is wrong!!!\n");
#endif
ProductionBreakpoint();
}
// Ability to support 3D sound effect is not
supported
// on all the hardware configurations.
if (!mix3DSupported())
{
ioctlmixFuncs[THREEDSET-0x40] =
ioctlmix_Unused;
ioctlmixFuncs[THREEDQUERY-0x40]
= ioctlmix_Unused;
}
// Fill in bSupport table. Indicate which
of the
// possible 256 IOCTL functions this driver
supports.
for (I = 0; I <= 0xFF; I++)
{
if (I >= 0x40 && I -
0x40 <= MaxIoctlmixFuncs)
{
// A function
is "supported" if it has an entry in dispatch table.
ioctl90SupportTable[I] = (ioctlmixFuncs[I-0x40] != ioctlmix_Unused);
}
else
{
// All
entries outside our table bounds are not supported.
ioctl90SupportTable[I] = FALSE;
}
}
}