home *** CD-ROM | disk | FTP | other *** search
/ Chip 1997 October / Chip_1997-10_cd.bin / tema / sybase / powerj / hpp.z / WPROCESS.HPP < prev    next >
C/C++ Source or Header  |  1996-10-18  |  8KB  |  254 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,8);
  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. #define WPROCESS_CREATE_DEFAULT_ERROR_MODE   0x04000000
  55. #define WPROCESS_CREATE_NEW_CONSOLE          0x00000010
  56. #define WPROCESS_CREATE_NEW_PROCESS_GROUP    0x00000200
  57. #define WPROCESS_CREATE_SEPARATE_WOW_VDM     0x00000800
  58. #define WPROCESS_CREATE_SHARED_WOW_VDM       0x00001000
  59. #define WPROCESS_CREATE_SUSPENDED            0x00000004
  60. #define WPROCESS_CREATE_UNICODE_ENVIRONMENT  0x00000400
  61. #define WPROCESS_DEBUG_PROCESS               0x00000001
  62. #define WPROCESS_DEBUG_ONLY_THIS_PROCESS     0x00000002
  63. #define WPROCESS_DETACHED_PROCESS            0x00000008
  64.  
  65. #define WPROCESS_NORMAL_PRIORITY_CLASS       0x00000020
  66. #define WPROCESS_IDLE_PRIORITY_CLASS         0x00000040
  67. #define WPROCESS_HIGH_PRIORITY_CLASS         0x00000080
  68. #define WPROCESS_REALTIME_PRIORITY_CLASS     0x00000100
  69.  
  70. enum WProcessHandle { NULLHPROCESS = 0, LASTHPROCESS = LAST_16TO32BIT };
  71.  
  72. //
  73. // WProcessBase -- An abstract base class.
  74. //
  75.  
  76. class WCMCLASS WProcessBase : public WObject {
  77.     WDeclareSubclass( WProcessBase, WObject );
  78.  
  79.     private:
  80.         WProcessBase( const WProcessBase & );
  81.         WProcessBase& operator=( const WProcessBase & );
  82.  
  83.     protected:
  84.         WProcessBase();
  85.  
  86.     public:
  87.         ~WProcessBase();
  88.  
  89.         /***********************************************************
  90.          * Properties
  91.          ***********************************************************/
  92.  
  93.         // Active
  94.         //
  95.         //    TRUE if the process is still running.
  96.  
  97.         WBool GetActive() const;
  98.  
  99.         // ExitCode
  100.         //
  101.         //    Returns the exit code for the process.  If the process
  102.         //    is still active the result is undefined.
  103.  
  104.         WDWord GetExitCode() const;
  105.  
  106.         // Handle
  107.  
  108.         virtual WProcessHandle GetHandle() const = 0;
  109.  
  110.         // ID
  111.  
  112.         virtual WDWord GetID() const = 0;
  113.  
  114.         // Valid
  115.         //
  116.         //    TRUE if the object represents (or represented)
  117.         //    a valid process.
  118.  
  119.         WBool GetValid() const;
  120.  
  121.         /***********************************************************
  122.          * Methods
  123.          ***********************************************************/
  124.  
  125.         // Terminate
  126.  
  127.         WBool Terminate( WDWord exitCode=0 );
  128.  
  129.         // Wait
  130.         //
  131.         //    Wait for the process to terminate, with a timeout in
  132.         //    milliseconds.  By default the timeout is infinite.
  133.         //    If blockMessageProcessing is TRUE, then no messages will be
  134.         //    responded to by this thread until the call to Wait() finishes.
  135.  
  136.         WBool Wait(); // 0xFFFFFFFF, TRUE
  137.         WBool Wait( WDWord timeout,
  138.                     WBool blockMessageProcessing );
  139. };
  140.  
  141. //
  142. // WCurrentProcess -- Represents the currently-running process.
  143. //
  144.  
  145. class WCMCLASS WCurrentProcess : public WProcessBase {
  146.     WDeclareSubclass( WCurrentProcess, WProcessBase );
  147.  
  148.     public:
  149.         WCurrentProcess();
  150.         WCurrentProcess( const WCurrentProcess & thd );
  151.  
  152.         ~WCurrentProcess(); // does not terminate process!
  153.  
  154.         WCurrentProcess& operator=( const WCurrentProcess & thd );
  155.  
  156.         /***********************************************************
  157.          * Properties
  158.          ***********************************************************/
  159.  
  160.         /***********************************************************
  161.          * Methods
  162.          ***********************************************************/
  163.  
  164.         /***********************************************************
  165.          * Static Methods
  166.          ***********************************************************/
  167.  
  168.         // Create
  169.  
  170.         static WProcess Create( const WChar *commandLine,
  171.                                 WThread *firstThread=NULL,
  172.                                 WPoint *startingPosition=NULL,
  173.                                 WSize *startingSize=NULL,
  174.                                 WShowStyle *startingShowStyle=NULL,
  175.                                 WDWord creationFlags=WPROCESS_NORMAL_PRIORITY_CLASS );
  176.  
  177.         /***********************************************************
  178.          * Overrides
  179.          ***********************************************************/
  180.  
  181.         virtual WProcessHandle GetHandle() const;
  182.  
  183.         virtual WDWord GetID() const;
  184. };
  185.  
  186.  
  187. //
  188. // WProcess -- Represents an arbitrary process.
  189. //
  190.  
  191. class WCMCLASS WProcess : public WProcessBase {
  192.     WDeclareSubclass( WProcess, WProcessBase );
  193.  
  194.     public:
  195.         WProcess();
  196.         WProcess( WProcessHandle handle, WDWord processID,
  197.                   WBool closeHandle=TRUE, WBool makeCopy=FALSE );
  198.         WProcess( const WProcess & thd );
  199.         WProcess( const WCurrentProcess & curr );
  200.  
  201.         ~WProcess(); // does not terminate process!
  202.  
  203.         WProcess& operator=( const WProcess & thd );
  204.         WProcess& operator=( const WCurrentProcess & thd );
  205.  
  206.         /***********************************************************
  207.          * Properties
  208.          ***********************************************************/
  209.  
  210.         /***********************************************************
  211.          * Methods
  212.          ***********************************************************/
  213.  
  214.         // Clear
  215.         //
  216.         //    Resets the object, closing the low-level kernel
  217.         //    handle if no one else is referencing the process.
  218.  
  219.         void Clear();
  220.  
  221.         // Create
  222.         //
  223.         //    Creates a new process.
  224.  
  225.         WBool Create( const WChar *commandLine, WThread *firstThread=NULL,
  226.                       WPoint *startingPosition=NULL,
  227.                       WSize *startingSize=NULL,
  228.                       WShowStyle *startingShowStyle=NULL,
  229.                       WDWord creationFlags=WPROCESS_NORMAL_PRIORITY_CLASS );
  230.  
  231.         /***********************************************************
  232.          * Overrides
  233.          ***********************************************************/
  234.  
  235.         virtual WProcessHandle GetHandle() const;
  236.  
  237.         virtual WDWord GetID() const;
  238.  
  239.         /***********************************************************
  240.          * Data Members
  241.          ***********************************************************/
  242.  
  243.     private:
  244.  
  245.         WProcessReference *_processRef;
  246. };
  247.  
  248. #ifndef _WNO_PRAGMA_PUSH
  249. #pragma enum pop;
  250. #pragma pack(pop);
  251. #endif
  252.  
  253. #endif // _WPROCESS_HPP_INCLUDED
  254.