| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright (C) 2013 Google Inc. All rights reserved. | 2 * Copyright (C) 2013 Google Inc. All rights reserved. |
| 3 * | 3 * |
| 4 * Redistribution and use in source and binary forms, with or without | 4 * Redistribution and use in source and binary forms, with or without |
| 5 * modification, are permitted provided that the following conditions are | 5 * modification, are permitted provided that the following conditions are |
| 6 * met: | 6 * met: |
| 7 * | 7 * |
| 8 * * Redistributions of source code must retain the above copyright | 8 * * Redistributions of source code must retain the above copyright |
| 9 * notice, this list of conditions and the following disclaimer. | 9 * notice, this list of conditions and the following disclaimer. |
| 10 * * Redistributions in binary form must reproduce the above | 10 * * Redistributions in binary form must reproduce the above |
| (...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 92 case TypeInput: | 92 case TypeInput: |
| 93 return "input"; | 93 return "input"; |
| 94 case TypeOutput: | 94 case TypeOutput: |
| 95 return "output"; | 95 return "output"; |
| 96 } | 96 } |
| 97 return emptyString(); | 97 return emptyString(); |
| 98 } | 98 } |
| 99 | 99 |
| 100 ScriptPromise MIDIPort::open(ScriptState* scriptState) | 100 ScriptPromise MIDIPort::open(ScriptState* scriptState) |
| 101 { | 101 { |
| 102 // TODO(toyoshim): Implement the latest open() algorithm. | 102 if (m_connection == ConnectionStateClosed) { |
| 103 switch (m_state) { | 103 switch (m_state) { |
| 104 case PortState::MIDIPortStateDisconnected: | 104 case PortState::MIDIPortStateDisconnected: |
| 105 return reject(scriptState, InvalidStateError, "The port has been disconn
ected."); | 105 setStates(m_state, ConnectionStatePending); |
| 106 case PortState::MIDIPortStateConnected: | 106 break; |
| 107 // TODO(toyoshim): Add blink API to perform a real open operation. | 107 case PortState::MIDIPortStateConnected: |
| 108 setStates(m_state, ConnectionStateOpen); | 108 // TODO(toyoshim): Add blink API to perform a real open and close |
| 109 return accept(scriptState); | 109 // operation. |
| 110 case PortState::MIDIPortStateOpened: | 110 setStates(m_state, ConnectionStateOpen); |
| 111 // TODO(toyoshim): Remove PortState::MIDIPortStateOpened. | 111 break; |
| 112 ASSERT_NOT_REACHED(); | 112 case PortState::MIDIPortStateOpened: |
| 113 // TODO(toyoshim): Remove PortState::MIDIPortStateOpened. |
| 114 ASSERT_NOT_REACHED(); |
| 115 break; |
| 116 } |
| 113 } | 117 } |
| 114 return reject(scriptState, InvalidStateError, "The port is in unknown state.
"); | 118 return accept(scriptState); |
| 115 } | 119 } |
| 116 | 120 |
| 117 ScriptPromise MIDIPort::close(ScriptState* scriptState) | 121 ScriptPromise MIDIPort::close(ScriptState* scriptState) |
| 118 { | 122 { |
| 119 // TODO(toyoshim): Implement the latest close() algorithm. | 123 if (m_connection != ConnectionStateClosed) { |
| 120 switch (m_state) { | 124 // TODO(toyoshim): Do clear() operation on MIDIOutput. |
| 121 case PortState::MIDIPortStateDisconnected: | |
| 122 return reject(scriptState, InvalidStateError, "The port has been disconn
ected."); | |
| 123 case PortState::MIDIPortStateConnected: | |
| 124 // TODO(toyoshim): Add blink API to perform a real close operation. | 125 // TODO(toyoshim): Add blink API to perform a real close operation. |
| 125 setStates(m_state, ConnectionStateClosed); | 126 setStates(m_state, ConnectionStateClosed); |
| 126 return accept(scriptState); | |
| 127 case PortState::MIDIPortStateOpened: | |
| 128 // TODO(toyoshim): Remove PortState::MIDIPortStateOpened. | |
| 129 ASSERT_NOT_REACHED(); | |
| 130 } | 127 } |
| 131 return reject(scriptState, InvalidStateError, "The port is in unknown state.
"); | 128 return accept(scriptState); |
| 132 } | 129 } |
| 133 | 130 |
| 134 void MIDIPort::setState(PortState state) | 131 void MIDIPort::setState(PortState state) |
| 135 { | 132 { |
| 136 setStates(state, m_connection); | 133 setStates(state, m_connection); |
| 137 } | 134 } |
| 138 | 135 |
| 139 ExecutionContext* MIDIPort::executionContext() const | 136 ExecutionContext* MIDIPort::executionContext() const |
| 140 { | 137 { |
| 141 return m_access->executionContext(); | 138 return m_access->executionContext(); |
| (...skipping 15 matching lines...) Expand all Loading... |
| 157 return ScriptPromise::rejectWithDOMException(scriptState, DOMException::crea
te(ec, message)); | 154 return ScriptPromise::rejectWithDOMException(scriptState, DOMException::crea
te(ec, message)); |
| 158 } | 155 } |
| 159 | 156 |
| 160 void MIDIPort::setStates(PortState state, ConnectionState connection) | 157 void MIDIPort::setStates(PortState state, ConnectionState connection) |
| 161 { | 158 { |
| 162 if (m_state == state && m_connection == connection) | 159 if (m_state == state && m_connection == connection) |
| 163 return; | 160 return; |
| 164 m_state = state; | 161 m_state = state; |
| 165 m_connection = connection; | 162 m_connection = connection; |
| 166 dispatchEvent(MIDIConnectionEvent::create(this)); | 163 dispatchEvent(MIDIConnectionEvent::create(this)); |
| 164 m_access->dispatchEvent(MIDIConnectionEvent::create(this)); |
| 167 } | 165 } |
| 168 | 166 |
| 169 } // namespace blink | 167 } // namespace blink |
| OLD | NEW |