Explicit resource allocation allows applications to reserve all the licensed resources they are going to need, on a per-channel basis, before they actually use them. By allocating resources in advance, applications can guarantee that the resources are available immediately at the time they are needed. Unfortunately, the allocated resources not being used cannot be used by any other application. Resource allocation is done through irReserveResource(3IRAPI). Resources are reserved according to capability and implementation. Capabilities, defined in IrRESOURCES(4IRAPI), are essentially the services provided by the resources. Current capabilities include:
For each capability there are one or more implementations. Currently supported implementations of each capability are listed in IrRESOURCES(4IRAPI). Applications can reserve resources without knowing which implementation they need by requesting the resource with implementation IRD_INVALID. This causes irReserveResource(3IRAPI) to reserve the default resource implementation. When resolving the default resource, irReserveResource(3IRAPI) consults the parameter switch associated with that capability. These parameter switches and the capabilities with which they are associated are also listed in IrRESOURCES(4IRAPI). For example, IRC_PLAY is associated with IRP_VOICE_TYPE. If irReserveResource(3IRAPI) is called with capability IRC_PLAY and the implementation is set to IRD_INVALID, the play implementation resources associated with the setting of IRP_VOICE_TYPE are reserved. IF IRP_VOICE_TYPE is set to IRD_LSPS_VOICE, an LSPS play resrouce is allocated. If IRP_VOICE_TYPE is set to IRD_SP_VOICE, a speech play resource is allocated. If IRP_VOICE_TYPE is set to IRD_TALK_VOICE, no resources are allocated since IRD_TALK_VOICE implies a static play resource bound to the channel.
The following example shows how resources could be pre-allocated for the speech recognition chantest program. Explicitly reserved resources are freed via a call to irDeinit(3IRAPI). Explicit resource allocations survive across irExec(3IRAPI) and irSubProg(3IRAPI) boundaries.
main()
{
.
.
.
static ir_reserve_t resourceRequest[] = {
{IRC_PLAY, IRD_SP_VOICE},
{IRC_ECHOCAN, IRD_SP_ECHO},
{IRC_RECOG, IRD_WHOLE_WORD},
{IRC_NULL, IRD_INVALID},
};
.
.
.
while (irWCheck(&ev) != IRR_FAIL) {
.
.
.
switch (ev.event_id) {
case IRE_EXEC:
.
.
.
/* After successful channel initialization */
if (irReserveResource(cid, 0, resourceRequest, IRD_IMMEDIATE,
NULL) == IRR_FAIL) {
cleanup("Explicit Resource Allocation failure", cid);
break;
}
.
.
.
}
}