dom/telephony/TelephonyCall.h

changeset 0
6474c204b198
equal deleted inserted replaced
-1:000000000000 0:fae3c51ba91f
1 /* -*- Mode: c++; c-basic-offset: 2; indent-tabs-mode: nil; tab-width: 40 -*- */
2 /* vim: set ts=2 et sw=2 tw=40: */
3 /* This Source Code Form is subject to the terms of the Mozilla Public
4 * License, v. 2.0. If a copy of the MPL was not distributed with this
5 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
6
7 #ifndef mozilla_dom_telephony_telephonycall_h__
8 #define mozilla_dom_telephony_telephonycall_h__
9
10 #include "mozilla/dom/telephony/TelephonyCommon.h"
11
12 #include "mozilla/dom/DOMError.h"
13
14 class nsPIDOMWindow;
15
16 namespace mozilla {
17 namespace dom {
18
19 class TelephonyCall MOZ_FINAL : public DOMEventTargetHelper
20 {
21 nsRefPtr<Telephony> mTelephony;
22 nsRefPtr<TelephonyCallGroup> mGroup;
23
24 uint32_t mServiceId;
25 nsString mNumber;
26 nsString mSecondNumber;
27 nsString mState;
28 bool mEmergency;
29 nsRefPtr<DOMError> mError;
30 bool mSwitchable;
31 bool mMergeable;
32
33 uint32_t mCallIndex;
34 uint16_t mCallState;
35 bool mLive;
36
37 public:
38 NS_DECL_ISUPPORTS_INHERITED
39 NS_REALLY_FORWARD_NSIDOMEVENTTARGET(DOMEventTargetHelper)
40 NS_DECL_CYCLE_COLLECTION_CLASS_INHERITED(TelephonyCall,
41 DOMEventTargetHelper)
42
43 friend class Telephony;
44
45 nsPIDOMWindow*
46 GetParentObject() const
47 {
48 return GetOwner();
49 }
50
51 // WrapperCache
52 virtual JSObject*
53 WrapObject(JSContext* aCx) MOZ_OVERRIDE;
54
55 // WebIDL
56 void
57 GetNumber(nsString& aNumber) const
58 {
59 aNumber.Assign(mNumber);
60 }
61
62 void
63 GetSecondNumber(nsString& aSecondNumber) const
64 {
65 aSecondNumber.Assign(mSecondNumber);
66 }
67
68 void
69 GetState(nsString& aState) const
70 {
71 aState.Assign(mState);
72 }
73
74 bool
75 Emergency() const
76 {
77 return mEmergency;
78 }
79
80 bool
81 Switchable() const
82 {
83 return mSwitchable;
84 }
85
86 bool
87 Mergeable() const
88 {
89 return mMergeable;
90 }
91
92 already_AddRefed<DOMError>
93 GetError() const;
94
95 already_AddRefed<TelephonyCallGroup>
96 GetGroup() const;
97
98 void
99 Answer(ErrorResult& aRv);
100
101 void
102 HangUp(ErrorResult& aRv);
103
104 void
105 Hold(ErrorResult& aRv);
106
107 void
108 Resume(ErrorResult& aRv);
109
110 IMPL_EVENT_HANDLER(statechange)
111 IMPL_EVENT_HANDLER(dialing)
112 IMPL_EVENT_HANDLER(alerting)
113 IMPL_EVENT_HANDLER(connecting)
114 IMPL_EVENT_HANDLER(connected)
115 IMPL_EVENT_HANDLER(disconnecting)
116 IMPL_EVENT_HANDLER(disconnected)
117 IMPL_EVENT_HANDLER(holding)
118 IMPL_EVENT_HANDLER(held)
119 IMPL_EVENT_HANDLER(resuming)
120 IMPL_EVENT_HANDLER(error)
121 IMPL_EVENT_HANDLER(groupchange)
122
123 static already_AddRefed<TelephonyCall>
124 Create(Telephony* aTelephony, uint32_t aServiceId,
125 const nsAString& aNumber, uint16_t aCallState,
126 uint32_t aCallIndex = telephony::kOutgoingPlaceholderCallIndex,
127 bool aEmergency = false, bool aIsConference = false,
128 bool aSwitchable = true, bool aMergeable = true);
129
130 void
131 ChangeState(uint16_t aCallState)
132 {
133 ChangeStateInternal(aCallState, true);
134 }
135
136 uint32_t
137 ServiceId() const
138 {
139 return mServiceId;
140 }
141
142 uint32_t
143 CallIndex() const
144 {
145 return mCallIndex;
146 }
147
148 void
149 UpdateCallIndex(uint32_t aCallIndex)
150 {
151 NS_ASSERTION(mCallIndex == telephony::kOutgoingPlaceholderCallIndex,
152 "Call index should not be set!");
153 mCallIndex = aCallIndex;
154 }
155
156 uint16_t
157 CallState() const
158 {
159 return mCallState;
160 }
161
162 void
163 UpdateEmergency(bool aEmergency)
164 {
165 mEmergency = aEmergency;
166 }
167
168 void
169 UpdateSecondNumber(const nsAString& aNumber)
170 {
171 mSecondNumber = aNumber;
172 }
173
174 void
175 UpdateSwitchable(bool aSwitchable) {
176 mSwitchable = aSwitchable;
177 }
178
179 void
180 UpdateMergeable(bool aMergeable) {
181 mMergeable = aMergeable;
182 }
183
184 void
185 NotifyError(const nsAString& aError);
186
187 void
188 ChangeGroup(TelephonyCallGroup* aGroup);
189
190 private:
191 TelephonyCall(nsPIDOMWindow* aOwner);
192
193 ~TelephonyCall();
194
195 void
196 ChangeStateInternal(uint16_t aCallState, bool aFireEvents);
197
198 nsresult
199 DispatchCallEvent(const nsAString& aType,
200 TelephonyCall* aCall);
201 };
202
203 } // namespace dom
204 } // namespace mozilla
205
206 #endif // mozilla_dom_telephony_telephonycall_h__

mercurial