Skip to content
This repository was archived by the owner on Oct 10, 2022. It is now read-only.

Commit b027ba5

Browse files
authored
Don't reload driver instances at each scan (#70)
1 parent 341a6ed commit b027ba5

2 files changed

Lines changed: 26 additions & 20 deletions

File tree

src/drivers/supporteddrivers.cpp

Lines changed: 24 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,8 @@ DPTR_IMPL(SupportedDrivers) {
3434

3535
void find_drivers(const QString &directory);
3636
void load_driver(const QString &filename);
37-
list<Driver*> instances() const;
37+
list<Driver*> instances();
38+
list<Driver*> _instances;
3839
};
3940

4041

@@ -64,19 +65,19 @@ void SupportedDrivers::Private::load_driver(const QString& filename)
6465
QString library_name = filename;
6566
library_name.remove(".json");
6667

67-
qDebug() << "trying " << filename << ": " << library_name;
68+
qDebug() << "[??] trying " << filename << ": " << library_name;
6869

6970
auto driver = make_shared<QLibrary>(library_name);
7071
if(driver->load()) {
71-
qDebug() << "Driver " << library_name << " loaded successfully";
72+
qDebug() << "[OK] Driver " << library_name << " loaded successfully";
7273
if(driver->resolve(PLANETARY_IMAGER_DRIVER_LOAD_F)) {
73-
qDebug() << "PlanetaryImager_loadDriver resolved on " << library_name;
74+
qDebug() << "[OK] PlanetaryImager_loadDriver resolved on " << library_name;
7475
drivers.push_back(driver);
7576
} else {
76-
qWarning() << "Error resolving PlanetaryImager_loadDriver function on " << library_name;
77+
qWarning() << "[ERR] Error resolving PlanetaryImager_loadDriver function on " << library_name;
7778
}
7879
} else {
79-
qWarning() << "Error loading driver: " << library_name;
80+
qWarning() << "[ERR] Error loading driver: " << library_name;
8081
}
8182
}
8283

@@ -94,27 +95,30 @@ void SupportedDrivers::aboutToQuit()
9495

9596
Driver::Cameras SupportedDrivers::cameras() const
9697
{
98+
qDebug() << "Detecting active cameras";
9799
Cameras cameras;
98100
for(auto driver: d->instances()) {
99101
if(driver)
100102
cameras.append(driver->cameras());
101103
}
102-
104+
qDebug() << "Detected cameras: " << cameras.size();
103105
return cameras;
104106
}
105107

106-
list<Driver *> SupportedDrivers::Private::instances() const
108+
list<Driver *> SupportedDrivers::Private::instances()
107109
{
108-
list<Driver*> instances;
109-
transform(begin(drivers), end(drivers), back_inserter(instances), [](const auto &p) -> Driver* {
110-
qDebug() << "Initializing driver" << p->fileName();
111-
try {
112-
auto driver_load_function = (LoadDriverFunction) p->resolve(PLANETARY_IMAGER_DRIVER_LOAD_F);
113-
return qobject_cast<Driver*>(driver_load_function());
114-
} catch(const Imager::exception &e) {
115-
qWarning() << "Error loading driver: " << e.what();
116-
return nullptr;
117-
}
118-
});
119-
return instances;
110+
if(_instances.size() == 0) {
111+
qDebug() << "Initialising driver instances";
112+
transform(begin(drivers), end(drivers), back_inserter(_instances), [](const auto &p) -> Driver* {
113+
qDebug() << "Initializing driver" << p->fileName();
114+
try {
115+
auto driver_load_function = (LoadDriverFunction) p->resolve(PLANETARY_IMAGER_DRIVER_LOAD_F);
116+
return qobject_cast<Driver*>(driver_load_function());
117+
} catch(const Imager::exception &e) {
118+
qWarning() << "Error loading driver: " << e.what();
119+
return nullptr;
120+
}
121+
});
122+
}
123+
return _instances;
120124
}

src/drivers/zwo_asi/zwo_asi_driver.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,7 @@ ZWO_ASI_Driver::ZWO_ASI_Driver() : dptr(this)
5656
metatypes_registered = true;
5757
qRegisterMetaType<ASI_IMG_TYPE>("ASI_IMG_TYPE");
5858
}
59+
qDebug() << "ZWO ASI Driver initialised";
5960
}
6061

6162
ZWO_ASI_Driver::~ZWO_ASI_Driver()
@@ -66,6 +67,7 @@ ZWO_ASI_Driver::~ZWO_ASI_Driver()
6667
Driver::Cameras ZWO_ASI_Driver::cameras() const
6768
{
6869
int ncams = ASIGetNumOfConnectedCameras();
70+
qDebug() << "ZWO AI Driver: detected" << ncams << "cameras";
6971
Driver::Cameras cameras;
7072
int index=0;
7173
for(int index=0; index<ncams; index++) {

0 commit comments

Comments
 (0)