|
1 // Copyright (c) 1999-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 <e32base.h> |
|
17 #include <e32std.h> |
|
18 #include <msvstd.h> |
|
19 #include <msvschedulepackage.h> |
|
20 #include <s32mem.h> |
|
21 #include <schinfo.h> |
|
22 |
|
23 // |
|
24 // |
|
25 // TMsvSchedulePackage Implementation |
|
26 // |
|
27 // |
|
28 |
|
29 /** |
|
30 Default constructor. |
|
31 */ |
|
32 |
|
33 EXPORT_C TMsvSchedulePackage::TMsvSchedulePackage() |
|
34 : iId(0), iCommandId(0), iPollProgress(0) |
|
35 { |
|
36 } |
|
37 |
|
38 |
|
39 HBufC* TMsvSchedulePackage::PackLC() const |
|
40 { |
|
41 //Externalize this into a CBufFlat |
|
42 CBufFlat* flat = CBufFlat::NewL(sizeof(TMsvSchedulePackage)); |
|
43 CleanupStack::PushL(flat); |
|
44 |
|
45 RBufWriteStream writeStream(*flat); |
|
46 ExternalizeL(writeStream); |
|
47 writeStream.CommitL(); |
|
48 |
|
49 const TPtr8 ptr8(flat->Ptr(0)); |
|
50 |
|
51 //Convert the CBufFlat into a HBufC16 |
|
52 HBufC* buf16 = Convert(ptr8).AllocL(); |
|
53 |
|
54 CleanupStack::PopAndDestroy(flat); |
|
55 CleanupStack::PushL(buf16); |
|
56 |
|
57 return buf16; |
|
58 } |
|
59 |
|
60 |
|
61 /** |
|
62 Packs the object into a 16-bit descriptor. |
|
63 |
|
64 The function then attempts to copy the descriptor into aTask.iName, |
|
65 if aTask.iName is large enough; otherwise, it copies it into aDes (a new |
|
66 HBufC). |
|
67 |
|
68 aDes is placed on the cleanup stack. |
|
69 |
|
70 @param aTask |
|
71 Task information for this message. |
|
72 |
|
73 @param aDes On return, a new descriptor, possibly packaging the object. |
|
74 aDes.Length() == 0 if the object was successfully packed in aTask.iName |
|
75 instead. |
|
76 */ |
|
77 |
|
78 EXPORT_C void TMsvSchedulePackage::PackLC(TTaskInfo& aTask, HBufC*& aDes) const |
|
79 { |
|
80 aTask.iName.Zero(); |
|
81 aDes = PackLC(); |
|
82 |
|
83 if (aDes->Length() <= aTask.iName.MaxLength()) |
|
84 { |
|
85 aTask.iName.Copy(*aDes); |
|
86 CleanupStack::PopAndDestroy(aDes); |
|
87 aDes = HBufC::NewLC(0); |
|
88 } |
|
89 } |
|
90 |
|
91 |
|
92 /** |
|
93 Restores this object from a 16-bit descriptor that was packed using PackLC(). |
|
94 |
|
95 @param aTask |
|
96 The object is restored from aTask.iName if aTask.iName.Length() doesn't equal |
|
97 zero. |
|
98 |
|
99 @param aDes |
|
100 The object is restored from this descriptor if aTask.iName.Length() equals |
|
101 zero. |
|
102 */ |
|
103 |
|
104 EXPORT_C void TMsvSchedulePackage::UnpackL(const TTaskInfo& aTask, const TDesC& aDes) |
|
105 { |
|
106 if (aTask.iName.Length() != 0) |
|
107 UnpackL(aTask.iName); |
|
108 else |
|
109 UnpackL(aDes); |
|
110 } |
|
111 |
|
112 |
|
113 void TMsvSchedulePackage::UnpackL(const TDesC& aDes) |
|
114 { |
|
115 const TPtrC8 ptr8(Convert(aDes)); |
|
116 RDesReadStream readStream(ptr8); |
|
117 InternalizeL(readStream); |
|
118 } |
|
119 |
|
120 |
|
121 void TMsvSchedulePackage::ExternalizeL(RWriteStream& aStream) const |
|
122 { |
|
123 aStream.WriteInt32L(iId); |
|
124 aStream.WriteInt32L(iCommandId); |
|
125 aStream.WriteInt32L(iPollProgress.Int()); |
|
126 aStream << iParameter; |
|
127 } |
|
128 |
|
129 |
|
130 void TMsvSchedulePackage::InternalizeL(RReadStream& aStream) |
|
131 { |
|
132 iId = aStream.ReadInt32L(); |
|
133 iCommandId = aStream.ReadInt32L(); |
|
134 iPollProgress = (TTimeIntervalMicroSeconds32) aStream.ReadInt32L(); |
|
135 aStream >> iParameter; |
|
136 } |
|
137 |
|
138 |
|
139 TPtrC TMsvSchedulePackage::Convert(const TDesC8& aDes) const |
|
140 { |
|
141 const TInt size8 = aDes.Size(); |
|
142 const TInt size16 = (size8 / 2) + (size8 % 2); |
|
143 return TPtrC(REINTERPRET_CAST(const TUint16*, aDes.Ptr()), size16); |
|
144 } |
|
145 |
|
146 |
|
147 TPtrC8 TMsvSchedulePackage::Convert(const TDesC16& aDes) const |
|
148 { |
|
149 return TPtrC8(REINTERPRET_CAST(const TUint8*, aDes.Ptr()), aDes.Size()); |
|
150 } |