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 "base/time/time.h" 14 #include "media/base/media_export.h" 15 16 namespace media { 17 18 class UsbMidiDevice; 19 20 // Delegate class for UsbMidiDevice. 21 // Each method is called when an corresponding event arrives at the device. 22 class MEDIA_EXPORT UsbMidiDeviceDelegate { 23 public: ~UsbMidiDeviceDelegate()24 virtual ~UsbMidiDeviceDelegate() {} 25 26 // Called when USB-MIDI data arrives at |device|. 27 virtual void ReceiveUsbMidiData(UsbMidiDevice* device, 28 int endpoint_number, 29 const uint8* data, 30 size_t size, 31 base::TimeTicks time) = 0; 32 }; 33 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 { 38 public: 39 typedef ScopedVector<UsbMidiDevice> Devices; 40 41 // Factory class for USB-MIDI devices. 42 // Each concrete implementation will find and create devices 43 // in platform-dependent way. 44 class Factory { 45 public: 46 typedef base::Callback<void(bool result, Devices* devices)> Callback; ~Factory()47 virtual ~Factory() {} 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 51 // devices. 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; 58 }; 59 ~UsbMidiDevice()60 virtual ~UsbMidiDevice() {} 61 62 // Returns the descriptor of this device. 63 virtual std::vector<uint8> GetDescriptor() = 0; 64 65 // Sends |data| to the given USB endpoint of this device. 66 virtual void Send(int endpoint_number, const std::vector<uint8>& data) = 0; 67 }; 68 69 } // namespace media 70 71 #endif // MEDIA_MIDI_USB_MIDI_DEVICE_H_ 72