Drive: Add BatchableRequest subclass.
[chromium-blink-merge.git] / media / midi / usb_midi_device.h
blob321661473c26fd1a5f247b26bee6412e5b9b0c03
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_
8 #include <vector>
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"
16 namespace media {
18 class MidiManagerUsb;
19 class UsbMidiDevice;
21 // Delegate class for UsbMidiDevice.
22 // Each method is called when an corresponding event arrives at the device.
23 class MEDIA_EXPORT UsbMidiDeviceDelegate {
24 public:
25 virtual ~UsbMidiDeviceDelegate() {}
27 // Called when USB-MIDI data arrives at |device|.
28 virtual void ReceiveUsbMidiData(UsbMidiDevice* device,
29 int endpoint_number,
30 const uint8* data,
31 size_t size,
32 base::TimeTicks time) = 0;
34 // Called when a USB-MIDI device is attached.
35 virtual void OnDeviceAttached(scoped_ptr<UsbMidiDevice> device) = 0;
36 // Called when a USB-MIDI device is detached.
37 virtual void OnDeviceDetached(size_t index) = 0;
40 // UsbMidiDevice represents a USB-MIDI device.
41 // This is an interface class and each platform-dependent implementation class
42 // will be a derived class.
43 class MEDIA_EXPORT UsbMidiDevice {
44 public:
45 typedef ScopedVector<UsbMidiDevice> Devices;
47 // Factory class for USB-MIDI devices.
48 // Each concrete implementation will find and create devices
49 // in platform-dependent way.
50 class Factory {
51 public:
52 typedef base::Callback<void(bool result, Devices* devices)> Callback;
53 virtual ~Factory() {}
55 // Enumerates devices.
56 // Devices that have no USB-MIDI interfaces can be omitted.
57 // When the operation succeeds, |callback| will be called with |true| and
58 // devices.
59 // Otherwise |callback| will be called with |false| and empty devices.
60 // When this factory is destroyed during the operation, the operation
61 // will be canceled silently (i.e. |callback| will not be called).
62 // This function can be called at most once per instance.
63 virtual void EnumerateDevices(UsbMidiDeviceDelegate* delegate,
64 Callback callback) = 0;
67 virtual ~UsbMidiDevice() {}
69 // Returns the descriptor of this device.
70 virtual std::vector<uint8> GetDescriptor() = 0;
72 // Sends |data| to the given USB endpoint of this device.
73 virtual void Send(int endpoint_number, const std::vector<uint8>& data) = 0;
76 } // namespace media
78 #endif // MEDIA_MIDI_USB_MIDI_DEVICE_H_