1 /* |
|
2 * Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies). |
|
3 * All rights reserved. |
|
4 * This component and the accompanying materials are made available |
|
5 * under the terms of "Eclipse Public License v1.0" |
|
6 * which accompanies this distribution, and is available |
|
7 * at the URL "http://www.eclipse.org/legal/epl-v10.html". |
|
8 * |
|
9 * Initial Contributors: |
|
10 * Nokia Corporation - initial contribution. |
|
11 * |
|
12 * Contributors: |
|
13 * |
|
14 * Description: This file contains the implementation of the |
|
15 * CHtiIPCommServer class. |
|
16 * CHtiIPCommServer handles Symbian server side operations |
|
17 * such as server starting and client session creation. |
|
18 * |
|
19 */ |
|
20 |
|
21 |
|
22 // INCLUDE FILES |
|
23 #include "HtiIPCommServerCommon.h" |
|
24 #include "HtiIPCommServer.h" |
|
25 #include "HtiIPCommServerSession.h" |
|
26 #include "HtiIPCommLogging.h" |
|
27 |
|
28 CHtiIPCommServer::CHtiIPCommServer() |
|
29 :CServer2( EPriorityUserInput, EUnsharableSessions ), |
|
30 iConnectionManager( NULL ), |
|
31 iRunning( EFalse ), |
|
32 iNrOfSessions( 0 ) |
|
33 { |
|
34 // NOTE: Server needs to have highest priority of all our active |
|
35 // objects to be able to service client requests while other active |
|
36 // objects are running. |
|
37 // |
|
38 // This also affects closing of sessions. If priorities |
|
39 // are the same ~CHtiIPCommServerSession does not get called before active |
|
40 // object completes. |
|
41 } |
|
42 |
|
43 CHtiIPCommServer::~CHtiIPCommServer() |
|
44 { |
|
45 delete iConnectionManager; |
|
46 } |
|
47 |
|
48 CHtiIPCommServer* CHtiIPCommServer::NewLC() |
|
49 { |
|
50 CHtiIPCommServer* self=new(ELeave) CHtiIPCommServer; |
|
51 CleanupStack::PushL( self ); |
|
52 self->ConstructL(); |
|
53 return self; |
|
54 } |
|
55 |
|
56 void CHtiIPCommServer::ConstructL() |
|
57 { |
|
58 iConnectionManager = CHtiConnectionManager::NewL( this ); |
|
59 StartL( KIPCommServerName ); |
|
60 } |
|
61 |
|
62 CSession2* CHtiIPCommServer::NewSessionL( const TVersion&, const RMessage2&) const |
|
63 { |
|
64 // There should be only one session |
|
65 if ( iNrOfSessions ) |
|
66 User::Leave( KErrAlreadyExists ); |
|
67 |
|
68 return new(ELeave) CHtiIPCommServerSession( (CHtiIPCommServer*)this ); |
|
69 } |
|
70 |
|
71 void CHtiIPCommServer::SessionOpened() |
|
72 { |
|
73 iNrOfSessions++; |
|
74 } |
|
75 |
|
76 void CHtiIPCommServer::SessionClosed() |
|
77 { |
|
78 // Die if no more sessions |
|
79 if ( --iNrOfSessions == 0 ) |
|
80 { |
|
81 HTI_LOG_TEXT( "HtiIPCommServer no more sessions - dying..." ); |
|
82 CloseServer(); |
|
83 } |
|
84 } |
|
85 |
|
86 void CHtiIPCommServer::CloseServer() |
|
87 { |
|
88 // Can be called from CHtiIPCommServer::SessionClosed and |
|
89 // CHtiConnectionManager::TimerExpiredL |
|
90 // So this can actually be called twice if it is called from |
|
91 // TimerExpiredL - hence the iRunning variable :) |
|
92 if ( iRunning ) |
|
93 { |
|
94 iRunning = EFalse; |
|
95 CActiveScheduler::Stop(); |
|
96 HTI_LOG_TEXT( "CActiveScheduler::Stop() called" ); |
|
97 } |
|
98 } |
|
99 |
|
100 static void RunServerL() |
|
101 { |
|
102 // naming the server thread after the server helps to debug panics |
|
103 |
|
104 User::LeaveIfError( RThread::RenameMe( KIPCommServerName ) ); |
|
105 |
|
106 // create and install the active scheduler we need |
|
107 CActiveScheduler* as = new ( ELeave ) CActiveScheduler; |
|
108 CleanupStack::PushL( as ); |
|
109 CActiveScheduler::Install( as ); |
|
110 |
|
111 // create the server (leave it on the cleanup stack) |
|
112 CHtiIPCommServer* server = CHtiIPCommServer::NewLC(); |
|
113 |
|
114 // Rendezvous with the client (RHtiIPCommServer::Connect) |
|
115 RProcess::Rendezvous(KErrNone); |
|
116 |
|
117 server->iRunning = ETrue; |
|
118 CActiveScheduler::Start(); |
|
119 |
|
120 CleanupStack::PopAndDestroy(2); // server, as |
|
121 } |
|
122 |
|
123 |
|
124 // Server process entry-point |
|
125 TInt E32Main() |
|
126 { |
|
127 |
|
128 HTI_LOG_TEXT( "*** Starting HtiIPCommServer ***" ); |
|
129 |
|
130 __UHEAP_MARK; |
|
131 |
|
132 CTrapCleanup* cleanup = CTrapCleanup::New(); |
|
133 TInt r = KErrNoMemory; |
|
134 |
|
135 if ( cleanup ) |
|
136 { |
|
137 TRAP( r, RunServerL() ); |
|
138 delete cleanup; |
|
139 } |
|
140 |
|
141 __UHEAP_MARKEND; |
|
142 |
|
143 HTI_LOG_TEXT( "*** HtiIPCommServer died! ***" ); |
|
144 |
|
145 return r; |
|
146 } |
|