diff --git a/src/cam.cpp b/src/cam.cpp index b07e6a0a0623b4c87cb03704822fd57f93a94367..77cf2780176d93e67d98e788e4ae24c790af8e26 100644 --- a/src/cam.cpp +++ b/src/cam.cpp @@ -26,26 +26,47 @@ _state(disconnected), _rec(/*Dflt Ctor*/) {} -Cam::Cam(const Cam& other) : IPrinter(), -_cam(other._cam), -_name(other._name), -_ip(other._ip), -_id(other._id), -_state(other._state) -{ - //careful of changing member vars of a copy only! - qDebug() << __LINE__ << "-" << __PRETTY_FUNCTION__ << "copy constructor"; -} +// Cam::Cam(const Cam& other) : IPrinter(), std::enable_shared_from_this<Cam>(other) +// _cam(other._cam), +// _name(other._name), +// _ip(other._ip), +// _id(other._id), +// _state(other._state)Cam::Cam(const Cam& other) : IPrinter(), std::enable_shared_from_this<Cam>(other) +// _cam(other._cam), +// _name(other._name), +// _ip(other._ip), +// _id(other._id), +// _state(other._state) +// { +// //careful of changing member vars of a copy only! +// qDebug() << __LINE__ << "-" << __PRETTY_FUNCTION__ << "copy constructor"; +// } + +// // Copy assignment operator +// Cam& operator=(const Cam& other) { +// if (this != &other) { +// // Copy other member variables here if necessary + +// // Explicitly initialize base class +// std::enable_shared_from_this<Cam>::operator=(other); +// } +// return *this; +// } Cam::~Cam() { qDebug() << __FUNCTION__ << "():" << __LINE__ << "id:" << _id << ", usecount:" << _cam.use_count(); if( _state == recording ) - stopRecording(); + rec()->stop(); // close() should be called automatically, when the last shared_ptr to the camera is destroyed } +RecordPtr Cam::rec() const +{ + return _rec; +} + QString Cam::name() const { return _name; @@ -191,7 +212,7 @@ QString Cam::camInfo() camInfo += stateToString(_state); if( _state == recording) - _rec->progressBar(); + _rec->showProgress(); } catch(const std::exception& e) diff --git a/src/cam.h b/src/cam.h index dda6732d6e93a8b7dc16d3af745758f95ecf4a42..2bccae96f9159a57adabfdee64d12f1779061f9d 100644 --- a/src/cam.h +++ b/src/cam.h @@ -17,14 +17,20 @@ public: // const QString& name, const int& nThreads Cam(QString name, QString ip); - Cam(const Cam&); + // Cam(const Cam&); + // Cam& operator=(const Cam& other); // Cam(CameraPtr pCamera); + + // Delete copy constructor and assignment operator + Cam(const Cam&) = delete; + Cam& operator=(const Cam&) = delete; + ~Cam(); QString id(); QString name() const; QString ip() const; - RecordPtr rec(); + RecordPtr rec() const; State state() const; void setState(const State&); diff --git a/src/cmd/console.cpp b/src/cmd/console.cpp index ae25116a450b9653e98b5be69c84dcadf9d72215..b5d4b0d1de695a19d2e87cb9a92c53e3731f3d24 100644 --- a/src/cmd/console.cpp +++ b/src/cmd/console.cpp @@ -214,7 +214,7 @@ void Controller::onNumberEntered(int number) if( getDur ) { - emit setDuration(number); + utils::recDuration((seconds)number); getDur = false; } else diff --git a/src/cmd/main.cpp b/src/cmd/main.cpp index 73bb88c30ec63ed6b391e0b2307fa97a6d9269fa..7eff11745fb46901f966deb0cd33bc351d585eb5 100644 --- a/src/cmd/main.cpp +++ b/src/cmd/main.cpp @@ -48,7 +48,6 @@ int main(int argc, char *argv[]) QObject::connect(&controller, &Controller::startRecording, &core, &Core::startRecording); QObject::connect(&controller, &Controller::stopRecording, &core, &Core::stopRecording); QObject::connect(&controller, &Controller::showRecordingStats, &core, &Core::showRecordingStats); - QObject::connect(&controller, &Controller::setDuration, &core, &Core::setDuration); QObject::connect(&controller, &Controller::loadSettings, &core, &Core::loadSettings); QObject::connect(&controller, &Controller::saveSettings, &core, &Core::saveSettings); // XXX add new func diff --git a/src/core.cpp b/src/core.cpp index 062f83fbbff274d26f8cbefba10a0358a09e9be7..359ccedd4b267f762a8737c98a8c633b95c40285 100644 --- a/src/core.cpp +++ b/src/core.cpp @@ -1,8 +1,9 @@ #include "core.h" #include "camobserver.h" #include "utils.h" +#include "cam.h" +#include "record.h" -#include <chrono> #include <iostream> #include <list> #include <vector> @@ -22,7 +23,6 @@ using namespace VmbCPP; Core::Core() : IPrinter(), _sys( VmbSystem::GetInstance() ), // create and get Vimba singleton - _recDuration( 6s ), //default _camObserver( new CamObserver ) { QTimer::singleShot(0, this, SLOT(init())); //delayed init to allow connections to be established -> print/error signals! @@ -41,7 +41,7 @@ void Core::init() //parse config file QList<QPair<QString, QString>> parsedCameras; - if( ! utils::parseConfig(parsedCameras, _recDuration) ) + if( ! utils::parseConfig(parsedCameras) ) { utils::running = false; qApp->quit(); @@ -161,7 +161,7 @@ void Core::startRecording() if( ! cam()->rec() ) return error(utils::errRecordInvalid); - cam()->rec()->start( _recDuration ); + cam()->rec()->start( utils::recDuration() ); } void Core::stopRecording() @@ -181,11 +181,6 @@ void Core::showRecordingStats() cam()->rec()->showStats(); } -void Core::setDuration(int dur) -{ - _recDuration = seconds(dur); -} - void Core::loadSettings() { if( cam() ) diff --git a/src/core.h b/src/core.h index 0e24e36255dfd60bd0c3272fab596ef4d22e3e8b..66ac20544904eb034dc4391bb8a5e3dfcb600dea 100644 --- a/src/core.h +++ b/src/core.h @@ -1,20 +1,16 @@ #pragma once -#include "VmbCPP/VmbCPPCommon.h" -#include "cam.h" -#include "camobserver.h" +#include "typeDefinitions.h" #include "iprinter.h" -#include <QObject> - #include <VmbCPP/Interface.h> -#include <chrono> -namespace VmbCPP { class VmbSystem; } +namespace VmbCPP { + class VmbSystem; + class CamObserver; +} using VmbCPP::VmbSystem; using VmbCPP::CamObserver; -using VmbCPP::UpdateTriggerType; -using std::chrono::seconds; class Core : public IPrinter { @@ -40,7 +36,6 @@ public slots: void startRecording(); void stopRecording(); void showRecordingStats(); - void setDuration(int); private slots: void init(); @@ -49,7 +44,6 @@ private: VmbSystem& _sys; CamPtrVector _cameras; - seconds _recDuration; CamObserver* _camObserver; }; diff --git a/src/frameobserver.cpp b/src/frameobserver.cpp index 613b5c490881c0df2b0c0c933c4c4ee974a115e9..c74b34679085b9fc5a54d4c6197e3ea11a44d633 100644 --- a/src/frameobserver.cpp +++ b/src/frameobserver.cpp @@ -1,6 +1,7 @@ #include "frameobserver.h" #include "frameprocessor.h" #include "cam.h" +#include "record.h" #include <VmbCPP/SharedPointerDefines.h> #include <VmbCPP/Camera.h> @@ -15,7 +16,7 @@ using namespace VmbCPP; FrameObserver::FrameObserver( CamPtr cam ) : IFrameObserver( cam->getCameraPtr() ), _cam(cam), - _processor(new FrameProcessor(cam->outDir())), + _processor(new FrameProcessor(cam->rec()->dir())), _pool(QThreadPool::globalInstance()) { // _pool->setMaxThreadCount(QThread::idealThreadCount()); //dflt diff --git a/src/record.cpp b/src/record.cpp index 1cc4ec206a116eeeda3979e0ed1ff6e27df22b61..fe367bb7754c22ed3aa759fbdc0e241e557c86ae 100644 --- a/src/record.cpp +++ b/src/record.cpp @@ -49,22 +49,11 @@ bool Record::checkDirExists() return false; } - checkDiskSpace(); - + checkDiskSpace(utils::outDir(), duration_cast<seconds>(_timer->intervalAsDuration())); info("writing frames to: " + _dir); return true; } -void Record::checkDiskSpace() -{ - //TODO - //check disk space - - //calculate disk space needed - //check if enough space - //if not, stop recording -} - /* Does: get Payloadsize get Pixelformat - eg RGB8 diff --git a/src/record.h b/src/record.h index 9d9fd952e2df754e21c88c2d5ddb9fc126332da5..65e56f403dec28e70078340ce662c908ce3793fb 100644 --- a/src/record.h +++ b/src/record.h @@ -26,9 +26,9 @@ public: void checkDiskSpace(const QString &, seconds); - operator bool() const { - return _cam != nullptr; - } + operator bool() const { return _cam != nullptr; } + + QString dir() const { return _dir; } public slots: void stop(); diff --git a/src/typeDefinitions.h b/src/typeDefinitions.h index cdd192e2dbfab8b07471e0384d66bd1c4ca9528b..e0c92fb6ff012c5de5d6a9c397aa87c1b2c26f54 100644 --- a/src/typeDefinitions.h +++ b/src/typeDefinitions.h @@ -4,6 +4,7 @@ #include <vector> #include <memory> //shared_ptr + #include <QObject> #include <QString> diff --git a/src/utils.cpp b/src/utils.cpp index f97ab783e969e92e2c7ed9486b55af53e9b9147a..16e13c8be2099f62bac20939f037c8d1c9d35d97 100644 --- a/src/utils.cpp +++ b/src/utils.cpp @@ -25,7 +25,7 @@ namespace utils { const int APP_VERSION_MAJOR = 0; -const int APP_VERSION_MINOR = 2; +const int APP_VERSION_MINOR = 3; const int APP_VERSION_PATCH = 0; std::atomic<bool> running(true); @@ -118,7 +118,7 @@ const QString errorCodeToMessage( VmbError_t err ) return msg; } -bool parseConfig(QList<QPair<QString,QString>>& parsedCameras, seconds& recDuration) +bool parseConfig(QList<QPair<QString,QString>>& parsedCameras) { qDebug() << "open " << configFile(); QFile file(configFile()); @@ -154,7 +154,8 @@ bool parseConfig(QList<QPair<QString,QString>>& parsedCameras, seconds& recDurat return false; } - recDuration = jsonObject["recordDurationInSeconds"].toInt() * 1s; //convert to s + // *1s == convert to s + recDuration(jsonObject["recordDurationInSeconds"].toInt() * 1s); //set global // Parse outDir if (!jsonObject.contains("outDir") || !jsonObject["outDir"].isString()) @@ -190,7 +191,7 @@ bool parseConfig(QList<QPair<QString,QString>>& parsedCameras, seconds& recDurat } ncam(parsedCameras.size()); //set global - qDebug() << "parsed recDuration:" << recDuration.count(); + qDebug() << "parsed recDuration:" << recDuration().count(); qDebug() << "parsed outDir:" << outDir(); qDebug() << "threads per cam:" << threadsPerCam(); @@ -212,6 +213,15 @@ QString outDir(QString dirname) return _outDir; } +seconds recDuration(seconds dur) +{ + static seconds _recDuration; + if( dur != 0s ) + _recDuration = dur; + + return _recDuration == 0s ? 10s : _recDuration; +} + // needed to find cams via ip QString configFile(QString filename) { diff --git a/src/utils.h b/src/utils.h index b03252542660b8a120548bfee92919a20497a377..bf59a6681e6098f8638c322c2890d82b7e1d4b24 100644 --- a/src/utils.h +++ b/src/utils.h @@ -17,7 +17,7 @@ using namespace std::chrono_literals; namespace utils { -bool parseConfig(QList<QPair<QString,QString>>&, seconds&); +bool parseConfig(QList<QPair<QString,QString>>&); QString configFile(QString filename=""); QString settingsFile(QString filename=""); QString outDir(QString dirname=""); @@ -35,6 +35,7 @@ const QString errorCodeToMessage( VmbError_t ); extern std::atomic<bool> running; //global flag to ensure proper exit of threads int threadsPerCam(); int ncam(const int& n=0); +seconds recDuration(seconds duration=0s); const QChar DELIM='|';