From faec000453efdaf9f2e6346893a1ed4522d83841 Mon Sep 17 00:00:00 2001
From: am0ebe <am0ebe@gmx.de>
Date: Fri, 5 Jul 2024 15:02:10 +0200
Subject: [PATCH] compiles but not tested. version bump 0.3

---
 src/cam.cpp           | 45 +++++++++++++++++++++++++++++++------------
 src/cam.h             | 10 ++++++++--
 src/cmd/console.cpp   |  2 +-
 src/cmd/main.cpp      |  1 -
 src/core.cpp          | 13 ++++---------
 src/core.h            | 16 +++++----------
 src/frameobserver.cpp |  3 ++-
 src/record.cpp        | 13 +------------
 src/record.h          |  6 +++---
 src/typeDefinitions.h |  1 +
 src/utils.cpp         | 18 +++++++++++++----
 src/utils.h           |  3 ++-
 12 files changed, 74 insertions(+), 57 deletions(-)

diff --git a/src/cam.cpp b/src/cam.cpp
index b07e6a0..77cf278 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 dda6732..2bccae9 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 ae25116..b5d4b0d 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 73bb88c..7eff117 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 062f83f..359cced 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 0e24e36..66ac205 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 613b5c4..c74b346 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 1cc4ec2..fe367bb 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 9d9fd95..65e56f4 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 cdd192e..e0c92fb 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 f97ab78..16e13c8 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 b032525..bf59a66 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='|';
 
-- 
GitLab