Upload upstream chromium 108.0.5359.1
[platform/framework/web/chromium-efl.git] / services / device / serial / serial_device_enumerator_mac.h
1 // Copyright 2014 The Chromium Authors
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 #ifndef SERVICES_DEVICE_SERIAL_SERIAL_DEVICE_ENUMERATOR_MAC_H_
6 #define SERVICES_DEVICE_SERIAL_SERIAL_DEVICE_ENUMERATOR_MAC_H_
7
8 #include <IOKit/IOKitLib.h>
9
10 #include <map>
11 #include <utility>
12
13 #include "base/mac/scoped_ionotificationportref.h"
14 #include "base/mac/scoped_ioobject.h"
15 #include "base/sequence_checker.h"
16 #include "base/unguessable_token.h"
17 #include "services/device/serial/serial_device_enumerator.h"
18
19 namespace device {
20
21 // Discovers and enumerates serial devices available to the host.
22 class SerialDeviceEnumeratorMac : public SerialDeviceEnumerator {
23  public:
24   SerialDeviceEnumeratorMac();
25
26   SerialDeviceEnumeratorMac(const SerialDeviceEnumeratorMac&) = delete;
27   SerialDeviceEnumeratorMac& operator=(const SerialDeviceEnumeratorMac&) =
28       delete;
29
30   ~SerialDeviceEnumeratorMac() override;
31
32  private:
33   static void FirstMatchCallback(void* context, io_iterator_t iterator);
34   static void TerminatedCallback(void* context, io_iterator_t iterator);
35
36   void AddDevices();
37   void RemoveDevices();
38
39   // Map from IORegistry entry IDs to the token used to refer to the device
40   // internally.
41   std::map<uint64_t, base::UnguessableToken> entries_;
42
43   base::mac::ScopedIONotificationPortRef notify_port_;
44   base::mac::ScopedIOObject<io_iterator_t> devices_added_iterator_;
45   base::mac::ScopedIOObject<io_iterator_t> devices_removed_iterator_;
46 };
47
48 }  // namespace device
49
50 #endif  // SERVICES_DEVICE_SERIAL_SERIAL_DEVICE_ENUMERATOR_MAC_H_