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 29 matching lines...) Expand all Loading... | |
40 | 40 |
41 using PortState = MIDIAccessor::MIDIPortState; | 41 using PortState = MIDIAccessor::MIDIPortState; |
42 | 42 |
43 MIDIPort::MIDIPort(MIDIAccess* access, const String& id, const String& manufactu rer, const String& name, MIDIPortTypeCode type, const String& version, PortState state) | 43 MIDIPort::MIDIPort(MIDIAccess* access, const String& id, const String& manufactu rer, const String& name, MIDIPortTypeCode type, const String& version, PortState state) |
44 : m_id(id) | 44 : m_id(id) |
45 , m_manufacturer(manufacturer) | 45 , m_manufacturer(manufacturer) |
46 , m_name(name) | 46 , m_name(name) |
47 , m_type(type) | 47 , m_type(type) |
48 , m_version(version) | 48 , m_version(version) |
49 , m_access(access) | 49 , m_access(access) |
50 , m_connection(MIDIPortConnectionStateClosed) | |
50 { | 51 { |
51 ASSERT(access); | 52 ASSERT(access); |
52 ASSERT(type == MIDIPortTypeInput || type == MIDIPortTypeOutput); | 53 ASSERT(type == MIDIPortTypeInput || type == MIDIPortTypeOutput); |
53 ASSERT(state == PortState::MIDIPortStateDisconnected | 54 ASSERT(state == PortState::MIDIPortStateDisconnected |
54 || state == PortState::MIDIPortStateConnected | 55 || state == PortState::MIDIPortStateConnected |
55 || state == PortState::MIDIPortStateOpened); | 56 || state == PortState::MIDIPortStateOpened); |
56 // FIXME: Remove following code once blink API has a real open and close | 57 // FIXME: Remove following code once blink API has a real open and close |
57 // operations. | 58 // operations. |
58 if (state == PortState::MIDIPortStateOpened) | 59 if (state == PortState::MIDIPortStateOpened) |
59 state = PortState::MIDIPortStateConnected; | 60 state = PortState::MIDIPortStateConnected; |
60 m_state = state; | 61 m_state = state; |
61 } | 62 } |
62 | 63 |
64 String MIDIPort::connection() const | |
65 { | |
66 switch (m_connection) { | |
67 case MIDIPortConnectionStateOpen: | |
68 return "open"; | |
69 case MIDIPortConnectionStateClosed: | |
70 return "closed"; | |
71 case MIDIPortConnectionStatePending: | |
72 return "pending"; | |
73 default: | |
tkent
2015/03/30 23:16:30
Please do not add "default:" It prevents compile-
Takashi Toyoshima
2015/03/31 01:19:48
Done.
| |
74 ASSERT_NOT_REACHED(); | |
75 } | |
76 return emptyString(); | |
77 } | |
78 | |
63 String MIDIPort::state() const | 79 String MIDIPort::state() const |
64 { | 80 { |
65 switch (m_state) { | 81 switch (m_state) { |
66 case PortState::MIDIPortStateDisconnected: | 82 case PortState::MIDIPortStateDisconnected: |
67 return "disconnected"; | 83 return "disconnected"; |
68 case PortState::MIDIPortStateConnected: | 84 case PortState::MIDIPortStateConnected: |
69 return "connected"; | 85 return "connected"; |
70 case PortState::MIDIPortStateOpened: | |
71 return "opened"; | |
72 default: | 86 default: |
73 ASSERT_NOT_REACHED(); | 87 ASSERT_NOT_REACHED(); |
74 } | 88 } |
75 return emptyString(); | 89 return emptyString(); |
76 } | 90 } |
77 | 91 |
78 String MIDIPort::type() const | 92 String MIDIPort::type() const |
79 { | 93 { |
80 switch (m_type) { | 94 switch (m_type) { |
81 case MIDIPortTypeInput: | 95 case MIDIPortTypeInput: |
82 return "input"; | 96 return "input"; |
83 case MIDIPortTypeOutput: | 97 case MIDIPortTypeOutput: |
84 return "output"; | 98 return "output"; |
85 default: | 99 default: |
86 ASSERT_NOT_REACHED(); | 100 ASSERT_NOT_REACHED(); |
87 } | 101 } |
88 return emptyString(); | 102 return emptyString(); |
89 } | 103 } |
90 | 104 |
91 ScriptPromise MIDIPort::open(ScriptState* scriptState) | 105 ScriptPromise MIDIPort::open(ScriptState* scriptState) |
92 { | 106 { |
107 // FIXME: Implement the latest open() algorithm. | |
tkent
2015/03/30 23:16:30
nit: FIXME -> TODO(toyoshim)
Takashi Toyoshima
2015/03/31 01:19:48
Done.
| |
93 switch (m_state) { | 108 switch (m_state) { |
94 case PortState::MIDIPortStateDisconnected: | 109 case PortState::MIDIPortStateDisconnected: |
95 return reject(scriptState, InvalidStateError, "The port has been disconn ected."); | 110 return reject(scriptState, InvalidStateError, "The port has been disconn ected."); |
96 case PortState::MIDIPortStateConnected: | 111 case PortState::MIDIPortStateConnected: |
97 // FIXME: Add blink API to perform a real open operation. | 112 // FIXME: Add blink API to perform a real open operation. |
98 setState(PortState::MIDIPortStateOpened); | 113 setStates(m_state, MIDIPortConnectionStateOpen); |
99 // fall through | |
100 case PortState::MIDIPortStateOpened: | |
101 return accept(scriptState); | 114 return accept(scriptState); |
102 default: | 115 default: |
103 ASSERT_NOT_REACHED(); | 116 ASSERT_NOT_REACHED(); |
104 } | 117 } |
105 return reject(scriptState, InvalidStateError, "The port is in unknown state. "); | 118 return reject(scriptState, InvalidStateError, "The port is in unknown state. "); |
106 } | 119 } |
107 | 120 |
108 ScriptPromise MIDIPort::close(ScriptState* scriptState) | 121 ScriptPromise MIDIPort::close(ScriptState* scriptState) |
109 { | 122 { |
123 // FIXME: Implement the latest close() algorithm. | |
tkent
2015/03/30 23:16:30
Ditto.
Takashi Toyoshima
2015/03/31 01:19:48
Done.
| |
110 switch (m_state) { | 124 switch (m_state) { |
111 case PortState::MIDIPortStateDisconnected: | 125 case PortState::MIDIPortStateDisconnected: |
112 return reject(scriptState, InvalidStateError, "The port has been disconn ected."); | 126 return reject(scriptState, InvalidStateError, "The port has been disconn ected."); |
113 case PortState::MIDIPortStateOpened: | 127 case PortState::MIDIPortStateConnected: |
114 // FIXME: Add blink API to perform a real close operation. | 128 // FIXME: Add blink API to perform a real close operation. |
115 setState(PortState::MIDIPortStateConnected); | 129 setStates(m_state, MIDIPortConnectionStateClosed); |
116 // fall through | |
117 case PortState::MIDIPortStateConnected: | |
118 return accept(scriptState); | 130 return accept(scriptState); |
119 default: | 131 default: |
120 ASSERT_NOT_REACHED(); | 132 ASSERT_NOT_REACHED(); |
121 } | 133 } |
122 return reject(scriptState, InvalidStateError, "The port is in unknown state. "); | 134 return reject(scriptState, InvalidStateError, "The port is in unknown state. "); |
123 } | 135 } |
124 | 136 |
125 void MIDIPort::setState(PortState state) | 137 void MIDIPort::setState(PortState state) |
126 { | 138 { |
127 if (m_state == state) | 139 setStates(state, m_connection); |
128 return; | |
129 m_state = state; | |
130 dispatchEvent(MIDIConnectionEvent::create(this)); | |
131 } | 140 } |
132 | 141 |
133 ExecutionContext* MIDIPort::executionContext() const | 142 ExecutionContext* MIDIPort::executionContext() const |
134 { | 143 { |
135 return m_access->executionContext(); | 144 return m_access->executionContext(); |
136 } | 145 } |
137 | 146 |
138 DEFINE_TRACE(MIDIPort) | 147 DEFINE_TRACE(MIDIPort) |
139 { | 148 { |
140 visitor->trace(m_access); | 149 visitor->trace(m_access); |
141 RefCountedGarbageCollectedEventTargetWithInlineData<MIDIPort>::trace(visitor ); | 150 RefCountedGarbageCollectedEventTargetWithInlineData<MIDIPort>::trace(visitor ); |
142 } | 151 } |
143 | 152 |
144 ScriptPromise MIDIPort::accept(ScriptState* scriptState) | 153 ScriptPromise MIDIPort::accept(ScriptState* scriptState) |
145 { | 154 { |
146 return ScriptPromise::cast(scriptState, toV8(this, scriptState->context()->G lobal(), scriptState->isolate())); | 155 return ScriptPromise::cast(scriptState, toV8(this, scriptState->context()->G lobal(), scriptState->isolate())); |
147 } | 156 } |
148 | 157 |
149 ScriptPromise MIDIPort::reject(ScriptState* scriptState, ExceptionCode ec, const String& message) | 158 ScriptPromise MIDIPort::reject(ScriptState* scriptState, ExceptionCode ec, const String& message) |
150 { | 159 { |
151 return ScriptPromise::rejectWithDOMException(scriptState, DOMException::crea te(ec, message)); | 160 return ScriptPromise::rejectWithDOMException(scriptState, DOMException::crea te(ec, message)); |
152 } | 161 } |
153 | 162 |
163 void MIDIPort::setStates(PortState state, MIDIPortConnectionState connection) | |
164 { | |
165 if (m_state == state && m_connection == connection) | |
166 return; | |
167 m_state = state; | |
168 m_connection = connection; | |
169 dispatchEvent(MIDIConnectionEvent::create(this)); | |
tkent
2015/03/30 23:16:30
Is it possible to delete |this| by JavaScript code
Takashi Toyoshima
2015/03/31 01:19:48
Ah, I see. JavaScript can release the last referen
| |
170 } | |
171 | |
154 } // namespace blink | 172 } // namespace blink |
OLD | NEW |