Commit adf77fc7 authored by Arnaud Blanchard's avatar Arnaud Blanchard

Toward C++17 impementation

parent 15e91361
# Set the minimum version of cmake required to build this project
cmake_minimum_required(VERSION 3.3)
cmake_minimum_required(VERSION 2.6)
project(gtk_channels)
#set(CMAKE_CXX_INCLUDE_WHAT_YOU_USE "/usr/local/Cellar/include-what-you-use/0.12/bin/include-what-you-use;-Xiwyu;--verbose=3;")
find_package(blc_channel REQUIRED)
find_package(blc_image REQUIRED)
find_package(blc_image REQUIRED) #Used to detect image format in channels
find_package(blc_program REQUIRED)
find_package(blc_process REQUIRED)
find_package(PkgConfig REQUIRED)
pkg_check_modules(GTK3 REQUIRED gtk+-3.0)
pkg_check_modules(GTK3_SOURCE_VIEW REQUIRED gtksourceview-4)
#pkg_check_modules(GTK3 gtk+-3.0 REQUIRED)
pkg_check_modules(GTKMM gtkmm-3.0 REQUIRED)
pkg_check_modules(VTE3 vte-2.91 REQUIRED) #libvtemm is not yet common
#pkg_check_modules(GTKMMPLPLOT REQUIRED gtkmm-plplot-2.0)
pkg_check_modules(VTE3 vte-2.91 REQUIRED) #libvtemm is not yet common and stable we
add_definitions(-std=c++14 ${BL_DEFINITIONS} ${GTK3_CFLAGS_OTHER} )
include_directories(${BL_INCLUDE_DIRS} ${GTK3_INCLUDE_DIRS} ${GTK3_SOURCE_VIEW_INCLUDE_DIRS} ${VTE_INCLUDE_DIRS} ${GTKMM_INCLUDE_DIRS} ${VTE3_INCLUDE_DIRS})
link_directories(${GTK3_LIBRARY_DIRS} ${VTE_LIBRARY_DIRS} /usr/local/lib)
add_executable(gtk_channels gtk_channels.cpp ChannelWidget.cpp ContextMenu.cpp ChannelColumns.cpp Process.cpp parse_help.cpp)
target_link_libraries(gtk_channels ${BL_LIBRARIES} ${GTK3_LIBRARIES} ${GTK3_SOURCE_VIEW_LIBRARIES} ${VTE_LIBRARIES} ${GTKMM_LIBRARIES} ${VTE3_LIBRARIES})
add_definitions(-std=c++17 -pedantic ${BL_DEFINITIONS})
include_directories(${BL_INCLUDE_DIRS} ${GTKMM_INCLUDE_DIRS} ${VTE3_INCLUDE_DIRS})
link_directories(${GTKMM_LIBRARY_DIRS} ${VTE3_LIBRARY_DIRS})
add_executable(gtk_channels gtk_channels.cpp ChannelWidget.cpp ContextMenu.cpp ChannelColumns.cpp Command.cpp Process.cpp parse_help.cpp)
target_link_libraries(gtk_channels ${BL_LIBRARIES} ${GTKMM_LIBRARIES} ${VTE3_LIBRARIES})
This diff is collapsed.
......@@ -12,11 +12,13 @@
#include <gtkmm.h>
#include <string>
#include <deque>
#include <set>
#include "blc_channel.h"
#include "ChannelColumns.hpp"
#include "ContextMenu.hpp"
#include "Command.hpp"
#include <unordered_map>
#include <map>
struct ChannelWidget:Gtk::TreeView{
blc_channel* channels; //This structure is coherent with blc_channel implementation
......@@ -24,13 +26,16 @@ struct ChannelWidget:Gtk::TreeView{
Gtk::CellRendererPixbuf terminal_cell_renderer, play_pause_cell_renderer, stop_cell_renderer;
Glib::RefPtr<Gtk::TreeStore> tree_store;
int channels_nb;
std::string program_dir;
std::string bin_dir;
std::map<std::string, Command> commands;
std::vector<Command> used_commands;
static ChannelColumns columns;
ChannelWidget();
blc_channel *find_channel(int id);
ContextMenu *create_menu();
void create_and_execute_command(std::string program_name, std::initializer_list<const char*> const optional_arguments);
void display_process(Gtk::TreeModel::Row &row);
void refresh_channel_list();
......
//
// Command.cpp
// gtk_channels
//
// Created by Arnaud Blanchard on 21/10/2019.
//
#include "Command.hpp"
#include <numeric> //accumulate
using namespace std;
Command::Command(string const &bin_dir, string program_name, initializer_list<char const*> default_args, function<bool(vector<blc_channel const*>)>valid_channels):binary(bin_dir+"/"+program_name), program_name(move(program_name)), valid_channels(valid_channels){
args.emplace_back(binary.data());
args.insert(args.end(), default_args);
}
Command::Command(Command const &command, vector<blc_channel const*> const channels){
*this=command;
args.reserve(args.size()+channels.size()+1);
for (auto const &channel:channels){
args.emplace_back(channel->name);
}
args.emplace_back(nullptr);
}
void Command::add_args(initializer_list<char const *> optional_args){
args.insert(args.end(), optional_args);
}
unique_ptr<Process> Command::execute(function<void(Process*)> after_launch) const{
/* for (auto &channel:channels){
process_args.emplace_back(channel->name);
}*/
}
//
// Command.hpp
// gtk_channels
//
// Created by Arnaud Blanchard on 21/10/2019.
//
#ifndef Command_hpp
#define Command_hpp
#include <string>
#include <vector>
#include "Process.h"
#include "blc_channel.h"
/* One command may have many processes */
struct Command{
std::string binary;
std::string program_name;
std::function<bool(std::vector<blc_channel const*> &channels)> valid_channels;
std::vector<const char *> args;
Command(std::string const &bin_dir, std::string program_name, std::initializer_list<char const*> default_args, std::function<bool(std::vector<blc_channel const*>)>validity);
Command(Command const &command, std::vector<blc_channel const*> const channel); //Copy command and add arguments
void add_args(std::initializer_list<char const *> optional_args);
std::unique_ptr<Process> execute(std::function<void(Process*)> after_launch) const;
};
#endif /* Command_hpp */
......@@ -4,15 +4,11 @@
//
// Created by Arnaud Blanchard on 13/10/2019.
//
#include "ChannelWidget.hpp"
#include "blc_image.h"
#include "ContextMenu.hpp"
using namespace Gtk;
using namespace std;
ContextMenu::ContextMenu(string program_dir):program_dir(move(program_dir)){}
void ContextMenu::add_item(string name, bool shortcut, function <void()> action){
MenuItem *item=new MenuItem(name, shortcut);
append(*item);
......@@ -23,7 +19,7 @@ void ContextMenu::add_separator(){
SeparatorMenuItem *separator_item = new SeparatorMenuItem();
append(*separator_item);
}
/*
void ContextMenu::add_program(char const *menu_name, std::string program_name, initializer_list<const char*> const optional_arguments, function <void(Process *process)> after_launch){
auto item=new MenuItem(menu_name);
auto args_vec=make_shared<vector<const char*>>(optional_arguments); //This will be destroyed by process
......@@ -37,4 +33,4 @@ void ContextMenu::add_program(char const *menu_name, std::string program_name, i
auto process = new Process(program_dir, program_name, args_vec);
process->run(after_launch);
});
}
}*/
......@@ -14,19 +14,13 @@
#include <string>
#include <vector>
#include "Process.h"
struct ContextMenu:Gtk::Menu{
std::string program_dir;
std::vector<blc_channel*> selected_channels;
Glib::RefPtr<Gtk::TreeSelection> row_selection;
ContextMenu(std::string program_dir);
void after_launch(Process *process);
void add_item(std::string name, bool shortcut, std::function<void ()>action);
void add_separator();
void add_program(char const *menu_name, std::string program_name, std::initializer_list<const char*> const optional_args, std::function <void(Process*)> after_launch);
// void add_program(char const *menu_name, std::string program_name, std::initializer_list<const char*> const optional_args, std::function <void(Process*)> after_launch);
};
#endif /* ContextMenu_hpp */
......@@ -6,16 +6,11 @@
//
//
#include "Process.h"
#include "blc_core.h"
#include <errno.h>
#include <unistd.h> //execve
#include <thread>
#include <vte/vte.h>
#include <sys/pipe.h>
#include <gtkmm.h>
#include <signal.h>
using namespace std;
using namespace Gtk;
......@@ -35,6 +30,7 @@ static void TerminalSpawnAsyncCallback (VteTerminal *terminal, GPid pid, GError
fprintf(stderr, "%s ", arg);
}
fprintf(stderr, "\n");
process->status=Process::running;
process->after_launch(process);
}
};
......@@ -50,26 +46,15 @@ void Process::on_quit(function<void(int exit_status)> on_quit){
g_signal_connect(G_OBJECT(terminal), "child-exited", G_CALLBACK(after_exectution) , this);
}
Process::Process(string const directory, string const program, shared_ptr<vector<const char*>> const optional_arguments):directory(move(directory)),program_name(move(program)){
command_path=directory+"/"+program;
arg_vector.emplace_back(command_path.data());
Process::Process(char const * const *argv, function<void(Process *)>after_launch){
this->after_launch=after_launch;
terminal=VTE_TERMINAL(vte_terminal_new());
vte_terminal_spawn_async(terminal, VTE_PTY_DEFAULT , nullptr, (char**)argv, nullptr, G_SPAWN_DEFAULT, nullptr, nullptr, nullptr, 1000, nullptr, TerminalSpawnAsyncCallback, (void*)this);
for( auto &arg : *optional_arguments){
arg_vector.emplace_back(arg);
}
};
Process::~Process(){
for (char const *&arg: arg_vector ){
free(&arg);
}
};
void Process::run(function <void(Process *process)> after_launch){
this->after_launch=after_launch;
terminal=VTE_TERMINAL(vte_terminal_new());
arg_vector.emplace_back(nullptr); //note the end of the list
void Process::run(){
vte_terminal_spawn_async(terminal, VTE_PTY_DEFAULT , nullptr, (char**)arg_vector.data(), nullptr, G_SPAWN_DEFAULT, nullptr, nullptr, nullptr, 1000, nullptr, TerminalSpawnAsyncCallback, (void*)this);
}
......@@ -87,6 +72,19 @@ void Process::display_terminal(){
terminal_window->show_all();
}
void Process::stop(){
signal(SIGTERM);
status=stopped;
};
void Process::pause(){
signal(SIGTSTP);
status=paused;
};
void Process::cont(){
signal(SIGCONT);
status=running;
};
void Process::signal(int signal) const{
kill(pid, signal);
}
......@@ -16,8 +16,8 @@
#include <vte/vte.h>
struct Process{
enum Status{paused, stopped, running} status=stopped;
pid_t pid;
std::string name;
std::string directory;
std::string program_name;
......@@ -28,11 +28,16 @@ struct Process{
std::function<void(Process *)> after_launch;
std::function<void(int exit_status)> on_quit_callback;
Process(std::string const directory, std::string const program_name, std::shared_ptr<std::vector<const char*>> const optional_arguments={});
~Process();
Process(char const* const* argv, std::function<void(Process*)> on_launch);
void run(std::function<void(Process*)> on_launch);
void run();
void stop();
void pause();
void cont();
void display_terminal();
void on_quit(std::function<void(int exit_status)> on_quit);
void signal(int signal) const;
......
#include "ChannelWidget.hpp"
#include "blc_program.h"
#include "libgen.h"
#include <gtkmm.h>
#include "ChannelWidget.hpp"
#include "thread"
using namespace std;
using namespace Gtk;
......@@ -16,11 +13,10 @@ struct App:Application{
//Overrides of default signal handlers:
void on_startup() override; //This is called for the first instance of the app
void on_activate() override;
void on_activate() override; //This is called a new instance of the app is called (i.e already existing)
};
App::App(int &argc, char **&argv):Application(argc, argv){
}
App::App(int &argc, char **&argv):Application(argc, argv){}
void App::on_startup(){
Application::on_startup();
......@@ -30,7 +26,6 @@ void App::on_startup(){
}
void App::on_activate(){
Application::on_activate();
add_window(main_window);
main_window.add(channel_widget);
......@@ -39,7 +34,7 @@ void App::on_activate(){
int main(int argc, char **argv)
{
App app(argc, argv); //AArgc argv allow to interpret option --g-fatal-warnings for debugging
App app(argc, argv); //Argc argv allow to interpret option --g-fatal-warnings for debugging
blc_program_set_description("Graphical interface for blaar programs");
blc_program_init(&argc, &argv, blc_quit);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment