* Copyright (c) Huawei Technologies Co., Ltd. 2025. All rights reserved.
* You can use this software according to the terms and conditions of the Mulan PSL v2.
* You may obtain a copy of Mulan PSL v2 at:
* http://license.coscl.org.cn/MulanPSL2
* THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND,
* EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT,
* MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE.
* See the Mulan PSL v2 for more details.
*/
#ifndef OMNISTREAM_AVAILABILITYSTATUS_H
#define OMNISTREAM_AVAILABILITYSTATUS_H
class AvailabilityStatus {
public:
enum class StatusType {
AVAILABLE,
UNAVAILABLE_NEED_REQUESTING_NOTIFICATION,
UNAVAILABLE_NEED_NOT_REQUESTING_NOTIFICATION
};
private:
StatusType type;
bool available;
bool needRequestingNotificationOfGlobalPoolAvailable;
AvailabilityStatus(StatusType type, bool available, bool needNotify)
: type(type),
available(available),
needRequestingNotificationOfGlobalPoolAvailable(needNotify) {}
public:
AvailabilityStatus(const AvailabilityStatus&) = delete;
AvailabilityStatus& operator=(const AvailabilityStatus&) = delete;
static const AvailabilityStatus& AVAILABLE() {
static const AvailabilityStatus instance(StatusType::AVAILABLE, true, false);
return instance;
}
static const AvailabilityStatus& UNAVAILABLE_NEED_REQUESTING_NOTIFICATION() {
static const AvailabilityStatus instance(StatusType::UNAVAILABLE_NEED_REQUESTING_NOTIFICATION, false, true);
return instance;
}
static const AvailabilityStatus& UNAVAILABLE_NEED_NOT_REQUESTING_NOTIFICATION() {
static const AvailabilityStatus instance(StatusType::UNAVAILABLE_NEED_NOT_REQUESTING_NOTIFICATION, false, false);
return instance;
}
bool isAvailable() const {
return available;
}
bool isNeedRequestingNotificationOfGlobalPoolAvailable() const {
return needRequestingNotificationOfGlobalPoolAvailable;
}
StatusType getType() const {
return type;
}
static const AvailabilityStatus& from(bool isAvailable, bool isNeedRequestingNotificationOfGlobalPoolAvailable) {
if (isAvailable) {
return AVAILABLE();
} else if (isNeedRequestingNotificationOfGlobalPoolAvailable) {
return UNAVAILABLE_NEED_REQUESTING_NOTIFICATION();
} else {
return UNAVAILABLE_NEED_NOT_REQUESTING_NOTIFICATION();
}
}
bool operator==(const AvailabilityStatus& other) const {
return this->type == other.type;
}
bool operator!=(const AvailabilityStatus& other) const {
return !(*this == other);
}
};
#endif