1 // Copyright (c) 2007-2009 Nokia Corporation and/or its subsidiary(-ies). |
1 // Copyright (c) 2007-2010 Nokia Corporation and/or its subsidiary(-ies). |
2 // All rights reserved. |
2 // All rights reserved. |
3 // This component and the accompanying materials are made available |
3 // This component and the accompanying materials are made available |
4 // under the terms of "Eclipse Public License v1.0" |
4 // under the terms of "Eclipse Public License v1.0" |
5 // which accompanies this distribution, and is available |
5 // which accompanies this distribution, and is available |
6 // at the URL "http://www.eclipse.org/legal/epl-v10.html". |
6 // at the URL "http://www.eclipse.org/legal/epl-v10.html". |
56 |
56 |
57 CEirManServer::CEirManServer(MHCICommandQueue& aCommandQueue, CLinkMgrProtocol& aLinkMgrProtocol) |
57 CEirManServer::CEirManServer(MHCICommandQueue& aCommandQueue, CLinkMgrProtocol& aLinkMgrProtocol) |
58 : CPolicyServer(CActive::EPriorityStandard, KEirManServerPolicy) |
58 : CPolicyServer(CActive::EPriorityStandard, KEirManServerPolicy) |
59 , iCommandQueue(aCommandQueue) |
59 , iCommandQueue(aCommandQueue) |
60 , iLinkMgrProtocol(aLinkMgrProtocol) |
60 , iLinkMgrProtocol(aLinkMgrProtocol) |
61 , iSessionCount(0) |
61 , iInternalSessionCount(0) |
|
62 , iExternalSessionCount(0) |
62 , iIsFeaturesReady(EFalse) |
63 , iIsFeaturesReady(EFalse) |
63 , iIsEirSupported(EFalse) |
64 , iIsEirSupported(EFalse) |
|
65 , iSessions(_FOFF(CEirManSession, iLink)) |
64 { |
66 { |
65 LOG_FUNC |
67 LOG_FUNC |
66 } |
68 } |
67 |
69 |
68 void CEirManServer::ConstructL() |
70 void CEirManServer::ConstructL() |
91 LEAVEIFERRORL(KErrNotSupported); |
93 LEAVEIFERRORL(KErrNotSupported); |
92 } |
94 } |
93 |
95 |
94 CEirManServer* ncThis = const_cast<CEirManServer*>(this); |
96 CEirManServer* ncThis = const_cast<CEirManServer*>(this); |
95 |
97 |
96 CEirManSession* sess = CEirManSession::NewL(*ncThis); |
98 CEirManExternalSession* sess = CEirManExternalSession::NewL(*ncThis); |
97 LOG1(_L("\tsess = 0x%08x"), sess); |
99 LOG1(_L("\tsess = 0x%08x"), sess); |
98 return sess; |
100 return sess; |
99 } |
101 } |
100 |
102 |
101 void CEirManServer::AddSession() |
103 CEirManInternalSession* CEirManServer::NewInternalSessionL(MEirInternalSessionNotifier& aParent) |
102 { |
104 { |
103 LOG_FUNC |
105 LOG_FUNC |
104 if(iSessionCount++ == 0) |
106 // Server will refuse to create any more session if we have found out eir isn't supported. |
105 { |
107 if(iIsFeaturesReady && !iIsEirSupported) |
106 // While we have clients we need to make sure that the protocol remains alive. |
108 { |
107 iLinkMgrProtocol.LocalOpen(); |
109 User::Leave(KErrNotSupported); |
108 } |
110 } |
109 } |
111 CEirManInternalSession* sess = CEirManInternalSession::NewL(*this, aParent); |
110 |
112 return sess; |
111 void CEirManServer::DropSession() |
113 } |
112 { |
114 |
113 LOG_FUNC |
115 void CEirManServer::AddSession(CEirManSession& aSession, TBool aInternalSession) |
114 if(--iSessionCount == 0) |
116 { |
115 { |
117 LOG_FUNC |
116 // There are no long |
118 |
117 iLinkMgrProtocol.LocalClose(); |
119 iSessions.AddLast(aSession); |
|
120 |
|
121 if (aInternalSession) |
|
122 { |
|
123 if(iInternalSessionCount++ == 0) |
|
124 { |
|
125 // While we have clients we need to make sure that the protocol remains alive. |
|
126 iLinkMgrProtocol.LocalOpen(); |
|
127 } |
|
128 } |
|
129 else |
|
130 { |
|
131 if(iExternalSessionCount++ == 0) |
|
132 { |
|
133 // While we have clients we need to make sure that the protocol remains alive. |
|
134 iLinkMgrProtocol.Open(); |
|
135 } |
|
136 } |
|
137 } |
|
138 |
|
139 void CEirManServer::DropSession(TBool aInternalSession) |
|
140 { |
|
141 LOG_FUNC |
|
142 if (aInternalSession) |
|
143 { |
|
144 if(--iInternalSessionCount == 0) |
|
145 { |
|
146 iLinkMgrProtocol.LocalClose(); |
|
147 } |
|
148 } |
|
149 else |
|
150 { |
|
151 if(--iExternalSessionCount == 0) |
|
152 { |
|
153 iLinkMgrProtocol.Close(); |
|
154 } |
118 } |
155 } |
119 } |
156 } |
120 |
157 |
121 void CEirManServer::NotifyFeaturesReady() |
158 void CEirManServer::NotifyFeaturesReady() |
122 { |
159 { |
124 { |
161 { |
125 __ASSERT_DEBUG(!iEirManager, EIR_SERVER_PANIC(EEirServerEirMangerAlreadyExists)); |
162 __ASSERT_DEBUG(!iEirManager, EIR_SERVER_PANIC(EEirServerEirMangerAlreadyExists)); |
126 TRAPD(err, iEirManager = CEirManager::NewL(iCommandQueue, iLinkMgrProtocol)); |
163 TRAPD(err, iEirManager = CEirManager::NewL(iCommandQueue, iLinkMgrProtocol)); |
127 iIsFeaturesReady = ETrue; |
164 iIsFeaturesReady = ETrue; |
128 |
165 |
129 iSessionIter.SetToFirst(); |
166 TDblQueIter<CEirManSession> sessionIter(iSessions); |
130 CSession2* sessionPtr; |
167 |
|
168 sessionIter.SetToFirst(); |
|
169 CEirManSession* sessionPtr; |
131 if(iLinkMgrProtocol.IsExtendedInquiryResponseSupportedLocally() && err == KErrNone) |
170 if(iLinkMgrProtocol.IsExtendedInquiryResponseSupportedLocally() && err == KErrNone) |
132 { |
171 { |
133 iIsEirSupported = ETrue; |
172 iIsEirSupported = ETrue; |
134 } |
173 } |
135 else |
174 else |
136 { |
175 { |
137 err = ((err != KErrNone) ? KErrNoMemory : KErrNotSupported); |
176 err = ((err != KErrNone) ? KErrNoMemory : KErrNotSupported); |
138 } |
177 } |
139 |
178 |
140 while((sessionPtr = iSessionIter++) != NULL) |
179 while((sessionPtr = sessionIter++) != NULL) |
141 { |
180 { |
142 CEirManSession* eirSession = static_cast<CEirManSession*>(sessionPtr); |
181 sessionPtr->NotifyEirFeatureState(err); |
143 eirSession->NotifyEirFeatureState(err); |
|
144 } |
182 } |
145 } |
183 } |
146 } |
184 } |
147 |
185 |
148 TEirFeatureState CEirManServer::EirFeatureState() |
186 TEirFeatureState CEirManServer::EirFeatureState() |