#1 Add some READMEs, add logger class, rearrange to use Core class

This commit is contained in:
James Hodgson
2022-06-05 18:56:43 +01:00
parent c4dc2f22ec
commit 06122376b4
20 changed files with 184 additions and 30 deletions

View File

@@ -1,7 +1,11 @@
cmake_minimum_required(VERSION 3.10) cmake_minimum_required(VERSION 3.10)
set(CMAKE_CXX_STANDARD 17) set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CXX_CLANG_TIDY clang-tidy -checks=-*,bugprone-*,concurrency-*,cppcoreguidelines-*,modernize-*,performance-*,readability-*,) set(
CMAKE_CXX_CLANG_TIDY
clang-tidy
-checks=-*,bugprone-*,concurrency-*,cppcoreguidelines-*,modernize-*,performance-*,readability-*,-modernize-use-trailing-return-type
)
project(JAMCS) project(JAMCS)

View File

@@ -1,3 +1,4 @@
add_subdirectory(logger)
add_subdirectory(ui) add_subdirectory(ui)
add_executable( add_executable(
@@ -9,6 +10,7 @@ target_link_libraries(
JAMCS JAMCS
PRIVATE PRIVATE
UI UI
Logger
) )
add_definitions (${GTK_CFLAGS_OTHER}) add_definitions (${GTK_CFLAGS_OTHER})

17
src/README.md Normal file
View File

@@ -0,0 +1,17 @@
## JAMCS
JAMCS is separated into components which take care of individual functions of the JAMCS software:
- Core
- Core object which holds references to the different components, used to talk between components
- UI
- Sets up the UI for display on the camera, i.e. viewfinder, gallery
- Camera
- Handles connecting to and controlling the physical camera device
- Processing
- Handles the images once a picture has been taken:
- Applies any image effects
- Saves the image to disk
- Uploads the image to a cloud service
- Web UI
- Runs the Web UI for JAMCS, allowing the entire app to be controlled remotely
- Logger
- Handles logging output to the console or a file

17
src/core/core.h Normal file
View File

@@ -0,0 +1,17 @@
// Header only core which has references to the instances of classes
#ifndef _CORE_H
#define _CORE_H
#include <gtkmm.h>
#include <memory>
#include "../logger/logger.h"
class Core
{
public:
Glib::RefPtr<Gtk::Application> app;
std::unique_ptr<Logger> logger;
};
#endif // _CORE_H

View File

@@ -0,0 +1,5 @@
add_library(
Logger
STATIC
logger.cpp
)

43
src/logger/logger.cpp Normal file
View File

@@ -0,0 +1,43 @@
#include "logger.h"
#include <iostream>
Logger::Logger(LogLevel logLevel)
{
this->SetLogLevel(logLevel);
}
void Logger::SetLogLevel(LogLevel logLevel)
{
this->level = logLevel;
}
void Logger::Log(std::wstring msg, LogLevel msgLevel)
{
// Check if the log level matches
if (msgLevel <= this->level)
{
// For now just print
std::wcout << msgLevel << L" : " << msg << std::endl;
}
}
void Logger::Debug(std::wstring msg)
{
this->Log(msg, LogLevel::DEBUG);
}
void Logger::Info(std::wstring msg)
{
this->Log(msg, LogLevel::INFO);
}
void Logger::Error(std::wstring msg)
{
this->Log(msg, LogLevel::ERROR);
}
void Logger::Critical(std::wstring msg)
{
this->Log(msg, LogLevel::CRITICAL);
}

29
src/logger/logger.h Normal file
View File

@@ -0,0 +1,29 @@
#ifndef _LOGGER_H
#define _LOGGER_H
#include <string>
enum LogLevel
{
DEBUG,
INFO,
ERROR,
CRITICAL
};
class Logger
{
private:
LogLevel level;
void Log(std::wstring msg, LogLevel msgLevel);
public:
Logger(LogLevel logLevel = LogLevel::INFO);
void SetLogLevel(LogLevel logLevel);
void Debug(std::wstring msg);
void Info(std::wstring msg);
void Error(std::wstring msg);
void Critical(std::wstring msg);
};
#endif // _LOGGER_H

View File

@@ -1,6 +1,8 @@
#include <gtkmm.h> #include <gtkmm.h>
#include <iostream> #include <iostream>
#include "core/core.h"
#include "logger/logger.h"
#include "ui/jamcswindow.h" #include "ui/jamcswindow.h"
// Default size for JAMCS window // Default size for JAMCS window
@@ -10,10 +12,17 @@ const static int DEFAULT_WINDOW_HEIGHT = 480;
int main(int argc, char* argv[]) int main(int argc, char* argv[])
{ {
auto app = Gtk::Application::create("org.gtkmm.examples.base"); auto core = std::make_shared<Core>(Core());
core->logger = std::make_unique<Logger>(Logger());
JamcsWindow window(app, "JAMCS", DEFAULT_WINDOW_WIDTH, DEFAULT_WINDOW_HEIGHT); core->logger->Info(L"Starting JAMCS");
// Create camera object and pass to core
core->app = Gtk::Application::create("org.gtkmm.examples.base");
JamcsWindow window(core, "JAMCS", DEFAULT_WINDOW_WIDTH, DEFAULT_WINDOW_HEIGHT);
window.show_all(); window.show_all();
return app->run(window); return core->app->run(window);
} }

View File

@@ -1,13 +1,14 @@
add_subdirectory(common) add_subdirectory(common)
add_subdirectory(viewfinder)
add_library( add_library(
UI UI
STATIC STATIC
jamcswindow.cpp jamcswindow.cpp
viewfinder.cpp
) )
target_link_libraries( target_link_libraries(
UI UI
PUBLIC PUBLIC
CommonUI CommonUI
Viewfinder
) )

2
src/ui/README.md Normal file
View File

@@ -0,0 +1,2 @@
## UI
This directory contains the code defining the camera UI.

2
src/ui/common/README.md Normal file
View File

@@ -0,0 +1,2 @@
## Common
Common UI elements used across multiple screens

View File

@@ -2,7 +2,7 @@
#include <gtkmm.h> #include <gtkmm.h>
CloseButton::CloseButton(const Glib::ustring &label, Glib::RefPtr<Gtk::Application> appPtr) : app(appPtr) CloseButton::CloseButton(std::shared_ptr<Core> appCore, const Glib::ustring &label) : core(appCore)
{ {
set_label(label); set_label(label);
@@ -11,5 +11,5 @@ CloseButton::CloseButton(const Glib::ustring &label, Glib::RefPtr<Gtk::Applicati
void CloseButton::on_button_clicked() void CloseButton::on_button_clicked()
{ {
this->app.get()->quit(); this->core->app.get()->quit();
} }

View File

@@ -2,14 +2,17 @@
#define _CLOSEBUTTON_H #define _CLOSEBUTTON_H
#include <gtkmm.h> #include <gtkmm.h>
#include <memory>
#include "../../core/core.h"
class CloseButton : public Gtk::Button class CloseButton : public Gtk::Button
{ {
private: private:
void on_button_clicked(); void on_button_clicked();
Glib::RefPtr<Gtk::Application> app; std::shared_ptr<Core> core;
public: public:
CloseButton(const Glib::ustring &label, Glib::RefPtr<Gtk::Application> appPtr); CloseButton(std::shared_ptr<Core> appCore, const Glib::ustring &label);
}; };
#endif // _CLOSEBUTTON_H #endif // _CLOSEBUTTON_H

View File

@@ -2,17 +2,20 @@
#include <gtkmm.h> #include <gtkmm.h>
#include "viewfinder.h" #include "../core/core.h"
#include "viewfinder/viewfinder.h"
JamcsWindow::JamcsWindow(Glib::RefPtr<Gtk::Application> appPtr, const Glib::ustring &title, int width, int height) : app(appPtr) JamcsWindow::JamcsWindow(std::shared_ptr<Core> appCore, const Glib::ustring &title, int width, int height) : core(appCore)
{ {
this->core->logger->Info(L"Initializing UI");
set_title(title); set_title(title);
set_default_size(width, height); set_default_size(width, height);
this->viewfinder = std::unique_ptr<Viewfinder>(new Viewfinder(app)); this->viewfinder = std::make_unique<Viewfinder>(Viewfinder(this->core));
this->stack.add(*this->viewfinder, "viewfinder"); this->stack.add(*this->viewfinder, "viewfinder");
this->stack.set_visible_child("viewfinder"); this->stack.set_visible_child("viewfinder");
this->add(this->stack); this->add(this->stack);
} };

View File

@@ -4,16 +4,17 @@
#include <gtkmm.h> #include <gtkmm.h>
#include <memory.h> #include <memory.h>
#include "viewfinder.h" #include "../core/core.h"
#include "viewfinder/viewfinder.h"
class JamcsWindow : public Gtk::Window class JamcsWindow : public Gtk::Window
{ {
private: private:
Glib::RefPtr<Gtk::Application> app;
Gtk::Stack stack; Gtk::Stack stack;
std::shared_ptr<Core> core = nullptr;
std::unique_ptr<Viewfinder> viewfinder = nullptr; std::unique_ptr<Viewfinder> viewfinder = nullptr;
public: public:
JamcsWindow(Glib::RefPtr<Gtk::Application> appPtr, const Glib::ustring &title, int width, int height); JamcsWindow(std::shared_ptr<Core> appCore, const Glib::ustring &title, int width, int height);
}; };
#endif // _WINDOW_H #endif // _WINDOW_H

View File

@@ -1,11 +0,0 @@
#include "viewfinder.h"
#include "common/common.h"
Viewfinder::Viewfinder(Glib::RefPtr<Gtk::Application> appPtr) : app(appPtr)
{
this->close_button = std::unique_ptr<CloseButton>(new CloseButton("X", app));
this->add(*this->close_button);
this->show_all();
}

View File

@@ -0,0 +1,10 @@
add_library(
Viewfinder
STATIC
viewfinder.cpp
)
target_link_libraries(
Viewfinder
PUBLIC
CommonUI
)

View File

@@ -0,0 +1,2 @@
## Viewfinder
Main viewfinder screen used to take pictures and videos.

View File

@@ -0,0 +1,14 @@
#include "viewfinder.h"
#include <memory>
#include "../../core/core.h"
#include "../common/common.h"
Viewfinder::Viewfinder(std::shared_ptr<Core> appCore) : core(appCore)
{
this->close_button = std::unique_ptr<CloseButton>(new CloseButton(this->core, "X"));
this->add(*this->close_button);
this->show_all();
}

View File

@@ -3,15 +3,16 @@
#include <gtkmm.h> #include <gtkmm.h>
#include "common/common.h" #include "../common/common.h"
#include "../../core/core.h"
class Viewfinder : public Gtk::Box class Viewfinder : public Gtk::Box
{ {
private: private:
Glib::RefPtr<Gtk::Application> app; std::shared_ptr<Core> core;
std::unique_ptr<CloseButton> close_button = nullptr; std::unique_ptr<CloseButton> close_button = nullptr;
public: public:
Viewfinder(Glib::RefPtr<Gtk::Application> appPtr); Viewfinder(std::shared_ptr<Core> appCore);
}; };
#endif // _VIEWFINDER_H #endif // _VIEWFINDER_H