task code is an index for a specific kind of task. with the index, you can get properties of this kind of task: name, type, priority, etc. you may want to refer to task_spec.h for the detailed task properties. Like dsn::blob, task_code is a special thrift primitive type that's defined by the rDSN framework. Internally as a C++ object, it's is represented as an integer, but in thrift representatio
| 96 | /// ✓: 1: dsn.task_code task_code; |
| 97 | /// |
| 98 | class task_code |
| 99 | { |
| 100 | public: |
| 101 | constexpr task_code() = default; |
| 102 | |
| 103 | constexpr explicit task_code(int code) : _internal_code(code) {} |
| 104 | |
| 105 | task_code(const char *name, |
| 106 | dsn_task_type_t tt, |
| 107 | dsn_task_priority_t pri, |
| 108 | dsn::threadpool_code pool); |
| 109 | |
| 110 | task_code(const char *name, |
| 111 | dsn_task_type_t tt, |
| 112 | dsn_task_priority_t pri, |
| 113 | dsn::threadpool_code pool, |
| 114 | bool is_storage_write, |
| 115 | bool allow_batch, |
| 116 | bool is_idempotent); |
| 117 | |
| 118 | const char *to_string() const; |
| 119 | |
| 120 | constexpr bool operator==(const task_code &r) const |
| 121 | { |
| 122 | return _internal_code == r._internal_code; |
| 123 | } |
| 124 | |
| 125 | constexpr bool operator!=(const task_code &r) const { return !(*this == r); } |
| 126 | |
| 127 | constexpr operator int() const { return _internal_code; } |
| 128 | |
| 129 | constexpr int code() const { return _internal_code; } |
| 130 | |
| 131 | // for serialization in thrift format |
| 132 | uint32_t read(::apache::thrift::protocol::TProtocol *iprot); |
| 133 | uint32_t write(::apache::thrift::protocol::TProtocol *oprot) const; |
| 134 | |
| 135 | static int max(); |
| 136 | static bool is_exist(const char *name); |
| 137 | static task_code try_get(const char *name, task_code default_value); |
| 138 | static task_code try_get(const std::string &name, task_code default_value); |
| 139 | |
| 140 | friend std::ostream &operator<<(std::ostream &os, const task_code &tc) |
| 141 | { |
| 142 | return os << tc.to_string(); |
| 143 | } |
| 144 | |
| 145 | private: |
| 146 | task_code(const char *name); |
| 147 | int _internal_code{0}; |
| 148 | }; |
| 149 | |
| 150 | // you can define task_code by the following macros |
| 151 | #define DEFINE_NAMED_TASK_CODE(x, name, pri, pool) \ |