|
1 /* |
|
2 * Copyright (c) 2009 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: Representation of single event |
|
15 * |
|
16 */ |
|
17 |
|
18 #include "mdeevent.h" |
|
19 #include "mdcitem.h" |
|
20 #include "mdcserializationbuffer.h" |
|
21 #include "mdeeventdef.h" |
|
22 #include "mdenamespacedef.h" |
|
23 |
|
24 CMdEEvent* CMdEEvent::NewL(CMdEEventDef& aDef, TItemId aObjectId, TTime aTime, |
|
25 const TDesC* aSource, const TDesC* aParticipant) |
|
26 { |
|
27 CMdEEvent* self = CMdEEvent::NewLC( aDef, aObjectId, aTime, aSource, aParticipant ); |
|
28 CleanupStack::Pop( self ); |
|
29 return self; |
|
30 } |
|
31 |
|
32 CMdEEvent* CMdEEvent::NewLC(CMdEEventDef& aDef, TItemId aObjectId, TTime aTime, |
|
33 const TDesC* aSource, const TDesC* aParticipant ) |
|
34 { |
|
35 CMdEEvent* self = new (ELeave) CMdEEvent( NULL, KNoId, aDef, aObjectId, aTime ); |
|
36 CleanupStack::PushL( self ); |
|
37 self->ConstructL( aSource, aParticipant ); |
|
38 return self; |
|
39 } |
|
40 |
|
41 |
|
42 CMdEEvent::CMdEEvent(CMdESession* aSession, TItemId aId, CMdEEventDef& aDef, TItemId aObjectId, TTime aTime) |
|
43 : CMdEInstanceItem(aSession, aId), iDef(aDef), iObjectId(aObjectId), iTime(aTime) |
|
44 { |
|
45 } |
|
46 |
|
47 void CMdEEvent::ConstructL(const TDesC* aSource, const TDesC* aParticipant) |
|
48 { |
|
49 InstanceItemBaseConstruct(); |
|
50 |
|
51 if( aSource ) |
|
52 { |
|
53 iSource = aSource->AllocL(); |
|
54 } |
|
55 else |
|
56 { |
|
57 iSource = NULL; |
|
58 } |
|
59 |
|
60 if( aParticipant ) |
|
61 { |
|
62 iParticipant = aParticipant->AllocL(); |
|
63 } |
|
64 else |
|
65 { |
|
66 iParticipant = NULL; |
|
67 } |
|
68 } |
|
69 |
|
70 CMdEEvent::~CMdEEvent() |
|
71 { |
|
72 delete iSource; |
|
73 delete iParticipant; |
|
74 } |
|
75 |
|
76 CMdEEvent* CMdEEvent::NewL(CMdESession* aSession, CMdCSerializationBuffer& aBuffer, CMdENamespaceDef& aNamespaceDef ) |
|
77 { |
|
78 CMdEEvent* ret = CMdEEvent::NewLC( aSession, aBuffer, aNamespaceDef ); |
|
79 CleanupStack::Pop( ret ); |
|
80 return ret; |
|
81 } |
|
82 |
|
83 CMdEEvent* CMdEEvent::NewLC(CMdESession* aSession, CMdCSerializationBuffer& aBuffer, CMdENamespaceDef& aNamespaceDef ) |
|
84 { |
|
85 const TMdCEvent& serializedEvent = TMdCEvent::GetFromBufferL( aBuffer ); |
|
86 if (serializedEvent.iId == KNoId) |
|
87 { |
|
88 User::Leave( KErrNotFound ); |
|
89 } |
|
90 if (serializedEvent.iDefId == KNoDefId) |
|
91 { |
|
92 User::Leave( KErrNotFound ); |
|
93 } |
|
94 |
|
95 CMdEEventDef* eventDef = aNamespaceDef.GetEventDefL( serializedEvent.iDefId ); |
|
96 if ( !eventDef ) |
|
97 { |
|
98 User::Leave( KErrNotFound ); |
|
99 } |
|
100 if ( serializedEvent.iObjectId == KNoId ) |
|
101 { |
|
102 User::Leave( KErrNotFound ); |
|
103 } |
|
104 |
|
105 CMdEEvent* event = new(ELeave) CMdEEvent( aSession, serializedEvent.iId, *eventDef, |
|
106 serializedEvent.iObjectId, serializedEvent.iTime ); |
|
107 CleanupStack::PushL( event ); |
|
108 |
|
109 TPtrC16 source; |
|
110 TPtrC16 participant; |
|
111 |
|
112 TPtrC16* sourcePtr = NULL; |
|
113 TPtrC16* participantPtr = NULL; |
|
114 |
|
115 if( serializedEvent.iSourceText.iPtr.iCount > 0 ) |
|
116 { |
|
117 aBuffer.PositionL( serializedEvent.iSourceText.iPtr.iOffset ); |
|
118 source.Set( aBuffer.ReceivePtr16L() ); |
|
119 sourcePtr = &source; |
|
120 } |
|
121 |
|
122 if( serializedEvent.iParticipantText.iPtr.iCount > 0 ) |
|
123 { |
|
124 aBuffer.PositionL( serializedEvent.iParticipantText.iPtr.iOffset ); |
|
125 participant.Set( aBuffer.ReceivePtr16L() ); |
|
126 participantPtr = &participant; |
|
127 } |
|
128 |
|
129 event->ConstructL( sourcePtr, participantPtr ); |
|
130 return event; |
|
131 } |
|
132 |
|
133 EXPORT_C CMdEEventDef& CMdEEvent::Def() const |
|
134 { |
|
135 return iDef; |
|
136 } |
|
137 |
|
138 |
|
139 EXPORT_C TItemId CMdEEvent::ObjectId() const |
|
140 { |
|
141 return iObjectId; |
|
142 } |
|
143 |
|
144 |
|
145 EXPORT_C TTime CMdEEvent::Time() const |
|
146 { |
|
147 return iTime; |
|
148 } |
|
149 |
|
150 |
|
151 EXPORT_C const TDesC* CMdEEvent::Source() const |
|
152 { |
|
153 return iSource; |
|
154 } |
|
155 |
|
156 |
|
157 EXPORT_C const TDesC* CMdEEvent::Participant() const |
|
158 { |
|
159 return iParticipant; |
|
160 } |
|
161 |
|
162 TUint32 CMdEEvent::RequiredBufferSize() const |
|
163 { |
|
164 TUint32 requiredSize = sizeof(TMdCEvent); |
|
165 |
|
166 if( iSource ) |
|
167 { |
|
168 requiredSize += CMdCSerializationBuffer::RequiredSize(*iSource); |
|
169 } |
|
170 |
|
171 if( iParticipant ) |
|
172 { |
|
173 requiredSize += CMdCSerializationBuffer::RequiredSize(*iParticipant); |
|
174 } |
|
175 |
|
176 return requiredSize; |
|
177 } |
|
178 |
|
179 TMdCOffset CMdEEvent::SerializeL(CMdCSerializationBuffer& aBuffer, TMdCOffset aFreespaceOffset) const |
|
180 { |
|
181 const TMdCOffset eventPosition = aBuffer.Position(); |
|
182 TMdCEvent event; |
|
183 event.iId = Id(); |
|
184 event.iDefId = iDef.Id(); |
|
185 event.iObjectId = iObjectId; |
|
186 event.iTime = iTime; |
|
187 |
|
188 if( iSource ) |
|
189 { |
|
190 event.iSourceText.iPtr.iCount = iSource->Length(); |
|
191 event.iSourceText.iPtr.iOffset = aFreespaceOffset; |
|
192 aBuffer.PositionL( aFreespaceOffset ); |
|
193 aFreespaceOffset = aBuffer.InsertL( *iSource ); |
|
194 } |
|
195 else |
|
196 { |
|
197 event.iSourceText.iPtr.iCount = 0; |
|
198 event.iSourceText.iPtr.iOffset = KNoOffset; |
|
199 } |
|
200 |
|
201 if( iParticipant ) |
|
202 { |
|
203 event.iParticipantText.iPtr.iCount = iParticipant->Length(); |
|
204 event.iParticipantText.iPtr.iOffset = aFreespaceOffset; |
|
205 aBuffer.PositionL( aFreespaceOffset ); |
|
206 aFreespaceOffset = aBuffer.InsertL( *iParticipant ); |
|
207 } |
|
208 else |
|
209 { |
|
210 event.iParticipantText.iPtr.iCount = 0; |
|
211 event.iParticipantText.iPtr.iOffset = KNoOffset; |
|
212 } |
|
213 |
|
214 aBuffer.PositionL( eventPosition ); |
|
215 event.SerializeL( aBuffer ); |
|
216 |
|
217 return aFreespaceOffset; |
|
218 } |
|
219 |
|
220 TMdEInstanceType CMdEEvent::InstanceType() const |
|
221 { |
|
222 return EMdETypeEvent; |
|
223 } |