ARC SDK
DataStatus.h
1 // -*- indent-tabs-mode: nil -*-
2 
3 #ifndef __ARC_DATASTATUS_H__
4 #define __ARC_DATASTATUS_H__
5 
6 #include <iostream>
7 #include <string>
8 #include <errno.h>
9 
10 #include <arc/StringConv.h>
11 #include <arc/Utils.h>
12 
13 namespace Arc {
14 
15 #define DataStatusRetryableBase (100)
16 
17 #define DataStatusErrnoBase 1000
18 #define EARCTRANSFERTIMEOUT (DataStatusErrnoBase + 1) // Transfer timed out
19 #define EARCCHECKSUM (DataStatusErrnoBase + 2) // Checksum mismatch
20 #define EARCLOGIC (DataStatusErrnoBase + 3) // Bad logic, eg calling StartWriting on a
21  // DataPoint currently reading
22 #define EARCRESINVAL (DataStatusErrnoBase + 4) // All results obtained from a service are invalid
23 #define EARCSVCTMP (DataStatusErrnoBase + 5) // Temporary service error
24 #define EARCSVCPERM (DataStatusErrnoBase + 6) // Permanent service error
25 #define EARCUIDSWITCH (DataStatusErrnoBase + 7) // Error switching uid
26 #define EARCREQUESTTIMEOUT (DataStatusErrnoBase + 8) // Request made to remote service timed out
27 #define EARCOTHER (DataStatusErrnoBase + 9) // Other / unknown error
28 
29 #define DataStatusErrnoMax EARCOTHER
30 
32 
54  class DataStatus {
55 
56  public:
57 
59 
65  // Order is important! Must be kept synchronised with status_string[]
66 
69 
72 
75 
78 
81 
84 
87 
90 
93 
96 
99 
102 
105 
108 
111 
114 
117 
120 
123 
126 
129 
132 
135 
138 
141 
146 
151 
154 
157 
160 
163 
166 
169 
172 
175 
178 
181 
184 
187 
190 
193 
196 
199 
200  // These Retryable error codes are deprecated but kept for backwards
201  // compatibility. They will be removed in a future major release.
202  // Instead of these codes the corresponding non-retryable code should be
203  // used with an errno, and this is used to determine whether the error is
204  // retryable.
205  ReadAcquireErrorRetryable = DataStatusRetryableBase+ReadAcquireError,
206  WriteAcquireErrorRetryable = DataStatusRetryableBase+WriteAcquireError,
207  ReadResolveErrorRetryable = DataStatusRetryableBase+ReadResolveError,
208  WriteResolveErrorRetryable = DataStatusRetryableBase+WriteResolveError,
209  ReadStartErrorRetryable = DataStatusRetryableBase+ReadStartError,
210  WriteStartErrorRetryable = DataStatusRetryableBase+WriteStartError,
211  ReadErrorRetryable = DataStatusRetryableBase+ReadError,
212  WriteErrorRetryable = DataStatusRetryableBase+WriteError,
213  TransferErrorRetryable = DataStatusRetryableBase+TransferError,
214  ReadStopErrorRetryable = DataStatusRetryableBase+ReadStopError,
215  WriteStopErrorRetryable = DataStatusRetryableBase+WriteStopError,
216  PreRegisterErrorRetryable = DataStatusRetryableBase+PreRegisterError,
217  PostRegisterErrorRetryable = DataStatusRetryableBase+PostRegisterError,
218  UnregisterErrorRetryable = DataStatusRetryableBase+UnregisterError,
219  CacheErrorRetryable = DataStatusRetryableBase+CacheError,
220  DeleteErrorRetryable = DataStatusRetryableBase+DeleteError,
221  CheckErrorRetryable = DataStatusRetryableBase+CheckError,
222  ListErrorRetryable = DataStatusRetryableBase+ListError,
223  StatErrorRetryable = DataStatusRetryableBase+StatError,
224  StageErrorRetryable = DataStatusRetryableBase+StageError,
225  ReadPrepareErrorRetryable = DataStatusRetryableBase+ReadPrepareError,
226  WritePrepareErrorRetryable = DataStatusRetryableBase+WritePrepareError,
227  ReadFinishErrorRetryable = DataStatusRetryableBase+ReadFinishError,
228  WriteFinishErrorRetryable = DataStatusRetryableBase+WriteFinishError,
230  RenameErrorRetryable = DataStatusRetryableBase+RenameError,
231  GenericErrorRetryable = DataStatusRetryableBase+GenericError
232  };
233 
235 
239  DataStatus(const DataStatusType& status, std::string desc="")
240  : status(status), Errno(0), desc(desc) {
241  if (!Passed()) Errno = EARCOTHER;
242  }
243 
245 
252  DataStatus(const DataStatusType& status, int error_no, const std::string& desc="")
253  : status(status), Errno(error_no), desc(desc) {}
254 
257  : status(Success), Errno(0), desc("") {}
258 
260  bool operator==(const DataStatusType& s) {
261  return status == s;
262  }
264  bool operator==(const DataStatus& s) {
265  return status == s.status;
266  }
267 
269  bool operator!=(const DataStatusType& s) {
270  return status != s;
271  }
273  bool operator!=(const DataStatus& s) {
274  return status != s.status;
275  }
276 
278 
282  status = s;
283  Errno = 0;
284  if (!Passed()) Errno = EARCOTHER;
285  return *this;
286  }
287 
289  bool operator!() const {
290  return (status != Success) && (status != SuccessCached);
291  }
293  operator bool() const {
294  return (status == Success) || (status == SuccessCached);
295  }
296 
298  bool Passed() const {
299  return ((status == Success) || (status == NotSupportedForDirectDataPointsError) ||
300  (status == ReadPrepareWait) || (status == WritePrepareWait) ||
301  (status == SuccessCached) || (status == SuccessCancelled));
302  }
303 
305 
309  bool Retryable() const;
310 
312  void SetErrno(int error_no) {
313  Errno = error_no;
314  }
315 
317  int GetErrno() const {
318  return Errno;
319  }
320 
322  std::string GetStrErrno() const;
323 
325  void SetDesc(const std::string& d) {
326  desc = trim(d);
327  }
328 
330  std::string GetDesc() const {
331  return desc;
332  }
333 
335  operator std::string(void) const;
336 
337  private:
338 
340  DataStatusType status;
342  int Errno;
344  std::string desc;
345 
346  };
347 
349 
350  inline std::ostream& operator<<(std::ostream& o, const DataStatus& d) {
351  return (o << ((std::string)d));
352  }
353 } // namespace Arc
354 
355 
356 #endif // __ARC_DATASTATUS_H__