blob: 8cb562dd7164f805c616e4e2c4de2cb6f8df1c27 [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"
shaochuane58f9c72016-08-30 22:27:08 -070011#include "media/midi/midi_manager.h"
12
shaochuane58f9c72016-08-30 22:27:08 -070013namespace midi {
14
toyoshimf4d61522017-02-10 02:03:32 -080015class MidiService;
shaochuane58f9c72016-08-30 22:27:08 -070016
17class MIDI_EXPORT MidiManagerWinrt final : public MidiManager {
18 public:
Takashi Toyoshima3f0ea8f2018-01-17 09:19:59 +000019 class MidiInPortManager;
20 class MidiOutPortManager;
21
toyoshimf4d61522017-02-10 02:03:32 -080022 explicit MidiManagerWinrt(MidiService* service);
shaochuane58f9c72016-08-30 22:27:08 -070023 ~MidiManagerWinrt() override;
24
25 // MidiManager overrides:
26 void StartInitialization() final;
27 void Finalize() final;
28 void DispatchSendMidiData(MidiManagerClient* client,
29 uint32_t port_index,
30 const std::vector<uint8_t>& data,
31 double timestamp) final;
32
33 private:
shaochuane58f9c72016-08-30 22:27:08 -070034 // Subclasses that access private/protected members of MidiManager.
35 template <typename InterfaceType,
36 typename RuntimeType,
37 typename StaticsInterfaceType,
38 base::char16 const* runtime_class_id>
39 class MidiPortManager;
shaochuane58f9c72016-08-30 22:27:08 -070040
Takashi Toyoshima3f0ea8f2018-01-17 09:19:59 +000041 // Callbacks on kComTaskRunner.
42 void InitializeOnComRunner();
43 void SendOnComRunner(uint32_t port_index, const std::vector<uint8_t>& data);
shaochuane58f9c72016-08-30 22:27:08 -070044
Takashi Toyoshima3f0ea8f2018-01-17 09:19:59 +000045 // Callback from MidiPortManager::OnEnumerationComplete on kComTaskRunner.
46 // Calls CompleteInitialization() when both MidiPortManagers are ready.
47 void OnPortManagerReady();
48
49 // Lock to ensure all smart pointers initialized in InitializeOnComRunner()
50 // and destroyed in FinalizeOnComRunner() will not be accidentally destructed
shaochuane58f9c72016-08-30 22:27:08 -070051 // twice in the destructor.
52 base::Lock lazy_init_member_lock_;
53
Takashi Toyoshima3f0ea8f2018-01-17 09:19:59 +000054 // All operations to Midi{In|Out}PortManager should be done on kComTaskRunner.
shaochuane58f9c72016-08-30 22:27:08 -070055 std::unique_ptr<MidiInPortManager>
56 port_manager_in_; // GUARDED_BY(lazy_init_member_lock_)
57 std::unique_ptr<MidiOutPortManager>
58 port_manager_out_; // GUARDED_BY(lazy_init_member_lock_)
59
shaochuane58f9c72016-08-30 22:27:08 -070060 // Incremented when a MidiPortManager is ready.
61 uint8_t port_manager_ready_count_ = 0;
62
63 DISALLOW_COPY_AND_ASSIGN(MidiManagerWinrt);
64};
65
66} // namespace midi
shaochuane58f9c72016-08-30 22:27:08 -070067
68#endif // MEDIA_MIDI_MIDI_MANAGER_WINRT_H_