QCodeEditor: Update to current cpeditor/QCodeEditor fork, commit ed1196a
[smuview.git] / src / session.hpp
blobbb88033a49df6c73670be567bc020737c9ce5acc
1 /*
2 * This file is part of the SmuView project.
4 * Copyright (C) 2017-2021 Frank Stettner <frank-stettner@gmx.net>
6 * This program is free software: you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation, either version 3 of the License, or
9 * (at your option) any later version.
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License
17 * along with this program. If not, see <http://www.gnu.org/licenses/>.
20 #ifndef SESSION_HPP
21 #define SESSION_HPP
23 #include <list>
24 #include <map>
25 #include <memory>
26 #include <string>
28 #include <QObject>
29 #include <QSettings>
31 using std::list;
32 using std::map;
33 using std::shared_ptr;
34 using std::string;
36 namespace sigrok {
37 class Context;
40 namespace sv {
42 class DeviceManager;
43 class MainWindow;
45 namespace devices {
46 class BaseDevice;
47 class HardwareDevice;
48 class UserDevice;
51 namespace python {
52 class SmuScriptRunner;
55 class Session : public QObject
57 Q_OBJECT
59 public:
60 static shared_ptr<sigrok::Context> sr_context;
61 // TODO: use std::chrono / std::time
62 static double session_start_timestamp;
64 public:
65 explicit Session(DeviceManager &device_manager);
66 ~Session();
68 DeviceManager &device_manager();
69 const DeviceManager &device_manager() const;
71 map<string, shared_ptr<devices::BaseDevice>> device_map() const;
72 list<shared_ptr<devices::HardwareDevice>> connect_device(
73 const string &conn_string);
74 void add_device(shared_ptr<devices::BaseDevice> device);
75 shared_ptr<devices::UserDevice> add_user_device();
76 void remove_device(shared_ptr<devices::BaseDevice> device);
78 shared_ptr<python::SmuScriptRunner> smu_script_runner();
79 void run_smu_script(const string &script_file);
81 void set_main_window(MainWindow *main_window);
82 MainWindow *main_window() const;
84 private:
85 DeviceManager &device_manager_;
86 map<string, shared_ptr<devices::BaseDevice>> device_map_;
87 MainWindow *main_window_;
88 shared_ptr<python::SmuScriptRunner> smu_script_runner_;
90 void free_unused_memory();
92 private Q_SLOTS:
93 void error_handler(const std::string &sender, const std::string &msg);
95 Q_SIGNALS:
96 void device_added(shared_ptr<sv::devices::BaseDevice> device);
97 void device_removed(shared_ptr<sv::devices::BaseDevice> device);
101 } // namespace sv
103 #endif // SESSION_HPP