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