示例#1
0
_WCRTLINK int   getpid( void )              /* get process id */
{
    PIDINFO pinfo;

    DosGetPID( &pinfo );
    return( pinfo.pid );
}
示例#2
0
static void alarm_init(void)
{
    PFNSIGHANDLER pfnPrev;
    USHORT       pfAction;
    PIDINFO      pid;

    bAlarmInit = TRUE;

    if (!DosAllocSeg( ALARM_STACK, (PSEL) &selAlarmStack, SEG_NONSHARED ))
    {
      OFFSETOF(pbAlarmStack) = ALARM_STACK - 2;
      SELECTOROF(pbAlarmStack) = selAlarmStack;
      /* Create the thread */
      if (DosCreateThread( alarm_thread, &tidAlarm, pbAlarmStack ))
      {
        fprintf(stderr,"Alarm thread failed to start.\n");
        exit(1);
      }
      /* Setup the signal handler for Process Flag A */
      if (DosSetSigHandler(AlarmSignal,&pfnPrev,&pfAction,SIGA_ACCEPT,SIG_PFLG_A))
      {
        fprintf(stderr,"SigHandler Failed to install.\n");
        exit(1);
      }
      /* Save main process ID, we'll need it for triggering the signal */
      DosGetPID(&pid);
      pidMain = pid.pid;
    }
    else
      exit(1);
}
/* This function is called from two threads, one each to monitor the
 * keyboard and mouse messages.
 * All packets are passed on unchanged.  The thread just clears a
 * semaphore to alert the main background process that there has been some
 * activity, which means it won't blank or will restore the screen if
 * it is already blanked.
 *
 * Parameter is name of device to be monitored.
 */
void CALLBACK
MonitorThread(NPSZ npName)
{
   int             rc;
   MONIN           mnin;        /* monitor buffers */
   MONOUT          mnout;
   HMONITOR        hmon;
   char            bDataBuf[sizeof(MONIN)];  /* buffer used */
   USHORT          cbDataBufLen;
   PIDINFO         pidi;

   /* It has to be time-critical, so it doesn't impact response. */
   DosGetPID(&pidi);
   DosSetPrty(PRTYS_THREAD, PRTYC_TIMECRITICAL, 0, pidi.tid);

   /* Initialize the lengths of the monitor buffer structures. */
   mnin.cb = sizeof(MONIN);
   mnout.cb = sizeof(MONOUT);

   /*
    * Register for the current session.
    */
   TRACE(tpMonOpen, TRUE, 0, npName);
   if (rc = DosMonOpen(npName, &hmon))
      ERRORCHK("DosMonOpen", rc);
   TRACE(tpMonReg, TRUE, 0, npName);
   rc = DosMonReg(hmon,
                  (PBYTE) & mnin,
                  (PBYTE) & mnout,
                  MONITOR_BEGIN, sgMonitor);
   TRACE(tpMonReg, FALSE, rc, npName);
   if (rc == 0)
      /*
       * Loop, passing on data and signalling main thread.
       */
      for (;;) {
         cbDataBufLen = sizeof(MONIN);
         if (DosMonRead((PBYTE) & mnin, DCWW_WAIT, bDataBuf, &cbDataBufLen))
            break;
         /* We shouldn't get a length 0 return, but best to check, before
          * testing the first byte... */
         if (cbDataBufLen > 0) {
            if (DosMonWrite((PBYTE) & mnout, bDataBuf, cbDataBufLen))
               break;
            /* Test for open/close/flush packets and ignore them;
             * they don't represent mouse/keyboard actions. */
            if (!(bDataBuf[0] & 0x07)) {
               TRACE(tpMonAction, FALSE, cbDataBufLen, npName);
               DosSemClear(&pSharedseg->semAction);
            }
         }
      }
   else {
      /* Failed to register */
      WtiLStrCpy(bDataBuf, "DosMonReg for ");
      WtiLStrCat(bDataBuf, npName);
      ERRORCHK(bDataBuf, rc);
   }

   /* If blanked, undo it, whatever the reason we're leaving... */
   if (pSharedseg->bBlanked)
      DosSemClear(&pSharedseg->semAction);

   /* Told to withdraw */
   DosExit(EXIT_THREAD, 0);
}