1 // Copyright 2014 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 #ifndef MEDIA_MIDI_USB_MIDI_DEVICE_H_
6 #define MEDIA_MIDI_USB_MIDI_DEVICE_H_
10 #include "base/basictypes.h"
11 #include "base/callback.h"
12 #include "base/memory/scoped_vector.h"
13 #include "base/time/time.h"
14 #include "media/base/media_export.h"
20 // Delegate class for UsbMidiDevice.
21 // Each method is called when an corresponding event arrives at the device.
22 class MEDIA_EXPORT UsbMidiDeviceDelegate
{
24 virtual ~UsbMidiDeviceDelegate() {}
26 // Called when USB-MIDI data arrives at |device|.
27 virtual void ReceiveUsbMidiData(UsbMidiDevice
* device
,
31 base::TimeTicks time
) = 0;
34 // UsbMidiDevice represents a USB-MIDI device.
35 // This is an interface class and each platform-dependent implementation class
36 // will be a derived class.
37 class MEDIA_EXPORT UsbMidiDevice
{
39 typedef ScopedVector
<UsbMidiDevice
> Devices
;
41 // Factory class for USB-MIDI devices.
42 // Each concrete implementation will find and create devices
43 // in platform-dependent way.
46 typedef base::Callback
<void(bool result
, Devices
* devices
)> Callback
;
48 // Enumerates devices.
49 // Devices that have no USB-MIDI interfaces can be omitted.
50 // When the operation succeeds, |callback| will be called with |true| and
52 // Otherwise |callback| will be called with |false| and empty devices.
53 // When this factory is destroyed during the operation, the operation
54 // will be canceled silently (i.e. |callback| will not be called).
55 // This function can be called at most once per instance.
56 virtual void EnumerateDevices(UsbMidiDeviceDelegate
* delegate
,
57 Callback callback
) = 0;
60 virtual ~UsbMidiDevice() {}
62 // Returns the descriptor of this device.
63 virtual std::vector
<uint8
> GetDescriptor() = 0;
65 // Sends |data| to the given USB endpoint of this device.
66 virtual void Send(int endpoint_number
, const std::vector
<uint8
>& data
) = 0;
71 #endif // MEDIA_MIDI_USB_MIDI_DEVICE_H_