Missed update to private test repo version.
[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 #include <boost/thread/mutex.hpp>
33 #include <boost/optional.hpp>
34
35 #ifdef DCPOMATIC_WINDOWS
36 #define WEXITSTATUS(w) (w)
37 #endif
38
39 class Log;
40 struct AVIOContext;
41
42 extern void dcpomatic_sleep_seconds (int);
43 extern void dcpomatic_sleep_milliseconds (int);
44 extern std::string cpu_info ();
45 extern void run_ffprobe (boost::filesystem::path, boost::filesystem::path);
46 extern std::list<std::pair<std::string, std::string>> mount_info ();
47 extern boost::filesystem::path openssl_path ();
48 extern void make_foreground_application ();
49 #ifdef DCPOMATIC_DISK
50 extern boost::filesystem::path disk_writer_path ();
51 #endif
52 #ifdef DCPOMATIC_WINDOWS
53 extern void maybe_open_console ();
54 #endif
55 extern boost::filesystem::path resources_path ();
56 extern boost::filesystem::path libdcp_resources_path ();
57 extern void start_batch_converter ();
58 extern void start_player ();
59 extern uint64_t thread_id ();
60 extern int avio_open_boost (AVIOContext** s, boost::filesystem::path file, int flags);
61 extern boost::filesystem::path home_directory ();
62 extern bool running_32_on_64 ();
63 extern void unprivileged ();
64 extern boost::filesystem::path config_path (boost::optional<std::string> version);
65 extern boost::filesystem::path directory_containing_executable ();
66 extern bool show_in_file_manager (boost::filesystem::path dir, boost::filesystem::path select);
67 namespace dcpomatic {
68         std::string get_process_id ();
69 }
70
71
72 /** @class Waker
73  *  @brief A class which tries to keep the computer awake on various operating systems.
74  *
75  *  Create a Waker to prevent sleep, and call nudge() every so often (every minute or so).
76  *  Destroy the Waker to allow sleep again.
77  */
78 class Waker
79 {
80 public:
81         Waker ();
82         ~Waker ();
83
84         void nudge ();
85
86 private:
87         boost::mutex _mutex;
88 #ifdef DCPOMATIC_OSX
89         IOPMAssertionID _assertion_id;
90 #endif
91 };
92
93 class Drive
94 {
95 public:
96         Drive (std::string device, std::vector<boost::filesystem::path> mount_points, uint64_t size, boost::optional<std::string> vendor, boost::optional<std::string> model)
97                 : _device(device)
98                 , _mount_points(mount_points)
99                 , _size(size)
100                 , _vendor(vendor)
101                 , _model(model)
102         {}
103
104         explicit Drive (std::string);
105
106         std::string as_xml () const;
107
108         std::string description () const;
109
110         std::string device () const {
111                 return _device;
112         }
113
114         bool mounted () const {
115                 return !_mount_points.empty();
116         }
117
118         std::string log_summary () const;
119
120         /** Unmount any mounted partitions on a drive.
121          *  @return true on success, false on failure.
122          */
123         bool unmount ();
124
125         static std::vector<Drive> get ();
126
127 private:
128         std::string _device;
129         std::vector<boost::filesystem::path> _mount_points;
130         /** size in bytes */
131         uint64_t _size;
132         boost::optional<std::string> _vendor;
133         boost::optional<std::string> _model;
134 };
135
136 void disk_write_finished ();
137
138
139 struct OSXMediaPath
140 {
141         bool real; ///< true for a "real" disk, false for a synthesized APFS one
142         std::vector<std::string> parts; ///< parts of the media path after the :
143 };
144
145
146 struct OSXDisk
147 {
148         std::string device;
149         boost::optional<std::string> vendor;
150         boost::optional<std::string> model;
151         OSXMediaPath media_path;
152         bool whole;
153         std::vector<boost::filesystem::path> mount_points;
154         unsigned long size;
155 };
156
157
158 boost::optional<OSXMediaPath> analyse_osx_media_path (std::string path);
159 std::vector<Drive> osx_disks_to_drives (std::vector<OSXDisk> disks);
160
161
162 class ArgFixer
163 {
164 public:
165         ArgFixer(int argc, char** argv);
166
167         int argc() const {
168                 return _argc;
169         }
170
171         char** argv() const {
172                  return _argv;
173         }
174
175 private:
176         int _argc;
177         char** _argv;
178 #ifdef DCPOMATIC_WINDOWS
179         std::vector<std::string> _argv_strings;
180 #endif
181
182 };
183
184
185 #endif