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

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

Issue 14044022: Web MIDI: implement MIDIAccess (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: haraken review Created 7 years, 7 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) 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 10 matching lines...) Expand all
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 MIDIPort_h 31 #ifndef MIDIAccess_h
32 #define MIDIPort_h 32 #define MIDIAccess_h
33 33
34 #include "core/dom/ActiveDOMObject.h" 34 #include "core/dom/ActiveDOMObject.h"
35 #include "core/dom/EventTarget.h" 35 #include "core/dom/EventTarget.h"
36 #include "modules/webmidi/MIDIPort.h"
36 #include "wtf/RefCounted.h" 37 #include "wtf/RefCounted.h"
37 #include "wtf/RefPtr.h" 38 #include "wtf/RefPtr.h"
38 #include "wtf/Vector.h" 39 #include "wtf/Vector.h"
39 40
40 namespace WebCore { 41 namespace WebCore {
41 42
42 class MIDIPort : public ActiveDOMObject, public RefCounted<MIDIPort>, public Eve ntTarget { 43 class MIDIInput;
44 class MIDIOutput;
45 class Navigator;
haraken 2013/04/26 17:33:25 Nit: This isn't needed.
46 class ScriptExecutionContext;
47
48 class MIDIAccess : public ActiveDOMObject, public RefCounted<MIDIAccess>, public EventTarget {
43 public: 49 public:
44 enum MIDIPortTypeCode { 50 virtual ~MIDIAccess();
Chris Rogers 2013/04/29 19:22:09 small nit: I'd move this destructor after the crea
45 MIDIPortTypeInput, 51 static PassRefPtr<MIDIAccess> create(ScriptExecutionContext*);
46 MIDIPortTypeOutput
47 };
48 52
49 static PassRefPtr<MIDIPort> create(ScriptExecutionContext*, const String& id , const String& manufacturer, const String& name, MIDIPortTypeCode, const String & version); 53 const MIDIPortVector& getInputs();
50 virtual ~MIDIPort(); 54 const MIDIPortVector& getOutputs();
55 RefPtr<MIDIInput> getInput(PassRefPtr<MIDIPort>, ExceptionCode&);
56 RefPtr<MIDIInput> getInput(const String&, ExceptionCode&);
57 RefPtr<MIDIInput> getInput(short, ExceptionCode&);
58 RefPtr<MIDIOutput> getOutput(PassRefPtr<MIDIPort>, ExceptionCode&);
59 RefPtr<MIDIOutput> getOutput(const String&, ExceptionCode&);
60 RefPtr<MIDIOutput> getOutput(short, ExceptionCode&);
51 61
52 String id() const { return m_id; } 62 using RefCounted<MIDIAccess>::ref;
53 String manufacturer() const { return m_manufacturer; } 63 using RefCounted<MIDIAccess>::deref;
54 String name() const { return m_name; }
55 String type() const;
56 String version() const { return m_version; }
57 64
58 using RefCounted<MIDIPort>::ref; 65 DEFINE_ATTRIBUTE_EVENT_LISTENER(connect);
59 using RefCounted<MIDIPort>::deref;
60
61 DEFINE_ATTRIBUTE_EVENT_LISTENER(disconnect); 66 DEFINE_ATTRIBUTE_EVENT_LISTENER(disconnect);
62 67
63 // EventTarget 68 // EventTarget
64 virtual const AtomicString& interfaceName() const OVERRIDE { return eventNam es().interfaceForMIDIPort; } 69 virtual const AtomicString& interfaceName() const OVERRIDE { return eventNam es().interfaceForMIDIAccess; }
65 virtual ScriptExecutionContext* scriptExecutionContext() const OVERRIDE { re turn ActiveDOMObject::scriptExecutionContext(); } 70 virtual ScriptExecutionContext* scriptExecutionContext() const OVERRIDE { re turn ActiveDOMObject::scriptExecutionContext(); }
66 71
67 // ActiveDOMObject 72 // ActiveDOMObject
68 virtual bool canSuspend() const OVERRIDE { return true; } 73 virtual bool canSuspend() const OVERRIDE { return true; }
69 74
70 protected: 75 private:
71 MIDIPort(ScriptExecutionContext*, const String& id, const String& manufactur er, const String& name, MIDIPortTypeCode, const String& version); 76 explicit MIDIAccess(ScriptExecutionContext*);
72 77
73 private:
74 // EventTarget 78 // EventTarget
75 virtual void refEventTarget() OVERRIDE { ref(); } 79 virtual void refEventTarget() OVERRIDE { ref(); }
76 virtual void derefEventTarget() OVERRIDE { deref(); } 80 virtual void derefEventTarget() OVERRIDE { deref(); }
77 virtual EventTargetData* eventTargetData() OVERRIDE { return &m_eventTargetD ata; } 81 virtual EventTargetData* eventTargetData() OVERRIDE { return &m_eventTargetD ata; }
78 virtual EventTargetData* ensureEventTargetData() OVERRIDE { return &m_eventT argetData; } 82 virtual EventTargetData* ensureEventTargetData() OVERRIDE { return &m_eventT argetData; }
79 83
80 String m_id; 84 MIDIPortVector m_inputs;
81 String m_manufacturer; 85 MIDIPortVector m_outputs;
82 String m_name;
83 MIDIPortTypeCode m_type;
84 String m_version;
85 EventTargetData m_eventTargetData; 86 EventTargetData m_eventTargetData;
86 }; 87 };
87 88
88 typedef Vector<RefPtr<MIDIPort> > MIDIPortVector;
89
90 } // namespace WebCore 89 } // namespace WebCore
91 90
92 #endif // MIDIPort_h 91 #endif // MIDIAccess_h
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698