35 { |
36 { |
36 Cancel(); |
37 Cancel(); |
37 iPendingOperations.Reset(); |
38 iPendingOperations.Reset(); |
38 iPendingOperations.Close(); |
39 iPendingOperations.Close(); |
39 iMTPClient.Close(); |
40 iMTPClient.Close(); |
|
41 iProperty.Close(); |
|
42 delete iTimer; |
40 __FLOG( _L8("+/-Dtor") ); |
43 __FLOG( _L8("+/-Dtor") ); |
41 __FLOG_CLOSE; |
44 __FLOG_CLOSE; |
42 } |
45 } |
43 |
46 |
44 void CMTPOperator::StartTransport( TUid aTransport ) |
47 void CMTPOperator::StartTransport( TUid aTransport ) |
45 { |
48 { |
46 __FLOG_1( _L8("+/-StartTransport( 0x%08X )"), aTransport.iUid ); |
49 __FLOG_1( _L8("+/-StartTransport( 0x%08X )"), aTransport.iUid ); |
|
50 |
47 TInt err = AppendOperation( EStartTransport, aTransport ); |
51 TInt err = AppendOperation( EStartTransport, aTransport ); |
48 if ( KErrNone != err ) |
52 if ( KErrNone != err ) |
49 { |
53 { |
50 iNotifier.HandleStartTrasnportCompleteL( err ); |
54 iNotifier.HandleStartTrasnportCompleteL( err ); |
51 } |
55 } |
59 { |
63 { |
60 iNotifier.HandleStartTrasnportCompleteL( err ); |
64 iNotifier.HandleStartTrasnportCompleteL( err ); |
61 } |
65 } |
62 } |
66 } |
63 |
67 |
|
68 void CMTPOperator::StartTimer(TInt aSecond) |
|
69 { |
|
70 __FLOG(_L8("StartTimer in cmtpoperator!")); |
|
71 iTimer->Start(aSecond); |
|
72 } |
|
73 |
64 void CMTPOperator::DoCancel() |
74 void CMTPOperator::DoCancel() |
65 { |
75 { |
66 __FLOG( _L8("+/-DoCancel") ); |
76 __FLOG( _L8("+/-DoCancel") ); |
|
77 iProperty.Cancel(); |
|
78 iConSubscribed = EFalse; |
67 } |
79 } |
68 |
80 |
69 void CMTPOperator::RunL() |
81 void CMTPOperator::RunL() |
70 { |
82 { |
71 __FLOG( _L8("+RunL") ); |
83 __FLOG( _L8("+RunL") ); |
72 |
84 |
|
85 iConSubscribed = EFalse; |
73 TInt count = iPendingOperations.Count(); |
86 TInt count = iPendingOperations.Count(); |
|
87 |
|
88 TInt connState = KInitialValue; |
|
89 |
74 if ( count > 0 ) |
90 if ( count > 0 ) |
75 { |
91 { |
76 TOperation& operation = iPendingOperations[0]; |
92 TOperation& operation = iPendingOperations[0]; |
77 TRAP_IGNORE( HandleOperationL( operation ) ); |
93 TRAP_IGNORE( HandleOperationL( operation ) ); |
78 iPendingOperations.Remove( 0 ); |
94 iPendingOperations.Remove( 0 ); |
79 } |
95 } |
80 |
96 else |
|
97 { |
|
98 //this will go on to get the updated connection status. |
|
99 SubscribeConnState(); |
|
100 |
|
101 |
|
102 TInt error = iProperty.Get(KMTPPublishConnStateCat, EMTPConnStateKey, connState); |
|
103 __FLOG_2(_L8("Before, the iConnState is %d and connState is %d"), iConnState, connState); |
|
104 if ( KErrNotFound == error ) |
|
105 { |
|
106 iConnState = KInitialValue; |
|
107 __FLOG( _L8("The key is deleted and mtp server shut down!") ); |
|
108 } |
|
109 else |
|
110 { |
|
111 if (iTimer->IsActive() && !iTimer->GetStopTransportStatus()) |
|
112 { |
|
113 __FLOG( _L8("Timer is cancelled!") ); |
|
114 iTimer->Cancel(); |
|
115 } |
|
116 //if the disconnect is not set, set the disconnect |
|
117 //else if the connState is disconnect, launch the timer to restart the server to unload dps. |
|
118 if ( KInitialValue == iConnState ) |
|
119 { |
|
120 iConnState = connState; |
|
121 __FLOG( _L8("the first time to launch mtp") ); |
|
122 } |
|
123 else |
|
124 { |
|
125 if (EDisconnectedFromHost == connState) |
|
126 { |
|
127 iConnState = connState; |
|
128 if (!iTimer->IsActive()) |
|
129 { |
|
130 iTimer->Start(KStopMTPSeconds); |
|
131 } |
|
132 __FLOG( _L8("Timer is launched.") ); |
|
133 } |
|
134 else |
|
135 { |
|
136 |
|
137 iConnState = connState; |
|
138 } |
|
139 } |
|
140 } |
|
141 __FLOG_2(_L8("After, the iConnState is %d and connState is %d"), iConnState, connState); |
|
142 } |
|
143 |
81 __FLOG( _L8("-RunL") ); |
144 __FLOG( _L8("-RunL") ); |
82 } |
145 } |
83 |
146 |
84 CMTPOperator::CMTPOperator( MMTPOperatorNotifier& aNotifier ): |
147 CMTPOperator::CMTPOperator( MMTPOperatorNotifier& aNotifier ): |
85 CActive( EPriorityStandard ), |
148 CActive( EPriorityStandard ), |
91 |
154 |
92 void CMTPOperator::ConstructL() |
155 void CMTPOperator::ConstructL() |
93 { |
156 { |
94 __FLOG( _L8("+ConstructL") ); |
157 __FLOG( _L8("+ConstructL") ); |
95 CActiveScheduler::Add( this ); |
158 CActiveScheduler::Add( this ); |
|
159 //if the server is running, the first disconnction shows the conection is down! |
|
160 if(KErrNone == iMTPClient.IsProcessRunning()) |
|
161 { |
|
162 iConnState = EDisconnectedFromHost; |
|
163 } |
|
164 else |
|
165 { |
|
166 iConnState = KInitialValue; |
|
167 } |
|
168 __FLOG_1( _L8("The connstate is set to %d"), iConnState ); |
96 User::LeaveIfError( iMTPClient.Connect() ); |
169 User::LeaveIfError( iMTPClient.Connect() ); |
|
170 User::LeaveIfError(iProperty.Attach(KMTPPublishConnStateCat, EMTPConnStateKey)); |
|
171 iTimer = CMTPControllerTimer::NewL(iMTPClient, *this); |
|
172 |
|
173 iConSubscribed = EFalse; |
97 __FLOG( _L8("-ConstructL") ); |
174 __FLOG( _L8("-ConstructL") ); |
98 } |
175 } |
99 |
176 |
100 TInt CMTPOperator::AppendOperation( TOperationType aType, TUid aTransport ) |
177 TInt CMTPOperator::AppendOperation( TOperationType aType, TUid aTransport ) |
101 { |
178 { |
102 TOperation operation = { aType, aTransport }; |
179 TOperation operation = { aType, aTransport }; |
103 TInt err = iPendingOperations.Append( operation ); |
180 TInt err = iPendingOperations.Append( operation ); |
|
181 __FLOG_1( _L8("+AppendOperation returns %d"), err ); |
104 if ( ( KErrNone == err ) && !IsActive() ) |
182 if ( ( KErrNone == err ) && !IsActive() ) |
105 { |
183 { |
106 Schedule( KErrNone ); |
184 Schedule( KErrNone ); |
107 } |
185 } |
108 __FLOG_1( _L8("+/-AppendOperation returns %d"), err ); |
186 else |
|
187 { |
|
188 if (iConSubscribed) |
|
189 { |
|
190 Cancel(); |
|
191 if (KErrNone == err) |
|
192 { |
|
193 Schedule( KErrNone ); |
|
194 } |
|
195 } |
|
196 } |
|
197 __FLOG( _L8("-AppendOperation") ); |
109 return err; |
198 return err; |
110 } |
199 } |
111 |
200 |
112 void CMTPOperator::Schedule( TInt aError ) |
201 void CMTPOperator::Schedule( TInt aError ) |
113 { |
202 { |
114 __FLOG_1( _L8("+/-Schedule( %d )"), aError ); |
203 __FLOG_1( _L8("+/-Schedule( %d )"), aError ); |
|
204 if(iTimer->IsActive()) |
|
205 { |
|
206 iTimer->Cancel(); |
|
207 } |
115 TRequestStatus* status = &iStatus; |
208 TRequestStatus* status = &iStatus; |
116 User::RequestComplete( status, aError ); |
209 User::RequestComplete( status, aError ); |
117 SetActive(); |
210 SetActive(); |
118 } |
211 } |
119 |
212 |
124 switch ( aOperation.iType ) |
217 switch ( aOperation.iType ) |
125 { |
218 { |
126 case EStartTransport: |
219 case EStartTransport: |
127 err = iMTPClient.StartTransport( aOperation.iTransport ); |
220 err = iMTPClient.StartTransport( aOperation.iTransport ); |
128 iNotifier.HandleStartTrasnportCompleteL( err ); |
221 iNotifier.HandleStartTrasnportCompleteL( err ); |
|
222 SubscribeConnState(); |
129 break; |
223 break; |
130 default: |
224 default: |
131 __ASSERT_DEBUG( ( EStopTransport == aOperation.iType ), User::Invariant() ); |
225 __ASSERT_DEBUG( ( EStopTransport == aOperation.iType ), User::Invariant() ); |
132 err = iMTPClient.StopTransport( aOperation.iTransport ); |
226 if(!iTimer->GetStopTransportStatus()) |
|
227 { |
|
228 err = iMTPClient.StopTransport( aOperation.iTransport ); |
|
229 } |
|
230 |
133 iNotifier.HandleStopTrasnportCompleteL( err ); |
231 iNotifier.HandleStopTrasnportCompleteL( err ); |
134 break; |
232 break; |
135 } |
233 } |
136 __FLOG( _L8("-HandleOperationL") ); |
234 __FLOG( _L8("-HandleOperationL") ); |
137 } |
235 } |
138 |
236 |
|
237 void CMTPOperator::SubscribeConnState() |
|
238 { |
|
239 if(!IsActive()) |
|
240 { |
|
241 __FLOG( _L8("Subscribe connection state changed)") ); |
|
242 iProperty.Subscribe(iStatus); |
|
243 iConSubscribed = ETrue; |
|
244 SetActive(); |
|
245 } |
|
246 |
|
247 } |
|
248 |
|
249 |