|
1 // Copyright (c) 1995-2009 Nokia Corporation and/or its subsidiary(-ies). |
|
2 // All rights reserved. |
|
3 // This component and the accompanying materials are made available |
|
4 // under the terms of "Eclipse Public License v1.0" |
|
5 // which accompanies this distribution, and is available |
|
6 // at the URL "http://www.eclipse.org/legal/epl-v10.html". |
|
7 // |
|
8 // Initial Contributors: |
|
9 // Nokia Corporation - initial contribution. |
|
10 // |
|
11 // Contributors: |
|
12 // |
|
13 // Description: |
|
14 // |
|
15 |
|
16 #include "Graphics/WSGRAPHICMSGBUF.H" |
|
17 #include "W32STDGRAPHIC.H" |
|
18 |
|
19 //so sue us; fixing a very nasty-to-track-down unsigned/signed conversion defect in code below |
|
20 #define KSizeOfTInt (TInt)sizeof(TInt) |
|
21 |
|
22 // TWsGraphicMsgBufParser \\\\\\\\\\\\\\\\\\\\\\\\ |
|
23 |
|
24 EXPORT_C TWsGraphicMsgBufParser::TWsGraphicMsgBufParser(const TDesC8& aData): iData(aData) |
|
25 /** Initialise a parser for the specified message buffer */ |
|
26 { |
|
27 } |
|
28 |
|
29 EXPORT_C TInt TWsGraphicMsgBufParser::Verify() const |
|
30 /** Verifies that the message buffer is properly formed |
|
31 @return KErrNone if buffer is ok, else a system-wide error code */ |
|
32 { |
|
33 const TInt length = iData.Length(); |
|
34 TInt ofs = 0; |
|
35 const TInt tmp = (length - sizeof(TInt)); |
|
36 while(ofs < tmp) |
|
37 { |
|
38 ofs += IntAt(ofs+KSizeOfTInt) + (KSizeOfTInt*2); |
|
39 } |
|
40 if(ofs == length) |
|
41 { |
|
42 return KErrNone; |
|
43 } |
|
44 return KErrCorrupt; |
|
45 } |
|
46 |
|
47 EXPORT_C TInt TWsGraphicMsgBufParser::Count() const |
|
48 /** Returns the number of elements in the buffer. |
|
49 @return the count of elements. |
|
50 */ |
|
51 { |
|
52 const TInt length = iData.Length(); |
|
53 TInt ofs = 0, count = 0; |
|
54 while(ofs < length) |
|
55 { |
|
56 count++; |
|
57 ofs += IntAt(ofs+KSizeOfTInt) + (KSizeOfTInt*2); |
|
58 } |
|
59 return count; |
|
60 } |
|
61 |
|
62 EXPORT_C TUid TWsGraphicMsgBufParser::Uid(TInt aIndex) const |
|
63 /** Returns the UID if the message, or null UID if the buffer is empty. |
|
64 @return KNullUid if the buffer is empty, otherwise the stored Uid |
|
65 */ |
|
66 { |
|
67 const TInt length = iData.Length(); |
|
68 TInt ofs = 0, count = 0; |
|
69 while(ofs < length) |
|
70 { |
|
71 if(count == aIndex) |
|
72 { |
|
73 return TUid::Uid(IntAt(ofs)); |
|
74 } |
|
75 count++; |
|
76 ofs += IntAt(ofs+KSizeOfTInt) + (KSizeOfTInt*2); |
|
77 } |
|
78 return KNullUid; |
|
79 } |
|
80 |
|
81 EXPORT_C TPtrC8 TWsGraphicMsgBufParser::Data(TInt aIndex) const |
|
82 /**Returns the buffer contents at a perticular offset (aIndex). |
|
83 @param aIndex - the index into of the buffer element required. |
|
84 @return KNullDesC8 if index is more than the element count, otherwise, the element at index aIndex. |
|
85 */ |
|
86 { |
|
87 const TInt length = iData.Length(); |
|
88 TInt ofs = 0, count = 0; |
|
89 while(ofs < length) |
|
90 { |
|
91 if(count == aIndex) |
|
92 { |
|
93 return iData.Mid(ofs+(KSizeOfTInt*2),IntAt(ofs+KSizeOfTInt)); |
|
94 } |
|
95 count++; |
|
96 ofs += IntAt(ofs+KSizeOfTInt) + (KSizeOfTInt*2); |
|
97 } |
|
98 return TPtrC8(KNullDesC8()); |
|
99 } |
|
100 |
|
101 EXPORT_C TInt TWsGraphicMsgBufParser::Find(TUid aUid,TInt aStartingFrom) const |
|
102 /** Finds the element equal to the aUid, and returns the index of the element in the buffer. |
|
103 @param aUid - the search item to be found in the buffer. |
|
104 @param aStartingFrom - the starting index. |
|
105 @return the position (index) of the found element, or KErrNotFound |
|
106 */ |
|
107 { |
|
108 const TInt length = iData.Length(); |
|
109 TInt ofs = 0, count = 0; |
|
110 while(ofs < length) |
|
111 { |
|
112 if((count >= aStartingFrom) && (aUid == TUid::Uid(IntAt(ofs)))) |
|
113 { |
|
114 return count; |
|
115 } |
|
116 count++; |
|
117 ofs += IntAt(ofs+KSizeOfTInt) + (KSizeOfTInt*2); |
|
118 } |
|
119 return KErrNotFound; |
|
120 } |
|
121 |
|
122 EXPORT_C TBool TWsGraphicMsgBufParser::LoadFixed(TUid aUid,TAny* aMsg,TInt aMsgSize,TInt aStartingFrom) const |
|
123 /** Loads the buffer of aMsg with the contents of the buffer, based on the aUid and aMsgSize. |
|
124 @param aUid - the Uid to match after which the loading is performed. |
|
125 @param aMsg - the pointer to the output buffer. |
|
126 @param aMsgSize - the size of the output buffer. |
|
127 @param aStartingFrom - the starting position to be used in the search of the buffer. |
|
128 @return ETrue if loaded, EFalse otherwise. |
|
129 */ |
|
130 { |
|
131 const TInt length = iData.Length(); |
|
132 TInt ofs = 0, count = 0; |
|
133 while(ofs < length) |
|
134 { |
|
135 if((count >= aStartingFrom) && (aUid == TUid::Uid(IntAt(ofs)))) |
|
136 { |
|
137 // found it? return it |
|
138 const TInt len = IntAt(ofs+KSizeOfTInt); |
|
139 if(len == aMsgSize) |
|
140 { |
|
141 TPtr8 msg(reinterpret_cast<TUint8*>(aMsg),aMsgSize); |
|
142 msg = iData.Mid(ofs+(KSizeOfTInt*2),len); |
|
143 return ETrue; |
|
144 } |
|
145 else // message was not the expected size! |
|
146 { |
|
147 return EFalse; |
|
148 } |
|
149 } |
|
150 count++; |
|
151 ofs += IntAt(ofs+KSizeOfTInt) + (KSizeOfTInt*2); |
|
152 } |
|
153 return EFalse; |
|
154 } |
|
155 |
|
156 TInt TWsGraphicMsgBufParser::IntAt(TInt aOfs) const |
|
157 /** @internalComponent @released */ |
|
158 { |
|
159 if((aOfs < 0) || ((aOfs+KSizeOfTInt) > iData.Length())) |
|
160 { |
|
161 return 0; |
|
162 } |
|
163 TInt ret; |
|
164 memcpy(&ret,iData.Ptr()+aOfs,KSizeOfTInt); |
|
165 return ret; |
|
166 } |
|
167 |
|
168 // TWsGraphicMsgAnimation \\\\\\\\\\\\\\\\\\\\\\\\ |
|
169 |
|
170 EXPORT_C TWsGraphicMsgAnimation::TWsGraphicMsgAnimation(): iFlags(EStopped) |
|
171 { |
|
172 } |
|
173 |
|
174 EXPORT_C TInt TWsGraphicMsgAnimation::Load(const TWsGraphicMsgBufParser& aData) |
|
175 { |
|
176 const TInt index = aData.Find(TUid::Uid(TWsGraphicAnimation::ETypeId)); |
|
177 if(index >= 0) |
|
178 { |
|
179 return Load(aData,index); |
|
180 } |
|
181 return index; |
|
182 } |
|
183 |
|
184 EXPORT_C TInt TWsGraphicMsgAnimation::Load(const TWsGraphicMsgBufParser& aData,TInt aIndex) |
|
185 { |
|
186 if(aData.Uid(aIndex).iUid != TWsGraphicAnimation::ETypeId) |
|
187 { |
|
188 return KErrArgument; |
|
189 } |
|
190 const TPtrC8 pckg = aData.Data(aIndex); |
|
191 if(pckg.Size() != sizeof(TWsGraphicMsgAnimation)) |
|
192 { |
|
193 return KErrCorrupt; |
|
194 } |
|
195 memcpy(this,pckg.Ptr(),sizeof(TWsGraphicMsgAnimation)); |
|
196 return KErrNone; |
|
197 } |
|
198 |
|
199 EXPORT_C TTimeIntervalMicroSeconds TWsGraphicMsgAnimation::AnimationTime(const TTime& aNow,const TTimeIntervalMicroSeconds& aAnimationLength) const |
|
200 { |
|
201 // an animation to time? |
|
202 if(aAnimationLength <= 0LL) |
|
203 { |
|
204 return 0LL; |
|
205 } |
|
206 switch(iFlags & EStateMask) |
|
207 { |
|
208 case EPaused: |
|
209 return ((iPauseOrStopping.Int64() - iPlay.Int64()) % aAnimationLength.Int64()); |
|
210 case EStopping: |
|
211 { |
|
212 const TInt64 elapsed = (aNow.Int64() - iPlay.Int64()); |
|
213 if(elapsed <= aAnimationLength.Int64()) |
|
214 { |
|
215 return (elapsed % aAnimationLength.Int64()); |
|
216 } |
|
217 return 0LL; |
|
218 } |
|
219 case EStopped: |
|
220 return 0LL; |
|
221 case EPlaying: |
|
222 { |
|
223 const TInt64 elapsed = (aNow.Int64() - iPlay.Int64()); |
|
224 if((iFlags & ELoop) || (elapsed <= aAnimationLength.Int64())) |
|
225 { |
|
226 return (elapsed % aAnimationLength.Int64()); |
|
227 } |
|
228 return 0LL; |
|
229 } |
|
230 default: |
|
231 return 0LL; |
|
232 } |
|
233 } |
|
234 |
|
235 EXPORT_C TBool TWsGraphicMsgAnimation::IsPlaying(const TTime& aNow,const TTimeIntervalMicroSeconds& aAnimationLength) const |
|
236 { |
|
237 // an animation to time? |
|
238 if(aAnimationLength <= 0LL) |
|
239 { |
|
240 return EFalse; |
|
241 } |
|
242 switch(iFlags & EStateMask) |
|
243 { |
|
244 case EPaused: |
|
245 return EFalse; |
|
246 case EStopping: |
|
247 { |
|
248 const TInt64 elapsed = (aNow.Int64() - iPlay.Int64()); |
|
249 if(elapsed <= aAnimationLength.Int64()) |
|
250 { |
|
251 return ETrue; |
|
252 } |
|
253 return EFalse; |
|
254 } |
|
255 case EStopped: |
|
256 return EFalse; |
|
257 case EPlaying: |
|
258 { |
|
259 const TInt64 elapsed = (aNow.Int64() - iPlay.Int64()); |
|
260 if((iFlags & ELoop) || (elapsed <= aAnimationLength.Int64())) |
|
261 { |
|
262 return ETrue; |
|
263 } |
|
264 return EFalse; |
|
265 } |
|
266 default: |
|
267 return EFalse; |
|
268 } |
|
269 } |
|
270 |