Discman
Loading...
Searching...
No Matches
drive_manager.h
Go to the documentation of this file.
1
6
7#ifndef DRIVE_MANAGER_H
8#define DRIVE_MANAGER_H
9
10#include <mutex>
11#include <thread>
12#include <regex>
13
14#include <glibmm/dispatcher.h>
15#include <sigc++/sigc++.h>
16#include <udisks2cc/manager.h>
17
18#include "cd/cd_drive.h"
20
23 public:
24
26 enum Drive {
29 };
30
33
36
38 typedef sigc::signal<void(Drive)> sig_drive;
39
41 struct NoDriveException : public std::exception {
42 const char* what() const throw() {
43 return "No drive is present";
44 }
45 };
46
49
52 void eject(const Drive drive);
53
54 bool is_disc_present() const;
55 bool is_removable_present() const;
56
57 UDisks2::Filesystem& removable();
59
60 private:
61 class Poller;
62
65
67
68 UDisks2::Manager _udisks2;
69 UDisks2::Filesystem* _removable_fs;
70
72
73 Glib::Dispatcher _dispatcher;
74
75 std::regex _acceptable_fs_pat;
76
77 void on_udisks2_init();
79 void on_cddrive_eject();
80
83 void on_removable_added(const std::string& path);
84
87 void on_removable_removed(const std::string& path);
88
90 void on_removable_mounted(const std::string&);
91
94};
95
98 public:
101 Poller(DriveManager& manager);
102
104 ~Poller();
105
106 void poll();
107
108 private:
110 bool _exit;
111
114 std::mutex _exit_lock;
115
117 std::thread _thread;
118};
119
120#endif // DRIVE_MANAGER_H
Abstracts the host's disc drive.
Definition cd_drive.h:39
The Poller uses a separate thread to poll the host for the presence of an audio CD.
Poller(DriveManager &manager)
Poller constructor.
~Poller()
Poller destructor.
bool _exit
Stores a request to exist poll().
DriveManager & _manager
The parent DriveManager.
void poll()
The execution loop performed by the thread.
std::mutex _exit_lock
Provides mutually exclusive access to the _exit member between the the application thread and the Pol...
std::thread _thread
The thread used to run poll().
sigc::signal< void(Drive)> sig_drive
"Inserted" and "Ejected" shared signal type.
void on_removable_added(const std::string &path)
Called when a new filesystem appears.
Drive
The two drives supported.
sig_drive signal_inserted()
Getter for ::_signal_inserted.
~DriveManager()
DriveManager destructor.
sig_drive _sig_inserted
Emitted when a drive is inserted.
std::regex _acceptable_fs_pat
Filters the filesystems reported by UDisks2 to acceptable ones.
void on_cddrive_eject()
Called when the disc drive successfully ejects.
bool is_disc_present() const
Returns the (cached) property of disc presence.
void on_removable_removed(const std::string &path)
Called when a filesystem is removed.
Glib::Dispatcher _dispatcher
Used to samely emit _sig_inserted for the disc drive.
sig_drive _sig_ejected
Emitted when a drive is removed.
Poller * _poller
When running, checks for the presence of a disc in _drive.
void on_udisks2_init()
Called when UDisks2 initializes the list of preregisterd drives and filesystems.
DriveManager()
DriveManager constructor.
CDDrive & disc_drive()
Returns the CDDrive associated with the disc drive.
bool is_removable_present() const
Returns the (cached) property of iPod presence.
UDisks2::Filesystem * _removable_fs
The filesystem associated with the iPod.
void eject(const Drive drive)
Eject one of the drives.
UDisks2::Manager _udisks2
UDisks2 provides access to removable disks.
CDDrive _drive
The disc drive.
sig_drive signal_ejected()
Getter for ::_signal_ejected.
void on_removable_mounted(const std::string &)
Called when the removable drive is mounted.
void on_notification_from_poller()
Called when _dispatcher is notified.
void on_removable_unmounted()
Called when the removable drive is unmounted.
UDisks2::Filesystem & removable()
Returns the UDisks2::Filesystem cassociated with the iPod.
Thrown when the assumption of the presence of a drive is false.
const char * what() const