|
1 /* |
|
2 * Copyright (c) 2008 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: Tone class definition. |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 // System Includes |
|
20 #include <e32math.h> |
|
21 #include <s32mem.h> |
|
22 |
|
23 // User Includes |
|
24 #include "evttoneaction.h" |
|
25 #include "evtdebug.h" |
|
26 |
|
27 // ================ Member funtions for CEvtToneAction class ====================== |
|
28 |
|
29 // --------------------------------------------------------------------------- |
|
30 // CEvtToneAction::CEvtToneAction |
|
31 // --------------------------------------------------------------------------- |
|
32 // |
|
33 EXPORT_C CEvtToneAction::CEvtToneAction(): |
|
34 iToneLoop( EFalse ) |
|
35 { |
|
36 } |
|
37 |
|
38 // --------------------------------------------------------------------------- |
|
39 // CEvtToneAction::~CEvtToneAction |
|
40 // --------------------------------------------------------------------------- |
|
41 // |
|
42 EXPORT_C CEvtToneAction::~CEvtToneAction() |
|
43 { |
|
44 delete iFileName; |
|
45 } |
|
46 |
|
47 // --------------------------------------------------------------------------- |
|
48 // CEvtToneAction::NewL |
|
49 // --------------------------------------------------------------------------- |
|
50 // |
|
51 EXPORT_C CEvtToneAction* CEvtToneAction::NewL() |
|
52 { |
|
53 CEvtToneAction* self = NewLC( ); |
|
54 CleanupStack::Pop( self ); |
|
55 return self; |
|
56 } |
|
57 |
|
58 // --------------------------------------------------------------------------- |
|
59 // CEvtToneAction::NewLC |
|
60 // --------------------------------------------------------------------------- |
|
61 // |
|
62 EXPORT_C CEvtToneAction* CEvtToneAction::NewLC() |
|
63 { |
|
64 CEvtToneAction* self = new ( ELeave )CEvtToneAction( ); |
|
65 CleanupStack::PushL( self ); |
|
66 self->ConstructL( ); |
|
67 return self; |
|
68 } |
|
69 |
|
70 // --------------------------------------------------------------------------- |
|
71 // CEvtToneAction::ConstructL |
|
72 // --------------------------------------------------------------------------- |
|
73 // |
|
74 EXPORT_C void CEvtToneAction::ConstructL() |
|
75 { |
|
76 // Allocate the Null string by default |
|
77 iFileName = KNullDesC().AllocL(); |
|
78 } |
|
79 |
|
80 // --------------------------------------------------------------------------- |
|
81 // CEvtToneAction::Tone |
|
82 // --------------------------------------------------------------------------- |
|
83 // |
|
84 |
|
85 EXPORT_C TPtrC CEvtToneAction::FileName() const |
|
86 { |
|
87 return iFileName->Des(); |
|
88 } |
|
89 |
|
90 // --------------------------------------------------------------------------- |
|
91 // CEvtToneAction::SetToneL |
|
92 // --------------------------------------------------------------------------- |
|
93 // |
|
94 |
|
95 EXPORT_C void CEvtToneAction::SetFileNameL( const TDesC& aFileName ) |
|
96 { |
|
97 delete iFileName; |
|
98 iFileName = NULL; |
|
99 iFileName = aFileName.AllocL(); |
|
100 } |
|
101 |
|
102 // --------------------------------------------------------------------------- |
|
103 // CEvtToneAction::ToneLoop |
|
104 // --------------------------------------------------------------------------- |
|
105 // |
|
106 |
|
107 EXPORT_C TBool CEvtToneAction::ToneLoop() const |
|
108 { |
|
109 return iToneLoop; |
|
110 } |
|
111 |
|
112 // --------------------------------------------------------------------------- |
|
113 // CEvtToneAction::SetToneLoop |
|
114 // --------------------------------------------------------------------------- |
|
115 // |
|
116 |
|
117 EXPORT_C void CEvtToneAction::SetToneLoop( const TBool aToneLoop ) |
|
118 { |
|
119 iToneLoop = aToneLoop; |
|
120 } |
|
121 |
|
122 // --------------------------------------------------------------------------- |
|
123 // CEvtToneAction::ExternalizeL |
|
124 // --------------------------------------------------------------------------- |
|
125 // |
|
126 EXPORT_C void CEvtToneAction::ExternalizeL( CEvtAction& aAction ) |
|
127 { |
|
128 CBufFlat* buffer = CBufFlat::NewL( TotalSize() ); |
|
129 CleanupStack::PushL( buffer ); |
|
130 |
|
131 // Allocate a common buffer for both read and write streams |
|
132 RBufWriteStream writestream( *buffer, 0 ); |
|
133 |
|
134 // Externalize from CEvtToneAction |
|
135 ExternalizeL( writestream ); |
|
136 |
|
137 // Covert the 8 bit Stream to 16 bit descriptor. |
|
138 TPtr8 bufPtr = buffer->Ptr(0); |
|
139 TPtrC display; |
|
140 display.Set( (TUint16*)bufPtr.Ptr(), (bufPtr.Length()>>1) ); |
|
141 |
|
142 // Internalize from CEvtAction |
|
143 aAction.SetActionL( display ); |
|
144 |
|
145 CleanupStack::PopAndDestroy( buffer ); |
|
146 } |
|
147 |
|
148 // --------------------------------------------------------------------------- |
|
149 // CEvtToneAction::InternalizeL |
|
150 // --------------------------------------------------------------------------- |
|
151 // |
|
152 EXPORT_C void CEvtToneAction::InternalizeL( CEvtAction& aAction ) |
|
153 { |
|
154 // Internalize from CEvtAction |
|
155 TPtrC ptr = aAction.Action( ); |
|
156 |
|
157 // Create a buffer of ptr's size granularity |
|
158 CBufFlat* buffer = CBufFlat::NewL( ptr.Size() ); |
|
159 CleanupStack::PushL( buffer ); |
|
160 |
|
161 // Insert the action String into buffer |
|
162 buffer->InsertL( 0, (TAny*)ptr.Ptr(), (ptr.Length()<<1) ); |
|
163 |
|
164 // Allocate a common buffer for both read and write streams |
|
165 RBufReadStream readstream( *buffer, 0 ); |
|
166 |
|
167 // Internalize from CEvtToneAction |
|
168 InternalizeL( readstream ); |
|
169 |
|
170 CleanupStack::PopAndDestroy( buffer ); |
|
171 } |
|
172 |
|
173 // --------------------------------------------------------------------------- |
|
174 // CEvtToneAction::ExternalizeL |
|
175 // --------------------------------------------------------------------------- |
|
176 // |
|
177 void CEvtToneAction::ExternalizeL( RWriteStream& aWriteStream ) |
|
178 { |
|
179 // Externalize will happen in the order of |
|
180 // - Action Type |
|
181 // - Tone String length |
|
182 // - Tone String |
|
183 // - Tone Loop |
|
184 TInt length = iFileName->Length(); |
|
185 aWriteStream.WriteUint8L( EAlarm ); |
|
186 aWriteStream.WriteUint32L( length ); |
|
187 |
|
188 // Avoid WriteL, if the Tone String length is 0. |
|
189 if( 0 != length ) |
|
190 aWriteStream.WriteL( iFileName->Des(), length ); |
|
191 aWriteStream.WriteUint8L( iToneLoop ); |
|
192 |
|
193 } |
|
194 |
|
195 // --------------------------------------------------------------------------- |
|
196 // CEvtToneAction::InternalizeL |
|
197 // --------------------------------------------------------------------------- |
|
198 // |
|
199 void CEvtToneAction::InternalizeL( RReadStream& aReadStream ) |
|
200 { |
|
201 // Internalize will happen in the order of |
|
202 // - Action Type |
|
203 // - Tone String length |
|
204 // - Tone String |
|
205 // - Tone Loop |
|
206 TEvtActionType type; |
|
207 type = static_cast<TEvtActionType>(aReadStream.ReadUint8L()); |
|
208 |
|
209 // Leave if the Action type is not EAlarm |
|
210 if( EAlarm != type ) |
|
211 User::Leave( KErrArgument ); |
|
212 |
|
213 // Get the length of tone String. |
|
214 TInt length = aReadStream.ReadUint32L(); |
|
215 if( iFileName ) |
|
216 delete iFileName; |
|
217 |
|
218 // Avoid ReadL, if the Tone String length is 0. |
|
219 if( 0 != length ) |
|
220 { |
|
221 iFileName = HBufC::NewL( length ); |
|
222 TPtr actn( iFileName->Des() ); |
|
223 |
|
224 // ReadL can leave if we try to read any intermediate 8 bit |
|
225 // descriptor. So we can ignore it. |
|
226 TRAP_IGNORE( aReadStream.ReadL(actn, length)); |
|
227 } |
|
228 else |
|
229 { |
|
230 iFileName = KNullDesC().AllocL(); |
|
231 } |
|
232 |
|
233 // Get the Toon Loop |
|
234 iToneLoop = static_cast<TBool>( aReadStream.ReadUint8L() ); |
|
235 } |
|
236 |
|
237 // --------------------------------------------------------------------------- |
|
238 // CEvtToneAction::TotalSize |
|
239 // --------------------------------------------------------------------------- |
|
240 // |
|
241 TInt CEvtToneAction::TotalSize( ) |
|
242 { |
|
243 TInt size=0; |
|
244 size += sizeof( TUint8 ); // Type Size |
|
245 size += sizeof( TUint32 ); // Tone Length Size |
|
246 size += iFileName->Des().MaxSize(); // Tone Size |
|
247 size += sizeof( TUint8 ); // Loop Size |
|
248 |
|
249 return size; |
|
250 } |
|
251 |
|
252 // End of File |