Using Event Notification

Event notification is an ideal mechanism for notifying ASPI clients of the completion of an ASPI request. ASPI clients may block on this event until completion. Upon completion of a request, the ASPI for Win32 manager sets the event to the signaled state. The ASPI client must make sure that the event is not in a signaled state when an ASPI command request is submitted to the ASPI for Win32 manager. Event notification is illustrated in the following code, which sends a SCSI Inquiry command to target #2.


SRB_ExecSCSICmd MySRB;
HANDLE ASPICompletionEvent;
DWORD ASPIEventStatus;
DWORD ASPIStatus;
char InquiryBuffer[32];   
.
/**************************************************/
/* Create event for MySRB.  Initial state         */
/* non-signaled, manual reset.                    */
/**************************************************/
if ((ASPICompletionEvent = CreateEvent(NULL,FALSE,FALSE,NULL)) == NULL)
   return FALSE;
/**************************************************/
/* Code is entered with 'MySRB' zeroed.           */
/**************************************************/
MySRB.SRB_Cmd     = SC_EXEC_SCSI_CMD;
MySRB.SRB_Flags     = SRB_DIR_SCSI|SRB_EVENT_NOTIFY;
MySRB.SRB_Target     = 2;
MySRB.SRB_BufLen     = 32;
MySRB.SRB_SenseLen    = SENSE_LEN;
MySRB.SRB_BufPointer   = InquiryBuffer;
MySRB.SRB_CDBLen     = 6;
MySRB.CDBByte[0]     = SCSI_INQUIRY;
MySRB.CDBByte[4]     = 32;
MySRB.SRB_PostProc    = ASPICompletionEvent;
.
.
ASPIStatus      = SendASPI32Command ( (LPSRB) &MySRB );
/**************************************************/
/* Block on event till signaled                   */ 
/**************************************************/
if ( MySRB.SRB_Status == SS_PENDING )
   ASPIEventStatus == WaitForSingleObject(ASPICompletionEvent, TIMEOUT);

/**************************************************/
/* Reset event to non-signaled state.             */ 
/**************************************************/
if (ASPIEventStatus == WAIT_OBJECT_0) 
  ResetEvent(ASPICompletionEvent);
          .
          .