Skip to content

Commit

Permalink
clang-format ran for all files (#759)
Browse files Browse the repository at this point in the history
Signed-off-by: The MathWorks, Inc. <alchrist@mathworks.com>

Signed-off-by: The MathWorks, Inc. <alchrist@mathworks.com>
  • Loading branch information
achristoforides committed Dec 2, 2022
1 parent c83f290 commit 50932a4
Show file tree
Hide file tree
Showing 205 changed files with 1,132 additions and 786 deletions.
109 changes: 55 additions & 54 deletions compendium/ConfigurationAdmin/src/ConfigurationAdminImpl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -220,10 +220,10 @@ ConfigurationAdminImpl::~ConfigurationAdminImpl()
const auto it = configurationsToInvalidate.find(managedService->getPid());
if (it != std::end(configurationsToInvalidate) &&
it->second->HasBeenUpdatedAtLeastOnce()) {
notifyServiceUpdated(managedService->getPid(),
*(managedService->getTrackedService()),
emptyMap,
*logger);
notifyServiceUpdated(managedService->getPid(),
*(managedService->getTrackedService()),
emptyMap,
*logger);
}
}
}
Expand All @@ -240,11 +240,12 @@ ConfigurationAdminImpl::~ConfigurationAdminImpl()
for (const auto& pid : it->second) {
// can only send a Removed notification if the managedServiceFactory has previously
// received an Updated notification.

const auto it = configurationsToInvalidate.find(pid);
if (it != std::end(configurationsToInvalidate) && (it->second->HasBeenUpdatedAtLeastOnce())) {
notifyServiceRemoved(
pid, *(managedServiceFactory->getTrackedService()), *logger);
if (it != std::end(configurationsToInvalidate) &&
(it->second->HasBeenUpdatedAtLeastOnce())) {
notifyServiceRemoved(
pid, *(managedServiceFactory->getTrackedService()), *logger);
}
}
}
Expand Down Expand Up @@ -392,7 +393,7 @@ std::vector<ConfigurationAddedInfo> ConfigurationAdminImpl::AddConfigurations(
std::vector<ConfigurationAddedInfo> pidsAndChangeCountsAndIDs;
std::vector<bool> createdOrUpdated;
std::vector<std::shared_ptr<ConfigurationImpl>> configurationsToInvalidate;

{
std::lock_guard<std::mutex> lk{ configurationsMutex };
for (const auto& configMetadata : configurationMetadata) {
Expand All @@ -402,21 +403,14 @@ std::vector<ConfigurationAddedInfo> ConfigurationAdminImpl::AddConfigurations(
if (it == std::end(configurations)) {
auto factoryPid = getFactoryPid(pid);
AddFactoryInstanceIfRequired(pid, factoryPid);
// construct the Configuration Object with a changeCount of 1
// construct the Configuration Object with a changeCount of 1
// since configuration objects created from metadata already
// have their properties (if any) present. The create operation
// counts as a create and an update operation.
auto newConfig = std::make_shared<ConfigurationImpl>(
this,
pid,
std::move(factoryPid),
configMetadata.properties,
1u);
this, pid, std::move(factoryPid), configMetadata.properties, 1u);
changeCount = newConfig->GetChangeCount();
it = configurations
.emplace(pid,
std::move(newConfig))
.first;
it = configurations.emplace(pid, std::move(newConfig)).first;
pidsAndChangeCountsAndIDs.emplace_back(
pid, changeCount, reinterpret_cast<std::uintptr_t>(it->second.get()));
createdOrUpdated.push_back(true);
Expand Down Expand Up @@ -542,7 +536,8 @@ void ConfigurationAdminImpl::RemoveConfigurations(
}

std::shared_future<void> ConfigurationAdminImpl::NotifyConfigurationUpdated(
const std::string& pid, const unsigned long changeCount)
const std::string& pid,
const unsigned long changeCount)
{
// NotifyConfigurationUpdated will only send a notification to the service if
// the configuration object has been updated at least once. In order to determine whether or not
Expand Down Expand Up @@ -744,19 +739,20 @@ ConfigurationAdminImpl::AddingService(
return nullptr;
}

// Send a notification in case a valid configuration object
// Send a notification in case a valid configuration object
// was created before the service was active. The service's properties
// need to be updated.
unsigned long initialChangeCount{0ul};
// need to be updated.
unsigned long initialChangeCount{ 0ul };

if (const auto it = configurations.find(pid); it != std::end(configurations)) {
if (const auto it = configurations.find(pid);
it != std::end(configurations)) {
AnyMap properties{ AnyMap::UNORDERED_MAP_CASEINSENSITIVE_KEYS };
// Only send notifications for configuration objects that have been
// Updated.
if (it->second->HasBeenUpdatedAtLeastOnce()) {
try {
properties = it->second->GetProperties();
// specifically set the initial change count here because there is
// specifically set the initial change count here because there is
// a race between the call to GetChangeCount() and HasBeenUpdatedAtLeastOnce().
// The logic is that, if HasBeenUpdatedAtLeastOnce() returns true, the change
// count will always be > 1 and should at this point be captured for the
Expand All @@ -782,13 +778,14 @@ ConfigurationAdminImpl::AddingService(
}

logger->Log(cppmicroservices::logservice::SeverityLevel::LOG_DEBUG,
"New ManagedService with PID " + pid +
" has been added.");
"New ManagedService with PID " + pid + " has been added.");

std::unordered_map<std::string, unsigned long> initialChangeCountByPid = {{pid, initialChangeCount}};
std::unordered_map<std::string, unsigned long> initialChangeCountByPid = {
{ pid, initialChangeCount }
};
auto trackedManagedService = std::make_shared<
TrackedServiceWrapper<cppmicroservices::service::cm::ManagedService>>(
pid, std::move(initialChangeCountByPid), std::move(managedService));
pid, std::move(initialChangeCountByPid), std::move(managedService));
trackedManagedServices_.emplace_back(trackedManagedService);
return trackedManagedService;
}
Expand All @@ -812,18 +809,20 @@ void ConfigurationAdminImpl::RemovedService(
// Lock because we are modifying the container of tracked managed services.
std::lock_guard<std::mutex> lk{ configurationsMutex };

auto elemIter = std::find_if(
std::begin(trackedManagedServices_),
std::end(trackedManagedServices_),
[&service](const auto& trackedServiceWrapper) {
return (service->getTrackedService() == trackedServiceWrapper->getTrackedService());
});
auto elemIter =
std::find_if(std::begin(trackedManagedServices_),
std::end(trackedManagedServices_),
[&service](const auto& trackedServiceWrapper) {
return (service->getTrackedService() ==
trackedServiceWrapper->getTrackedService());
});
if (elemIter != trackedManagedServices_.end()) {
trackedManagedServices_.erase(elemIter);
}
// ManagedService won't receive any more updates to its Configuration.
logger->Log(cppmicroservices::logservice::SeverityLevel::LOG_DEBUG,
"ManagedService with PID " + service->getPid() + " has been removed.");
"ManagedService with PID " + service->getPid() +
" has been removed.");
}

std::shared_ptr<
Expand Down Expand Up @@ -854,7 +853,7 @@ ConfigurationAdminImpl::AddingService(
(bundle ? bundle.GetSymbolicName() : "Unknown") +
" as it does not have a service.pid or component.name property");
return nullptr;
}
}

std::vector<std::pair<std::string, AnyMap>> pidsAndProperties;
std::unordered_map<std::string, unsigned long> initialChangeCountPerPid;
Expand All @@ -866,20 +865,21 @@ ConfigurationAdminImpl::AddingService(
assert(configurationIt != std::end(configurations) &&
"Invalid Configuration iterator");
try {
// Notifications can only be sent for configuration objects that
// Notifications can only be sent for configuration objects that
// been Updated. Only add it to the notification list if it has
// been Updated.
if (configurationIt->second->HasBeenUpdatedAtLeastOnce()) {
auto properties = configurationIt->second->GetProperties();
initialChangeCountPerPid[configurationIt->second->GetPid()] = configurationIt->second->GetChangeCount();
initialChangeCountPerPid[configurationIt->second->GetPid()] =
configurationIt->second->GetChangeCount();
pidsAndProperties.emplace_back(instance, std::move(properties));
}
} catch (const std::runtime_error&) {
// Configuration is being removed
logger->Log(
SeverityLevel::LOG_WARNING,
"Attempted to retrieve properties for a configuration which has been removed.",
std::current_exception());
logger->Log(SeverityLevel::LOG_WARNING,
"Attempted to retrieve properties for a configuration "
"which has been removed.",
std::current_exception());
}
}
}
Expand All @@ -895,13 +895,13 @@ ConfigurationAdminImpl::AddingService(
});
}

logger->Log(
cppmicroservices::logservice::SeverityLevel::LOG_DEBUG,
"New ManagedServiceFactory with PID " + pid +
" has been added, and async Update has been queued for all updated instances.");
logger->Log(cppmicroservices::logservice::SeverityLevel::LOG_DEBUG,
"New ManagedServiceFactory with PID " + pid +
" has been added, and async Update has been queued for all "
"updated instances.");
auto trackedManagedServiceFactory = std::make_shared<TrackedServiceWrapper<
cppmicroservices::service::cm::ManagedServiceFactory>>(
pid, std::move(initialChangeCountPerPid), std::move(managedServiceFactory));
pid, std::move(initialChangeCountPerPid), std::move(managedServiceFactory));
trackedManagedServiceFactories_.emplace_back(trackedManagedServiceFactory);
return trackedManagedServiceFactory;
}
Expand All @@ -924,12 +924,13 @@ void ConfigurationAdminImpl::RemovedService(
// Lock because we are modifying the container of tracked managed services.
std::lock_guard<std::mutex> lk{ configurationsMutex };

auto elemIter = std::find_if(
std::begin(trackedManagedServiceFactories_),
std::end(trackedManagedServiceFactories_),
[&service](const auto& trackedServiceWrapper) {
return (service->getTrackedService() == trackedServiceWrapper->getTrackedService());
});
auto elemIter =
std::find_if(std::begin(trackedManagedServiceFactories_),
std::end(trackedManagedServiceFactories_),
[&service](const auto& trackedServiceWrapper) {
return (service->getTrackedService() ==
trackedServiceWrapper->getTrackedService());
});
if (elemIter != trackedManagedServiceFactories_.end()) {
trackedManagedServiceFactories_.erase(elemIter);
}
Expand Down
2 changes: 1 addition & 1 deletion compendium/ConfigurationAdmin/src/ConfigurationImpl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ std::shared_future<void> ConfigurationImpl::Update(AnyMap newProperties)
}
std::lock_guard<std::mutex> lk{ configAdminMutex };
if (configAdminImpl) {
return configAdminImpl->NotifyConfigurationUpdated(pid, changeCount);
return configAdminImpl->NotifyConfigurationUpdated(pid, changeCount);
}
std::promise<void> ready;
std::shared_future<void> fut = ready.get_future();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,8 @@ namespace metadata {
MetadataParserImplV1::MetadataParserImplV1(
std::shared_ptr<cppmicroservices::logservice::LogService> lggr)
: logger(std::move(lggr))
{}
{
}

std::vector<ConfigurationMetadata>
MetadataParserImplV1::ParseAndGetConfigurationMetadata(
Expand Down
9 changes: 6 additions & 3 deletions compendium/ConfigurationAdmin/test/TestAsyncWorkService.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,8 @@ class TestAsyncWorkServiceEndToEnd
public:
TestAsyncWorkServiceEndToEnd()
: framework(cppmicroservices::FrameworkFactory().NewFramework())
{}
{
}

void SetUp() override
{
Expand Down Expand Up @@ -146,7 +147,8 @@ class AsyncWorkServiceInline : public cppmicroservices::async::AsyncWorkService
public:
AsyncWorkServiceInline()
: cppmicroservices::async::AsyncWorkService()
{}
{
}

void post(std::packaged_task<void()>&& task) override { task(); }
};
Expand All @@ -157,7 +159,8 @@ class AsyncWorkServiceStdAsync
public:
AsyncWorkServiceStdAsync()
: cppmicroservices::async::AsyncWorkService()
{}
{
}

void post(std::packaged_task<void()>&& task) override
{
Expand Down
3 changes: 2 additions & 1 deletion compendium/ConfigurationAdmin/test/TestCMActivator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,8 @@ class TestCMActivator : public ::testing::Test
protected:
TestCMActivator()
: framework(cppmicroservices::FrameworkFactory().NewFramework())
{}
{
}
~TestCMActivator() override = default;

void SetUp() override { framework.Start(); }
Expand Down
3 changes: 2 additions & 1 deletion compendium/ConfigurationAdmin/test/TestCMBundleExtension.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,8 @@ class TestCMBundleExtension : public ::testing::Test
protected:
TestCMBundleExtension()
: framework(cppmicroservices::FrameworkFactory().NewFramework())
{}
{
}
~TestCMBundleExtension() = default;

void SetUp() override { framework.Start(); }
Expand Down
35 changes: 16 additions & 19 deletions compendium/ConfigurationAdmin/test/TestCMLogger.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,8 @@ class TestCMLogger : public ::testing::Test
protected:
TestCMLogger()
: framework(cppmicroservices::FrameworkFactory().NewFramework())
{}
{
}

~TestCMLogger() override = default;

Expand All @@ -70,16 +71,14 @@ TEST_F(TestCMLogger, VerifyWithoutLoggerService)
// check that calling log method is safe even if a LogService is unavailable
EXPECT_NO_THROW({
logger.Log(SeverityLevel::LOG_DEBUG, "sample log message");
logger.Log(
SeverityLevel::LOG_DEBUG,
"sample log message",
std::make_exception_ptr(std::runtime_error("error occured")));
logger.Log(SeverityLevel::LOG_DEBUG,
"sample log message",
std::make_exception_ptr(std::runtime_error("error occured")));
logger.Log(dummyRef, SeverityLevel::LOG_DEBUG, "sample log message");
logger.Log(
dummyRef,
SeverityLevel::LOG_DEBUG,
"sample log message",
std::make_exception_ptr(std::runtime_error("error occured")));
logger.Log(dummyRef,
SeverityLevel::LOG_DEBUG,
"sample log message",
std::make_exception_ptr(std::runtime_error("error occured")));
});
}

Expand All @@ -106,18 +105,16 @@ TEST_F(TestCMLogger, VerifyWithLoggerService)
// exercise methods on instance of CMLogger
CMLogger logger(bundleContext);
logger.Log(SeverityLevel::LOG_DEBUG, "some sample debug message");
logger.Log(
SeverityLevel::LOG_ERROR,
"some sample error message",
std::make_exception_ptr(std::runtime_error("error occured")));
logger.Log(SeverityLevel::LOG_ERROR,
"some sample error message",
std::make_exception_ptr(std::runtime_error("error occured")));
cppmicroservices::ServiceReferenceU dummyRef;
logger.Log(
dummyRef, SeverityLevel::LOG_WARNING, "some sample warning message");
logger.Log(
dummyRef,
SeverityLevel::LOG_ERROR,
"some sample error message with service reference",
std::make_exception_ptr(std::runtime_error("error occured")));
logger.Log(dummyRef,
SeverityLevel::LOG_ERROR,
"some sample error message with service reference",
std::make_exception_ptr(std::runtime_error("error occured")));
reg.Unregister();
});
}
Expand Down

0 comments on commit 50932a4

Please sign in to comment.