|
1 // Copyright (c) 2007-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 #include "cptpipsockethandler.h" //CPTPIPSockethandler |
|
18 |
|
19 |
|
20 |
|
21 CPTPIPSocketHandler* CPTPIPSocketHandler::NewLC() |
|
22 { |
|
23 CPTPIPSocketHandler* self = new (ELeave) CPTPIPSocketHandler; |
|
24 CleanupStack::PushL(self); |
|
25 self->ConstructL(); |
|
26 return self; |
|
27 } |
|
28 |
|
29 /* |
|
30 Factory Method |
|
31 */ |
|
32 CPTPIPSocketHandler* CPTPIPSocketHandler::NewL() |
|
33 { |
|
34 CPTPIPSocketHandler* self = CPTPIPSocketHandler::NewLC(); |
|
35 CleanupStack::Pop(self); |
|
36 return self; |
|
37 } |
|
38 |
|
39 |
|
40 CPTPIPSocketHandler::CPTPIPSocketHandler(): |
|
41 CActive(EPriorityStandard),iReceiveChunk(NULL,0),iWriteChunk(NULL,0) |
|
42 { |
|
43 CActiveScheduler::Add(this); |
|
44 iState=EReadState; |
|
45 } |
|
46 |
|
47 void CPTPIPSocketHandler::ConstructL() |
|
48 { |
|
49 |
|
50 |
|
51 } |
|
52 |
|
53 |
|
54 RSocket& CPTPIPSocketHandler::Socket() |
|
55 { |
|
56 return iSocket; |
|
57 } |
|
58 |
|
59 TSocketHandlerState& CPTPIPSocketHandler::State() |
|
60 { |
|
61 return iState; |
|
62 } |
|
63 |
|
64 |
|
65 |
|
66 CPTPIPSocketHandler::~CPTPIPSocketHandler() |
|
67 { |
|
68 Socket().Close(); |
|
69 } |
|
70 |
|
71 /* |
|
72 Reads from the current accepted socket |
|
73 @param TRequestStatus passed from PTPIP Controller |
|
74 */ |
|
75 void CPTPIPSocketHandler::ReadFromSocket(MMTPType& aData,TRequestStatus& aCallerStatus) |
|
76 { |
|
77 iReadData = &aData; |
|
78 iChunkStatus = aData.FirstWriteChunk(iReceiveChunk); |
|
79 //ToDo check this works or not |
|
80 iCallerStatus=&aCallerStatus; |
|
81 |
|
82 /* complete the reading of whole packet and then hit RunL |
|
83 */ |
|
84 Socket().Recv(iReceiveChunk,0,iStatus); |
|
85 |
|
86 //start timer |
|
87 SetActive(); |
|
88 } |
|
89 |
|
90 /*Writes to the current socket |
|
91 @param TRequestStatus passed from PTPIP Controller |
|
92 */ |
|
93 void CPTPIPSocketHandler::WriteToSocket(MMTPType& aData,TRequestStatus& aCallerStatus) |
|
94 { |
|
95 iWriteData=&aData; |
|
96 iChunkStatus = aData.FirstReadChunk(iWriteChunk); |
|
97 |
|
98 iCallerStatus=&aCallerStatus; |
|
99 Socket().Write(iWriteChunk,iStatus); |
|
100 SetActive(); |
|
101 |
|
102 } |
|
103 |
|
104 |
|
105 |
|
106 void CPTPIPSocketHandler::RunL() |
|
107 { |
|
108 TInt err = iStatus.Int(); |
|
109 User::LeaveIfError(err); |
|
110 |
|
111 switch(iState) |
|
112 { |
|
113 case EReadState: |
|
114 if(iChunkStatus!=KMTPChunkSequenceCompletion) |
|
115 { |
|
116 if(iReadData->CommitRequired()) |
|
117 { |
|
118 iReadData->CommitChunkL(iReceiveChunk); |
|
119 } |
|
120 iChunkStatus = iReadData->NextWriteChunk(iReceiveChunk); |
|
121 Socket().Recv(iReceiveChunk,0,iStatus,iLen); |
|
122 SetActive(); |
|
123 } |
|
124 |
|
125 else |
|
126 { |
|
127 |
|
128 |
|
129 User ::RequestComplete(iCallerStatus,err); |
|
130 iState=EWriteState; |
|
131 } |
|
132 break; |
|
133 |
|
134 case EWriteState: |
|
135 |
|
136 |
|
137 if(iChunkStatus!=KMTPChunkSequenceCompletion) |
|
138 { |
|
139 iChunkStatus = iWriteData->NextReadChunk(iWriteChunk); |
|
140 Socket().Write(iWriteChunk,iStatus); |
|
141 SetActive(); |
|
142 } |
|
143 |
|
144 else |
|
145 { |
|
146 |
|
147 User ::RequestComplete(iCallerStatus,err); |
|
148 iState=EReadState; |
|
149 } |
|
150 break; |
|
151 } |
|
152 } |
|
153 |
|
154 TInt CPTPIPSocketHandler::RunError(TInt aErr) |
|
155 { |
|
156 User ::RequestComplete(iCallerStatus,aErr); |
|
157 return KErrNone; |
|
158 } |
|
159 |
|
160 |
|
161 |
|
162 void CPTPIPSocketHandler::DoCancel() |
|
163 { |
|
164 if(iState==EReadState) |
|
165 Socket().CancelRecv(); |
|
166 else if(iState==EWriteState) |
|
167 Socket().CancelWrite(); |
|
168 } |
|
169 |
|
170 |
|
171 |
|
172 |
|
173 |