|
1 // Copyright (c) 2001-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 // $Workfile: IRS.CPP $ |
|
15 // $Author: Stevep $ |
|
16 // $Revision: 8 $ |
|
17 // $Date: 25/03/02 8:49 $ |
|
18 // |
|
19 // |
|
20 |
|
21 //class include |
|
22 #include "IRS.H" |
|
23 |
|
24 //system includes |
|
25 #include <msventry.h> |
|
26 #include <ircmtm.h> // For the send command |
|
27 |
|
28 //user includes |
|
29 #include <irheader.h> |
|
30 #include "sendopn.h" |
|
31 const TInt KErrIrObexClientSubsequentPutFailed = -5511; |
|
32 |
|
33 EXPORT_C CIrSrvMtm* CIrSrvMtm::NewL(CRegisteredMtmDll& aRegisteredMtmDll, CMsvServerEntry* aEntry) |
|
34 /** |
|
35 * NewL factory function. Calls ReleaseLibrary() if construction fails. |
|
36 * |
|
37 * @param aRegisteredMtmDll Registration data for MTM DLL. |
|
38 * @param aEntry Context on which to operate. |
|
39 * @return Pointer to a newly constructed CIrSrvMtm. |
|
40 * @leave KErrXXX System-wide error codes |
|
41 */ |
|
42 { |
|
43 CIrSrvMtm* mysvrmtm = new CIrSrvMtm(aRegisteredMtmDll, aEntry); |
|
44 if (mysvrmtm==NULL) |
|
45 { |
|
46 aRegisteredMtmDll.ReleaseLibrary(); |
|
47 User::Leave(KErrNoMemory); |
|
48 } |
|
49 CleanupStack::PushL(mysvrmtm); |
|
50 mysvrmtm->ConstructL(); |
|
51 CleanupStack::Pop(); |
|
52 return mysvrmtm; |
|
53 } |
|
54 |
|
55 CIrSrvMtm::CIrSrvMtm(CRegisteredMtmDll& aRegisteredMtmDll, CMsvServerEntry* aEntry): |
|
56 CObexSrvMtm(aRegisteredMtmDll, aEntry) |
|
57 /** |
|
58 * Constructor. Calls CObexSrvMtm's constructor in initialisation list. |
|
59 * @param aRegisteredMtmDll Registration data for MTM DLL. |
|
60 * @param aEntry Context on which to operate. |
|
61 */ |
|
62 { |
|
63 __DECLARE_NAME(_S("CIrSrvMtm")); |
|
64 } |
|
65 |
|
66 /** |
|
67 * Destructor. Deletes the header member |
|
68 */ |
|
69 |
|
70 EXPORT_C CIrSrvMtm::~CIrSrvMtm() |
|
71 { |
|
72 delete iHeader; |
|
73 } |
|
74 |
|
75 EXPORT_C void CIrSrvMtm::StartCommandL (CMsvEntrySelection& aSelection, |
|
76 TInt aCommand, |
|
77 const TDesC8& aParameter, |
|
78 TRequestStatus& aStatus) |
|
79 /** |
|
80 * Instantiates and initiates a CIrServerSemdOperation class to begin sending the specified OBEX object |
|
81 * via Infrared. Called in response to InvokeAsyncFunctionL() in the client MTM, and passes through |
|
82 * all the arguments passed in to that function. Only supports aCommand==EIrMtmCmdSend |
|
83 * @param aSelection Entry to operate on. |
|
84 * @param aCommand Command to start. Only EIrMtmCmdSend is supported. |
|
85 * @param aParameter Package buffer containing timeout, port and password info needed for the send operation. |
|
86 * @param aStatus Used to notify observer of completion. |
|
87 * @leave KErrNotSupported if aCommand!=EIrMtmCmdSend |
|
88 * @leave KErrXXX if aCommand!= EIrMtmCmdSend |
|
89 */ |
|
90 { |
|
91 switch (aCommand) |
|
92 { |
|
93 //The only supported command is EIrcCmdSend; switch statement used for potential future extension |
|
94 case CIrClientMtm::EIrcCmdSend: |
|
95 { |
|
96 TPckgBuf<CIrClientMtm::STimeouts> sendParamsBuf; |
|
97 sendParamsBuf.Copy(aParameter); |
|
98 iTimeouts = sendParamsBuf(); |
|
99 |
|
100 //Zeroth selection is the TMsvId of the entry to send. |
|
101 iEntry = iServerEntry->NewEntryL(aSelection[0]); |
|
102 |
|
103 TMsvEntry messageEntry=iEntry->Entry(); |
|
104 messageEntry.SetSendingState(KMsvSendStateSending); |
|
105 iEntry->ChangeEntry(messageEntry); |
|
106 |
|
107 //Construct a header |
|
108 delete iHeader; |
|
109 iHeader = NULL; |
|
110 iHeader = CIrHeader::NewL(); |
|
111 |
|
112 //Get the entry's store |
|
113 CMsvStore* store = iEntry->ReadStoreL(); |
|
114 CleanupStack::PushL(store); |
|
115 |
|
116 //read the header from the store, and destroy the store |
|
117 iHeader->RestoreL(*store); |
|
118 CleanupStack::PopAndDestroy(); //store |
|
119 |
|
120 iProtocolInfo = iHeader->IrProtocolInfo(); |
|
121 |
|
122 iFirstSendAttempt = ETrue; |
|
123 |
|
124 aStatus = KRequestPending; |
|
125 iReportStatus = &aStatus; |
|
126 |
|
127 SendL(); |
|
128 |
|
129 break; |
|
130 } |
|
131 default: |
|
132 User::Leave(KErrNotSupported); |
|
133 } |
|
134 |
|
135 } |
|
136 |
|
137 /** |
|
138 * Creates a server send operation to perform the send |
|
139 */ |
|
140 |
|
141 |
|
142 void CIrSrvMtm::SendL() |
|
143 { |
|
144 // Password is not supported for IR |
|
145 TPtrC connectPassword; |
|
146 // connectPassword.Set(sendParamsBuf().iConnectPassword); |
|
147 |
|
148 //Now make the send operation, which will start automatically. aStatus is passed in to |
|
149 //report completion. |
|
150 |
|
151 delete iSendOperation; |
|
152 iSendOperation = NULL; |
|
153 |
|
154 //If NewL() leaves , the progress should be recorded |
|
155 |
|
156 iSendOperation = CIrServerSendOperation::NewL(*iEntry, iProtocolInfo, |
|
157 iTimeouts.iConnectTimeout, iTimeouts.iPutTimeout, &connectPassword, iStatus, !iFirstSendAttempt); |
|
158 |
|
159 SetActive(); |
|
160 } |
|
161 |
|
162 /** |
|
163 * Obtains progress information, which, if valid, results in calling Send() |
|
164 */ |
|
165 |
|
166 EXPORT_C void CIrSrvMtm::DoRunL() |
|
167 { |
|
168 // If the first attempt to send the message fails then retry with OBEX::IrXfer |
|
169 |
|
170 TPckgBuf<TObexMtmProgress> package; |
|
171 package.Copy(iSendOperation->ProgressL()); |
|
172 TInt error = package().iError; |
|
173 |
|
174 if ((error != KErrNone) && (iFirstSendAttempt)) |
|
175 { |
|
176 // If we have made only one send attempt so far, we will retry now |
|
177 |
|
178 // If the error code indicates that we have not found the OBEX class |
|
179 // name, change to use the OBEX:IrXfer class name as some older |
|
180 // implementations only understand that one. |
|
181 if (error == KErrIrObexClientPeerDoesNotHaveObex) |
|
182 { |
|
183 iProtocolInfo.iClassName = KIrXferClassName; |
|
184 } |
|
185 |
|
186 iFirstSendAttempt = EFalse; |
|
187 if(error == KErrIrObexClientSubsequentPutFailed) |
|
188 { |
|
189 User::RequestComplete(iReportStatus, KErrNone); |
|
190 } |
|
191 else |
|
192 { |
|
193 SendL(); |
|
194 } |
|
195 } |
|
196 else |
|
197 { |
|
198 // Always report with a no error, any failure is recorded in the progress. |
|
199 User::RequestComplete(iReportStatus, KErrNone); |
|
200 } |
|
201 } |