|
1 /* |
|
2 * Copyright (c) 2007 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 class defines extensions to the functionality of CPosLandmarkDatabase class. |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 #include <ecom/ecom.h> |
|
20 #include <uri16.h> |
|
21 #include "EPos_LandmarksUids.hrh" |
|
22 #include <epos_cposlandmarkdatabaseextended.h> |
|
23 #include "epos_mposlmdatabasefastcounters.h" |
|
24 |
|
25 // ============================ MEMBER FUNCTIONS =============================== |
|
26 |
|
27 // ----------------------------------------------------------------------------- |
|
28 // ----------------------------------------------------------------------------- |
|
29 // |
|
30 EXPORT_C CPosLandmarkDatabaseExtended::CPosLandmarkDatabaseExtended() |
|
31 { |
|
32 } |
|
33 |
|
34 // ----------------------------------------------------------------------------- |
|
35 // ----------------------------------------------------------------------------- |
|
36 // |
|
37 EXPORT_C CPosLandmarkDatabaseExtended* CPosLandmarkDatabaseExtended::OpenL() |
|
38 { |
|
39 TUid implementationUid; |
|
40 implementationUid.iUid = KPosLmLocalDatabaseExtImplUid; |
|
41 |
|
42 // Check if any implementation supports this protocol |
|
43 TUid interfaceUid; |
|
44 interfaceUid.iUid = KPosLmDatabaseExtendedIfUid; |
|
45 |
|
46 RImplInfoPtrArray implInfoArray; |
|
47 REComSession::ListImplementationsL( interfaceUid, implInfoArray ); |
|
48 if ( implInfoArray.Count() == 0 ) |
|
49 { |
|
50 User::Leave( KErrNotSupported ); |
|
51 } |
|
52 else |
|
53 { |
|
54 implInfoArray.ResetAndDestroy(); |
|
55 } |
|
56 |
|
57 TAny* ptr = REComSession::CreateImplementationL( |
|
58 implementationUid, |
|
59 _FOFF( CPosLandmarkDatabaseExtended, iDtorIdKey ), |
|
60 NULL ); |
|
61 |
|
62 return reinterpret_cast<CPosLandmarkDatabaseExtended*>( ptr ); |
|
63 } |
|
64 |
|
65 // ----------------------------------------------------------------------------- |
|
66 // ----------------------------------------------------------------------------- |
|
67 // |
|
68 EXPORT_C CPosLandmarkDatabaseExtended* CPosLandmarkDatabaseExtended::OpenL( |
|
69 const TDesC& aDatabaseUri ) |
|
70 { |
|
71 // Determine which implementation id to use by checking the protocol of |
|
72 // the URI (e.g. http). If no protocol is specified "file" is used. |
|
73 _LIT8( KDefaultProtocol, "file" ); |
|
74 _LIT( KProtocolDelimiter, "://" ); |
|
75 |
|
76 TInt position = aDatabaseUri.Find( KProtocolDelimiter ); |
|
77 |
|
78 TEComResolverParams params; |
|
79 HBufC8* protocol8 = NULL; |
|
80 |
|
81 if ( position != KErrNotFound && position != 0 ) |
|
82 { |
|
83 protocol8 = HBufC8::NewLC( position + 1 ); |
|
84 protocol8->Des().FillZ(); |
|
85 protocol8->Des().Copy( aDatabaseUri.Left( position ) ); |
|
86 params.SetDataType( *protocol8 ); |
|
87 } |
|
88 else |
|
89 { |
|
90 params.SetDataType( KDefaultProtocol ); |
|
91 } |
|
92 |
|
93 // Check if any implementation supports this protocol |
|
94 TUid interfaceUid; |
|
95 interfaceUid.iUid = KPosLmDatabaseExtendedIfUid; |
|
96 |
|
97 RImplInfoPtrArray implInfoArray; |
|
98 REComSession::ListImplementationsL( interfaceUid, params, implInfoArray ); |
|
99 if ( implInfoArray.Count() == 0 ) |
|
100 { |
|
101 User::Leave( KErrNotSupported ); |
|
102 } |
|
103 else |
|
104 { |
|
105 implInfoArray.ResetAndDestroy(); |
|
106 } |
|
107 |
|
108 // Send the protocol name to the Ecom server |
|
109 // which determines the implementation. |
|
110 HBufC* strPtr = aDatabaseUri.AllocLC(); |
|
111 |
|
112 TAny* ptr = REComSession::CreateImplementationL( |
|
113 interfaceUid, |
|
114 _FOFF( CPosLandmarkDatabaseExtended, iDtorIdKey ), |
|
115 strPtr, |
|
116 params ); |
|
117 |
|
118 CleanupStack::PopAndDestroy( strPtr ); |
|
119 |
|
120 if ( protocol8 ) |
|
121 { |
|
122 CleanupStack::PopAndDestroy( protocol8 ); |
|
123 } |
|
124 |
|
125 return reinterpret_cast<CPosLandmarkDatabaseExtended*>( ptr ); |
|
126 } |
|
127 |
|
128 // ----------------------------------------------------------------------------- |
|
129 // ----------------------------------------------------------------------------- |
|
130 // |
|
131 EXPORT_C CPosLandmarkDatabaseExtended::~CPosLandmarkDatabaseExtended() |
|
132 { |
|
133 } |
|
134 |
|
135 // ----------------------------------------------------------------------------- |
|
136 // ----------------------------------------------------------------------------- |
|
137 // |
|
138 EXPORT_C TInt CPosLandmarkDatabaseExtended::LandmarksCount() |
|
139 { |
|
140 MPosLmDatabaseFastCounters* extension = |
|
141 reinterpret_cast<MPosLmDatabaseFastCounters*>( GetExtension( TUid::Uid( KPosLmDatabaseFastCountersIfUid ) ) ); |
|
142 if ( extension ) |
|
143 { |
|
144 return extension->TotalLandmarksCount(); |
|
145 } |
|
146 else |
|
147 { |
|
148 return KErrNotSupported; |
|
149 } |
|
150 } |
|
151 |
|
152 // ----------------------------------------------------------------------------- |
|
153 // ----------------------------------------------------------------------------- |
|
154 // |
|
155 EXPORT_C TInt CPosLandmarkDatabaseExtended::CategoriesCount() |
|
156 { |
|
157 MPosLmDatabaseFastCounters* extension = |
|
158 reinterpret_cast<MPosLmDatabaseFastCounters*>( GetExtension( TUid::Uid( KPosLmDatabaseFastCountersIfUid ) ) ); |
|
159 if ( extension ) |
|
160 { |
|
161 return extension->TotalCategoriesCount(); |
|
162 } |
|
163 else |
|
164 { |
|
165 return KErrNotSupported; |
|
166 } |
|
167 } |