26 #include "cmtpserversession.h" |
26 #include "cmtpserversession.h" |
27 #include "cmtpshutdown.h" |
27 #include "cmtpshutdown.h" |
28 #include "mtpclientserver.h" |
28 #include "mtpclientserver.h" |
29 #include "mtpdebug.h" |
29 #include "mtpdebug.h" |
30 #include "rmtpframework.h" |
30 #include "rmtpframework.h" |
|
31 #include "OstTraceDefinitions.h" |
|
32 #ifdef OST_TRACE_COMPILER_IN_USE |
|
33 #include "cmtpserverTraces.h" |
|
34 #endif |
|
35 |
31 |
36 |
32 #define UNUSED_VAR(a) (a) = (a) |
37 #define UNUSED_VAR(a) (a) = (a) |
33 |
|
34 __FLOG_STMT(_LIT8(KComponent,"Server");) |
|
35 |
38 |
36 /** |
39 /** |
37 PlatSec policy. |
40 PlatSec policy. |
38 */ |
41 */ |
39 const TUint8 KMTPPolicyElementNetworkAndLocal = 0; |
42 const TUint8 KMTPPolicyElementNetworkAndLocal = 0; |
69 /** |
72 /** |
70 Destructor. |
73 Destructor. |
71 */ |
74 */ |
72 CMTPServer::~CMTPServer() |
75 CMTPServer::~CMTPServer() |
73 { |
76 { |
74 __FLOG(_L8("~CMTPServer - Entry")); |
77 OstTraceFunctionEntry0( CMTPSERVER_CMTPSERVER_DES_ENTRY ); |
75 delete iShutdown; |
78 delete iShutdown; |
76 iShutdown = NULL; |
79 iShutdown = NULL; |
77 iFrameworkSingletons.ConnectionMgr().StopTransports(); |
80 iFrameworkSingletons.ConnectionMgr().StopTransports(); |
78 iFrameworkSingletons.DpController().UnloadDataProviders(); |
81 iFrameworkSingletons.DpController().UnloadDataProviders(); |
79 iFrameworkSingletons.Close(); |
82 iFrameworkSingletons.Close(); |
80 REComSession::FinalClose(); |
83 REComSession::FinalClose(); |
81 __FLOG(_L8("~CMTPServer - Exit")); |
84 OstTraceFunctionExit0( CMTPSERVER_CMTPSERVER_DES_EXIT ); |
82 __FLOG_CLOSE; |
|
83 } |
85 } |
84 |
86 |
85 /** |
87 /** |
86 Creates and executes a new CMTPServer instance. |
88 Creates and executes a new CMTPServer instance. |
87 @leave One of the system wide error codes, if a processing failure occurs. |
89 @leave One of the system wide error codes, if a processing failure occurs. |
88 */ |
90 */ |
89 void CMTPServer::RunServerL() |
91 void CMTPServer::RunServerL() |
90 { |
92 { |
91 __FLOG_STATIC(KMTPSubsystem, KComponent, _L8("RunServerL - Entry")); |
93 OstTraceFunctionEntry0( CMTPSERVER_RUNSERVERL_ENTRY ); |
92 |
94 |
93 // Naming the server thread after the server helps to debug panics |
95 // Naming the server thread after the server helps to debug panics |
94 User::LeaveIfError(User::RenameProcess(KMTPServerName)); |
96 TInt ret = User::RenameProcess(KMTPServerName); |
|
97 LEAVEIFERROR(ret, OstTrace0(TRACE_ERROR, CMTPSERVER_RUNSERVERL, "Rename process error")); |
95 |
98 |
96 // Create and install the active scheduler. |
99 // Create and install the active scheduler. |
97 CActiveScheduler* scheduler(new(ELeave) CActiveScheduler); |
100 CActiveScheduler* scheduler(new(ELeave) CActiveScheduler); |
98 CleanupStack::PushL(scheduler); |
101 CleanupStack::PushL(scheduler); |
99 CActiveScheduler::Install(scheduler); |
102 CActiveScheduler::Install(scheduler); |
103 |
106 |
104 // Initialisation complete, signal the client |
107 // Initialisation complete, signal the client |
105 RProcess::Rendezvous(KErrNone); |
108 RProcess::Rendezvous(KErrNone); |
106 |
109 |
107 // Execute the server. |
110 // Execute the server. |
|
111 OstTraceDef0( OST_TRACE_CATEGORY_PRODUCTION, TRACE_IMPORTANT, DUP1_CMTPSERVER_RUNSERVERL, "MTP server starts up" ); |
108 CActiveScheduler::Start(); |
112 CActiveScheduler::Start(); |
|
113 OstTraceDef0( OST_TRACE_CATEGORY_PRODUCTION, TRACE_IMPORTANT, DUP2_CMTPSERVER_RUNSERVERL, "MTP server closed" ); |
109 |
114 |
110 // Server shutting down. |
115 // Server shutting down. |
111 CleanupStack::PopAndDestroy(server); |
116 CleanupStack::PopAndDestroy(server); |
112 |
117 |
113 CleanupStack::PopAndDestroy(1); // scheduler |
118 CleanupStack::PopAndDestroy(1); // scheduler |
114 __FLOG_STATIC(KMTPSubsystem, KComponent, _L8("RunServerL - Exit")); |
119 OstTraceFunctionExit0( CMTPSERVER_RUNSERVERL_EXIT ); |
115 } |
120 } |
116 |
121 |
117 /** |
122 /** |
118 Adds a new CMTPServer session. |
123 Adds a new CMTPServer session. |
119 */ |
124 */ |
120 void CMTPServer::AddSession() |
125 void CMTPServer::AddSession() |
121 { |
126 { |
122 __FLOG(_L8("AddSession - Entry")); |
127 OstTraceFunctionEntry0( CMTPSERVER_ADDSESSION_ENTRY ); |
123 if(iShutdown && iShutdown->IsActive()) |
128 if(iShutdown && iShutdown->IsActive()) |
124 { |
129 { |
125 iShutdown->Cancel(); |
130 iShutdown->Cancel(); |
126 } |
131 } |
127 ++iSessionCount; |
132 ++iSessionCount; |
128 __FLOG(_L8("AddSession - Exit")); |
133 OstTraceFunctionExit0( CMTPSERVER_ADDSESSION_EXIT ); |
129 } |
134 } |
130 |
135 |
131 /** |
136 /** |
132 Removes a CMTPServer session. If there are no active MTP client API sessions |
137 Removes a CMTPServer session. If there are no active MTP client API sessions |
133 remaining and no active MTP connections, then a shutdown timer is started to |
138 remaining and no active MTP connections, then a shutdown timer is started to |
134 terminate the server thread. |
139 terminate the server thread. |
135 */ |
140 */ |
136 void CMTPServer::DropSession() |
141 void CMTPServer::DropSession() |
137 { |
142 { |
138 __FLOG(_L8("DropSession - Entry")); |
143 OstTraceFunctionEntry0( CMTPSERVER_DROPSESSION_ENTRY ); |
139 |
144 |
140 if (--iSessionCount==0 && iFrameworkSingletons.ConnectionMgr().TransportCount() == 0) |
145 if (--iSessionCount==0 && iFrameworkSingletons.ConnectionMgr().TransportCount() == 0) |
141 { |
146 { |
142 // No active MTP client API sessions remain, start the shutdown timer. |
147 // No active MTP client API sessions remain, start the shutdown timer. |
143 if (iShutdown) |
148 if (iShutdown) |
144 { |
149 { |
145 __FLOG(_L8("Shutdown Started - Entry")); |
150 OstTrace0( TRACE_NORMAL, CMTPSERVER_DROPSESSION, "Shutdown Started" ); |
146 iShutdown->Start(); |
151 iShutdown->Start(); |
147 } |
152 } |
148 } |
153 } |
149 __FLOG(_L8("DropSession - Exit")); |
154 OstTraceFunctionExit0( CMTPSERVER_DROPSESSION_EXIT ); |
150 } |
155 } |
151 |
156 |
152 CSession2* CMTPServer::NewSessionL(const TVersion&,const RMessage2&) const |
157 CSession2* CMTPServer::NewSessionL(const TVersion&,const RMessage2&) const |
153 { |
158 { |
154 __FLOG(_L8("NewSessionL - Entry")); |
159 OstTraceFunctionEntry0( CMTPSERVER_NEWSESSIONL_ENTRY ); |
155 __FLOG(_L8("NewSessionL - Exit")); |
160 OstTraceFunctionExit0( CMTPSERVER_NEWSESSIONL_Exit ); |
156 return new(ELeave) CMTPServerSession(); |
161 return new(ELeave) CMTPServerSession(); |
157 } |
162 } |
158 |
163 |
159 /** |
164 /** |
160 CMTPServer factory method. A pointer to the constructed CMTPServer instance is |
165 CMTPServer factory method. A pointer to the constructed CMTPServer instance is |
182 /** |
187 /** |
183 second-phase constructor. |
188 second-phase constructor. |
184 */ |
189 */ |
185 void CMTPServer::ConstructL() |
190 void CMTPServer::ConstructL() |
186 { |
191 { |
187 __FLOG_OPEN(KMTPSubsystem, KComponent); |
192 OstTraceFunctionEntry0( CMTPSERVER_CONSTRUCTL_ENTRY ); |
188 __FLOG(_L8("ConstructL - Entry")); |
|
189 StartL(KMTPServerName); |
193 StartL(KMTPServerName); |
190 iFrameworkSingletons.OpenL(); |
194 iFrameworkSingletons.OpenL(); |
191 if (!iShutdown) |
195 if (!iShutdown) |
192 { |
196 { |
193 TRAPD(error, iShutdown = CMTPShutdown::NewL()); |
197 TRAPD(error, iShutdown = CMTPShutdown::NewL()); |
194 __FLOG(_L8("CMTPShutdown Loaded- Entry")); |
198 OstTrace0( TRACE_NORMAL, CMTPSERVER_CONSTRUCTL, "CMTPShutdown Loaded" ); |
195 UNUSED_VAR(error); |
199 UNUSED_VAR(error); |
196 } |
200 } |
197 __FLOG(_L8("ConstructL - Exit")); |
201 OstTraceFunctionExit0( CMTPSERVER_CONSTRUCTL_EXIT ); |
198 } |
202 } |
199 |
203 |
200 /* |
204 /* |
201 RMessage::Panic() also completes the message. This is: |
205 RMessage::Panic() also completes the message. This is: |
202 (a) important for efficient cleanup within the kernel |
206 (a) important for efficient cleanup within the kernel |
204 @param aMessage Message to be paniced. |
208 @param aMessage Message to be paniced. |
205 @param aPanic Panic code. |
209 @param aPanic Panic code. |
206 */ |
210 */ |
207 void PanicClient(const RMessagePtr2& aMessage,TMTPPanic aPanic) |
211 void PanicClient(const RMessagePtr2& aMessage,TMTPPanic aPanic) |
208 { |
212 { |
209 __FLOG_STATIC(KMTPSubsystem, KComponent, _L8("PanicClient - Entry")); |
213 OstTraceFunctionEntry0( _PANICCLIENT_ENTRY ); |
210 __FLOG_STATIC_VA((KMTPSubsystem, KComponent, _L8("Panic = %d"), aPanic)); |
214 OstTraceDef1(OST_TRACE_CATEGORY_PRODUCTION, TRACE_IMPORTANT, _PANICCLIENT, "Panic = %d", aPanic ); |
|
215 |
211 _LIT(KPanic,"MTPServer"); |
216 _LIT(KPanic,"MTPServer"); |
212 aMessage.Panic(KPanic, aPanic); |
217 aMessage.Panic(KPanic, aPanic); |
213 __FLOG_STATIC(KMTPSubsystem, KComponent, _L8("PanicClient - Exit")); |
218 OstTraceFunctionExit0( _PANICCLIENT_EXIT ); |
214 } |
219 } |
215 |
220 |
216 /** |
221 /** |
217 Process entry point |
222 Process entry point |
218 */ |
223 */ |
219 TInt E32Main() |
224 TInt E32Main() |
220 { |
225 { |
221 __UHEAP_MARK; |
226 __UHEAP_MARK; |
222 __FLOG_STATIC(KMTPSubsystem, KComponent, _L8("E32Main - Entry")); |
227 OstTraceFunctionEntry0( CMTPSERVER_E32MAIN_ENTRY ); |
223 __MTP_HEAP_FLOG |
228 #ifdef OST_TRACE_COMPILER_IN_USE |
|
229 __MTP_HEAP_OSTTRACE(OstTraceExt4(TRACE_NORMAL,CMTPSERVER_E32MAIN_HEAP,"Heap: Size = %d, Allocated = %d, Available = %d, Largest block = %d", size, allocated, available, largest)); |
|
230 #endif |
224 |
231 |
225 CTrapCleanup* cleanup=CTrapCleanup::New(); |
232 CTrapCleanup* cleanup=CTrapCleanup::New(); |
226 TInt ret = KErrNoMemory; |
233 TInt ret = KErrNoMemory; |
227 if (cleanup) |
234 if (cleanup) |
228 { |
235 { |