Skip to content
This repository was archived by the owner on Oct 10, 2022. It is now read-only.
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
4 changes: 4 additions & 0 deletions cmake/functions.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,12 @@ function(add_driver)
set(disabled_drivers ${disabled_drivers} ${add_driver_NAME} CACHE INTERNAL "")
return()
endif()
configure_file(${CMAKE_CURRENT_SOURCE_DIR}/driver.json ${CMAKE_CURRENT_BINARY_DIR}/driver_${add_driver_NAME}.json)
add_library(${add_driver_NAME} MODULE ${add_driver_SRCS})
target_link_libraries(${add_driver_NAME} GuLinux_Qt_Commons GuLinux_c++_Commons drivers planetaryimager-commons ${add_driver_LINK} Qt5::Core Qt5::Qml ${OpenCV_LIBS})

set_target_properties(${add_driver_NAME} PROPERTIES PREFIX "driver_")
install(TARGETS ${add_driver_NAME} LIBRARY DESTINATION ${drivers_destination})
install(FILES ${CMAKE_CURRENT_BINARY_DIR}/${add_driver_NAME}.json DESTINATION ${drivers_destination})
set(enabled_drivers ${enabled_drivers} ${add_driver_NAME} CACHE INTERNAL "")
endfunction()
15 changes: 10 additions & 5 deletions src/drivers/driver.h
Original file line number Diff line number Diff line change
Expand Up @@ -38,10 +38,15 @@ class Driver : public QObject {
virtual Cameras cameras() const = 0;
};
typedef QList<Driver::ptr> Drivers;
#define DRIVER_IID "net.gulinux.planetaryimager.driver"
Q_DECLARE_INTERFACE(Driver, DRIVER_IID)
#define DECLARE_DRIVER_PLUGIN \
Q_INTERFACES(Driver) \
Q_PLUGIN_METADATA(IID DRIVER_IID FILE "driver.json")
typedef Driver *(*LoadDriverFunction)();

#ifdef Q_OS_WIN
#define EXPORT_DECL __declspec(dllexport)
#else
#define EXPORT_DECL
#endif

#define PLANETARY_IMAGER_DRIVER_LOAD_F "PlanetaryImager_loadDriver"
#define DECLARE_DRIVER_PLUGIN_INIT(DriverClass) extern "C" EXPORT_DECL Driver *PlanetaryImager_loadDriver() { return new DriverClass(); }

#endif
2 changes: 1 addition & 1 deletion src/drivers/flycapture2/driver.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"name": "FlyCapture2",
"description": "FLIR/Point Grey native API",
"version": "0.8"
"version": "${FULL_VERSION}"
}
2 changes: 2 additions & 0 deletions src/drivers/flycapture2/fc2_driver.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -108,3 +108,5 @@ FC2Driver::FC2Driver(): dptr()
FC2Driver::~FC2Driver()
{
}

DECLARE_DRIVER_PLUGIN_INIT(FC2Driver)
2 changes: 0 additions & 2 deletions src/drivers/flycapture2/fc2_driver.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,6 @@ class FC2Driver: public Driver

public:

DECLARE_DRIVER_PLUGIN

FC2Driver();

~FC2Driver();
Expand Down
2 changes: 1 addition & 1 deletion src/drivers/iidc/driver.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"name": "IIDC",
"description": "Instrumentation & Industrial Digital Camera, a standard for camera control over FireWire and USB",
"version": "0.8"
"version": "${FULL_VERSION}"
}
3 changes: 3 additions & 0 deletions src/drivers/iidc/iidc_driver.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -138,3 +138,6 @@ IIDCDriver::IIDCDriver(): dptr()
}

IIDCDriver::~IIDCDriver() { }


DECLARE_DRIVER_PLUGIN_INIT(IIDCDriver)
2 changes: 0 additions & 2 deletions src/drivers/iidc/iidc_driver.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,6 @@ class IIDCDriver: public Driver

public:

DECLARE_DRIVER_PLUGIN

IIDCDriver();

~IIDCDriver();
Expand Down
2 changes: 1 addition & 1 deletion src/drivers/qhy/driver.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"name": "QHY",
"description": "QHYCCD Cameras driver",
"version": "0.7"
"version": "${FULL_VERSION}"
}
1 change: 1 addition & 0 deletions src/drivers/qhy/qhydriver.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -82,3 +82,4 @@ Driver::Cameras QHYDriver::cameras() const
return cameras;
}

DECLARE_DRIVER_PLUGIN_INIT(QHYDriver)
1 change: 0 additions & 1 deletion src/drivers/qhy/qhydriver.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ class QHYDriver : public Driver
{
Q_OBJECT
public:
DECLARE_DRIVER_PLUGIN
QHYDriver();
virtual ~QHYDriver();
Cameras cameras() const override;
Expand Down
2 changes: 1 addition & 1 deletion src/drivers/simulator/driver.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"name": "Simulator",
"description": "Various simulator imagers, useful mostly for debugging",
"version": "0.7"
"version": "${FULL_VERSION}"
}
1 change: 1 addition & 0 deletions src/drivers/simulator/simulatordriver.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -65,4 +65,5 @@ SimulatorDriver::SimulatorDriver()



DECLARE_DRIVER_PLUGIN_INIT(SimulatorDriver)
#include "simulatordriver.moc"
2 changes: 1 addition & 1 deletion src/drivers/simulator/simulatordriver.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,9 @@ class SimulatorDriver : public Driver
{
Q_OBJECT
public:
DECLARE_DRIVER_PLUGIN
SimulatorDriver();
virtual Driver::Cameras cameras() const;
};


#endif // SIMULATORDRIVER_H
39 changes: 24 additions & 15 deletions src/drivers/supporteddrivers.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
*/

#include "supporteddrivers.h"
#include <QPluginLoader>
#include <QLibrary>
#include <QDebug>
#include <QDirIterator>
#include <QFile>
Expand All @@ -30,7 +30,8 @@ using namespace std;

DPTR_IMPL(SupportedDrivers) {
SupportedDrivers *q;
QList<shared_ptr<QPluginLoader>> drivers;
QList<shared_ptr<QLibrary>> drivers;

void find_drivers(const QString &directory);
void load_driver(const QString &filename);
list<Driver*> instances() const;
Expand All @@ -57,18 +58,25 @@ void SupportedDrivers::Private::find_drivers(const QString& directory)

void SupportedDrivers::Private::load_driver(const QString& filename)
{
auto plugin = make_shared<QPluginLoader>(filename);
qDebug() << "trying " << filename << ": " << plugin->metaData();
auto getClassName = [](const auto &p) { return p->metaData().value("className"); };
if(plugin->metaData().value("IID").toString() == DRIVER_IID &&
find_if(drivers.begin(), drivers.end(), [&](const auto &p) { return getClassName(p) == getClassName(plugin); }) == drivers.end() ) {
if(plugin->load()) {
auto metadata = QJsonDocument{plugin->metaData()}.toVariant().toMap();
qInfo() << "driver " << plugin->fileName() << "loaded:" << metadata["className"].toString() << metadata["MetaData"].toMap()["description"].toString();
drivers.push_back(plugin);
} else {
qWarning() << "Error loading driver " << plugin->fileName() << ": " << plugin->errorString();
}
if(!filename.startsWith("driver_") && ! filename.endsWith(".json")) {
return;
}
QString library_name = filename;
library_name.remove(".json");

qDebug() << "trying " << filename << ": " << library_name;

auto driver = make_shared<QLibrary>(library_name);
if(driver->load()) {
qDebug() << "Driver " << library_name << " loaded successfully";
if(driver->resolve(PLANETARY_IMAGER_DRIVER_LOAD_F)) {
qDebug() << "PlanetaryImager_loadDriver resolved on " << library_name;
drivers.push_back(driver);
} else {
qWarning() << "Error resolving PlanetaryImager_loadDriver function on " << library_name;
}
} else {
qWarning() << "Error loading driver: " << library_name;
}
}

Expand Down Expand Up @@ -101,7 +109,8 @@ list<Driver *> SupportedDrivers::Private::instances() const
transform(begin(drivers), end(drivers), back_inserter(instances), [](const auto &p) -> Driver* {
qDebug() << "Initializing driver" << p->fileName();
try {
return qobject_cast<Driver*>(p->instance());
auto driver_load_function = (LoadDriverFunction) p->resolve(PLANETARY_IMAGER_DRIVER_LOAD_F);
return qobject_cast<Driver*>(driver_load_function());
} catch(const Imager::exception &e) {
qWarning() << "Error loading driver: " << e.what();
return nullptr;
Expand Down
2 changes: 1 addition & 1 deletion src/drivers/v4l2/driver.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"name": "V4L2",
"description": "V4L2 Devices driver (webcams, The Imaging Soure, Celestron Skyris",
"version": "0.7"
"version": "${FULL_VERSION}"
}
1 change: 1 addition & 0 deletions src/drivers/v4l2/v4l2driver.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -66,3 +66,4 @@ Driver::Cameras V4L2Driver::cameras() const
}


DECLARE_DRIVER_PLUGIN_INIT(V4L2Driver)
1 change: 0 additions & 1 deletion src/drivers/v4l2/v4l2driver.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ class V4L2Driver : public Driver
{
Q_OBJECT
public:
DECLARE_DRIVER_PLUGIN
V4L2Driver();
~V4L2Driver();
virtual Driver::Cameras cameras() const;
Expand Down
2 changes: 1 addition & 1 deletion src/drivers/zwo_asi/driver.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"name": "ASI",
"description": "ZWO ASI CMOS Cameras driver",
"version": "0.7"
"version": "${FULL_VERSION}"
}
2 changes: 2 additions & 0 deletions src/drivers/zwo_asi/zwo_asi_driver.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -76,3 +76,5 @@ Driver::Cameras ZWO_ASI_Driver::cameras() const
}
return cameras;
}

DECLARE_DRIVER_PLUGIN_INIT(ZWO_ASI_Driver)
1 change: 0 additions & 1 deletion src/drivers/zwo_asi/zwo_asi_driver.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@ class ZWO_ASI_Driver : public Driver
{
Q_OBJECT
public:
DECLARE_DRIVER_PLUGIN
ZWO_ASI_Driver();
~ZWO_ASI_Driver();
virtual Driver::Cameras cameras() const;
Expand Down