1
    2
    3
    4
    5
    6
    7
    8
    9
   10
   11
   12
   13
   14
   15
   16
   17
   18
   19
   20
   21
   22
   23
   24
   25
   26
   27
   28
   29
   30
   31
   32
   33
   34
   35
   36
   37
   38
   39
   40
   41
   42
   43
   44
   45
   46
   47
   48
   49
   50
   51
   52
   53
   54
   55
   56
   57
   58
   59
   60
   61
   62
   63
   64
   65
   66
   67
   68
   69

media / midi / midi_manager_winrt.h [blame]

// Copyright 2016 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#ifndef MEDIA_MIDI_MIDI_MANAGER_WINRT_H_
#define MEDIA_MIDI_MIDI_MANAGER_WINRT_H_

#include <memory>

#include "base/thread_annotations.h"
#include "media/midi/midi_manager.h"

namespace midi {

class MidiService;

class MIDI_EXPORT MidiManagerWinrt final : public MidiManager {
 public:
  class MidiInPortManager;
  class MidiOutPortManager;

  explicit MidiManagerWinrt(MidiService* service);

  MidiManagerWinrt(const MidiManagerWinrt&) = delete;
  MidiManagerWinrt& operator=(const MidiManagerWinrt&) = delete;

  ~MidiManagerWinrt() override;

  // MidiManager overrides:
  void StartInitialization() final;
  void DispatchSendMidiData(MidiManagerClient* client,
                            uint32_t port_index,
                            const std::vector<uint8_t>& data,
                            base::TimeTicks timestamp) final;

 private:
  // Subclasses that access private/protected members of MidiManager.
  template <typename InterfaceType,
            typename RuntimeType,
            typename StaticsInterfaceType,
            wchar_t const* runtime_class_id>
  class MidiPortManager;

  // Callbacks on kComTaskRunner.
  void InitializeOnComRunner();
  void SendOnComRunner(uint32_t port_index, const std::vector<uint8_t>& data);

  // Callback from MidiPortManager::OnEnumerationComplete on kComTaskRunner.
  // Calls CompleteInitialization() when both MidiPortManagers are ready.
  void OnPortManagerReady();

  // Lock to ensure all smart pointers initialized in InitializeOnComRunner()
  // and destroyed in FinalizeOnComRunner() will not be accidentally destructed
  // twice in the destructor.
  base::Lock lazy_init_member_lock_;

  // All operations to Midi{In|Out}PortManager should be done on kComTaskRunner.
  std::unique_ptr<MidiInPortManager> port_manager_in_
      GUARDED_BY(lazy_init_member_lock_);
  std::unique_ptr<MidiOutPortManager> port_manager_out_
      GUARDED_BY(lazy_init_member_lock_);

  // Incremented when a MidiPortManager is ready.
  uint8_t port_manager_ready_count_ = 0;
};

}  // namespace midi

#endif  // MEDIA_MIDI_MIDI_MANAGER_WINRT_H_