|
1 /* |
|
2 * Copyright (c) 2002-2007 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: RAknSoundServerSession implementation. Direct copy from |
|
15 * aknsoundplayer.cpp. |
|
16 * |
|
17 */ |
|
18 |
|
19 #include <e32std.h> |
|
20 #include <s32mem.h> |
|
21 #include <eikkeysound.h> |
|
22 #include "aknsoundserversession.h" |
|
23 |
|
24 // CONSTANTS |
|
25 const TInt KAknResourceBufferSize = 512; |
|
26 |
|
27 // RAknSoundServerSession |
|
28 |
|
29 TInt RAknSoundServerSession::Connect() |
|
30 { |
|
31 iKeySoundServerExists = EFalse; |
|
32 |
|
33 // Create a session with zero message slots (since we have no asycronous calls) |
|
34 TInt ret=CreateSession(__KEYSOUND_SERVER_NAME,TVersion(KKeySoundServMajorVN,KKeySoundServMinorVN,KKeySoundServBuildVN),0); |
|
35 if ( ret == KErrNone ) |
|
36 { |
|
37 iKeySoundServerExists = ETrue; |
|
38 } |
|
39 return KErrNone; |
|
40 } |
|
41 |
|
42 TInt RAknSoundServerSession::ServerRequest(TInt aFunction,const TIpcArgs& aArgs) |
|
43 { |
|
44 TInt err = KErrServerTerminated; |
|
45 if (Handle()) |
|
46 { |
|
47 err = SendReceive(aFunction, aArgs); |
|
48 } |
|
49 |
|
50 if (err == KErrServerTerminated) |
|
51 { |
|
52 // Try to reconnect, if the keysound server has been shutdown |
|
53 Connect(); |
|
54 if ( iKeySoundServerExists ) |
|
55 { |
|
56 err = SendReceive(aFunction, aArgs); |
|
57 } |
|
58 else |
|
59 { |
|
60 return KErrNone; // We couldn't start KeySoundServer, just omit the error.. |
|
61 } |
|
62 } |
|
63 return err; |
|
64 } |
|
65 |
|
66 TBool RAknSoundServerSession::Init(TInt aUid) |
|
67 { |
|
68 // Initialise returnCode to ETrue because ServerRequest may fail to set it if sound |
|
69 // server is broken, and in that case we do not want to attempt to load sounds from |
|
70 // resource, which may happen if the uninitialised value == EFalse. |
|
71 TPckgBuf<TInt> returnCode(ETrue); |
|
72 |
|
73 TIpcArgs args ( &returnCode, aUid ); |
|
74 ServerRequest(EKeySoundServerInit,args); |
|
75 return returnCode(); |
|
76 } |
|
77 |
|
78 #pragma warning( disable : 4244 ) |
|
79 //\S60\AVKON\SRC\Aknsoundplayer.cpp(404) : warning C4244: '=' : conversion from 'int' to 'short', possible loss of data |
|
80 |
|
81 void RAknSoundServerSession::AddSoundInfoResourceL(TInt aUid, TResourceReader aReader) |
|
82 { |
|
83 // Read information from resource read, and package up as a buffer |
|
84 CBufFlat* buffer = CBufFlat::NewL(KAknResourceBufferSize); |
|
85 CleanupStack::PushL(buffer); |
|
86 |
|
87 RBufWriteStream bufStream; |
|
88 bufStream.Open(*buffer); |
|
89 |
|
90 CleanupClosePushL(bufStream); |
|
91 |
|
92 TInt count = aReader.ReadInt16(); |
|
93 |
|
94 bufStream.WriteUint16L(count); |
|
95 |
|
96 for (TInt ii=0; ii<count; ii++) |
|
97 { |
|
98 TInt struct_id1 = aReader.ReadInt16(); |
|
99 TInt struct_id2 = aReader.ReadInt16(); |
|
100 TInt sid; |
|
101 TInt priority; |
|
102 TBool isAverell1Structure = ETrue; |
|
103 if (struct_id1 == 0x1234 && struct_id2 == 0x5678) |
|
104 { |
|
105 isAverell1Structure = EFalse; |
|
106 sid = aReader.ReadInt16(); |
|
107 priority = aReader.ReadInt16(); |
|
108 } |
|
109 else |
|
110 { |
|
111 sid = struct_id1; |
|
112 priority = struct_id2; |
|
113 } |
|
114 |
|
115 TInt soundId = (aUid << 16) + sid; |
|
116 TInt preference = aReader.ReadInt32(); |
|
117 TPtrC file = aReader.ReadTPtrC(); |
|
118 TInt frequency = aReader.ReadInt16(); |
|
119 TInt ms = aReader.ReadInt32(); |
|
120 |
|
121 TInt seqLength = aReader.ReadInt16(); |
|
122 |
|
123 bufStream.WriteUint32L(soundId); |
|
124 bufStream.WriteUint16L(priority); |
|
125 bufStream.WriteUint32L(preference); |
|
126 if (file.Length() != 0) |
|
127 { |
|
128 bufStream.WriteUint8L(0); // type 0, file |
|
129 bufStream << file; |
|
130 } |
|
131 else if (seqLength == 0) |
|
132 { |
|
133 bufStream.WriteUint8L(1); // type 1, tone |
|
134 bufStream.WriteUint16L(frequency); |
|
135 bufStream.WriteUint32L(ms); |
|
136 } |
|
137 else |
|
138 { |
|
139 // Write sequence |
|
140 bufStream.WriteUint8L(2); // type 2, sequence |
|
141 TInt actualLength = aReader.ReadUint16(); |
|
142 bufStream.WriteUint16L(actualLength); |
|
143 for (TInt count=0; count<actualLength; count++) |
|
144 { |
|
145 bufStream.WriteUint8L(aReader.ReadUint8()); |
|
146 } |
|
147 } |
|
148 if ( !seqLength && !isAverell1Structure ) |
|
149 { |
|
150 aReader.ReadUint16(); // ignore |
|
151 } |
|
152 |
|
153 bufStream.WriteUint8L(aReader.ReadUint8()); // Read volume info. |
|
154 } |
|
155 |
|
156 CleanupStack::PopAndDestroy(); // bufstream close |
|
157 |
|
158 TPtr8 bufPtr = buffer->Ptr(0); |
|
159 TIpcArgs args (aUid, bufPtr.Length(), &bufPtr); |
|
160 User::LeaveIfError( ServerRequest(EKeySoundServerAddSIDS,args) ); |
|
161 |
|
162 CleanupStack::PopAndDestroy(); // buffer |
|
163 } |
|
164 |
|
165 void RAknSoundServerSession::PushContextL(TInt aUid, TResourceReader& aReader, TInt aResourceId) |
|
166 { |
|
167 TInt items = aReader.ReadInt16(); |
|
168 // RDebug::Print(_L("Items:%d"), items); |
|
169 |
|
170 TInt resSize = (items * 5); |
|
171 |
|
172 CBufFlat* buffer = CBufFlat::NewL(resSize); |
|
173 CleanupStack::PushL(buffer); |
|
174 |
|
175 RBufWriteStream bufStream; |
|
176 bufStream.Open(*buffer); |
|
177 |
|
178 CleanupClosePushL(bufStream); |
|
179 |
|
180 for (TInt ii=0; ii<items; ii++) |
|
181 { |
|
182 TInt sid = aReader.ReadInt16(); |
|
183 // RDebug::Print(_L("sid:%d"), sid); |
|
184 |
|
185 TInt key = aReader.ReadUint16(); |
|
186 // RDebug::Print(_L("key:%d"), key); |
|
187 |
|
188 TInt type = aReader.ReadInt8(); |
|
189 // RDebug::Print(_L("type (8bit):%d"), type); |
|
190 |
|
191 bufStream.WriteInt16L(sid); |
|
192 bufStream.WriteUint16L(key); |
|
193 bufStream.WriteUint8L(type); |
|
194 } |
|
195 |
|
196 CleanupStack::PopAndDestroy(); // bufstream close |
|
197 |
|
198 TPtr8 bufPtr = buffer->Ptr(0); |
|
199 TIpcArgs args (items, &bufPtr, aUid, aResourceId); |
|
200 User::LeaveIfError(ServerRequest(EKeySoundServerPushContext,args)); |
|
201 CleanupStack::PopAndDestroy(); // buffer |
|
202 } |
|
203 |
|
204 void RAknSoundServerSession::PopContext() |
|
205 { |
|
206 ServerRequest(EKeySoundServerPopContext,TIpcArgs()); |
|
207 } |
|
208 |
|
209 void RAknSoundServerSession::PlaySound(TInt aSid) |
|
210 { |
|
211 ServerRequest(EKeySoundServerPlaySID,TIpcArgs(aSid)); |
|
212 } |
|
213 |
|
214 void RAknSoundServerSession::StopSound(TInt aSid) |
|
215 { |
|
216 ServerRequest(EKeySoundServerStopCurrentTone,TIpcArgs(aSid)); |
|
217 } |
|
218 |
|
219 void RAknSoundServerSession::KeyPressed(TInt aKey, TBool aRepeat) |
|
220 { |
|
221 TIpcArgs args (aKey,aRepeat); |
|
222 ServerRequest(EKeySoundServerPlayKey,args); |
|
223 } |
|
224 |
|
225 void RAknSoundServerSession::BringToForeground() |
|
226 { |
|
227 ServerRequest(EKeySoundServerBringToForeground,TIpcArgs()); |
|
228 } |
|
229 |
|
230 void RAknSoundServerSession::LockContext() |
|
231 { |
|
232 ServerRequest(EKeySoundServerLockContext,TIpcArgs()); |
|
233 } |
|
234 |
|
235 void RAknSoundServerSession::ReleaseContext() |
|
236 { |
|
237 ServerRequest(EKeySoundServerReleaseContext,TIpcArgs()); |
|
238 } |
|
239 |
|
240 TInt RAknSoundServerSession::TopContext() |
|
241 { |
|
242 TInt aContextResourceId = 0; |
|
243 TPckg<TInt> pckg(aContextResourceId); |
|
244 ServerRequest(EKeySoundServerTopContext,TIpcArgs(&pckg)); |
|
245 return aContextResourceId; |
|
246 } |
|
247 |
|
248 // End of file |