Upstream version 5.34.104.0
[platform/framework/web/crosswalk.git] / src / media / midi / usb_midi_device.h
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.
4
5 #ifndef MEDIA_MIDI_USB_MIDI_DEVICE_H_
6 #define MEDIA_MIDI_USB_MIDI_DEVICE_H_
7
8 #include <vector>
9
10 #include "base/basictypes.h"
11 #include "base/callback.h"
12 #include "base/memory/scoped_vector.h"
13 #include "media/base/media_export.h"
14
15 namespace media {
16
17 class UsbMidiDevice;
18
19 // Delegate class for UsbMidiDevice.
20 // Each method is called when an corresponding event arrives at the device.
21 class MEDIA_EXPORT UsbMidiDeviceDelegate {
22  public:
23   virtual ~UsbMidiDeviceDelegate() {}
24
25   // Called when USB-MIDI data arrives at |device|.
26   virtual void ReceiveUsbMidiData(UsbMidiDevice* device,
27                                   int endpoint_number,
28                                   const uint8* data,
29                                   size_t size,
30                                   double timestamp) = 0;
31 };
32
33 // UsbMidiDevice represents a USB-MIDI device.
34 // This is an interface class and each platform-dependent implementation class
35 // will be a derived class.
36 class MEDIA_EXPORT UsbMidiDevice {
37  public:
38   typedef ScopedVector<UsbMidiDevice> Devices;
39
40   // Factory class for USB-MIDI devices.
41   // Each concrete implementation will find and create devices
42   // in platform-dependent way.
43   class Factory {
44    public:
45     typedef base::Callback<void(bool result, Devices* devices)> Callback;
46     virtual ~Factory() {}
47     // Enumerates devices.
48     // Devices that have no USB-MIDI interfaces can be omitted.
49     // When the operation succeeds, |callback| will be called with |true| and
50     // devices.
51     // Otherwise |callback| will be called with |false| and empty devices.
52     // When this factory is destroyed during the operation, the operation
53     // will be canceled silently (i.e. |callback| will not be called).
54     // This function can be called at most once per instance.
55     virtual void EnumerateDevices(UsbMidiDeviceDelegate* delegate,
56                                   Callback callback) = 0;
57   };
58
59   virtual ~UsbMidiDevice() {}
60
61   // Returns the descriptor of this device.
62   virtual std::vector<uint8> GetDescriptor() = 0;
63
64   // Sends |data| to the given USB endpoint of this device.
65   virtual void Send(int endpoint_number, const std::vector<uint8>& data) = 0;
66 };
67
68 }  // namespace media
69
70 #endif  // MEDIA_MIDI_USB_MIDI_DEVICE_H_