HDK
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
PDG_ServiceClient.h
Go to the documentation of this file.
1 /*
2  * PROPRIETARY INFORMATION. This software is proprietary to
3  * Side Effects Software Inc., and is not to be reproduced,
4  * transmitted, or disclosed in any way without written permission.
5  *
6  * COMMENTS:
7  */
8 
9 #ifndef __PDG_SERVICE_CLIENT_H__
10 #define __PDG_SERVICE_CLIENT_H__
11 
12 #include "PDG_API.h"
13 #include "PDG_WorkItemTypes.h"
14 
15 #include <UT/UT_StringArray.h>
16 #include <UT/UT_StringHolder.h>
17 #include <UT/UT_WorkBuffer.h>
18 
19 class PDG_Scheduler;
20 class PDG_Service;
21 
22 /*
23  * Basic information about a service client and utilities for generating a
24  * client's command line string and spawning a client as a standalone
25  * process
26  */
28 {
29 public:
30  /// Constructs a new client info instance
32  const PDG_Service* service,
33  const UT_StringHolder& server_address,
34  int server_port,
35  int client_num);
36 
37  /// Constructs an incomplete client instance -- this is used for
38  /// compatbility with older version of Houdini that did not
39  /// explicitly track client info
41  const UT_StringHolder& client_name,
42  int client_num);
43 
44  /// Returns the command for the client as a string, but combining the
45  /// command arguments
46  UT_StringHolder commandString() const;
47 
48 
49  /// Returns the current command line args for the service client
50  inline const UT_StringArray&
51  commandArgs() const
52  { return myCommandArgs; }
53 
54  /// Returns the current name of the service client
55  inline const UT_StringHolder&
56  name() const
57  { return myName; }
58 
59  /// Returns the log path for the client
60  inline const UT_StringHolder&
61  logPath() const
62  { return myLogPath; }
63 
64  /// Returns the MQ connection address
65  inline const UT_StringHolder&
66  address() const
67  { return myAddress; }
68 
69 
70  /// Returns the client number
71  inline exint clientNumber() const
72  { return myClientNumber; }
73 
74  /// Returns the MQ connection port
75  inline exint port() const
76  { return myPort; }
77 
78  /// Returns the process or job ID
79  inline exint id() const
80  { return myId; }
81 
82  /// Sets the current job ID
83  inline void setId(exint id)
84  { myId = id; }
85 
86  /// Returns the total number of jobs the client has cooked
87  inline exint totalCooks() const
88  { return myTotalCooks; }
89 
90  /// Returns the current memory usage
91  inline exint memoryUsage() const
92  { return myMemoryUsage; }
93 
94 
95  /// Gets the current client work item lock, or -1 if one isn't set
96  inline PDG_WorkItemID lock() const
97  { return myLock; }
98 
99  /// Returns whether or not the client is connected to the MQ
100  inline bool isConnected() const
101  { return myIsConnected; }
102 
103  /// Returns whether or not the client is active
104  inline bool isActive() const
105  { return myIsActive; }
106 
107 private:
108  friend class PDG_Service;
109 
110  /// Spawns the client as a child process, and returns true on
111  /// success
112  bool spawnProcess();
113 
114  /// Kills the active client process, if one exists
115  bool killProcess(
116  UT_WorkBuffer& errors,
117  PDG_Service* service,
118  PDG_Scheduler* scheduler);
119 
120  /// Waits for the active client process, if one exists, and returns
121  /// its exit code
122  int waitProcess();
123 
124  /// Checks if the spawned process is still valid and active
125  bool hasValidProcess();
126 
127  /// Marks the client as in use, which also increments its total cook
128  /// count and sets the lock if a non-empty ID is passed in
129  void startCook(PDG_WorkItemID lock_id);
130 
131  /// Marks the client as no longer in use, and reports its last known
132  /// memory usage
133  void stopCook(exint memory_usage);
134 
135  /// Sets whether or no the client is connected
136  void setConnected(bool connected);
137 
138  /// Unlocks the client
139  void setUnlocked();
140 
141  /// Resets the total cooks and memory usage of the client
142  void resetStats();
143 
144  /// Starts an operation that can time out, with the given timeout value
145  /// in seconds
146  void startTimeout(fpreal timeout);
147 
148  /// Updates and checks the current timeout operation, returns true if
149  /// the timeout has been reached
150  bool updateTimeout(fpreal delta);
151 
152 private:
153  /// The array of command line args for the client
154  UT_StringArray myCommandArgs;
155 
156  /// The name of the service client
157  UT_StringHolder myName;
158 
159  /// The log path for client output
160  UT_StringHolder myLogPath;
161 
162  /// The connection address
163  UT_StringHolder myAddress;
164 
165 
166  /// The current timeout, for operations that should be limited
167  /// to a maximum wait time. When this hits 0 the operation should be
168  /// canceled.
169  fpreal myCurrentTimeout;
170 
171 
172  /// The client number, within the list of all clients for the service
173  exint myClientNumber;
174 
175  /// The connection port
176  exint myPort;
177 
178  /// The process or job id for the client
179  exint myId;
180 
181  /// The total number of tasks the service has cooked
182  exint myTotalCooks;
183 
184  /// The amount of memory in use by the process, as recorded by the
185  /// last task that cooked using the client
186  int64 myMemoryUsage;
187 
188 
189  /// The ID of the work item that has locked the service client, if
190  /// any
191  PDG_WorkItemID myLock;
192 
193  /// Set to true once the client has connected
194  bool myIsConnected;
195 
196  /// Set to true if the client is active for a job
197  bool myIsActive;
198 };
199 
200 #endif
exint PDG_WorkItemID
Type defs for unique work item IDs.
exint clientNumber() const
Returns the client number.
const UT_StringHolder & name() const
Returns the current name of the service client.
exint id() const
Returns the process or job ID.
#define PDG_API
Definition: PDG_API.h:23
const UT_StringHolder & address() const
Returns the MQ connection address.
int64 exint
Definition: SYS_Types.h:125
PDG_WorkItemID lock() const
Gets the current client work item lock, or -1 if one isn't set.
bool isActive() const
Returns whether or not the client is active.
exint port() const
Returns the MQ connection port.
void setId(exint id)
Sets the current job ID.
GLbitfield GLuint64 timeout
Definition: glcorearb.h:1599
long long int64
Definition: SYS_Types.h:116
exint totalCooks() const
Returns the total number of jobs the client has cooked.
GLuint id
Definition: glcorearb.h:655
const UT_StringHolder & logPath() const
Returns the log path for the client.
exint memoryUsage() const
Returns the current memory usage.
fpreal64 fpreal
Definition: SYS_Types.h:283
const UT_StringArray & commandArgs() const
Returns the current command line args for the service client.
bool isConnected() const
Returns whether or not the client is connected to the MQ.