TTKMusicPlayer  3.7.0.0
TTKMusicPlayer imitates Kugou UI, the music player uses of qmmp core library based on Qt for windows and linux
qdevicewatcher_mac.cpp
Go to the documentation of this file.
1 #include "qdevicewatcher_p.h"
2 #include <QtCore/QStringList>
3 
4 #include <CoreServices/CoreServices.h>
5 #include <IOKit/storage/IOCDMedia.h>
6 #include <IOKit/storage/IODVDMedia.h>
7 
8 static QStringList sDevices; //disk list, or mount point list?
9 
10 static void onDiskAppear(DADiskRef disk, void *context)
11 {
12  QString disk_name = DADiskGetBSDName(disk);
13  if (sDevices.contains(disk_name))
14  return;
15  sDevices.append(disk_name);
17  p->emitDeviceAdded(disk_name);
18 }
19 
20 static void onDiskDisappear(DADiskRef disk, void *context)
21 {
22  QString disk_name = DADiskGetBSDName(disk);
23  sDevices.removeAll(disk_name); //erase?
25  p->emitDeviceRemoved(disk_name);
26 }
27 
29 {
30  stop();
31 }
32 
34 {
35  initialize();
36  QThread::start();
37 }
38 
40 {
41  mStop = true;
42  wait();
43  //DAUnregisterApprovalCallback
44  DAUnregisterCallback(mSession, (void*)onDiskAppear, this);
45  DAUnregisterCallback(mSession, (void*)onDiskDisappear, this);
46 }
47 
49 {
50 }
51 
53 {
54  //get sDevices
55  //FSGetVolumeInfo()
56  mSession = DASessionCreate(kCFAllocatorDefault);
57 
58  DARegisterDiskAppearedCallback(mSession, nullptr, onDiskAppear, this);
59  DARegisterDiskDisappearedCallback(mSession, nullptr, onDiskDisappear, this);
60 }
61 
62 void QDeviceWatcherPrivate::run()
63 {
64  mStop = false;
65 
66  DASessionScheduleWithRunLoop(mSession, CFRunLoopGetCurrent(), kCFRunLoopDefaultMode);
67  SInt32 result;
68  do {
69  result = CFRunLoopRunInMode(kCFRunLoopDefaultMode, 1, true);
70  } while (!mStop && result);
71 
72  DASessionUnscheduleFromRunLoop(mSession, CFRunLoopGetCurrent(), kCFRunLoopDefaultMode);
73 }
#define TTKStaticCast(x, y)
Definition: ttkglobal.h:159
static void onDiskDisappear(DADiskRef disk, void *context)
void emitDeviceAdded(const QString &dev)
static QStringList sDevices
static void onDiskAppear(DADiskRef disk, void *context)
void emitDeviceRemoved(const QString &dev)
The class of the device watcher private.