Merge Chromium + Blink git repositories
[chromium-blink-merge.git] / media / midi / usb_midi_device.h
blobc1dc8cd71dcd9a7f25f04bfe756a67bbabd5ef5f
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/midi/usb_midi_export.h"
16 namespace media {
17 namespace midi {
19 class MidiManagerUsb;
20 class UsbMidiDevice;
22 // Delegate class for UsbMidiDevice.
23 // Each method is called when an corresponding event arrives at the device.
24 class USB_MIDI_EXPORT UsbMidiDeviceDelegate {
25 public:
26 virtual ~UsbMidiDeviceDelegate() {}
28 // Called when USB-MIDI data arrives at |device|.
29 virtual void ReceiveUsbMidiData(UsbMidiDevice* device,
30 int endpoint_number,
31 const uint8* data,
32 size_t size,
33 base::TimeTicks time) = 0;
35 // Called when a USB-MIDI device is attached.
36 virtual void OnDeviceAttached(scoped_ptr<UsbMidiDevice> device) = 0;
37 // Called when a USB-MIDI device is detached.
38 virtual void OnDeviceDetached(size_t index) = 0;
41 // UsbMidiDevice represents a USB-MIDI device.
42 // This is an interface class and each platform-dependent implementation class
43 // will be a derived class.
44 class USB_MIDI_EXPORT UsbMidiDevice {
45 public:
46 typedef ScopedVector<UsbMidiDevice> Devices;
48 // Factory class for USB-MIDI devices.
49 // Each concrete implementation will find and create devices
50 // in platform-dependent way.
51 class Factory {
52 public:
53 typedef base::Callback<void(bool result, Devices* devices)> Callback;
54 virtual ~Factory() {}
56 // Enumerates devices.
57 // Devices that have no USB-MIDI interfaces can be omitted.
58 // When the operation succeeds, |callback| will be called with |true| and
59 // devices.
60 // Otherwise |callback| will be called with |false| and empty devices.
61 // When this factory is destroyed during the operation, the operation
62 // will be canceled silently (i.e. |callback| will not be called).
63 // This function can be called at most once per instance.
64 virtual void EnumerateDevices(UsbMidiDeviceDelegate* delegate,
65 Callback callback) = 0;
68 virtual ~UsbMidiDevice() {}
70 // Returns the descriptors of this device.
71 virtual std::vector<uint8> GetDescriptors() = 0;
73 // Return the name of the manufacturer.
74 virtual std::string GetManufacturer() = 0;
76 // Retur the name of the device.
77 virtual std::string GetProductName() = 0;
79 // Return the device version.
80 virtual std::string GetDeviceVersion() = 0;
82 // Sends |data| to the given USB endpoint of this device.
83 virtual void Send(int endpoint_number, const std::vector<uint8>& data) = 0;
86 } // namespace midi
87 } // namespace media
89 #endif // MEDIA_MIDI_USB_MIDI_DEVICE_H_