sbDeviceEvent.cpp
Go to the documentation of this file.
1 /* vim: set sw=2 :miv */
2 /*
3 //
4 // BEGIN SONGBIRD GPL
5 //
6 // This file is part of the Songbird web player.
7 //
8 // Copyright(c) 2005-2008 POTI, Inc.
9 // http://songbirdnest.com
10 //
11 // This file may be licensed under the terms of of the
12 // GNU General Public License Version 2 (the "GPL").
13 //
14 // Software distributed under the License is distributed
15 // on an "AS IS" basis, WITHOUT WARRANTY OF ANY KIND, either
16 // express or implied. See the GPL for the specific language
17 // governing rights and limitations.
18 //
19 // You should have received a copy of the GPL along with this
20 // program. If not, go to http://www.gnu.org/licenses/gpl.html
21 // or write to the Free Software Foundation, Inc.,
22 // 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
23 //
24 // END SONGBIRD GPL
25 //
26 */
27 
28 #include "sbDeviceEvent.h"
29 
30 #include <nsIVariant.h>
31 
32 #include <sbIDevice.h>
33 #include "sbIDeviceEventTarget.h"
34 
35 /* note that we have a "sbDeviceEvent" IID so we can get pointers to this
36  concrete class from a COM pointer */
40 
41 sbDeviceEvent* sbDeviceEvent::CreateEvent() {
42  return new sbDeviceEvent();
43 }
44 
46  : mType(0),
47  mWasDispatched(PR_FALSE),
48  mDeviceState(sbIDevice::STATE_IDLE),
49  mDeviceSubState(sbIDevice::STATE_IDLE)
50 {
51  /* member initializers and constructor code */
52 }
53 
55 {
56  /* destructor code */
57 }
58 
59 nsresult sbDeviceEvent::InitEvent(PRUint32 aType,
60  nsIVariant *aData,
61  nsISupports *aOrigin,
62  PRUint32 aDeviceState,
63  PRUint32 aDeviceSubState)
64 {
65  NS_ENSURE_FALSE(mWasDispatched, NS_ERROR_UNEXPECTED);
66  mType = aType;
67  mData = aData;
68  mOrigin = aOrigin;
69  mDeviceState = aDeviceState;
70  mDeviceSubState = aDeviceSubState;
71  return NS_OK;
72 }
73 
74 /* readonly attribute PRUint32 type; */
75 NS_IMETHODIMP sbDeviceEvent::GetType(PRUint32 *aType)
76 {
77  NS_ENSURE_ARG_POINTER(aType);
78  *aType = mType;
79  return NS_OK;
80 }
81 
82 /* readonly attribute nsIVariant data; */
83 NS_IMETHODIMP sbDeviceEvent::GetData(nsIVariant * *aData)
84 {
85  NS_ENSURE_ARG_POINTER(aData);
86  NS_IF_ADDREF(*aData = mData);
87  return NS_OK;
88 }
89 
90 /* attribute sbIDeviceEventTarget target setter; */
92 {
93  mTarget = aTarget;
94  return NS_OK;
95 }
96 
97 /* readonly attribute sbIDeviceEventTarget target; */
98 NS_IMETHODIMP sbDeviceEvent::GetTarget(sbIDeviceEventTarget * *aTarget)
99 {
100  NS_ENSURE_ARG_POINTER(aTarget);
101  NS_IF_ADDREF(*aTarget = mTarget);
102  return NS_OK;
103 }
104 
105 /* readonly attribute nsISupports origin; */
106 NS_IMETHODIMP sbDeviceEvent::GetOrigin(nsISupports * *aOrigin)
107 {
108  NS_ENSURE_ARG_POINTER(aOrigin);
109  NS_IF_ADDREF(*aOrigin = mOrigin);
110  return NS_OK;
111 }
112 
113 nsresult sbDeviceEvent::CreateEvent(PRUint32 aType,
114  nsIVariant *aData,
115  nsISupports *aOrigin,
116  PRUint32 aDeviceState,
117  PRUint32 aDeviceSubState,
118  sbIDeviceEvent **_retval)
119 {
120  NS_ENSURE_ARG_POINTER(_retval);
121  nsCOMPtr<sbDeviceEvent> event = new sbDeviceEvent();
122  NS_ENSURE_TRUE(event, NS_ERROR_OUT_OF_MEMORY);
123 
124  nsresult rv = event->InitEvent(aType,
125  aData,
126  aOrigin,
127  aDeviceState,
128  aDeviceSubState);
129  NS_ENSURE_SUCCESS(rv, rv);
130  return CallQueryInterface(event, _retval);
131 }
132 
133 NS_IMETHODIMP sbDeviceEvent::GetDeviceState(PRUint32 * aDeviceState)
134 {
135  NS_ENSURE_ARG_POINTER(aDeviceState);
136 
137  *aDeviceState = mDeviceState;
138  return NS_OK;
139 }
140 
141 NS_IMETHODIMP sbDeviceEvent::GetDeviceSubState(PRUint32 * aDeviceSubState)
142 {
143  NS_ENSURE_ARG_POINTER(aDeviceSubState);
144 
145  *aDeviceSubState = mDeviceSubState;
146  return NS_OK;
147 }
nsCOMPtr< sbIDeviceEventTarget > mTarget
Definition: sbDeviceEvent.h:76
static sbDeviceEvent * CreateEvent()
return NS_OK
NS_IMPL_THREADSAFE_ISUPPORTS2(sbDeviceEvent, sbDeviceEvent, sbIDeviceEvent) sbDeviceEvent *sbDeviceEvent
PRUint32 mType
Definition: sbDeviceEvent.h:74
var event
const STATE_IDLE
NS_DECL_ISUPPORTS NS_DECL_SBIDEVICEEVENT nsresult InitEvent(PRUint32 aType, nsIVariant *aData, nsISupports *aOrigin, PRUint32 aDeviceState, PRUint32 aDeviceSubState)
virtual nsresult SetTarget(sbIDeviceEventTarget *aTarget)
PRUint32 mDeviceSubState
Definition: sbDeviceEvent.h:80
nsCOMPtr< nsISupports > mOrigin
Definition: sbDeviceEvent.h:77
PRUint32 mDeviceState
Definition: sbDeviceEvent.h:79
nsCOMPtr< nsIVariant > mData
Definition: sbDeviceEvent.h:75
PRBool mWasDispatched
Definition: sbDeviceEvent.h:78
_updateTextAndScrollDataForFrame aData