1 // Copyright (c) 2005-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 /** |
|
17 @file |
|
18 @released |
|
19 @internalComponent |
|
20 */ |
|
21 |
|
22 #include <obexfinalpacketobserver.h> |
|
23 #include "logger.h" |
|
24 #include "obexpacketsignaller.h" |
|
25 #include "OBEXUTIL.H" |
|
26 #include "obexfaults.h" |
|
27 #include "obexclient.h" |
|
28 |
|
29 #ifdef __FLOG_ACTIVE |
|
30 _LIT8(KLogComponent, "OBEX"); |
|
31 #endif |
|
32 |
|
33 /** Constructor. |
|
34 This Active Object has a priority of EPriorityHigh + 1. This is to ensure |
|
35 that, when a final packet is sent, the RunLs are executed in the following order: |
|
36 1/ signaller (EObexFinalPacketStarted) |
|
37 2/ activeRW (the final packet actually being sent) |
|
38 3/ signaller (EObexFinalPacketFinished) |
|
39 The priority chosen is EPriorityHigh + 1 because the priorities of the |
|
40 transport controllers' writer (CActiveRW) AOs tends to be EPriorityHigh. |
|
41 As long as this is the case, our guarantee holds. Our documentation says that |
|
42 new licensee transport controllers must have writers with priorities that |
|
43 continue to support this guarantee. |
|
44 */ |
|
45 CObexPacketSignaller::CObexPacketSignaller() : CActive(CActive::EPriorityHigh + 1) |
|
46 { |
|
47 } |
|
48 |
|
49 /** Factory function. |
|
50 |
|
51 @return A fully constructed CObexPacketSignaller. |
|
52 */ |
|
53 CObexPacketSignaller* CObexPacketSignaller::NewL() |
|
54 { |
|
55 CObexPacketSignaller* signaller = new(ELeave)CObexPacketSignaller(); |
|
56 return signaller; |
|
57 } |
|
58 |
|
59 /** Destructor. |
|
60 */ |
|
61 CObexPacketSignaller::~CObexPacketSignaller() |
|
62 { |
|
63 Cancel(); |
|
64 } |
|
65 |
|
66 /** Sets observer to be notified of packet process events. |
|
67 |
|
68 This clears any events that are currently outstanding. |
|
69 |
|
70 @param aObserver The observer to receive events. May be set to NULL. |
|
71 */ |
|
72 void CObexPacketSignaller::SetFinalPacketObserver(MObexFinalPacketObserver* aObserver) |
|
73 { |
|
74 LOG1(_L8("CObexPacketSignaller::SetObserver(0x%x)"), aObserver); |
|
75 |
|
76 // Clear outstanding events for the final packet observer |
|
77 // If there's an outstanding final packet event this means |
|
78 // it won't get signalled. |
|
79 iOutstandingEvents &= ~(EObexFinalPacketStarted | EObexFinalPacketFinished); |
|
80 |
|
81 // Add or remove from scheduler if necessary |
|
82 if(!iFinalPacketObserver &&!iReadActivityObserver && aObserver) |
|
83 { |
|
84 CActiveScheduler::Add(this); |
|
85 } |
|
86 else if(iFinalPacketObserver && !iReadActivityObserver && !aObserver) |
|
87 { |
|
88 Deque(); |
|
89 } |
|
90 |
|
91 iFinalPacketObserver = aObserver; |
|
92 } |
|
93 |
|
94 void CObexPacketSignaller::SetReadActivityObserver(MObexReadActivityObserver* aObserver) |
|
95 { |
|
96 LOG1(_L8("CObexPacketSignaller::SetObserver(0x%x)"), aObserver); |
|
97 |
|
98 // Clear outstanding events for the read activity observer |
|
99 // If there's an outstanding read activity event this means |
|
100 // it won't get signalled. |
|
101 iOutstandingEvents &= ~EObexReadActivityDetected; |
|
102 |
|
103 //UpdateScheduler(); |
|
104 // Add or remove from scheduler if necessary |
|
105 if(!iFinalPacketObserver &&!iReadActivityObserver && aObserver) |
|
106 { |
|
107 CActiveScheduler::Add(this); |
|
108 } |
|
109 else if(iReadActivityObserver && !iFinalPacketObserver && !aObserver) |
|
110 { |
|
111 Deque(); |
|
112 } |
|
113 |
|
114 iReadActivityObserver = aObserver; |
|
115 } |
|
116 |
|
117 |
|
118 /** Signal that an event has occurred. |
|
119 |
|
120 @param aEvent The event that has occurred. |
|
121 */ |
|
122 void CObexPacketSignaller::Signal(TObexPacketProcessEvent aEvent) |
|
123 { |
|
124 LOG1(_L8("CObexPacketSignaller::Signal(%d)"), aEvent); |
|
125 __ASSERT_DEBUG((aEvent != 0), IrOBEXUtil::Panic(EBadPacketProcessEvent)); |
|
126 |
|
127 TBool appropriateObserver = EFalse; |
|
128 switch(aEvent) |
|
129 { |
|
130 case EObexFinalPacketStarted: |
|
131 case EObexFinalPacketFinished: |
|
132 { |
|
133 if(iFinalPacketObserver) |
|
134 { |
|
135 appropriateObserver = ETrue; |
|
136 } |
|
137 } |
|
138 break; |
|
139 case EObexReadActivityDetected: |
|
140 { |
|
141 if(iReadActivityObserver) |
|
142 { |
|
143 appropriateObserver = ETrue; |
|
144 } |
|
145 } |
|
146 break; |
|
147 default: |
|
148 break; //drop - not for us |
|
149 } |
|
150 |
|
151 if(appropriateObserver) |
|
152 { |
|
153 iOutstandingEvents |= aEvent; |
|
154 |
|
155 if(!IsActive()) |
|
156 { |
|
157 SetActive(); |
|
158 TRequestStatus* status = &iStatus; |
|
159 User::RequestComplete(status, KErrNone); |
|
160 } |
|
161 } |
|
162 } |
|
163 |
|
164 /** Active object completion function. |
|
165 */ |
|
166 void CObexPacketSignaller::RunL() |
|
167 { |
|
168 LOG1(_L8("CObexPacketSignaller::RunL() with iOutstandingEvents %d"), iOutstandingEvents); |
|
169 |
|
170 __ASSERT_DEBUG(iFinalPacketObserver || !(iOutstandingEvents & (EObexFinalPacketStarted | EObexFinalPacketFinished)), |
|
171 IrOBEXUtil::Panic(ENoPacketProcessObserverSet)); |
|
172 __ASSERT_DEBUG(iReadActivityObserver || !(iOutstandingEvents & EObexReadActivityDetected), |
|
173 IrOBEXUtil::Panic(ENoPacketProcessObserverSet)); |
|
174 // Signal each event in order |
|
175 // Should be safe against an observer becoming |
|
176 // unset as if it is unset then associated outstanding events are |
|
177 // cleared. |
|
178 if(iOutstandingEvents & EObexFinalPacketStarted) |
|
179 { |
|
180 iOutstandingEvents &= ~EObexFinalPacketStarted; |
|
181 if(iFinalPacketObserver!=NULL) |
|
182 { |
|
183 iFinalPacketObserver->MofpoFinalPacketStarted(); |
|
184 } |
|
185 } |
|
186 |
|
187 if(iOutstandingEvents & EObexFinalPacketFinished) |
|
188 { |
|
189 iOutstandingEvents &= ~EObexFinalPacketFinished; |
|
190 if(iFinalPacketObserver!=NULL) |
|
191 { |
|
192 iFinalPacketObserver->MofpoFinalPacketFinished(); |
|
193 } |
|
194 } |
|
195 |
|
196 if(iOutstandingEvents & EObexReadActivityDetected) |
|
197 { |
|
198 iOutstandingEvents &= ~EObexReadActivityDetected; |
|
199 if(iReadActivityObserver!=NULL) |
|
200 { |
|
201 iReadActivityObserver->MoraoReadActivity(); |
|
202 } |
|
203 } |
|
204 |
|
205 // If we've been signalled as a result of client's notification |
|
206 // handling events may be outstanding... |
|
207 if(iOutstandingEvents) |
|
208 { |
|
209 SetActive(); |
|
210 TRequestStatus* status = &iStatus; |
|
211 User::RequestComplete(status, KErrNone); |
|
212 } |
|
213 } |
|
214 |
|
215 /** From CActive. |
|
216 */ |
|
217 void CObexPacketSignaller::DoCancel() |
|
218 { |
|
219 iOutstandingEvents = 0; |
|
220 } |
|
221 |
|