|
1 /* |
|
2 * Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies). |
|
3 * All rights reserved. |
|
4 * This component and the accompanying materials are made available |
|
5 * under the terms of "Eclipse Public License v1.0" |
|
6 * which accompanies this distribution, and is available |
|
7 * at the URL "http://www.eclipse.org/legal/epl-v10.html". |
|
8 * |
|
9 * Initial Contributors: |
|
10 * Nokia Corporation - initial contribution. |
|
11 * |
|
12 * Contributors: |
|
13 * |
|
14 * Description: Telephony Multimedia Service |
|
15 * |
|
16 */ |
|
17 |
|
18 #include <tms.h> |
|
19 #include <tmsbuffer.h> |
|
20 #include "tmsutility.h" |
|
21 #include "tmsshared.h" |
|
22 #include "tmsqueuehandler.h" |
|
23 #include "tmsmembuffer.h" |
|
24 #include "tmsglobalcontext.h" |
|
25 #include "tmscallproxy.h" |
|
26 |
|
27 using namespace TMS; |
|
28 |
|
29 // ---------------------------------------------------------------------------- |
|
30 // CQueueHandler::NewL |
|
31 // Symbian constructor |
|
32 // ---------------------------------------------------------------------------- |
|
33 // |
|
34 CQueueHandler* CQueueHandler::NewL(RMsgQueue<TmsMsgBuf>* aMsgQueue, |
|
35 TMSGlobalContext* glblCtx) |
|
36 { |
|
37 CQueueHandler* self = new (ELeave) CQueueHandler(aMsgQueue, glblCtx); |
|
38 CleanupStack::PushL(self); |
|
39 self->ConstructL(); |
|
40 CleanupStack::Pop(self); |
|
41 return self; |
|
42 } |
|
43 |
|
44 // ---------------------------------------------------------------------------- |
|
45 // CQueueHandler::ConstructL |
|
46 // Second phase constructor. |
|
47 // ---------------------------------------------------------------------------- |
|
48 // |
|
49 void CQueueHandler::ConstructL() |
|
50 { |
|
51 iObserver = NULL; |
|
52 } |
|
53 |
|
54 // ---------------------------------------------------------------------------- |
|
55 // CQueueHandler::~CQueueHandler |
|
56 // Destructor. |
|
57 // ---------------------------------------------------------------------------- |
|
58 // |
|
59 CQueueHandler::~CQueueHandler() |
|
60 { |
|
61 Cancel(); |
|
62 if (iMsgQueue->Handle() > 0) |
|
63 { |
|
64 iMsgQueue->Close(); |
|
65 } |
|
66 iObserversList.Reset(); |
|
67 iClientList.Reset(); |
|
68 iChunk.Close(); |
|
69 delete iBuffer; |
|
70 iObserver = NULL; |
|
71 } |
|
72 |
|
73 // ---------------------------------------------------------------------------- |
|
74 // CQueueHandler::CQueueHandler |
|
75 // Constructor. |
|
76 // ---------------------------------------------------------------------------- |
|
77 // |
|
78 CQueueHandler::CQueueHandler(RMsgQueue<TmsMsgBuf>* aMsgQueue, |
|
79 TMSGlobalContext* glblCtx) : |
|
80 CActive(CActive::EPriorityStandard), |
|
81 iMsgQueue(aMsgQueue), |
|
82 iChunkDataPtr(0, 0, 0) |
|
83 { |
|
84 CActiveScheduler::Add(this); |
|
85 iTMSGlobalContext = glblCtx; |
|
86 } |
|
87 |
|
88 // ---------------------------------------------------------------------------- |
|
89 // CQueueHandler::Start |
|
90 // Start listening for events on queue 0. |
|
91 // ---------------------------------------------------------------------------- |
|
92 // |
|
93 void CQueueHandler::Start() |
|
94 { |
|
95 if (!IsActive()) |
|
96 { |
|
97 iMsgQueue->NotifyDataAvailable(iStatus); |
|
98 SetActive(); |
|
99 } |
|
100 } |
|
101 |
|
102 // ---------------------------------------------------------------------------- |
|
103 // CQueueHandler::AddObserver |
|
104 // |
|
105 // ---------------------------------------------------------------------------- |
|
106 // |
|
107 TInt CQueueHandler::AddObserver(MQueueHandlerObserver& aObserver, |
|
108 TInt /*aClientId*/) |
|
109 { |
|
110 TInt status = KErrNone; |
|
111 |
|
112 if (iObserver == NULL) |
|
113 { |
|
114 iObserver = &aObserver; |
|
115 } |
|
116 else |
|
117 { |
|
118 status = KErrAlreadyExists; |
|
119 } |
|
120 return status; |
|
121 } |
|
122 |
|
123 // ---------------------------------------------------------------------------- |
|
124 // CQueueHandler::AddObserver |
|
125 // Marks observer as inactive in the list |
|
126 // ---------------------------------------------------------------------------- |
|
127 // |
|
128 TInt CQueueHandler::RemoveObserver(MQueueHandlerObserver& /*aObserver*/) |
|
129 { |
|
130 iObserver = NULL; |
|
131 return KErrNone; |
|
132 } |
|
133 |
|
134 // ---------------------------------------------------------------------------- |
|
135 // CQueueHandler::DoCancel |
|
136 // Cancel outstanding request |
|
137 // ---------------------------------------------------------------------------- |
|
138 // |
|
139 void CQueueHandler::DoCancel() |
|
140 { |
|
141 iMsgQueue->CancelDataAvailable(); |
|
142 } |
|
143 |
|
144 // ---------------------------------------------------------------------------- |
|
145 // CQueueHandler::RunL |
|
146 // Process requests. |
|
147 // ---------------------------------------------------------------------------- |
|
148 // |
|
149 void CQueueHandler::RunL() |
|
150 { |
|
151 TmsMsgBuf msgBuf; |
|
152 TInt err = iMsgQueue->Receive(msgBuf); |
|
153 |
|
154 // Start monitoring for more events before calling the observer in case |
|
155 // client decides to destroy us before this RunL completes executing. |
|
156 Start(); |
|
157 |
|
158 if (iObserver == NULL) |
|
159 { |
|
160 return; |
|
161 } |
|
162 |
|
163 if (err == KErrNone) |
|
164 { |
|
165 switch (msgBuf.iRequest) |
|
166 { |
|
167 case ECmdGlobalEffectChange: |
|
168 iObserver->QueueEvent(msgBuf.iInt, msgBuf.iStatus, NULL); |
|
169 break; |
|
170 case ECmdRingToneOpenComplete: |
|
171 iObserver->QueueEvent(TMS_EVENT_RINGTONE_OPEN_COMPLETE, |
|
172 msgBuf.iStatus, &msgBuf.iInt64); |
|
173 break; |
|
174 case ECmdRingTonePlayComplete: |
|
175 iObserver->QueueEvent(TMS_EVENT_RINGTONE_PLAY_COMPLETE, |
|
176 msgBuf.iStatus, NULL); |
|
177 break; |
|
178 case ECmdGlobalRoutingChange: |
|
179 iObserver->QueueEvent(msgBuf.iInt, msgBuf.iStatus, |
|
180 &msgBuf.iUint); |
|
181 break; |
|
182 case ECmdDTMFOpenDnlinkComplete: |
|
183 case ECmdDTMFOpenUplinkComplete: |
|
184 iObserver->QueueEvent(TMS_EVENT_DTMF_TONE_STARTED, |
|
185 msgBuf.iStatus, NULL); |
|
186 break; |
|
187 case ECmdDTMFTonePlayFinished: |
|
188 iObserver->QueueEvent(TMS_EVENT_DTMF_TONE_STOPPED, |
|
189 msgBuf.iStatus, NULL); |
|
190 break; |
|
191 default: |
|
192 break; |
|
193 } |
|
194 } |
|
195 } |
|
196 |
|
197 // ---------------------------------------------------------------------------- |
|
198 // CQueueHandler::RunError |
|
199 // Process requests. |
|
200 // ---------------------------------------------------------------------------- |
|
201 // |
|
202 TInt CQueueHandler::RunError(TInt /*aError*/) |
|
203 { |
|
204 // Current implementation of RunL does not leave |
|
205 return 0; |
|
206 } |
|
207 |
|
208 // ---------------------------------------------------------------------------- |
|
209 // CQueueHandler::Status |
|
210 // Return request status. |
|
211 // ---------------------------------------------------------------------------- |
|
212 // |
|
213 TRequestStatus* CQueueHandler::Status() |
|
214 { |
|
215 return &iStatus; |
|
216 } |
|
217 |
|
218 // End of File |