home *** CD-ROM | disk | FTP | other *** search
/ io Programmo 10 / ioProg_10.iso / soft / optima / hpp.z / WPROCESS.HPP < prev    next >
Encoding:
C/C++ Source or Header  |  1996-03-22  |  6.5 KB  |  236 lines

  1.  
  2. /********************************************************************
  3.  *
  4.  * Processes
  5.  *
  6.  *    Two classes are available:
  7.  *
  8.  *       WCurrentProcess -- Always refers to the current process.
  9.  *
  10.  *       WProcess -- Refers to a specific process.
  11.  *
  12.  *    If you want to do something related to the current process,
  13.  *    use an object of type WCurrentProcess.  Otherwise you need
  14.  *    an object of class WProcess, which can only be had in the
  15.  *    following manner:
  16.  *
  17.  *      1) Calling the Create method.
  18.  *
  19.  *      2) Assignment from another WProcess.
  20.  *
  21.  *      3) Assignment from a WCurrentProcess. 
  22.  *
  23.  ********************************************************************/
  24.  
  25. #ifndef _WPROCESS_HPP_INCLUDED
  26. #define _WPROCESS_HPP_INCLUDED
  27.  
  28. #ifndef _WNO_PRAGMA_PUSH
  29. #pragma pack(push,4);
  30. #pragma enum int;
  31. #endif
  32.  
  33. #ifndef _WDEF_HPP_INCLUDED
  34. #  include "wdef.hpp"
  35. #endif
  36. #ifndef _WOBJECT_HPP_INCLUDED
  37. #  include "wobject.hpp"
  38. #endif
  39. #ifndef _WSEMAPHORE_HPP_INCLUDED
  40. #  include "wsemaphr.hpp"
  41. #endif
  42.  
  43. class WProcess;
  44. class WThread;
  45. class WProcessReference;
  46.  
  47. enum WProcessPriority {
  48.     ProcessPriorityIdle,
  49.     ProcessPriorityNormal,
  50.     ProcessPriorityHigh,
  51.     ProcessPriorityRealTime
  52. };
  53.  
  54. enum WProcessHandle { NULLHPROCESS = 0, LASTHPROCESS = LAST_16TO32BIT };
  55.  
  56. //
  57. // WProcessBase -- An abstract base class.
  58. //
  59.  
  60. class WCMCLASS WProcessBase : public WObject {
  61.     WDeclareSubclass( WProcessBase, WObject );
  62.  
  63.     private:
  64.         WProcessBase( const WProcessBase & );
  65.         WProcessBase& operator=( const WProcessBase & );
  66.  
  67.     protected:
  68.         WProcessBase();
  69.  
  70.     public:
  71.         ~WProcessBase();
  72.  
  73.         /***********************************************************
  74.          * Properties
  75.          ***********************************************************/
  76.  
  77.         // Active
  78.         //
  79.         //    TRUE if the process is still running.
  80.  
  81.         WBool GetActive() const;
  82.  
  83.         // ExitCode
  84.         //
  85.         //    Returns the exit code for the process.  If the process
  86.         //    is still active the result is undefined.
  87.  
  88.         WDWord GetExitCode() const;
  89.  
  90.         // Handle
  91.  
  92.         virtual WProcessHandle GetHandle() const = 0;
  93.  
  94.         // ID
  95.  
  96.         virtual WDWord GetID() const = 0;
  97.  
  98.         // Valid
  99.         //
  100.         //    TRUE if the object represents (or represented)
  101.         //    a valid process.
  102.  
  103.         WBool GetValid() const;
  104.  
  105.         /***********************************************************
  106.          * Methods
  107.          ***********************************************************/
  108.  
  109.         // Terminate
  110.  
  111.         WBool Terminate( WDWord exitCode=0 );
  112.  
  113.         // Wait
  114.         //
  115.         //    Wait for the process to terminate, with a timeout in
  116.         //    milliseconds.  By default the timeout is infinite.
  117.         //    If blockMessageProcessing is TRUE, then no messages will be
  118.         //    responded to by this thread until the call to Wait() finishes.
  119.  
  120.         WBool Wait(); // 0xFFFFFFFF, TRUE
  121.         WBool Wait( WDWord timeout,
  122.                     WBool blockMessageProcessing );
  123. };
  124.  
  125. //
  126. // WCurrentProcess -- Represents the currently-running process.
  127. //
  128.  
  129. class WCMCLASS WCurrentProcess : public WProcessBase {
  130.     WDeclareSubclass( WCurrentProcess, WProcessBase );
  131.  
  132.     public:
  133.         WCurrentProcess();
  134.         WCurrentProcess( const WCurrentProcess & thd );
  135.  
  136.         ~WCurrentProcess(); // does not terminate process!
  137.  
  138.         WCurrentProcess& operator=( const WCurrentProcess & thd );
  139.  
  140.         /***********************************************************
  141.          * Properties
  142.          ***********************************************************/
  143.  
  144.         /***********************************************************
  145.          * Methods
  146.          ***********************************************************/
  147.  
  148.         /***********************************************************
  149.          * Static Methods
  150.          ***********************************************************/
  151.  
  152.         // Create
  153.  
  154.         static WProcess Create( const WChar *commandLine,
  155.                                 WThread *firstThread=NULL,
  156.                                 WPoint *startingPosition=NULL,
  157.                                 WSize *startingSize=NULL,
  158.                                 WShowStyle *startingShowStyle=NULL );
  159.  
  160.         /***********************************************************
  161.          * Overrides
  162.          ***********************************************************/
  163.  
  164.         virtual WProcessHandle GetHandle() const;
  165.  
  166.         virtual WDWord GetID() const;
  167. };
  168.  
  169.  
  170. //
  171. // WProcess -- Represents an arbitrary process.
  172. //
  173.  
  174. class WCMCLASS WProcess : public WProcessBase {
  175.     WDeclareSubclass( WProcess, WProcessBase );
  176.  
  177.     public:
  178.         WProcess();
  179.         WProcess( WProcessHandle handle, WDWord processID,
  180.                   WBool closeHandle=TRUE, WBool makeCopy=FALSE );
  181.         WProcess( const WProcess & thd );
  182.         WProcess( const WCurrentProcess & curr );
  183.  
  184.         ~WProcess(); // does not terminate process!
  185.  
  186.         WProcess& operator=( const WProcess & thd );
  187.         WProcess& operator=( const WCurrentProcess & thd );
  188.  
  189.         /***********************************************************
  190.          * Properties
  191.          ***********************************************************/
  192.  
  193.         /***********************************************************
  194.          * Methods
  195.          ***********************************************************/
  196.  
  197.         // Clear
  198.         //
  199.         //    Resets the object, closing the low-level kernel
  200.         //    handle if no one else is referencing the process.
  201.  
  202.         void Clear();
  203.  
  204.         // Create
  205.         //
  206.         //    Creates a new process.
  207.  
  208.         WBool Create( const WChar *commandLine, WThread *firstThread=NULL,
  209.                       WPoint *startingPosition=NULL,
  210.                       WSize *startingSize=NULL,
  211.                       WShowStyle *startingShowStyle=NULL );
  212.  
  213.         /***********************************************************
  214.          * Overrides
  215.          ***********************************************************/
  216.  
  217.         virtual WProcessHandle GetHandle() const;
  218.  
  219.         virtual WDWord GetID() const;
  220.  
  221.         /***********************************************************
  222.          * Data Members
  223.          ***********************************************************/
  224.  
  225.     private:
  226.  
  227.         WProcessReference *_processRef;
  228. };
  229.  
  230. #ifndef _WNO_PRAGMA_PUSH
  231. #pragma enum pop;
  232. #pragma pack(pop);
  233. #endif
  234.  
  235. #endif // _WPROCESS_HPP_INCLUDED
  236.