Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(7)

Side by Side Diff: Source/modules/webmidi/MIDIPort.h

Issue 13843021: Web MIDI: implement MIDIPort (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: (rebase) Created 7 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 /* 1 /*
2 * Copyright (C) 2012 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
11 * copyright notice, this list of conditions and the following disclaimer 11 * copyright notice, this list of conditions and the following disclaimer
12 * in the documentation and/or other materials provided with the 12 * in the documentation and/or other materials provided with the
13 * distribution. 13 * distribution.
14 * * Neither the name of Google Inc. nor the names of its 14 * * Neither the name of Google Inc. nor the names of its
15 * contributors may be used to endorse or promote products derived from 15 * contributors may be used to endorse or promote products derived from
16 * this software without specific prior written permission. 16 * this software without specific prior written permission.
17 * 17 *
18 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 18 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
19 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 19 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
20 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 20 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
21 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 21 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
22 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 22 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
23 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 23 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
24 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 24 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
25 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 25 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
26 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 26 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
27 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 27 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
28 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 28 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29 */ 29 */
30 30
31 #ifndef SourceBufferList_h 31 #ifndef MIDIPort_h
32 #define SourceBufferList_h 32 #define MIDIPort_h
33 33
34 #include "core/dom/ActiveDOMObject.h"
34 #include "core/dom/EventTarget.h" 35 #include "core/dom/EventTarget.h"
35 #include "wtf/RefCounted.h" 36 #include "wtf/RefCounted.h"
37 #include "wtf/RefPtr.h"
36 #include "wtf/Vector.h" 38 #include "wtf/Vector.h"
37 39
38 namespace WebCore { 40 namespace WebCore {
39 41
40 class SourceBuffer; 42 class MIDIPort : public ActiveDOMObject, public RefCounted<MIDIPort>, public Eve ntTarget {
41 class GenericEventQueue; 43 public:
44 enum MIDIPortTypeCode {
45 MIDIPortTypeInput,
46 MIDIPortTypeOutput
47 };
42 48
43 class SourceBufferList : public RefCounted<SourceBufferList>, public EventTarget { 49 static PassRefPtr<MIDIPort> create(ScriptExecutionContext*, const String& id , const String& manufacturer, const String& name, MIDIPortTypeCode, const String & version);
44 public: 50 virtual ~MIDIPort();
45 static PassRefPtr<SourceBufferList> create(ScriptExecutionContext* context, GenericEventQueue* asyncEventQueue)
46 {
47 return adoptRef(new SourceBufferList(context, asyncEventQueue));
48 }
49 virtual ~SourceBufferList() { }
50 51
51 unsigned long length() const; 52 String id() const { return m_id; }
52 SourceBuffer* item(unsigned index) const; 53 String manufacturer() const { return m_manufacturer; }
54 String name() const { return m_name; }
55 String type() const;
56 String version() const { return m_version; }
53 57
54 void add(PassRefPtr<SourceBuffer>); 58 using RefCounted<MIDIPort>::ref;
55 bool remove(SourceBuffer*); 59 using RefCounted<MIDIPort>::deref;
56 void clear();
57 60
58 // EventTarget interface 61 DEFINE_ATTRIBUTE_EVENT_LISTENER(disconnect);
59 virtual const AtomicString& interfaceName() const OVERRIDE;
60 virtual ScriptExecutionContext* scriptExecutionContext() const OVERRIDE;
61 62
62 using RefCounted<SourceBufferList>::ref; 63 // EventTarget
63 using RefCounted<SourceBufferList>::deref; 64 virtual const AtomicString& interfaceName() const OVERRIDE { return eventNam es().interfaceForMIDIPort; }
65 virtual ScriptExecutionContext* scriptExecutionContext() const OVERRIDE { re turn ActiveDOMObject::scriptExecutionContext(); }
66
67 // ActiveDOMObject
68 virtual bool canSuspend() const OVERRIDE { return true; }
64 69
65 protected: 70 protected:
66 virtual EventTargetData* eventTargetData() OVERRIDE; 71 MIDIPort(ScriptExecutionContext*, const String& id, const String& manufactur er, const String& name, MIDIPortTypeCode, const String& version);
67 virtual EventTargetData* ensureEventTargetData() OVERRIDE;
68 72
69 private: 73 private:
70 SourceBufferList(ScriptExecutionContext*, GenericEventQueue*); 74 // EventTarget
71
72 void createAndFireEvent(const AtomicString&);
73
74 virtual void refEventTarget() OVERRIDE { ref(); } 75 virtual void refEventTarget() OVERRIDE { ref(); }
75 virtual void derefEventTarget() OVERRIDE { deref(); } 76 virtual void derefEventTarget() OVERRIDE { deref(); }
77 virtual EventTargetData* eventTargetData() OVERRIDE { return &m_eventTargetD ata; }
78 virtual EventTargetData* ensureEventTargetData() OVERRIDE { return &m_eventT argetData; }
76 79
80 String m_id;
81 String m_manufacturer;
82 String m_name;
83 MIDIPortTypeCode m_type;
84 String m_version;
77 EventTargetData m_eventTargetData; 85 EventTargetData m_eventTargetData;
78 ScriptExecutionContext* m_scriptExecutionContext; 86 };
79 GenericEventQueue* m_asyncEventQueue;
80 87
81 Vector<RefPtr<SourceBuffer> > m_list; 88 typedef Vector<RefPtr<MIDIPort> > MIDIPortVector;
82 };
83 89
84 } // namespace WebCore 90 } // namespace WebCore
85 91
86 #endif 92 #endif // MIDIPort_h
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698