Supporters update.
[dcpomatic.git] / src / lib / cross.h
1 /*
2     Copyright (C) 2012-2020 Carl Hetherington <cth@carlh.net>
3
4     This file is part of DCP-o-matic.
5
6     DCP-o-matic 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 2 of the License, or
9     (at your option) any later version.
10
11     DCP-o-matic 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.
15
16     You should have received a copy of the GNU General Public License
17     along with DCP-o-matic.  If not, see <http://www.gnu.org/licenses/>.
18
19 */
20
21 /** @file  src/lib/cross.h
22  *  @brief Cross-platform compatibility code.
23  */
24
25 #ifndef DCPOMATIC_CROSS_H
26 #define DCPOMATIC_CROSS_H
27
28 #ifdef DCPOMATIC_OSX
29 #include <IOKit/pwr_mgt/IOPMLib.h>
30 #endif
31 #include <boost/filesystem.hpp>
32 /* windows.h defines this but we want to use it */
33 #undef ERROR
34 #include <boost/thread/mutex.hpp>
35 #include <boost/optional.hpp>
36
37 #ifdef DCPOMATIC_WINDOWS
38 #define WEXITSTATUS(w) (w)
39 #endif
40
41 class Log;
42 struct AVIOContext;
43
44 extern void dcpomatic_sleep_seconds (int);
45 extern void dcpomatic_sleep_milliseconds (int);
46 extern std::string cpu_info ();
47 extern void run_ffprobe(boost::filesystem::path content, boost::filesystem::path out, bool err = true, std::string args = {});
48 extern std::list<std::pair<std::string, std::string>> mount_info ();
49 extern boost::filesystem::path openssl_path ();
50 extern void make_foreground_application ();
51 #ifdef DCPOMATIC_DISK
52 extern boost::filesystem::path disk_writer_path ();
53 #endif
54 #ifdef DCPOMATIC_WINDOWS
55 extern void maybe_open_console ();
56 #endif
57 extern boost::filesystem::path resources_path ();
58 extern boost::filesystem::path libdcp_resources_path ();
59 extern void start_batch_converter ();
60 extern void start_player ();
61 extern uint64_t thread_id ();
62 extern int avio_open_boost (AVIOContext** s, boost::filesystem::path file, int flags);
63 extern boost::filesystem::path home_directory ();
64 extern bool running_32_on_64 ();
65 extern void unprivileged ();
66 extern boost::filesystem::path config_path (boost::optional<std::string> version);
67 extern boost::filesystem::path directory_containing_executable ();
68 extern bool show_in_file_manager (boost::filesystem::path dir, boost::filesystem::path select);
69 namespace dcpomatic {
70         std::string get_process_id ();
71 }
72
73
74 /** @class Waker
75  *  @brief A class which tries to keep the computer awake on various operating systems.
76  *
77  *  Create a Waker to prevent sleep, and call nudge() every so often (every minute or so).
78  *  Destroy the Waker to allow sleep again.
79  */
80 class Waker
81 {
82 public:
83         Waker ();
84         ~Waker ();
85
86         void nudge ();
87
88 private:
89         boost::mutex _mutex;
90 #ifdef DCPOMATIC_OSX
91         IOPMAssertionID _assertion_id;
92 #endif
93 };
94
95 class Drive
96 {
97 public:
98         Drive (std::string device, std::vector<boost::filesystem::path> mount_points, uint64_t size, boost::optional<std::string> vendor, boost::optional<std::string> model)
99                 : _device(device)
100                 , _mount_points(mount_points)
101                 , _size(size)
102                 , _vendor(vendor)
103                 , _model(model)
104         {}
105
106         explicit Drive (std::string);
107
108         std::string as_xml () const;
109
110         std::string description () const;
111
112         std::string device () const {
113                 return _device;
114         }
115
116         bool mounted () const {
117                 return !_mount_points.empty();
118         }
119
120         std::string log_summary () const;
121
122         /** Unmount any mounted partitions on a drive.
123          *  @return true on success, false on failure.
124          */
125         bool unmount ();
126
127         static std::vector<Drive> get ();
128
129 private:
130         std::string _device;
131         std::vector<boost::filesystem::path> _mount_points;
132         /** size in bytes */
133         uint64_t _size;
134         boost::optional<std::string> _vendor;
135         boost::optional<std::string> _model;
136 };
137
138 void disk_write_finished ();
139
140
141 struct OSXMediaPath
142 {
143         bool real; ///< true for a "real" disk, false for a synthesized APFS one
144         std::vector<std::string> parts; ///< parts of the media path after the :
145 };
146
147
148 struct OSXDisk
149 {
150         std::string device;
151         boost::optional<std::string> vendor;
152         boost::optional<std::string> model;
153         OSXMediaPath media_path;
154         bool whole;
155         std::vector<boost::filesystem::path> mount_points;
156         unsigned long size;
157 };
158
159
160 boost::optional<OSXMediaPath> analyse_osx_media_path (std::string path);
161 std::vector<Drive> osx_disks_to_drives (std::vector<OSXDisk> disks);
162
163
164 class ArgFixer
165 {
166 public:
167         ArgFixer(int argc, char** argv);
168
169         int argc() const {
170                 return _argc;
171         }
172
173         char** argv() const {
174                  return _argv;
175         }
176
177 private:
178         int _argc;
179         char** _argv;
180 #ifdef DCPOMATIC_WINDOWS
181         std::vector<std::string> _argv_strings;
182 #endif
183
184 };
185
186
187 #endif