| 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 15 matching lines...) Expand all Loading... |
| 147 } | 157 } |
| 148 | 158 |
| 149 size_t clients_size_for_testing() const { return clients_.size(); } | 159 size_t clients_size_for_testing() const { return clients_.size(); } |
| 150 size_t pending_clients_size_for_testing() const { | 160 size_t pending_clients_size_for_testing() const { |
| 151 return pending_clients_.size(); | 161 return pending_clients_.size(); |
| 152 } | 162 } |
| 153 | 163 |
| 154 private: | 164 private: |
| 155 void CompleteInitializationInternal(Result result); | 165 void CompleteInitializationInternal(Result result); |
| 156 void AddInitialPorts(MidiManagerClient* client); | 166 void AddInitialPorts(MidiManagerClient* client); |
| 167 void ShutdownOnSessionThread(); |
| 157 | 168 |
| 158 // Keeps track of all clients who wish to receive MIDI data. | 169 // Keeps track of all clients who wish to receive MIDI data. |
| 159 typedef std::set<MidiManagerClient*> ClientSet; | 170 typedef std::set<MidiManagerClient*> ClientSet; |
| 160 ClientSet clients_; | 171 ClientSet clients_; |
| 161 | 172 |
| 162 // Keeps track of all clients who are waiting for CompleteStartSession(). | 173 // Keeps track of all clients who are waiting for CompleteStartSession(). |
| 163 ClientSet pending_clients_; | 174 ClientSet pending_clients_; |
| 164 | 175 |
| 165 // Keeps a SingleThreadTaskRunner of the thread that calls StartSession in | 176 // Keeps a SingleThreadTaskRunner of the thread that calls StartSession in |
| 166 // order to invoke CompleteStartSession() on the thread. | 177 // order to invoke CompleteStartSession() on the thread. |
| 167 scoped_refptr<base::SingleThreadTaskRunner> session_thread_runner_; | 178 scoped_refptr<base::SingleThreadTaskRunner> session_thread_runner_; |
| 168 | 179 |
| 169 // Keeps true if platform dependent initialization is already completed. | 180 // Keeps true if platform dependent initialization is already completed. |
| 170 bool initialized_; | 181 bool initialized_; |
| 171 | 182 |
| 183 // Keeps false until Finalize() is called. |
| 184 bool finalized_; |
| 185 |
| 172 // Keeps the platform dependent initialization result if initialization is | 186 // Keeps the platform dependent initialization result if initialization is |
| 173 // completed. Otherwise keeps Result::NOT_INITIALIZED. | 187 // completed. Otherwise keeps Result::NOT_INITIALIZED. |
| 174 Result result_; | 188 Result result_; |
| 175 | 189 |
| 176 // Keeps all MidiPortInfo. | 190 // Keeps all MidiPortInfo. |
| 177 MidiPortInfoList input_ports_; | 191 MidiPortInfoList input_ports_; |
| 178 MidiPortInfoList output_ports_; | 192 MidiPortInfoList output_ports_; |
| 179 | 193 |
| 180 // Protects access to |clients_|, |pending_clients_|, |initialized_|, | 194 // Protects access to |clients_|, |pending_clients_|, |initialized_|, |
| 181 // |result_|, |input_ports_| and |output_ports_|. | 195 // |finalize_|, |result_|, |input_ports_| and |output_ports_|. |
| 182 base::Lock lock_; | 196 base::Lock lock_; |
| 183 | 197 |
| 184 DISALLOW_COPY_AND_ASSIGN(MidiManager); | 198 DISALLOW_COPY_AND_ASSIGN(MidiManager); |
| 185 }; | 199 }; |
| 186 | 200 |
| 187 } // namespace midi | 201 } // namespace midi |
| 188 } // namespace media | 202 } // namespace media |
| 189 | 203 |
| 190 #endif // MEDIA_MIDI_MIDI_MANAGER_H_ | 204 #endif // MEDIA_MIDI_MIDI_MANAGER_H_ |
| OLD | NEW |