Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix code scanning alerts #861

Merged
merged 1 commit into from
May 19, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 10 additions & 10 deletions compendium/DeclarativeServices/src/manager/BindingPolicy.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ namespace cppmicroservices
ReferenceManagerBaseImpl::BindingPolicy::Log(std::string const& logStr,
cppmicroservices::logservice::SeverityLevel logLevel)
{
mgr.logger->Log(logLevel, logStr);
mgr.logger_->Log(logLevel, logStr);
}

bool
Expand Down Expand Up @@ -62,14 +62,14 @@ namespace cppmicroservices
std::vector<RefChangeNotification> notifications;
if (ShouldClearBoundRefs(reference))
{
Log("Notify UNSATISFIED for reference " + mgr.metadata.name);
notifications.emplace_back(mgr.metadata.name, RefEvent::BECAME_UNSATISFIED);
Log("Notify UNSATISFIED for reference " + mgr.metadata_.name);
notifications.emplace_back(mgr.metadata_.name, RefEvent::BECAME_UNSATISFIED);

ClearBoundRefs();
if (mgr.UpdateBoundRefs())
{
Log("Notify SATISFIED for reference " + mgr.metadata.name);
notifications.emplace_back(mgr.metadata.name, RefEvent::BECAME_SATISFIED);
Log("Notify SATISFIED for reference " + mgr.metadata_.name);
notifications.emplace_back(mgr.metadata_.name, RefEvent::BECAME_SATISFIED);
}

mgr.BatchNotifyAllListeners(notifications);
Expand Down Expand Up @@ -107,18 +107,18 @@ namespace cppmicroservices
if (!boundRefsHandle->empty())
{
svcRefToBind = *(boundRefsHandle->begin());
Log("Notify BIND for reference " + mgr.metadata.name);
Log("Notify BIND for reference " + mgr.metadata_.name);
}
}

Log("Notify UNBIND for reference " + mgr.metadata.name);
notifications.emplace_back(mgr.metadata.name, RefEvent::REBIND, svcRefToBind, reference);
Log("Notify UNBIND for reference " + mgr.metadata_.name);
notifications.emplace_back(mgr.metadata_.name, RefEvent::REBIND, svcRefToBind, reference);
}

if (!mgr.IsSatisfied())
{
Log("Notify UNSATISFIED for reference " + mgr.metadata.name);
notifications.emplace_back(mgr.metadata.name, RefEvent::BECAME_UNSATISFIED);
Log("Notify UNSATISFIED for reference " + mgr.metadata_.name);
notifications.emplace_back(mgr.metadata_.name, RefEvent::BECAME_UNSATISFIED);
}

mgr.BatchNotifyAllListeners(notifications);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ namespace cppmicroservices
auto boundRefsHandle = mgr.boundRefs.lock(); // acquires lock on boundRefs
if (boundRefsHandle->empty())
{
notifications.emplace_back(mgr.metadata.name, RefEvent::REBIND, reference);
notifications.emplace_back(mgr.metadata_.name, RefEvent::REBIND, reference);
}
else
{ // there are bound refs, determine whether to rebind
Expand All @@ -83,14 +83,14 @@ namespace cppmicroservices
// to eliminate any gaps between unbinding the current bound target service
// and binding to the new bound target service.
notifications.push_back(
RefChangeNotification { mgr.metadata.name, RefEvent::REBIND, reference, svcRefToUnBind });
RefChangeNotification { mgr.metadata_.name, RefEvent::REBIND, reference, svcRefToUnBind });
}
}

if (notifySatisfied)
{
Log("Notify SATISFIED for reference " + mgr.metadata.name);
notifications.emplace_back(mgr.metadata.name, RefEvent::BECAME_SATISFIED);
Log("Notify SATISFIED for reference " + mgr.metadata_.name);
notifications.emplace_back(mgr.metadata_.name, RefEvent::BECAME_SATISFIED);
}
mgr.BatchNotifyAllListeners(notifications);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,19 +54,19 @@ namespace cppmicroservices
// is optional and there are no bound refs.
if (0 == mgr.GetBoundReferences().size())
{
Log("Notify BIND for reference " + mgr.metadata.name);
Log("Notify BIND for reference " + mgr.metadata_.name);

ClearBoundRefs();
mgr.UpdateBoundRefs();

notifications.emplace_back(mgr.metadata.name, RefEvent::REBIND, reference);
notifications.emplace_back(mgr.metadata_.name, RefEvent::REBIND, reference);
}
}

if (notifySatisfied)
{
Log("Notify SATISFIED for reference " + mgr.metadata.name);
notifications.emplace_back(mgr.metadata.name, RefEvent::BECAME_SATISFIED);
Log("Notify SATISFIED for reference " + mgr.metadata_.name);
notifications.emplace_back(mgr.metadata_.name, RefEvent::BECAME_SATISFIED);
}
mgr.BatchNotifyAllListeners(notifications);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -82,8 +82,8 @@ namespace cppmicroservices
std::vector<RefChangeNotification> notifications;
if (replacementNeeded)
{
Log("Notify UNSATISFIED for reference " + mgr.metadata.name);
notifications.emplace_back(mgr.metadata.name, RefEvent::BECAME_UNSATISFIED, reference);
Log("Notify UNSATISFIED for reference " + mgr.metadata_.name);
notifications.emplace_back(mgr.metadata_.name, RefEvent::BECAME_UNSATISFIED, reference);
// The following "clear and copy" strategy is sufficient for
// updating the boundRefs for static binding policy
if (serviceToUnbind)
Expand All @@ -94,8 +94,8 @@ namespace cppmicroservices
}
if (notifySatisfied)
{
Log("Notify SATISFIED for reference " + mgr.metadata.name);
notifications.emplace_back(mgr.metadata.name, RefEvent::BECAME_SATISFIED, reference);
Log("Notify SATISFIED for reference " + mgr.metadata_.name);
notifications.emplace_back(mgr.metadata_.name, RefEvent::BECAME_SATISFIED, reference);
}
mgr.BatchNotifyAllListeners(notifications);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,8 @@ namespace cppmicroservices
auto notifySatisfied = ShouldNotifySatisfied();
if (notifySatisfied)
{
Log("Notify SATISFIED for reference " + mgr.metadata.name);
notifications.emplace_back(mgr.metadata.name, RefEvent::BECAME_SATISFIED, reference);
Log("Notify SATISFIED for reference " + mgr.metadata_.name);
notifications.emplace_back(mgr.metadata_.name, RefEvent::BECAME_SATISFIED, reference);
}

mgr.BatchNotifyAllListeners(notifications);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@
wchar_count = MultiByteToWideChar(CP_UTF8, 0, inStr.c_str(), -1, wBuf.get(), wchar_count);
if (wchar_count == 0)
{
std::invalid_argument("Failed to convert " + inStr + " to UTF16.");
throw std::invalid_argument("Failed to convert " + inStr + " to UTF16.");

Check warning on line 81 in compendium/DeclarativeServices/src/manager/BundleLoader.cpp

View check run for this annotation

Codecov / codecov/patch

compendium/DeclarativeServices/src/manager/BundleLoader.cpp#L81

Added line #L81 was not covered by tests
}
return wBuf.get();
}
Expand Down
32 changes: 16 additions & 16 deletions compendium/DeclarativeServices/src/manager/ReferenceManagerImpl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -79,25 +79,25 @@
std::shared_ptr<cppmicroservices::logservice::LogService> logger,
std::string const& configName,
std::unique_ptr<BindingPolicy> policy)
: metadata(metadata)
: metadata_(metadata)
, tracker(nullptr)
, logger(std::move(logger))
, configName(configName)
, logger_(std::move(logger))
, configName_(configName)
, bindingPolicy(std::move(policy))
{
if (!bc || !this->logger)
if (!bc || !logger_)
{
throw std::invalid_argument("Failed to create object, Invalid arguments passed to constructor");
}
try
{
tracker = std::make_unique<ServiceTracker<void>>(bc, GetReferenceLDAPFilter(metadata), this);
tracker = std::make_unique<ServiceTracker<void>>(bc, GetReferenceLDAPFilter(metadata_), this);
tracker->Open();
}
catch (...)
{
logger->Log(SeverityLevel::LOG_ERROR,
"could not open service tracker for " + metadata.interfaceName,
logger_->Log(SeverityLevel::LOG_ERROR,

Check warning on line 99 in compendium/DeclarativeServices/src/manager/ReferenceManagerImpl.cpp

View check run for this annotation

Codecov / codecov/patch

compendium/DeclarativeServices/src/manager/ReferenceManagerImpl.cpp#L99

Added line #L99 was not covered by tests
"could not open service tracker for " + metadata_.interfaceName,
std::current_exception());
tracker.reset();
throw std::current_exception();
Expand All @@ -113,8 +113,8 @@
}
catch (...)
{
logger->Log(SeverityLevel::LOG_ERROR,
"Exception caught while closing service tracker for " + metadata.interfaceName,
logger_->Log(SeverityLevel::LOG_ERROR,

Check warning on line 116 in compendium/DeclarativeServices/src/manager/ReferenceManagerImpl.cpp

View check run for this annotation

Codecov / codecov/patch

compendium/DeclarativeServices/src/manager/ReferenceManagerImpl.cpp#L116

Added line #L116 was not covered by tests
"Exception caught while closing service tracker for " + metadata_.interfaceName,
std::current_exception());
}
}
Expand All @@ -137,13 +137,13 @@
bool
ReferenceManagerBaseImpl::IsOptional() const
{
return (metadata.minCardinality == 0);
return (metadata_.minCardinality == 0);
}

bool
ReferenceManagerBaseImpl::IsSatisfied() const
{
return (boundRefs.lock()->size() >= metadata.minCardinality);
return (boundRefs.lock()->size() >= metadata_.minCardinality);
}

ReferenceManagerBaseImpl::~ReferenceManagerBaseImpl() { StopTracking(); }
Expand All @@ -157,12 +157,12 @@
{
auto matchedRefsHandle = matchedRefs.lock(); // acquires lock on matchedRefs
auto const matchedRefsHandleSize = matchedRefsHandle->size();
if (matchedRefsHandleSize >= metadata.minCardinality)
if (matchedRefsHandleSize >= metadata_.minCardinality)
{
auto boundRefsHandle = boundRefs.lock(); // acquires lock on boundRefs
boundRefsHandle->clear();
std::copy_n(matchedRefsHandle->rbegin(),
std::min(metadata.maxCardinality, matchedRefsHandleSize),
std::min(metadata_.maxCardinality, matchedRefsHandleSize),
std::inserter(*(boundRefsHandle), boundRefsHandle->begin()));
return true;
}
Expand All @@ -181,7 +181,7 @@
// ASSUMPTION: If there is no component configuration name then its assumed this service was not registered
// by DS and could not satisfy itself since it is not managed by DS.
auto const compConfigName = reference.GetProperty(COMPONENT_NAME);
if ((true == compConfigName.Empty()) || (configName != compConfigName.ToStringNoExcept()))
if ((true == compConfigName.Empty()) || (configName_ != compConfigName.ToStringNoExcept()))
{
// acquire lock on matchedRefs
auto matchedRefsHandle = matchedRefs.lock();
Expand Down Expand Up @@ -239,7 +239,7 @@
auto notifySatisfied = UpdateBoundRefs();
if (notifySatisfied)
{
RefChangeNotification notification { metadata.name, RefEvent::BECAME_SATISFIED };
RefChangeNotification notification { metadata_.name, RefEvent::BECAME_SATISFIED };
notify(notification);
}

Expand Down Expand Up @@ -289,7 +289,7 @@
}
catch (...)
{
logger->Log(SeverityLevel::LOG_ERROR,
logger_->Log(SeverityLevel::LOG_ERROR,
"Exception caught while notifying service reference "
"listeners for reference name "
+ notification.senderName,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ namespace cppmicroservices
std::string
GetReferenceName() const override
{
return metadata.name;
return metadata_.name;
}

/**
Expand All @@ -91,7 +91,7 @@ namespace cppmicroservices
std::string
GetReferenceScope() const override
{
return metadata.scope;
return metadata_.scope;
}

/**
Expand All @@ -100,7 +100,7 @@ namespace cppmicroservices
std::string
GetLDAPString() const override
{
return metadata.target;
return metadata_.target;
}

/**
Expand Down Expand Up @@ -131,7 +131,7 @@ namespace cppmicroservices
metadata::ReferenceMetadata const&
GetMetadata() const
{
return metadata;
return metadata_;
}

/**
Expand Down Expand Up @@ -269,11 +269,11 @@ namespace cppmicroservices
*/
void BatchNotifyAllListeners(std::vector<RefChangeNotification> const& notification) noexcept;

const metadata::ReferenceMetadata metadata; ///< reference information from the component description
const metadata::ReferenceMetadata metadata_; ///< reference information from the component description
std::unique_ptr<ServiceTracker<void>> tracker; ///< used to track service availability
std::shared_ptr<cppmicroservices::logservice::LogService> logger; ///< logger for this runtime
std::shared_ptr<cppmicroservices::logservice::LogService> logger_; ///< logger for this runtime
const std::string
configName; ///< Keep track of which component configuration object this reference manager belongs to.
configName_; ///< Keep track of which component configuration object this reference manager belongs to.

mutable Guarded<std::set<cppmicroservices::ServiceReferenceBase>>
boundRefs; ///< guarded set of bound references
Expand Down
2 changes: 1 addition & 1 deletion framework/include/cppmicroservices/detail/Threads.h
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ namespace cppmicroservices
UniqueLock(UniqueLock&& o) noexcept : m_Lock(std::move(o.m_Lock)) {}

UniqueLock&
operator=(UniqueLock&& o)
operator=(UniqueLock&& o) noexcept
{
m_Lock = std::move(o.m_Lock);
return *this;
Expand Down
4 changes: 2 additions & 2 deletions framework/src/bundle/BundlePrivate.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -263,7 +263,7 @@ namespace cppmicroservices
return;
}
}
// INTENTIONALLY FALLS THROUGH - in case of lazy activation.
[[fallthrough]];
case Bundle::STATE_RESOLVED:
{
state = Bundle::STATE_STARTING;
Expand Down Expand Up @@ -337,7 +337,7 @@ namespace cppmicroservices
}
}
}
// INTENTIONALLY FALLS THROUGH
[[fallthrough]];
case Bundle::STATE_RESOLVED:
case Bundle::STATE_INSTALLED:
{
Expand Down
4 changes: 2 additions & 2 deletions framework/src/util/FrameworkPrivate.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,7 @@ namespace cppmicroservices
break;
case Bundle::STATE_ACTIVE:
wasActive = true;
// Fall through
[[fallthrough]];
case Bundle::STATE_STARTING:
{
bool const wa = wasActive;
Expand Down Expand Up @@ -187,7 +187,7 @@ namespace cppmicroservices
case Bundle::STATE_INSTALLED:
case Bundle::STATE_RESOLVED:
DoInit();
// Fall through
[[fallthrough]];
case Bundle::STATE_STARTING:
operation = BundlePrivate::OP_ACTIVATING;
break;
Expand Down
Loading