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