|
1 /* |
|
2 * Copyright (c) 2006 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: CNcdSessionHandler implementation |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 #include "ncdsessionhandler.h" |
|
20 #include "ncdkeyvaluepair.h" |
|
21 #include "catalogsdebug.h" |
|
22 #include "ncdutils.h" |
|
23 |
|
24 // --------------------------------------------------------------------------- |
|
25 // NewL |
|
26 // --------------------------------------------------------------------------- |
|
27 // |
|
28 CNcdSessionHandler* CNcdSessionHandler::NewL() |
|
29 { |
|
30 CNcdSessionHandler* self = new( ELeave ) CNcdSessionHandler; |
|
31 return self; |
|
32 } |
|
33 |
|
34 |
|
35 // --------------------------------------------------------------------------- |
|
36 // Destructor |
|
37 // --------------------------------------------------------------------------- |
|
38 // |
|
39 CNcdSessionHandler::~CNcdSessionHandler() |
|
40 { |
|
41 // Delete sessions |
|
42 iSessions.ResetAndDestroy(); |
|
43 } |
|
44 |
|
45 |
|
46 // --------------------------------------------------------------------------- |
|
47 // CreateSessionL |
|
48 // --------------------------------------------------------------------------- |
|
49 // |
|
50 void CNcdSessionHandler::CreateSessionL( const TDesC& aServerUri, |
|
51 const TDesC& aNameSpace, |
|
52 const TDesC& aSessionId ) |
|
53 { |
|
54 TInt index = FindSession( aServerUri, aNameSpace ); |
|
55 if ( index != KErrNotFound ) |
|
56 { |
|
57 User::Leave( KErrAlreadyExists ); |
|
58 } |
|
59 |
|
60 // Create session info and add it to sessions |
|
61 CNcdServerSession* serverSession = CNcdSessionHandler::CNcdServerSession::NewLC( aServerUri, |
|
62 aNameSpace, |
|
63 aSessionId ); |
|
64 iSessions.AppendL( serverSession ); |
|
65 CleanupStack::Pop( serverSession ); |
|
66 } |
|
67 |
|
68 |
|
69 // --------------------------------------------------------------------------- |
|
70 // RemoveSession |
|
71 // --------------------------------------------------------------------------- |
|
72 // |
|
73 void CNcdSessionHandler::RemoveSession( const TDesC& aServerUri, |
|
74 const TDesC& aNameSpace ) |
|
75 { |
|
76 TInt index = FindSession( aServerUri, aNameSpace ); |
|
77 DLTRACE( ( "Index: %i", index ) ); |
|
78 |
|
79 if ( index != KErrNotFound ) |
|
80 { |
|
81 delete iSessions[index]; |
|
82 iSessions.Remove( index ); |
|
83 } |
|
84 } |
|
85 |
|
86 // --------------------------------------------------------------------------- |
|
87 // RemoveAllSessions |
|
88 // --------------------------------------------------------------------------- |
|
89 // |
|
90 void CNcdSessionHandler::RemoveAllSessions() |
|
91 { |
|
92 DLTRACEIN(("")); |
|
93 iSessions.ResetAndDestroy(); |
|
94 } |
|
95 |
|
96 // --------------------------------------------------------------------------- |
|
97 // Session |
|
98 // --------------------------------------------------------------------------- |
|
99 // |
|
100 const TDesC& CNcdSessionHandler::Session( const TDesC& aServerUri, |
|
101 const TDesC& aNameSpace ) |
|
102 { |
|
103 TInt index = FindSession( aServerUri, aNameSpace ); |
|
104 if ( index != KErrNotFound ) |
|
105 { |
|
106 return iSessions[index]->SessionId(); |
|
107 } |
|
108 |
|
109 return KNullDesC; |
|
110 } |
|
111 |
|
112 |
|
113 // --------------------------------------------------------------------------- |
|
114 // DoesSessionExist |
|
115 // --------------------------------------------------------------------------- |
|
116 // |
|
117 TBool CNcdSessionHandler::DoesSessionExist( const TDesC& aServerUri, |
|
118 const TDesC& aNameSpace ) |
|
119 { |
|
120 return ( FindSession( aServerUri, aNameSpace ) >= 0 ); |
|
121 } |
|
122 |
|
123 |
|
124 // --------------------------------------------------------------------------- |
|
125 // FindSession |
|
126 // --------------------------------------------------------------------------- |
|
127 // |
|
128 TInt CNcdSessionHandler::FindSession( const TDesC& aServerUri, |
|
129 const TDesC& aNameSpace ) |
|
130 { |
|
131 for ( TInt i = 0; i < iSessions.Count(); ++i ) |
|
132 { |
|
133 if ( iSessions[i]->ServerUri().Compare( aServerUri ) == 0 && |
|
134 iSessions[i]->NameSpace().Compare( aNameSpace ) == 0 ) |
|
135 { |
|
136 return i; |
|
137 } |
|
138 } |
|
139 return KErrNotFound; |
|
140 } |
|
141 |
|
142 CNcdSessionHandler::CNcdServerSession* CNcdSessionHandler::CNcdServerSession::NewL( const TDesC& aServerUri, |
|
143 const TDesC& aNameSpace, |
|
144 const TDesC& aSessionId ) |
|
145 { |
|
146 CNcdServerSession* self = NewLC( aServerUri, aNameSpace, aSessionId ); |
|
147 CleanupStack::Pop( self ); |
|
148 return self; |
|
149 } |
|
150 |
|
151 CNcdSessionHandler::CNcdServerSession* CNcdSessionHandler::CNcdServerSession::NewLC( const TDesC& aServerUri, |
|
152 const TDesC& aNameSpace, |
|
153 const TDesC& aSessionId ) |
|
154 { |
|
155 CNcdServerSession* self = new (ELeave) CNcdServerSession; |
|
156 CleanupStack::PushL( self ); |
|
157 self->ConstructL( aServerUri, aNameSpace, aSessionId ); |
|
158 return self; |
|
159 } |
|
160 |
|
161 CNcdSessionHandler::CNcdServerSession::~CNcdServerSession() |
|
162 { |
|
163 delete iServerUri; |
|
164 delete iNameSpace; |
|
165 delete iSessionId; |
|
166 } |
|
167 |
|
168 const TDesC& CNcdSessionHandler::CNcdServerSession::ServerUri() |
|
169 { |
|
170 return *iServerUri; |
|
171 } |
|
172 |
|
173 const TDesC& CNcdSessionHandler::CNcdServerSession::NameSpace() |
|
174 { |
|
175 return *iNameSpace; |
|
176 } |
|
177 |
|
178 const TDesC& CNcdSessionHandler::CNcdServerSession::SessionId() |
|
179 { |
|
180 return *iSessionId; |
|
181 } |
|
182 |
|
183 CNcdSessionHandler::CNcdServerSession::CNcdServerSession() |
|
184 { |
|
185 } |
|
186 |
|
187 void CNcdSessionHandler::CNcdServerSession::ConstructL( const TDesC& aServerUri, |
|
188 const TDesC& aNameSpace, |
|
189 const TDesC& aSessionId ) |
|
190 { |
|
191 iServerUri = aServerUri.AllocL(); |
|
192 iNameSpace = aNameSpace.AllocL(); |
|
193 iSessionId = aSessionId.AllocL(); |
|
194 } |
|
195 |