home *** CD-ROM | disk | FTP | other *** search
/ Fresh Fish 5 / FreshFish_July-August1994.bin / bbs / gnu / aplusplus-1.01-src.lha / src / amiga / aplusplus-1.01 / testprgs / exec / LvObject_test.cxx next >
C/C++ Source or Header  |  1994-04-23  |  2KB  |  94 lines

  1. /******************************************************************************
  2.  *
  3.  *    $Source: apphome:APlusPlus/RCS/TESTPRGS/exec/LvObject_test.cxx,v $
  4.  *
  5.  *    Demo for the A++ Library
  6.  *    Copyright (C) 1994 by Armin Vogt, EMail: armin@uni-paderborn.de
  7.  *
  8.  *       $Revision: 1.3 $
  9.  *       $Date: 1994/04/23 21:26:15 $
  10.  *       $Author: Armin_Vogt $
  11.  *
  12.  ******************************************************************************/
  13.  
  14.  
  15. #include <APlusPlus/exec/LvObject.h>
  16. #include <APlusPlus/exec/SignalResponder.h>
  17.  
  18.  
  19. volatile static char rcs_id[] = "$Id: LvObject_test.cxx,v 1.3 1994/04/23 21:26:15 Armin_Vogt Exp Armin_Vogt $";
  20.  
  21.  
  22. class MySRSP : public SignalResponder
  23. {
  24.    private:
  25.       BOOL running;
  26.    public:
  27.       MySRSP() : SignalResponder(SIGBREAKB_CTRL_C,0)
  28.       { running = TRUE; }
  29.       ~MySRSP() {}
  30.  
  31.       // overload the virtual 'signal received' action callback method.
  32.       void actionCallback()
  33.       {
  34.          cout << "**Break. You pressed CTRL-C.\n";
  35.          running = FALSE;
  36.       }
  37.  
  38.       BOOL hasNotOccured() { return running==TRUE; }
  39. };
  40.  
  41.  
  42. class MyTask : public LivingObject
  43. {
  44.     protected:
  45.         int main();
  46.     public:
  47.         MyTask() { activate(); }    // start task on creation
  48.         ~MyTask() {}
  49.             
  50. };
  51.  
  52. int MyTask::main()
  53. {
  54.     cout << "\tHello! I'm a living object running on a seperate task.\n" 
  55.           << "\tI'm now engaging my SignalResponder which will catch your CTRL-C break signal..\n";
  56.           
  57.     MySRSP ctrlCBreak;
  58.     
  59.     while ( ctrlCBreak.hasNotOccured() )
  60.    {
  61.       SignalResponder::WaitSignal();
  62.    }
  63.  
  64.    cout << "\tThanks. Bye.\n\n";
  65.     return 0;
  66. }
  67.  
  68. main()
  69. {{
  70.     cout << "Welcome to Task_test!\n"
  71.           << "IMPORTANT NOTE: if the program does not respond to your CTRL-C key press,\n"
  72.           << "send it a break signal from a shell with the command 'break <process-no>'\n";
  73.     
  74.     cout << "Now I'm going to create a living object of 'MyTask' class..\n\n";    
  75.     
  76.     MyTask child;    // create and start task that executes MyTask::main().
  77.  
  78.     cout << "This is main: I'm setting up a CTRL-C break SignalResponder.\n"
  79.           << "Press CTRL-C to leave this demo.\n";
  80.           
  81.     MySRSP ctrlCBreak;    // create a signal responder that catches CTRL-C break signal.
  82.     
  83.     
  84.     while ( ctrlCBreak.hasNotOccured() )
  85.    {
  86.       SignalResponder::WaitSignal();    // wait for any signals
  87.    }
  88.     
  89.     cout << "I got your break signal. Thank You.\nNow, waiting for child process to terminate..\n";
  90.     }
  91.     cout << "Child process terminated. Goodbye.\n";
  92.     return 0;
  93. }
  94.