19 @file |
19 @file |
20 @internalComponent |
20 @internalComponent |
21 */ |
21 */ |
22 |
22 |
23 #include "cmtpoperator.h" |
23 #include "cmtpoperator.h" |
24 |
24 #include "mtpdebug.h" |
25 __FLOG_STMT( _LIT8( KComponent, "mtpoperator" ); ) |
25 #include "OstTraceDefinitions.h" |
26 |
26 #ifdef OST_TRACE_COMPILER_IN_USE |
|
27 #include "cmtpoperatorTraces.h" |
|
28 #endif |
27 |
29 |
28 CMTPOperator* CMTPOperator::NewL( MMTPOperatorNotifier& aNotifier ) |
30 CMTPOperator* CMTPOperator::NewL( MMTPOperatorNotifier& aNotifier ) |
29 { |
31 { |
30 CMTPOperator* self = new( ELeave ) CMTPOperator( aNotifier ); |
32 CMTPOperator* self = new( ELeave ) CMTPOperator( aNotifier ); |
31 self->ConstructL(); |
33 self->ConstructL(); |
32 return self; |
34 return self; |
33 } |
35 } |
34 |
36 |
35 CMTPOperator::~CMTPOperator() |
37 CMTPOperator::~CMTPOperator() |
36 { |
38 { |
|
39 OstTraceFunctionEntry0( CMTPOPERATOR_DES_ENTRY ); |
37 Cancel(); |
40 Cancel(); |
38 iPendingOperations.Reset(); |
41 iPendingOperations.Reset(); |
39 iPendingOperations.Close(); |
42 iPendingOperations.Close(); |
40 iMTPClient.Close(); |
43 iMTPClient.Close(); |
41 iProperty.Close(); |
44 iProperty.Close(); |
42 delete iTimer; |
45 delete iTimer; |
43 __FLOG( _L8("+/-Dtor") ); |
46 OstTraceFunctionExit0( CMTPOPERATOR_DES_EXIT ); |
44 __FLOG_CLOSE; |
|
45 } |
47 } |
46 |
48 |
47 void CMTPOperator::StartTransport( TUid aTransport ) |
49 void CMTPOperator::StartTransport( TUid aTransport ) |
48 { |
50 { |
49 __FLOG_1( _L8("+/-StartTransport( 0x%08X )"), aTransport.iUid ); |
51 OstTraceFunctionEntry0( CMTPOPERATOR_STARTTRANSPORT_ENTRY ); |
50 |
52 OstTrace1( TRACE_NORMAL, CMTPOPERATOR_STARTTRANSPORT, "The transport uid is 0x%08X", aTransport.iUid ); |
51 TInt err = AppendOperation( EStartTransport, aTransport ); |
53 TInt err = AppendOperation( EStartTransport, aTransport ); |
52 if ( KErrNone != err ) |
54 if ( KErrNone != err ) |
53 { |
55 { |
54 iNotifier.HandleStartTrasnportCompleteL( err ); |
56 iNotifier.HandleStartTrasnportCompleteL( err ); |
55 } |
57 } |
|
58 OstTraceFunctionExit0( CMTPOPERATOR_STARTTRANSPORT_EXIT ); |
56 } |
59 } |
57 |
60 |
58 void CMTPOperator::StopTransport( TUid aTransport ) |
61 void CMTPOperator::StopTransport( TUid aTransport ) |
59 { |
62 { |
60 __FLOG_1( _L8("+/-StopTransport( 0x%08X )"), aTransport.iUid ); |
63 OstTraceFunctionEntry0( CMTPOPERATOR_STOPTRANSPORT_ENTRY ); |
|
64 OstTrace1( TRACE_NORMAL, CMTPOPERATOR_STOPTRANSPORT, "The transport uid is 0x%08X", aTransport.iUid ); |
61 TInt err = AppendOperation( EStopTransport, aTransport ); |
65 TInt err = AppendOperation( EStopTransport, aTransport ); |
62 if ( KErrNone != err ) |
66 if ( KErrNone != err ) |
63 { |
67 { |
64 iNotifier.HandleStartTrasnportCompleteL( err ); |
68 iNotifier.HandleStartTrasnportCompleteL( err ); |
65 } |
69 } |
|
70 OstTraceFunctionExit0( CMTPOPERATOR_STOPTRANSPORT_EXIT ); |
66 } |
71 } |
67 |
72 |
68 void CMTPOperator::StartTimer(TInt aSecond) |
73 void CMTPOperator::StartTimer(TInt aSecond) |
69 { |
74 { |
70 __FLOG(_L8("StartTimer in cmtpoperator!")); |
75 OstTraceFunctionEntry0( CMTPOPERATOR_STARTTIMER_ENTRY ); |
71 iTimer->Start(aSecond); |
76 iTimer->Start(aSecond); |
|
77 OstTraceFunctionExit0( CMTPOPERATOR_STARTTIMER_EXIT ); |
72 } |
78 } |
73 |
79 |
74 void CMTPOperator::DoCancel() |
80 void CMTPOperator::DoCancel() |
75 { |
81 { |
76 __FLOG( _L8("+/-DoCancel") ); |
82 OstTraceFunctionEntry0( CMTPOPERATOR_DOCANCEL_ENTRY ); |
77 iProperty.Cancel(); |
83 iProperty.Cancel(); |
78 iConSubscribed = EFalse; |
84 iConSubscribed = EFalse; |
|
85 OstTraceFunctionExit0( CMTPOPERATOR_DOCANCEL_EXIT ); |
79 } |
86 } |
80 |
87 |
81 void CMTPOperator::RunL() |
88 void CMTPOperator::RunL() |
82 { |
89 { |
83 __FLOG( _L8("+RunL") ); |
90 OstTraceFunctionEntry0( CMTPOPERATOR_RUNL_ENTRY ); |
84 |
91 |
85 iConSubscribed = EFalse; |
92 iConSubscribed = EFalse; |
86 TInt count = iPendingOperations.Count(); |
93 TInt count = iPendingOperations.Count(); |
87 |
94 |
88 TInt connState = KInitialValue; |
95 TInt connState = KInitialValue; |
98 //this will go on to get the updated connection status. |
105 //this will go on to get the updated connection status. |
99 SubscribeConnState(); |
106 SubscribeConnState(); |
100 |
107 |
101 |
108 |
102 TInt error = iProperty.Get(KMTPPublishConnStateCat, EMTPConnStateKey, connState); |
109 TInt error = iProperty.Get(KMTPPublishConnStateCat, EMTPConnStateKey, connState); |
103 __FLOG_2(_L8("Before, the iConnState is %d and connState is %d"), iConnState, connState); |
110 OstTraceExt2( TRACE_NORMAL, CMTPOPERATOR_RUNL, "Before, the iConnState is %d and connState is %d", iConnState, connState ); |
104 if ( KErrNotFound == error ) |
111 if ( KErrNotFound == error ) |
105 { |
112 { |
106 iConnState = KInitialValue; |
113 iConnState = KInitialValue; |
107 __FLOG( _L8("The key is deleted and mtp server shut down!") ); |
114 OstTrace0( TRACE_NORMAL, DUP1_CMTPOPERATOR_RUNL, "The key is deleted and mtp server shut down!" ); |
108 } |
115 } |
109 else |
116 else |
110 { |
117 { |
111 if (iTimer->IsActive() && !iTimer->GetStopTransportStatus()) |
118 if (iTimer->IsActive() && !iTimer->GetStopTransportStatus()) |
112 { |
119 { |
113 __FLOG( _L8("Timer is cancelled!") ); |
120 OstTrace0( TRACE_NORMAL, DUP2_CMTPOPERATOR_RUNL, "Timer is cancelled!" ); |
114 iTimer->Cancel(); |
121 iTimer->Cancel(); |
115 } |
122 } |
116 //if the disconnect is not set, set the disconnect |
123 //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. |
124 //else if the connState is disconnect, launch the timer to restart the server to unload dps. |
118 if ( KInitialValue == iConnState ) |
125 if ( KInitialValue == iConnState ) |
119 { |
126 { |
120 iConnState = connState; |
127 iConnState = connState; |
121 __FLOG( _L8("the first time to launch mtp") ); |
128 OstTrace0( TRACE_NORMAL, DUP3_CMTPOPERATOR_RUNL, "the first time to launch mtp" ); |
122 } |
129 } |
123 else |
130 else |
124 { |
131 { |
125 if (EDisconnectedFromHost == connState) |
132 if (EDisconnectedFromHost == connState) |
126 { |
133 { |
127 iConnState = connState; |
134 iConnState = connState; |
128 if (!iTimer->IsActive()) |
135 if (!iTimer->IsActive()) |
129 { |
136 { |
130 iTimer->Start(KStopMTPSeconds); |
137 iTimer->Start(KStopMTPSeconds); |
131 } |
138 } |
132 __FLOG( _L8("Timer is launched.") ); |
139 OstTrace0( TRACE_NORMAL, DUP4_CMTPOPERATOR_RUNL, "Timer is launched." ); |
133 } |
140 } |
134 else |
141 else |
135 { |
142 { |
136 |
143 |
137 iConnState = connState; |
144 iConnState = connState; |
138 } |
145 } |
139 } |
146 } |
140 } |
147 } |
141 __FLOG_2(_L8("After, the iConnState is %d and connState is %d"), iConnState, connState); |
148 OstTraceExt2( TRACE_NORMAL, DUP5_CMTPOPERATOR_RUNL, "After, the iConnState is %d and connState is %d", iConnState, connState ); |
142 } |
149 } |
143 |
150 OstTraceFunctionExit0( CMTPOPERATOR_RUNL_EXIT ); |
144 __FLOG( _L8("-RunL") ); |
|
145 } |
151 } |
146 |
152 |
147 CMTPOperator::CMTPOperator( MMTPOperatorNotifier& aNotifier ): |
153 CMTPOperator::CMTPOperator( MMTPOperatorNotifier& aNotifier ): |
148 CActive( EPriorityStandard ), |
154 CActive( EPriorityStandard ), |
149 iNotifier( aNotifier ) |
155 iNotifier( aNotifier ) |
150 { |
156 { |
151 __FLOG_OPEN( KMTPSubsystem, KComponent ); |
157 OstTraceFunctionEntry0( CMTPOPERATOR_CONS_ENTRY ); |
152 __FLOG( _L8("+/-Ctor") ); |
158 OstTraceFunctionExit0( CMTPOPERATOR_CONS_EXIT ); |
153 } |
159 } |
154 |
160 |
155 void CMTPOperator::ConstructL() |
161 void CMTPOperator::ConstructL() |
156 { |
162 { |
157 __FLOG( _L8("+ConstructL") ); |
163 OstTraceFunctionEntry0( CMTPOPERATOR_CONSTRUCTL_ENTRY ); |
158 CActiveScheduler::Add( this ); |
164 CActiveScheduler::Add( this ); |
159 //if the server is running, the first disconnction shows the conection is down! |
165 //if the server is running, the first disconnction shows the conection is down! |
160 if(KErrNone == iMTPClient.IsProcessRunning()) |
166 if(KErrNone == iMTPClient.IsProcessRunning()) |
161 { |
167 { |
162 iConnState = EDisconnectedFromHost; |
168 iConnState = EDisconnectedFromHost; |
163 } |
169 } |
164 else |
170 else |
165 { |
171 { |
166 iConnState = KInitialValue; |
172 iConnState = KInitialValue; |
167 } |
173 } |
168 __FLOG_1( _L8("The connstate is set to %d"), iConnState ); |
174 OstTrace1( TRACE_NORMAL, CMTPOPERATOR_CONSTRUCTL, "The connstate is set to %d", iConnState ); |
169 User::LeaveIfError( iMTPClient.Connect() ); |
175 |
170 User::LeaveIfError(iProperty.Attach(KMTPPublishConnStateCat, EMTPConnStateKey)); |
176 LEAVEIFERROR( iMTPClient.Connect(), |
|
177 OstTrace0( TRACE_ERROR, DUP1_CMTPOPERATOR_CONSTRUCTL, "Leave when the client connects to mtp server" )); |
|
178 |
|
179 LEAVEIFERROR(iProperty.Attach(KMTPPublishConnStateCat, EMTPConnStateKey), |
|
180 OstTrace0( TRACE_ERROR, DUP2_CMTPOPERATOR_CONSTRUCTL, "iProperty attached failed." )); |
171 iTimer = CMTPControllerTimer::NewL(iMTPClient, *this); |
181 iTimer = CMTPControllerTimer::NewL(iMTPClient, *this); |
172 |
182 |
173 iConSubscribed = EFalse; |
183 iConSubscribed = EFalse; |
174 __FLOG( _L8("-ConstructL") ); |
184 OstTraceFunctionExit0( CMTPOPERATOR_CONSTRUCTL_EXIT ); |
175 } |
185 } |
176 |
186 |
177 TInt CMTPOperator::AppendOperation( TOperationType aType, TUid aTransport ) |
187 TInt CMTPOperator::AppendOperation( TOperationType aType, TUid aTransport ) |
178 { |
188 { |
|
189 OstTraceFunctionEntry0( CMTPOPERATOR_APPENDOPERATION_ENTRY ); |
179 TOperation operation = { aType, aTransport }; |
190 TOperation operation = { aType, aTransport }; |
180 TInt err = iPendingOperations.Append( operation ); |
191 TInt err = iPendingOperations.Append( operation ); |
181 __FLOG_1( _L8("+AppendOperation returns %d"), err ); |
192 OstTrace1( TRACE_NORMAL, CMTPOPERATOR_APPENDOPERATION, "The return value is %d", err ); |
182 if ( ( KErrNone == err ) && !IsActive() ) |
193 if ( ( KErrNone == err ) && !IsActive() ) |
183 { |
194 { |
184 Schedule( KErrNone ); |
195 Schedule( KErrNone ); |
185 } |
196 } |
186 else |
197 else |
192 { |
203 { |
193 Schedule( KErrNone ); |
204 Schedule( KErrNone ); |
194 } |
205 } |
195 } |
206 } |
196 } |
207 } |
197 __FLOG( _L8("-AppendOperation") ); |
208 |
|
209 OstTraceFunctionExit0( CMTPOPERATOR_APPENDOPERATION_EXIT ); |
198 return err; |
210 return err; |
199 } |
211 } |
200 |
212 |
201 void CMTPOperator::Schedule( TInt aError ) |
213 void CMTPOperator::Schedule( TInt aError ) |
202 { |
214 { |
203 __FLOG_1( _L8("+/-Schedule( %d )"), aError ); |
215 OstTraceFunctionEntry0( CMTPOPERATOR_SCHEDULE_ENTRY ); |
|
216 OstTrace1( TRACE_NORMAL, CMTPOPERATOR_SCHEDULE, "The error value is %d", aError ); |
204 if(iTimer->IsActive()) |
217 if(iTimer->IsActive()) |
205 { |
218 { |
206 iTimer->Cancel(); |
219 iTimer->Cancel(); |
207 } |
220 } |
208 TRequestStatus* status = &iStatus; |
221 TRequestStatus* status = &iStatus; |
209 User::RequestComplete( status, aError ); |
222 User::RequestComplete( status, aError ); |
210 SetActive(); |
223 SetActive(); |
|
224 OstTraceFunctionExit0( CMTPOPERATOR_SCHEDULE_EXIT ); |
211 } |
225 } |
212 |
226 |
213 void CMTPOperator::HandleOperationL( const TOperation& aOperation ) |
227 void CMTPOperator::HandleOperationL( const TOperation& aOperation ) |
214 { |
228 { |
215 __FLOG_2( _L8("+HandleOperationL( 0x%08X, 0x%08X )"), aOperation.iTransport.iUid, aOperation.iType ); |
229 OstTraceFunctionEntry0( CMTPOPERATOR_HANDLEOPERATIONL_ENTRY ); |
|
230 OstTraceExt2( TRACE_NORMAL, CMTPOPERATOR_HANDLEOPERATIONL, "The transport id is 0x%08X and the operation is 0x%08X", (TInt)aOperation.iTransport.iUid, aOperation.iType ); |
216 TInt err = KErrNone; |
231 TInt err = KErrNone; |
217 switch ( aOperation.iType ) |
232 switch ( aOperation.iType ) |
218 { |
233 { |
219 case EStartTransport: |
234 case EStartTransport: |
220 err = iMTPClient.StartTransport( aOperation.iTransport ); |
235 err = iMTPClient.StartTransport( aOperation.iTransport ); |