diff --git a/src/BasicChannel.cpp b/src/BasicChannel.cpp index 132ea83..8c63ea4 100644 --- a/src/BasicChannel.cpp +++ b/src/BasicChannel.cpp @@ -13,9 +13,12 @@ using namespace std::chrono; using namespace ts; BasicChannel::BasicChannel(ChannelId parentId, ChannelId channelId) { - this->setProperties(make_shared()); + { + auto properties = std::make_shared(); + properties->register_property_type(); + this->setProperties(properties); + } - this->_properties->register_property_type(); this->properties()[property::CHANNEL_ID] = channelId; this->properties()[property::CHANNEL_PID] = parentId; } @@ -35,17 +38,17 @@ void BasicChannel::setProperties(const std::shared_ptr& pro this->_properties = props; this->properties()->registerNotifyHandler([&](Property& prop){ - if(prop.type() == property::CHANNEL_FLAG_DEFAULT) + if(prop.type() == property::CHANNEL_FLAG_DEFAULT) { this->properties()[property::CHANNEL_FLAG_PASSWORD] = false; - else if(prop.type() == property::CHANNEL_ID) + } else if(prop.type() == property::CHANNEL_ID) { this->_channel_id = prop; - else if(prop.type() == property::CHANNEL_ORDER) + } else if(prop.type() == property::CHANNEL_ORDER) { this->_channel_order = prop; + } }); //Update cached variables - if(props->has(property::CHANNEL_ORDER)) this->_channel_order = this->properties()[property::CHANNEL_ORDER]; - else this->_channel_order = 0; + this->_channel_order = this->properties()[property::CHANNEL_ORDER]; this->_channel_id = this->channelId(); } @@ -108,9 +111,13 @@ BasicChannel::BasicChannel(std::shared_ptr parent, ChannelId chann BasicChannel::~BasicChannel() { } ChannelType::ChannelType BasicChannel::channelType() { - if (this->properties()[property::CHANNEL_FLAG_PERMANENT].as_unchecked()) return ChannelType::ChannelType::permanent; - else if (this->properties()[property::CHANNEL_FLAG_SEMI_PERMANENT].as_unchecked()) return ChannelType::ChannelType::semipermanent; - else return ChannelType::ChannelType::temporary; + if(this->properties()[property::CHANNEL_FLAG_PERMANENT].as_or(true)) { + return ChannelType::ChannelType::permanent; + } else if (this->properties()[property::CHANNEL_FLAG_SEMI_PERMANENT].as_or(false)) { + return ChannelType::ChannelType::semipermanent; + } else { + return ChannelType::ChannelType::temporary; + } } void BasicChannel::setChannelType(ChannelType::ChannelType type) { @@ -269,16 +276,24 @@ deque> BasicChannelTree::delete_channel_root(c } bool BasicChannelTree::setDefaultChannel(const shared_ptr &ch) { - if (!ch) return false; - for (const auto &elm : this->channels()) - elm->properties()[property::CHANNEL_FLAG_DEFAULT] = false; + if (!ch) { + return false; + } + + for (const auto &elm : this->channels()) { + elm->properties()[property::CHANNEL_FLAG_DEFAULT].update_value(false); + } + ch->properties()[property::CHANNEL_FLAG_DEFAULT] = true; return true; } std::shared_ptr BasicChannelTree::getDefaultChannel() { - for (auto elm : this->channels()) - if (elm->properties()[property::CHANNEL_FLAG_DEFAULT].as_unchecked()) return elm; + for (auto elm : this->channels()) { + if (elm->properties()[property::CHANNEL_FLAG_DEFAULT].as_or(false)) { + return elm; + } + } return nullptr; } diff --git a/src/Properties.cpp b/src/Properties.cpp index 9ea9c91..758aef5 100644 --- a/src/Properties.cpp +++ b/src/Properties.cpp @@ -104,9 +104,11 @@ void PropertyManager::do_register_property_type(ts::property::PropertyType type, property.casted_value.~any(); } + bundle->value_mutex.~mutex(); ::free(bundle); }); + new (&ptr->value_mutex) std::mutex{}; ptr->type = type; ptr->property_count = length;