Tidy up nanomsg class API; add unmounting for Linux.
[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 void dcpomatic_sleep_seconds (int);
43 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 #ifdef DCPOMATIC_DISK
49 extern boost::filesystem::path disk_writer_path ();
50 #endif
51 #ifdef DCPOMATIC_OSX
52 extern boost::filesystem::path app_contents ();
53 #endif
54 #ifdef DCPOMATIC_WINDOWS
55 extern void maybe_open_console ();
56 #endif
57 extern boost::filesystem::path shared_path ();
58 extern FILE * fopen_boost (boost::filesystem::path, std::string);
59 extern int dcpomatic_fseek (FILE *, int64_t, int);
60 extern void start_batch_converter (boost::filesystem::path dcpomatic);
61 extern void start_player (boost::filesystem::path dcpomatic);
62 extern uint64_t thread_id ();
63 extern int avio_open_boost (AVIOContext** s, boost::filesystem::path file, int flags);
64 extern boost::filesystem::path home_directory ();
65 extern std::string command_and_read (std::string cmd);
66 extern bool running_32_on_64 ();
67 extern void unprivileged ();
68 extern boost::filesystem::path config_path ();
69
70 class PrivilegeEscalator
71 {
72 public:
73         PrivilegeEscalator ();
74         ~PrivilegeEscalator ();
75 };
76
77 /** @class Waker
78  *  @brief A class which tries to keep the computer awake on various operating systems.
79  *
80  *  Create a Waker to prevent sleep, and call nudge() every so often (every minute or so).
81  *  Destroy the Waker to allow sleep again.
82  */
83 class Waker
84 {
85 public:
86         Waker ();
87         ~Waker ();
88
89         void nudge ();
90
91 private:
92         boost::mutex _mutex;
93 #ifdef DCPOMATIC_OSX
94         IOPMAssertionID _assertion_id;
95 #endif
96 };
97
98 class Drive
99 {
100 public:
101         Drive (std::string internal_name, uint64_t size, bool mounted, boost::optional<std::string> vendor, boost::optional<std::string> model)
102                 : _internal_name(internal_name)
103                 , _size(size)
104                 , _mounted(mounted)
105                 , _vendor(vendor)
106                 , _model(model)
107         {}
108
109         std::string description () const;
110         std::string internal_name () const {
111                 return _internal_name;
112         }
113         bool mounted () const {
114                 return _mounted;
115         }
116
117 private:
118         std::string _internal_name;
119         /** size in bytes */
120         uint64_t _size;
121         bool _mounted;
122         boost::optional<std::string> _vendor;
123         boost::optional<std::string> _model;
124 };
125
126 std::vector<Drive> get_drives ();
127 /** Unmount any mounted partitions on a drive.
128  *  @return true on success, false on failure.
129  */
130 bool unmount_drive (std::string drive);
131
132 #endif