blob: e083a6d3ee71c75be496e11b56dc526f4dec0e83 [file] [log] [blame]
shaochuane58f9c72016-08-30 22:27:08 -07001// Copyright 2016 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_MIDI_MANAGER_WINRT_H_
6#define MEDIA_MIDI_MIDI_MANAGER_WINRT_H_
7
8#include <memory>
9
10#include "base/strings/string16.h"
Takashi Toyoshimad4f37cd2018-10-01 07:43:39 +000011#include "base/thread_annotations.h"
shaochuane58f9c72016-08-30 22:27:08 -070012#include "media/midi/midi_manager.h"
13
shaochuane58f9c72016-08-30 22:27:08 -070014namespace midi {
15
toyoshimf4d61522017-02-10 02:03:32 -080016class MidiService;
shaochuane58f9c72016-08-30 22:27:08 -070017
18class MIDI_EXPORT MidiManagerWinrt final : public MidiManager {
19 public:
Takashi Toyoshima3f0ea8f2018-01-17 09:19:59 +000020 class MidiInPortManager;
21 class MidiOutPortManager;
22
toyoshimf4d61522017-02-10 02:03:32 -080023 explicit MidiManagerWinrt(MidiService* service);
shaochuane58f9c72016-08-30 22:27:08 -070024 ~MidiManagerWinrt() override;
25
26 // MidiManager overrides:
27 void StartInitialization() final;
28 void Finalize() final;
29 void DispatchSendMidiData(MidiManagerClient* client,
30 uint32_t port_index,
31 const std::vector<uint8_t>& data,
tzik925e2c62018-02-02 07:39:45 +000032 base::TimeTicks timestamp) final;
shaochuane58f9c72016-08-30 22:27:08 -070033
34 private:
shaochuane58f9c72016-08-30 22:27:08 -070035 // Subclasses that access private/protected members of MidiManager.
36 template <typename InterfaceType,
37 typename RuntimeType,
38 typename StaticsInterfaceType,
39 base::char16 const* runtime_class_id>
40 class MidiPortManager;
shaochuane58f9c72016-08-30 22:27:08 -070041
Takashi Toyoshima3f0ea8f2018-01-17 09:19:59 +000042 // Callbacks on kComTaskRunner.
43 void InitializeOnComRunner();
44 void SendOnComRunner(uint32_t port_index, const std::vector<uint8_t>& data);
shaochuane58f9c72016-08-30 22:27:08 -070045
Takashi Toyoshima3f0ea8f2018-01-17 09:19:59 +000046 // Callback from MidiPortManager::OnEnumerationComplete on kComTaskRunner.
47 // Calls CompleteInitialization() when both MidiPortManagers are ready.
48 void OnPortManagerReady();
49
50 // Lock to ensure all smart pointers initialized in InitializeOnComRunner()
51 // and destroyed in FinalizeOnComRunner() will not be accidentally destructed
shaochuane58f9c72016-08-30 22:27:08 -070052 // twice in the destructor.
53 base::Lock lazy_init_member_lock_;
54
Takashi Toyoshima3f0ea8f2018-01-17 09:19:59 +000055 // All operations to Midi{In|Out}PortManager should be done on kComTaskRunner.
Takashi Toyoshimad4f37cd2018-10-01 07:43:39 +000056 std::unique_ptr<MidiInPortManager> port_manager_in_
57 GUARDED_BY(lazy_init_member_lock_);
58 std::unique_ptr<MidiOutPortManager> port_manager_out_
59 GUARDED_BY(lazy_init_member_lock_);
shaochuane58f9c72016-08-30 22:27:08 -070060
shaochuane58f9c72016-08-30 22:27:08 -070061 // Incremented when a MidiPortManager is ready.
62 uint8_t port_manager_ready_count_ = 0;
63
64 DISALLOW_COPY_AND_ASSIGN(MidiManagerWinrt);
65};
66
67} // namespace midi
shaochuane58f9c72016-08-30 22:27:08 -070068
69#endif // MEDIA_MIDI_MIDI_MANAGER_WINRT_H_