Skip to content

Commit

Permalink
Added code to check for AsyncWS before creating fallback (#659)
Browse files Browse the repository at this point in the history
Signed-off-by: The MathWorks, Inc. <alchrist@mathworks.com>
  • Loading branch information
achristoforides committed Apr 25, 2022
1 parent a240213 commit 1983c52
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 7 deletions.
15 changes: 13 additions & 2 deletions compendium/ConfigurationAdmin/src/CMAsyncWorkService.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ class FallbackAsyncWorkService final
} catch (...) {
auto exceptionPtr = std::current_exception();
std::string msg =
"An exception has occured while trying to shutdown "
"An exception has occurred while trying to shutdown "
"the fallback cppmicroservices::async::AsyncWorkService "
"instance.";
logger->Log(cppmicroservices::logservice::SeverityLevel::LOG_WARNING,
Expand Down Expand Up @@ -102,9 +102,20 @@ CMAsyncWorkService::CMAsyncWorkService(
: scrContext(context)
, serviceTracker(std::make_unique<cppmicroservices::ServiceTracker<
cppmicroservices::async::AsyncWorkService>>(context, this))
, asyncWorkService(std::make_shared<FallbackAsyncWorkService>(logger_))
, asyncWorkService(nullptr)
, logger(logger_)
{
if (auto asyncWSSRef =
context
.GetServiceReference<cppmicroservices::async::AsyncWorkService>();
asyncWSSRef) {
asyncWorkService =
context.GetService<cppmicroservices::async::AsyncWorkService>(
asyncWSSRef);
} else {
asyncWorkService = std::make_shared<FallbackAsyncWorkService>(logger_);
}

serviceTracker->Open();
}

Expand Down
15 changes: 13 additions & 2 deletions compendium/DeclarativeServices/src/SCRAsyncWorkService.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -98,13 +98,24 @@ class FallbackAsyncWorkService final

SCRAsyncWorkService::SCRAsyncWorkService(
cppmicroservices::BundleContext context,
const std::shared_ptr<SCRLogger>& logger_)
const std::shared_ptr<cppmicroservices::logservice::LogService>& logger_)
: scrContext(context)
, serviceTracker(std::make_unique<cppmicroservices::ServiceTracker<
cppmicroservices::async::AsyncWorkService>>(context, this))
, asyncWorkService(std::make_shared<FallbackAsyncWorkService>(logger_))
, asyncWorkService(nullptr)
, logger(logger_)
{
if (auto asyncWSSRef =
context
.GetServiceReference<cppmicroservices::async::AsyncWorkService>();
asyncWSSRef) {
asyncWorkService =
context.GetService<cppmicroservices::async::AsyncWorkService>(
asyncWSSRef);
} else {
asyncWorkService = std::make_shared<FallbackAsyncWorkService>(logger_);
}

serviceTracker->Open();
}

Expand Down
7 changes: 4 additions & 3 deletions compendium/DeclarativeServices/src/SCRAsyncWorkService.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,9 @@ class SCRAsyncWorkService final
cppmicroservices::async::AsyncWorkService>
{
public:
explicit SCRAsyncWorkService(cppmicroservices::BundleContext context,
const std::shared_ptr<SCRLogger>& logger_);
explicit SCRAsyncWorkService(
cppmicroservices::BundleContext context,
const std::shared_ptr<cppmicroservices::logservice::LogService>& logger_);
SCRAsyncWorkService(const SCRAsyncWorkService&) noexcept = delete;
SCRAsyncWorkService(SCRAsyncWorkService&&) noexcept = delete;
SCRAsyncWorkService& operator=(const SCRAsyncWorkService&) noexcept = delete;
Expand Down Expand Up @@ -85,7 +86,7 @@ class SCRAsyncWorkService final
cppmicroservices::ServiceTracker<cppmicroservices::async::AsyncWorkService>>
serviceTracker;
std::shared_ptr<cppmicroservices::async::AsyncWorkService> asyncWorkService;
std::shared_ptr<SCRLogger> logger;
std::shared_ptr<cppmicroservices::logservice::LogService> logger;
};
}
}
Expand Down

0 comments on commit 1983c52

Please sign in to comment.