Hermes  0.9.5-beta
Hierarchical Distributed I/O Buffering System
hermes_status.h
Go to the documentation of this file.
1 /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
2  * Distributed under BSD 3-Clause license. *
3  * Copyright by The HDF Group. *
4  * Copyright by the Illinois Institute of Technology. *
5  * All rights reserved. *
6  * *
7  * This file is part of Hermes. The full Hermes copyright notice, including *
8  * terms governing use, modification, and redistribution, is contained in *
9  * the COPYING file, which can be found at the top directory. If you do not *
10  * have access to the file, you may request a copy from help@hdfgroup.org. *
11  * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
12 
13 #ifndef HERMES_STATUS_H_
14 #define HERMES_STATUS_H_
15 
16 #include <iostream>
17 
20 namespace hermes {
22 #define RETURN_CODES(X) \
23  X(2, HERMES_OK_MAX, \
24  "Maximum supported HERMES success with " \
25  "caveat.") \
26  X(1, BLOB_IN_SWAP_PLACE, "Blob is placed into swap place.") \
27  X(0, HERMES_SUCCESS, "No error!") \
28  X(-1, INVALID_BUCKET, "Bucket ID is invalid.") \
29  X(-2, BUCKET_NAME_TOO_LONG, "Bucket name exceeds max length (256).") \
30  X(-3, VBUCKET_NAME_TOO_LONG, "VBucket name exceeds max length (256).") \
31  X(-4, BLOB_NAME_TOO_LONG, "Blob name exceeds max length (64).") \
32  X(-5, INVALID_BLOB, \
33  "Blob data is invalid. Please check " \
34  "address and size.") \
35  X(-6, BLOB_NOT_IN_BUCKET, "Blob is not in this bucket.") \
36  X(-7, BLOB_NOT_LINKED_TO_VBUCKET, "Blob is not linked to this vbucket.") \
37  X(-8, TRAIT_NOT_VALID, "Selected trait is not valid.") \
38  X(-9, TRAIT_EXISTS_ALREADY, "Selected trait already exists.") \
39  X(-10, OFFSET_MAP_EMPTY, "Offset_map is empty.") \
40  X(-11, BLOB_NOT_LINKED_IN_MAP, "Map doesn't have the blob linked.") \
41  X(-12, BUCKET_IN_USE, \
42  "Bucket cannot be destroyed because its " \
43  "reference count is greater than 1.") \
44  X(-13, DPE_RANDOM_FOUND_NO_TGT, \
45  "DPE random found no target with enough " \
46  "space for blob.") \
47  X(-14, DPE_GET_INVALID_TGT, "DPE got an invalid target ID.") \
48  X(-15, DPE_ORTOOLS_NO_SOLUTION, \
49  "DPE GLPK does not find a solution " \
50  "with provided constraints.") \
51  X(-16, DPE_PLACEMENTSCHEMA_EMPTY, "DPE PlacementSchema is empty.") \
52  X(-17, READ_BLOB_FAILED, "Read blob from its id failed.") \
53  X(-18, STDIO_OFFSET_ERROR, "Offset invalid or fseek() failed.") \
54  X(-19, STDIO_FWRITE_FAILED, "Func fwrite failed. System err msg: ") \
55  X(-20, STDIO_FOPEN_FAILED, "Func fopen failed. System err msg: ") \
56  X(-21, STDIO_FCLOSE_FAILED, "Func fclose failed. System err msg: ") \
57  X(-23, INVALID_FILE, "File is not valid.") \
58  X(-24, PLACE_SWAP_BLOB_TO_BUF_FAILED, \
59  "Place blob from swap space into " \
60  "buffering system failed.") \
61  X(-25, DPE_RR_FIND_TGT_FAILED, \
62  "DPE round-robin failed to find " \
63  "proper target for blob.") \
64  X(-26, HERMES_ERROR_MAX, "Maximum supported HERMES errors.")
65 
67 #define RETURN_ENUM(ID, NAME, TEXT) NAME = ID,
68 
70 #define RETURN_TEXT(ID, NAME, TEXT) \
71  case ID: \
72  return TEXT;
73 
76 
77 namespace api {
78 
80 class Status {
81  public:
83  explicit Status(StatusCode ret_code = HERMES_SUCCESS) : status_(ret_code) {}
84 
86  bool Succeeded() const { return (status_ == HERMES_SUCCESS); }
87 
89  bool Acceptable() const {
90  return (status_ > HERMES_SUCCESS && status_ < HERMES_OK_MAX);
91  }
92 
94  bool Failed() const {
95  return (status_ < HERMES_SUCCESS && status_ > HERMES_ERROR_MAX);
96  }
97 
99  bool operator==(StatusCode code) { return (status_ == code); }
100 
102  void operator=(StatusCode code) { status_ = code; }
103 
105  StatusCode GetStatus() const { return status_; }
106 
108  std::string Msg() const {
109  switch (status_) { RETURN_CODES(RETURN_TEXT) }
110 
111  return "Unknown error";
112  }
113 
114  private:
116 };
117 
118 } // namespace api
119 
120 } // namespace hermes
121 #endif // HERMES_STATUS_H_
Definition: hermes_status.h:80
bool Succeeded() const
Definition: hermes_status.h:86
StatusCode GetStatus() const
Definition: hermes_status.h:105
bool Acceptable() const
Definition: hermes_status.h:89
bool Failed() const
Definition: hermes_status.h:94
Status(StatusCode ret_code=HERMES_SUCCESS)
Definition: hermes_status.h:83
void operator=(StatusCode code)
Definition: hermes_status.h:102
std::string Msg() const
Definition: hermes_status.h:108
bool operator==(StatusCode code)
Definition: hermes_status.h:99
#define RETURN_TEXT(ID, NAME, TEXT)
Definition: hermes_status.h:70
StatusCode status_
Definition: hermes_status.h:115
#define RETURN_CODES(X)
Definition: hermes_status.h:22
#define RETURN_ENUM(ID, NAME, TEXT)
Definition: hermes_status.h:67
Definition: adapter_utils.cc:35
StatusCode
Definition: hermes_status.h:75