Commit 19d8426a authored by Mccaskey, Alex's avatar Mccaskey, Alex
Browse files

Adding info statements to plugin loading


Signed-off-by: Mccaskey, Alex's avatarAlex McCaskey <mccaskeyaj@ornl.gov>
parent a694420c
......@@ -53,7 +53,13 @@ void Initialize(int arc, char** arv) {
// Get reference to the service registry
auto serviceRegistry = xacc::ServiceRegistry::instance();
serviceRegistry->initialize();
try {
serviceRegistry->initialize();
} catch (std::exception& e) {
XACCLogger::instance()->error(
std::string(e.what())
+ " - Could not initialize XACC Framework");
}
// Parse any user-supplied command line options
xaccCLParser->parse(argc, argv);
......@@ -170,6 +176,11 @@ std::shared_ptr<Accelerator> getAccelerator(const std::string& name) {
}
bool hasAccelerator(const std::string& name) {
if (!xacc::xaccFrameworkInitialized) {
error(
"XACC not initialized before use. Please execute "
"xacc::Initialize() before using API.");
}
return ServiceRegistry::instance()->hasService<Accelerator>(name);
}
......
......@@ -6,15 +6,9 @@ void ServiceRegistry::initialize() {
if (!initialized) {
framework = FrameworkFactory().NewFramework();
try {
// Initialize the framework, such that we can call
// GetBundleContext() later.
framework.Init();
} catch (const std::exception& e) {
XACCLogger::instance()->error(
std::string(e.what())
+ " - Could not initialize XACC Framework");
}
// Initialize the framework, such that we can call
// GetBundleContext() later.
framework.Init();
context = framework.GetBundleContext();
if (!context) {
......@@ -23,12 +17,13 @@ void ServiceRegistry::initialize() {
}
const std::string xaccLibDir = std::string(XACC_INSTALL_DIR) + std::string("/lib");
XACCLogger::instance()->info("Plugin Lib Directory: " + xaccLibDir);
for (auto &entry : boost::make_iterator_range(
boost::filesystem::directory_iterator(xaccLibDir), { })) {
// We want the gate and aqc bundles that come with XACC
if (boost::contains(entry.path().filename().string(),
"libxacc-quantum")) {
XACCLogger::instance()->info("Installing plugin " + entry.path().string());
context.InstallBundles(entry.path().string());
}
}
......@@ -46,6 +41,7 @@ void ServiceRegistry::initialize() {
for (auto& entry : boost::make_iterator_range(
boost::filesystem::directory_iterator(itr->path()),
{ })) {
XACCLogger::instance()->info("Installing plugin " + entry.path().string());
context.InstallBundles(entry.path().string());
}
}
......@@ -57,25 +53,19 @@ void ServiceRegistry::initialize() {
"There are no plugins. Install plugins to begin working with XACC.");
}
// Start the framework itself.
framework.Start();
try {
// Start the framework itself.
framework.Start();
// Our bundles depend on each other in the sense that the consumer
// bundle expects a ServiceTime service in its activator Start()
// function. This is done here for simplicity, but is actually
// bad practice.
auto bundles = context.GetBundles();
for (auto b : bundles) {
b.Start();
}
initialized = true;
} catch (const std::exception& e) {
XACCLogger::instance()->error(
"Failure to start XACC plugins. " + std::string(e.what()));
// Our bundles depend on each other in the sense that the consumer
// bundle expects a ServiceTime service in its activator Start()
// function. This is done here for simplicity, but is actually
// bad practice.
auto bundles = context.GetBundles();
for (auto b : bundles) {
b.Start();
}
initialized = true;
}
}
......
......@@ -94,6 +94,7 @@ public:
template<typename ServiceInterface>
std::shared_ptr<ServiceInterface> getService(const std::string name) {
std::shared_ptr<ServiceInterface> ret;
auto allServiceRefs = context.GetServiceReferences<ServiceInterface>();
for (auto s : allServiceRefs) {
auto service = context.GetService(s);
......@@ -102,14 +103,19 @@ public:
auto checkCloneable = std::dynamic_pointer_cast<
xacc::Cloneable<ServiceInterface>>(service);
if (checkCloneable) {
return checkCloneable->clone();
ret = checkCloneable->clone();
} else {
return service;
ret = service;
}
}
}
XACCLogger::instance()->error("Could not find service with name " + name + ". "
"Perhaps the service is not Identifiable.");
if (!ret) {
XACCLogger::instance()->error("Could not find service with name " + name + ". "
"Perhaps the service is not Identifiable.");
}
return ret;
}
template<typename ServiceInterface>
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment