OLD | NEW |
---|---|
1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #ifndef MEDIA_MIDI_MIDI_MANAGER_H_ | 5 #ifndef MEDIA_MIDI_MIDI_MANAGER_H_ |
6 #define MEDIA_MIDI_MIDI_MANAGER_H_ | 6 #define MEDIA_MIDI_MIDI_MANAGER_H_ |
7 | 7 |
8 #include <set> | 8 #include <set> |
9 #include <vector> | 9 #include <vector> |
10 | 10 |
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
68 public: | 68 public: |
69 static const size_t kMaxPendingClientCount = 128; | 69 static const size_t kMaxPendingClientCount = 128; |
70 | 70 |
71 MidiManager(); | 71 MidiManager(); |
72 virtual ~MidiManager(); | 72 virtual ~MidiManager(); |
73 | 73 |
74 // The constructor and the destructor will be called on the CrBrowserMain | 74 // The constructor and the destructor will be called on the CrBrowserMain |
75 // thread. | 75 // thread. |
76 static MidiManager* Create(); | 76 static MidiManager* Create(); |
77 | 77 |
78 // Called on the CrBrowserMain thread to notify the Chrome_IOThread will stop | |
79 // and the instance will be destructed on the CrBrowserMain thread soon. | |
80 void Shutdown(); | |
81 | |
78 // A client calls StartSession() to receive and send MIDI data. | 82 // A client calls StartSession() to receive and send MIDI data. |
79 // If the session is ready to start, the MIDI system is lazily initialized | 83 // If the session is ready to start, the MIDI system is lazily initialized |
80 // and the client is registered to receive MIDI data. | 84 // and the client is registered to receive MIDI data. |
81 // CompleteStartSession() is called with Result::OK if the session is started. | 85 // CompleteStartSession() is called with Result::OK if the session is started. |
82 // Otherwise CompleteStartSession() is called with proper Result code. | 86 // Otherwise CompleteStartSession() is called with proper Result code. |
83 // StartSession() and EndSession() can be called on the Chrome_IOThread. | 87 // StartSession() and EndSession() can be called on the Chrome_IOThread. |
84 // CompleteStartSession() will be invoked on the same Chrome_IOThread. | 88 // CompleteStartSession() will be invoked on the same Chrome_IOThread. |
85 void StartSession(MidiManagerClient* client); | 89 void StartSession(MidiManagerClient* client); |
86 | 90 |
87 // A client calls EndSession() to stop receiving MIDI data. | 91 // A client calls EndSession() to stop receiving MIDI data. |
(...skipping 24 matching lines...) Expand all Loading... | |
112 // default implementation that synchronously calls CompleteInitialization() | 116 // default implementation that synchronously calls CompleteInitialization() |
113 // with Result::NOT_SUPPORTED on the caller thread. A derived class for a | 117 // with Result::NOT_SUPPORTED on the caller thread. A derived class for a |
114 // specific platform should override this method correctly. | 118 // specific platform should override this method correctly. |
115 // This method is called on Chrome_IOThread thread inside StartSession(). | 119 // This method is called on Chrome_IOThread thread inside StartSession(). |
116 // Platform dependent initialization can be processed synchronously or | 120 // Platform dependent initialization can be processed synchronously or |
117 // asynchronously. When the initialization is completed, | 121 // asynchronously. When the initialization is completed, |
118 // CompleteInitialization() should be called with |result|. | 122 // CompleteInitialization() should be called with |result|. |
119 // |result| should be Result::OK on success, otherwise a proper Result. | 123 // |result| should be Result::OK on success, otherwise a proper Result. |
120 virtual void StartInitialization(); | 124 virtual void StartInitialization(); |
121 | 125 |
126 // Finalizes the platform dependent MIDI system. Called on Chrome_IOThread | |
127 // thread and the thread will stop immediately after this call. | |
128 // Platform dependent resources that were allocated on the Chrome_IOThread | |
129 // should be disposed inside this method. | |
130 virtual void Finalize() {} | |
131 | |
122 // Called from a platform dependent implementation of StartInitialization(). | 132 // Called from a platform dependent implementation of StartInitialization(). |
123 // It invokes CompleteInitializationInternal() on the thread that calls | 133 // It invokes CompleteInitializationInternal() on the thread that calls |
124 // StartSession() and distributes |result| to MIDIManagerClient objects in | 134 // StartSession() and distributes |result| to MIDIManagerClient objects in |
125 // |pending_clients_|. | 135 // |pending_clients_|. |
126 void CompleteInitialization(Result result); | 136 void CompleteInitialization(Result result); |
127 | 137 |
128 void AddInputPort(const MidiPortInfo& info); | 138 void AddInputPort(const MidiPortInfo& info); |
129 void AddOutputPort(const MidiPortInfo& info); | 139 void AddOutputPort(const MidiPortInfo& info); |
130 void SetInputPortState(uint32 port_index, MidiPortState state); | 140 void SetInputPortState(uint32 port_index, MidiPortState state); |
131 void SetOutputPortState(uint32 port_index, MidiPortState state); | 141 void SetOutputPortState(uint32 port_index, MidiPortState state); |
(...skipping 30 matching lines...) Expand all Loading... | |
162 // Keeps track of all clients who are waiting for CompleteStartSession(). | 172 // Keeps track of all clients who are waiting for CompleteStartSession(). |
163 ClientSet pending_clients_; | 173 ClientSet pending_clients_; |
164 | 174 |
165 // Keeps a SingleThreadTaskRunner of the thread that calls StartSession in | 175 // Keeps a SingleThreadTaskRunner of the thread that calls StartSession in |
166 // order to invoke CompleteStartSession() on the thread. | 176 // order to invoke CompleteStartSession() on the thread. |
167 scoped_refptr<base::SingleThreadTaskRunner> session_thread_runner_; | 177 scoped_refptr<base::SingleThreadTaskRunner> session_thread_runner_; |
168 | 178 |
169 // Keeps true if platform dependent initialization is already completed. | 179 // Keeps true if platform dependent initialization is already completed. |
170 bool initialized_; | 180 bool initialized_; |
171 | 181 |
182 // Keeps false until Shutdown() is called. | |
183 bool shutted_down_; | |
yhirano
2015/09/07 06:00:25
"shut"'s past participle form is "shut", not "shut
Takashi Toyoshima
2015/09/07 19:04:39
Done.
| |
184 | |
172 // Keeps the platform dependent initialization result if initialization is | 185 // Keeps the platform dependent initialization result if initialization is |
173 // completed. Otherwise keeps Result::NOT_INITIALIZED. | 186 // completed. Otherwise keeps Result::NOT_INITIALIZED. |
174 Result result_; | 187 Result result_; |
175 | 188 |
176 // Keeps all MidiPortInfo. | 189 // Keeps all MidiPortInfo. |
177 MidiPortInfoList input_ports_; | 190 MidiPortInfoList input_ports_; |
178 MidiPortInfoList output_ports_; | 191 MidiPortInfoList output_ports_; |
179 | 192 |
180 // Protects access to |clients_|, |pending_clients_|, |initialized_|, | 193 // Protects access to |clients_|, |pending_clients_|, |initialized_|, |
181 // |result_|, |input_ports_| and |output_ports_|. | 194 // |result_|, |input_ports_| and |output_ports_|. |
182 base::Lock lock_; | 195 base::Lock lock_; |
183 | 196 |
184 DISALLOW_COPY_AND_ASSIGN(MidiManager); | 197 DISALLOW_COPY_AND_ASSIGN(MidiManager); |
185 }; | 198 }; |
186 | 199 |
187 } // namespace midi | 200 } // namespace midi |
188 } // namespace media | 201 } // namespace media |
189 | 202 |
190 #endif // MEDIA_MIDI_MIDI_MANAGER_H_ | 203 #endif // MEDIA_MIDI_MIDI_MANAGER_H_ |
OLD | NEW |