| 41 | } |
| 42 | |
| 43 | bool |
| 44 | Stat::init(const string &name, Stat::SyncType type, bool persistent) |
| 45 | { |
| 46 | if (TSStatFindName(name.c_str(), &stat_id_) == TS_SUCCESS) { |
| 47 | LOG_DEBUG("Attached to stat '%s' with stat_id = %d", name.c_str(), stat_id_); |
| 48 | return true; |
| 49 | } |
| 50 | |
| 51 | // TS_RECORDDATATYPE_INT is the only type currently supported |
| 52 | // so that's why this api doesn't expose other types, TSStatSync is equivalent to StatSyncType |
| 53 | stat_id_ = TSStatCreate(name.c_str(), TS_RECORDDATATYPE_INT, persistent ? TS_STAT_PERSISTENT : TS_STAT_NON_PERSISTENT, |
| 54 | static_cast<TSStatSync>(type)); |
| 55 | if (stat_id_ != TS_ERROR) { |
| 56 | LOG_DEBUG("Created new stat named '%s' with stat_id = %d", name.c_str(), stat_id_); |
| 57 | } else { |
| 58 | LOG_ERROR("Unable to create stat named '%s'.", name.c_str()); |
| 59 | } |
| 60 | |
| 61 | if (stat_id_ == TS_ERROR) { |
| 62 | return false; |
| 63 | } |
| 64 | |
| 65 | if (!persistent) { |
| 66 | set(0); |
| 67 | } |
| 68 | |
| 69 | return true; |
| 70 | } |
| 71 | |
| 72 | void |
| 73 | Stat::set(int64_t value) |
nothing calls this directly
no test coverage detected