|
1 /* |
|
2 * Copyright (c) 2006 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: Event capsulation for shared ownership. |
|
15 * |
|
16 */ |
|
17 |
|
18 #include "ximpeventcapsule.h" |
|
19 #include "ximpeventcodec.h" |
|
20 #include "ximpapieventbase.h" |
|
21 #include "ximprbufhelpers.h" |
|
22 #include <ximprequestcompleteevent.h> |
|
23 |
|
24 |
|
25 // --------------------------------------------------------------------------- |
|
26 // CXIMPEventCapsule::NewL() |
|
27 // --------------------------------------------------------------------------- |
|
28 // |
|
29 EXPORT_C CXIMPEventCapsule* CXIMPEventCapsule::NewL( CXIMPApiEventBase& aEvent, |
|
30 TBool aEventReady /* = ETrue */ ) |
|
31 { |
|
32 CXIMPEventCapsule* self = new( ELeave ) CXIMPEventCapsule( aEventReady ); |
|
33 CleanupClosePushL( *self ); |
|
34 self->ConstructL( aEvent ); |
|
35 CleanupStack::Pop( self ); |
|
36 return self; |
|
37 } |
|
38 |
|
39 |
|
40 // --------------------------------------------------------------------------- |
|
41 // CXIMPEventCapsule::~CXIMPEventCapsule |
|
42 // --------------------------------------------------------------------------- |
|
43 // |
|
44 CXIMPEventCapsule::~CXIMPEventCapsule() |
|
45 { |
|
46 iEventBuf.Close(); |
|
47 delete iBuffer; |
|
48 } |
|
49 |
|
50 |
|
51 // --------------------------------------------------------------------------- |
|
52 // CXIMPEventCapsule::ConstructL() |
|
53 // --------------------------------------------------------------------------- |
|
54 // |
|
55 void CXIMPEventCapsule::ConstructL( CXIMPApiEventBase& aEvent ) |
|
56 { |
|
57 iReqId = TXIMPRequestId::Null(); |
|
58 |
|
59 iBuffer = CBufFlat::NewL( 10 ); // initial granularity to 10 |
|
60 XIMPEventCodec::PackL( aEvent, iEventType, iBuffer ); |
|
61 iEventBuf.CreateL( iBuffer->Ptr( 0 ) ); |
|
62 |
|
63 InitReqId( aEvent ); |
|
64 } |
|
65 |
|
66 // --------------------------------------------------------------------------- |
|
67 // CXIMPEventCapsule::CXIMPEventCapsule() |
|
68 // --------------------------------------------------------------------------- |
|
69 // |
|
70 CXIMPEventCapsule::CXIMPEventCapsule( TBool aEventReady ) |
|
71 : iEventReady( aEventReady ) |
|
72 { |
|
73 } |
|
74 |
|
75 |
|
76 // --------------------------------------------------------------------------- |
|
77 // CXIMPEventCapsule::EventData() |
|
78 // --------------------------------------------------------------------------- |
|
79 // |
|
80 EXPORT_C const TDesC8& CXIMPEventCapsule::EventData() const |
|
81 { |
|
82 return iEventBuf; |
|
83 } |
|
84 |
|
85 |
|
86 // --------------------------------------------------------------------------- |
|
87 // CXIMPEventCapsule::EventData() |
|
88 // --------------------------------------------------------------------------- |
|
89 // |
|
90 EXPORT_C TXIMPRequestId CXIMPEventCapsule::EventReqId() const |
|
91 { |
|
92 return iReqId; |
|
93 } |
|
94 |
|
95 |
|
96 // --------------------------------------------------------------------------- |
|
97 // CXIMPEventCapsule::EventType() |
|
98 // --------------------------------------------------------------------------- |
|
99 // |
|
100 EXPORT_C TInt32 CXIMPEventCapsule::EventType() const |
|
101 { |
|
102 return iEventType; |
|
103 } |
|
104 |
|
105 |
|
106 // --------------------------------------------------------------------------- |
|
107 // CXIMPEventCapsule::Ready() |
|
108 // --------------------------------------------------------------------------- |
|
109 // |
|
110 EXPORT_C TBool CXIMPEventCapsule::Ready() const |
|
111 { |
|
112 return iEventReady; |
|
113 } |
|
114 |
|
115 // --------------------------------------------------------------------------- |
|
116 // CXIMPEventCapsule::UpdateEventDataL() |
|
117 // --------------------------------------------------------------------------- |
|
118 // |
|
119 EXPORT_C void CXIMPEventCapsule::UpdateEventDataL( CXIMPApiEventBase& aEvent ) |
|
120 { |
|
121 XIMPEventCodec::PackL( aEvent, iEventType, iBuffer ); |
|
122 XIMPRBuf8Helper::SetNewValueL( iEventBuf, iBuffer->Ptr( 0 ) ); |
|
123 |
|
124 InitReqId( aEvent ); |
|
125 } |
|
126 |
|
127 // --------------------------------------------------------------------------- |
|
128 // CXIMPEventCapsule::UpdateEventData() |
|
129 // --------------------------------------------------------------------------- |
|
130 // |
|
131 EXPORT_C void CXIMPEventCapsule::UpdateEventData( CXIMPApiEventBase& aEvent ) |
|
132 { |
|
133 // If update fails old data is used. |
|
134 TRAP_IGNORE( |
|
135 UpdateEventDataL( aEvent ); |
|
136 ) |
|
137 } |
|
138 |
|
139 // --------------------------------------------------------------------------- |
|
140 // CXIMPEventCapsule::SetReady() |
|
141 // --------------------------------------------------------------------------- |
|
142 // |
|
143 EXPORT_C void CXIMPEventCapsule::SetReady( TBool aReady ) |
|
144 { |
|
145 iEventReady = aReady; |
|
146 } |
|
147 |
|
148 // --------------------------------------------------------------------------- |
|
149 // CXIMPEventCapsule::operator<() |
|
150 // --------------------------------------------------------------------------- |
|
151 // |
|
152 TBool CXIMPEventCapsule::operator<( const CXIMPEventCapsule& aOther ) const |
|
153 { |
|
154 return iTimeStamp < aOther.iTimeStamp; |
|
155 } |
|
156 |
|
157 // --------------------------------------------------------------------------- |
|
158 // CXIMPEventCapsule::SetTimeStamp() |
|
159 // --------------------------------------------------------------------------- |
|
160 // |
|
161 void CXIMPEventCapsule::SetTimeStamp( TUint32 aTimeStamp ) |
|
162 { |
|
163 iTimeStamp = aTimeStamp; |
|
164 } |
|
165 |
|
166 |
|
167 // --------------------------------------------------------------------------- |
|
168 // CXIMPEventCapsule::InitReqId() |
|
169 // --------------------------------------------------------------------------- |
|
170 // |
|
171 void CXIMPEventCapsule::InitReqId( const CXIMPApiEventBase& aEvent ) |
|
172 { |
|
173 if( aEvent.Base().GetInterfaceId() == MXIMPRequestCompleteEvent::KInterfaceId ) |
|
174 { |
|
175 const MXIMPRequestCompleteEvent* complEvent = |
|
176 TXIMPGetInterface< const MXIMPRequestCompleteEvent >::From( aEvent.Base(), |
|
177 MXIMPBase::EPanicIfUnknown ); |
|
178 |
|
179 iReqId = complEvent->RequestId(); |
|
180 } |
|
181 } |
|
182 |
|
183 // End of file |