|
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 // All methods in this file act either to initialise the wrapper object or to forward calls |
|
15 // from the async server notify class to the synchronous version. |
|
16 // |
|
17 // |
|
18 |
|
19 /** |
|
20 @file |
|
21 @internalComponent |
|
22 @see MObexServerNotify |
|
23 @see MObexServerNotifyAsync |
|
24 */ |
|
25 |
|
26 #include <e32base.h> |
|
27 #include <obexserver.h> |
|
28 #include <obexobjects.h> |
|
29 #include "logger.h" |
|
30 #include "OBEXUTIL.H" |
|
31 #include "obexservernotifysyncwrapper.h" |
|
32 #include "obexserverstatemachine.h" |
|
33 |
|
34 |
|
35 #ifdef _DEBUG |
|
36 // Save the return value as debugger will (hopefully) then make it easier to see... |
|
37 #define CHECK_NOERROR(expr) TInt _saved_error = (expr); __ASSERT_ALWAYS(_saved_error == KErrNone, IrOBEXUtil::Fault(ESyncWrapperCallbackError)); |
|
38 #else |
|
39 #define CHECK_NOERROR(expr) (void)expr |
|
40 #endif |
|
41 // |
|
42 // Initialisation methods |
|
43 // |
|
44 CObexServerNotifySyncWrapper* CObexServerNotifySyncWrapper::NewL(CObexServer& aOwner, CObexServerStateMachine& aStateMachine) |
|
45 { |
|
46 CObexServerNotifySyncWrapper* self = new (ELeave) CObexServerNotifySyncWrapper(aOwner, aStateMachine); |
|
47 return self; |
|
48 } |
|
49 |
|
50 CObexServerNotifySyncWrapper::CObexServerNotifySyncWrapper(CObexServer& aOwner, CObexServerStateMachine& aStateMachine) |
|
51 : iOwner(aOwner), iStateMachine(aStateMachine) |
|
52 {} |
|
53 |
|
54 CObexServerNotifySyncWrapper::~CObexServerNotifySyncWrapper() |
|
55 { |
|
56 } |
|
57 |
|
58 void CObexServerNotifySyncWrapper::SetNotifier(MObexServerNotify* aNotify) |
|
59 { |
|
60 // if aNotify is NULL this will cause any forwarding methods to dereference NULL. |
|
61 // But this should never happen. K-E 3 will result if they do, but all we'd |
|
62 // do otherwise would be to panic anyway... |
|
63 iNotify = aNotify; |
|
64 } |
|
65 |
|
66 // |
|
67 // Forwarding methods |
|
68 // |
|
69 void CObexServerNotifySyncWrapper::ErrorIndication(TInt aError) |
|
70 { |
|
71 iNotify->ErrorIndication(aError); |
|
72 } |
|
73 |
|
74 void CObexServerNotifySyncWrapper::TransportUpIndication() |
|
75 { |
|
76 iNotify->TransportUpIndication(); |
|
77 } |
|
78 |
|
79 void CObexServerNotifySyncWrapper::TransportDownIndication() |
|
80 { |
|
81 iNotify->TransportDownIndication(); |
|
82 } |
|
83 |
|
84 void CObexServerNotifySyncWrapper::ObexConnectIndication(const TObexConnectInfo& aRemoteInfo, const TDesC8& aInfo) |
|
85 { |
|
86 // Explicitly code that we're ignoring the return value. See the doxygen comment. |
|
87 (void)iNotify->ObexConnectIndication(aRemoteInfo, aInfo); |
|
88 } |
|
89 |
|
90 void CObexServerNotifySyncWrapper::ObexDisconnectIndication(const TDesC8& aInfo) |
|
91 { |
|
92 iNotify->ObexDisconnectIndication(aInfo); |
|
93 } |
|
94 |
|
95 // |
|
96 // Forward the request to the MObexServerNotify implementation, then immediately |
|
97 // downcall into CObexServer. |
|
98 // |
|
99 void CObexServerNotifySyncWrapper::PutRequestIndication() |
|
100 { |
|
101 WRAPPER_LOG(_L8("Put request indication")); |
|
102 iCallbackOutstanding = ETrue; |
|
103 iStateMachine.SetAppResponse(ERespSuccess); |
|
104 // A NULL return here is OK as it is the response to reject the request. |
|
105 CObexBaseObject* object = iNotify->PutRequestIndication(); |
|
106 |
|
107 WRAPPER_LOG(_L8("Put request indication complete")); |
|
108 if(iCallbackOutstanding && (iStateMachine.AppResponse() == ERespSuccess)) |
|
109 { |
|
110 CHECK_NOERROR(iOwner.RequestIndicationCallback(object)); |
|
111 } |
|
112 } |
|
113 |
|
114 TInt CObexServerNotifySyncWrapper::PutPacketIndication() |
|
115 { |
|
116 return iNotify->PutPacketIndication(); |
|
117 } |
|
118 |
|
119 void CObexServerNotifySyncWrapper::PutCompleteIndication() |
|
120 { |
|
121 iCallbackOutstanding = ETrue; |
|
122 TInt err = iNotify->PutCompleteIndication(); |
|
123 TObexResponse resp = IrOBEXUtil::ObexResponse(err, ERespSuccess); |
|
124 if(iCallbackOutstanding) |
|
125 { |
|
126 CHECK_NOERROR(iOwner.RequestCompleteIndicationCallback(resp)); |
|
127 } |
|
128 } |
|
129 |
|
130 // |
|
131 // Forward the request to the MObexServerNotify implementation, then immediately |
|
132 // downcall into CObexServer. |
|
133 // |
|
134 void CObexServerNotifySyncWrapper::GetRequestIndication(CObexBaseObject* aRequiredObject) |
|
135 { |
|
136 WRAPPER_LOG(_L8("Get request indication")); |
|
137 iCallbackOutstanding = ETrue; |
|
138 iStateMachine.SetAppResponse(ERespSuccess); |
|
139 // A NULL return here is OK as it is the response to reject the request. |
|
140 CObexBaseObject* object = iNotify->GetRequestIndication(aRequiredObject); |
|
141 |
|
142 WRAPPER_LOG(_L8("Get request indication complete")); |
|
143 if(iCallbackOutstanding && (iStateMachine.AppResponse() == ERespSuccess)) |
|
144 { |
|
145 CHECK_NOERROR(iOwner.RequestIndicationCallback(object)); |
|
146 } |
|
147 } |
|
148 |
|
149 TInt CObexServerNotifySyncWrapper::GetPacketIndication() |
|
150 { |
|
151 return iNotify->GetPacketIndication(); |
|
152 } |
|
153 |
|
154 void CObexServerNotifySyncWrapper::GetCompleteIndication() |
|
155 { |
|
156 iCallbackOutstanding = ETrue; |
|
157 TInt err = iNotify->GetCompleteIndication(); |
|
158 TObexResponse resp = IrOBEXUtil::ObexResponse(err, ERespSuccess); |
|
159 if(iCallbackOutstanding) |
|
160 { |
|
161 CHECK_NOERROR(iOwner.RequestCompleteIndicationCallback(resp)); |
|
162 } |
|
163 } |
|
164 |
|
165 void CObexServerNotifySyncWrapper::SetPathIndication(const CObex::TSetPathInfo& aPathInfo, const TDesC8& aInfo) |
|
166 { |
|
167 iCallbackOutstanding = ETrue; |
|
168 TInt err = iNotify->SetPathIndication(aPathInfo, aInfo); |
|
169 TObexResponse resp = IrOBEXUtil::ObexResponse(err, ERespSuccess); |
|
170 if(iCallbackOutstanding) |
|
171 { |
|
172 CHECK_NOERROR(iOwner.RequestCompleteIndicationCallback(resp)); |
|
173 } |
|
174 } |
|
175 |
|
176 void CObexServerNotifySyncWrapper::AbortIndication() |
|
177 { |
|
178 iNotify->AbortIndication(); |
|
179 } |
|
180 |
|
181 void CObexServerNotifySyncWrapper::CancelIndicationCallback() |
|
182 { |
|
183 //Appilcation may stop the obex server for whatever reason during an Indication |
|
184 //thus resets the state machine. We have to make sure not to call indication |
|
185 //callback in such cases because the statemachine will panic. |
|
186 iCallbackOutstanding = EFalse; |
|
187 } |