TIP: Click on subject to list as thread! ANSI
echo: os2prog
to: Mike Bilow
from: Doug Nazar
date: 1996-04-07 22:49:36
subject: Rexx

Hello Mike!


-- CUT -------- Begin test.cpp -------- CUT --
#include 

#include 
#include 
#include 
#include 
#include 

#define INCL_ERRORS
#define INCL_DOSSEMAPHORES
#define INCL_DOSPROCESS
#define INCL_DOSMEMMGR
#include 

#define INCL_REXXSAA
#include 

#include "Test.h"



ULONG APIENTRY _Export GetPID(
                     PSZ name,
                     LONG argc,
                     RXSTRING argv[],
                     PSZ queuename,
                     PRXSTRING retstr) {

   PTIB ptib;
   PPIB ppib;
   APIRET ulrc = 0;

   ulrc = DosGetInfoBlocks(&ptib, &ppib);

   sprintf(retstr->strptr, "%lu", ppib->pib_ulpid);
   retstr->strlength = strlen(retstr->strptr);
   return 0;
}

ULONG APIENTRY _Export GetTID(
                     PSZ name,
                     LONG argc,
                     RXSTRING argv[],
                     PSZ queuename,
                     PRXSTRING retstr) {

   PTIB ptib;
   PPIB ppib;
   APIRET ulrc = 0;

   ulrc = DosGetInfoBlocks(&ptib, &ppib);

   sprintf(retstr->strptr, "%lu", ptib->tib_ptib2->tib2_ultid);
   retstr->strlength = strlen(retstr->strptr);
   return 0;
}

ULONG APIENTRY _Export TimeOut(
                      PSZ name,
                      LONG argc,
                      RXSTRING argv[],
                      PSZ queuename,
                      PRXSTRING retstr) {

   TID tid = 0;
   TimerData *timerdata = 0;
   APIRET ulrc = 0;

   if (argc == 3) {
      ulrc =
DosAllocMem((PPVOID)&timerdata,sizeof(TimerData),PAG_COMMIT|PAG_READ|PAG_WRITE)
;

      cout << "---" << endl;
      cout << argv[0].strptr << endl;
      cout << argv[1].strptr << endl;
      cout << argv[2].strptr << endl;
      cout << "---" << endl;

      timerdata->processId    = atol(argv[0].strptr);
      timerdata->threadId     = atol(argv[1].strptr);
      timerdata->milliseconds = atol(argv[2].strptr);
      ulrc = DosCreateThread(&tid, RexxTimeoutThread, (ULONG)timerdata, 0, 8192);

      sprintf(retstr->strptr, "%lu", tid);
      retstr->strlength = strlen(retstr->strptr);
   }
   else {
      return 1;
   }

   return 0;
}

ULONG APIENTRY _Export CancelTimeOut(
                            PSZ name,
                            LONG argc,
                            RXSTRING argv[],
                            PSZ queuename,
                            PRXSTRING retstr) {

   APIRET ulrc = 0;
   char eventsem[256] = {0};
   HEV hev = 0;

   if (argc == 2) {

      sprintf(eventsem,"\\SEM32\\REXXTIMEOUT\\%lu\\%lu",
              atol(argv[0].strptr),
              atol(argv[1].strptr));

      ulrc = DosOpenEventSem(eventsem, &hev);

      ulrc = DosPostEventSem(hev);

      ulrc = DosCloseEventSem(hev);

      sprintf(retstr->strptr, "%lu", 0);
      retstr->strlength = strlen(retstr->strptr);
   }
   else {
      return 1;
   }

   return 0;
}

void APIENTRY RexxTimeoutThread(ULONG data) {
   TimerData *timerdata = (TimerData*) data;
   APIRET ulrc = 0;
   char eventsem[256] = {0};
   HEV hev = 0;

   sprintf(eventsem,"\\SEM32\\REXXTIMEOUT\\%lu\\%lu",
           timerdata->processId,
           timerdata->threadId);
   cout << "eventsem = " << eventsem << endl;

   ulrc = DosCreateEventSem(eventsem, &hev, 0, 0);
   if (ulrc) {
      cerr << "DosCreateEventSem() = " << ulrc << endl;
   }
   ulrc = DosWaitEventSem(hev,timerdata->milliseconds);
   if (ulrc == ERROR_TIMEOUT) {
      ulrc = RexxSetHalt(timerdata->processId, timerdata->threadId);
      if (ulrc) {
         cerr << "RexxSetHalt() = " << ulrc << endl;
      }
   }
   else
   if (ulrc) {
      cerr << "DosWaitEventSem() = " << ulrc << endl;
   }

   ulrc = DosCloseEventSem(hev);
   ulrc = DosFreeMem(timerdata);
}

-- CUT --------- End test.cpp --------- CUT --

Doug

--- GoldED/2 2.50+
* Origin: Realm of the Dragons - `Where thy mind hath no limits' (1:250/516)
SEEN-BY: 50/99 78/0 270/101 620/243 711/401 409 410 413 430 808 809 934 955
SEEN-BY: 712/407 515 517 628 713/888 800/1 7877/2809
@PATH: 250/516 101 99 3615/50 396/1 270/101 712/515 711/808 809 934

SOURCE: echomail via fidonet.ozzmosis.com

Email questions or comments to sysop@ipingthereforeiam.com
All parts of this website painstakingly hand-crafted in the U.S.A.!
IPTIA BBS/MUD/Terminal/Game Server List, © 2025 IPTIA Consulting™.