|
1 // Copyright (c) 2004-2009 Nokia Corporation and/or its subsidiary(-ies). |
|
2 // All rights reserved. |
|
3 // This component and the accompanying materials are made available |
|
4 // under the terms of "Eclipse Public License v1.0" |
|
5 // which accompanies this distribution, and is available |
|
6 // at the URL "http://www.eclipse.org/legal/epl-v10.html". |
|
7 // |
|
8 // Initial Contributors: |
|
9 // Nokia Corporation - initial contribution. |
|
10 // |
|
11 // Contributors: |
|
12 // |
|
13 // Description: |
|
14 // Converter manager. |
|
15 // |
|
16 // |
|
17 |
|
18 /** |
|
19 @file |
|
20 @internalComponent |
|
21 */ |
|
22 |
|
23 #include <bluetooth/logger.h> |
|
24 #include <remcon/remconconverterplugin.h> |
|
25 #include <remcon/remconconverterinterface.h> |
|
26 #include "convertermanager.h" |
|
27 #include "utils.h" |
|
28 |
|
29 #ifdef __FLOG_ACTIVE |
|
30 _LIT8(KLogComponent, LOG_COMPONENT_REMCON_SERVER); |
|
31 #endif |
|
32 |
|
33 #ifdef _DEBUG |
|
34 PANICCATEGORY("convman"); |
|
35 #endif |
|
36 |
|
37 #ifdef __FLOG_ACTIVE |
|
38 #define LOGCONVERTERS LogConverters() |
|
39 #else |
|
40 #define LOGCONVERTERS |
|
41 #endif |
|
42 |
|
43 CConverterManager* CConverterManager::NewL() |
|
44 { |
|
45 LOG_STATIC_FUNC |
|
46 CConverterManager* self = new(ELeave) CConverterManager(); |
|
47 CleanupStack::PushL(self); |
|
48 self->ConstructL(); |
|
49 CLEANUPSTACK_POP1(self); |
|
50 return self; |
|
51 } |
|
52 |
|
53 CConverterManager::~CConverterManager() |
|
54 { |
|
55 LOG_FUNC; |
|
56 LOGCONVERTERS; |
|
57 |
|
58 iConverterIfs.Reset(); |
|
59 |
|
60 // Destroy all converter instances. |
|
61 iConverters.ResetAndDestroy(); |
|
62 |
|
63 LOGCONVERTERS; |
|
64 } |
|
65 |
|
66 CConverterManager::CConverterManager() |
|
67 { |
|
68 LOG_FUNC |
|
69 } |
|
70 |
|
71 void CConverterManager::ConstructL() |
|
72 { |
|
73 LOG_FUNC; |
|
74 |
|
75 // Instantiate all converters at construction time. |
|
76 LoadAllConvertersL(); |
|
77 |
|
78 LOGCONVERTERS; |
|
79 } |
|
80 |
|
81 void CConverterManager::LoadAllConvertersL() |
|
82 { |
|
83 LOG_FUNC; |
|
84 |
|
85 // Use ECOM to instantiate each implementation of the plugin interface. |
|
86 const TUid KUidRemoteControlConverterPluginInterface = TUid::Uid(KRemConConverterInterfaceUid); |
|
87 RImplInfoPtrArray implementations; |
|
88 const TEComResolverParams noResolverParams; |
|
89 REComSession::ListImplementationsL(KUidRemoteControlConverterPluginInterface, |
|
90 noResolverParams, |
|
91 KRomOnlyResolverUid, |
|
92 implementations); |
|
93 CleanupResetAndDestroyPushL(implementations); |
|
94 const TUint count = implementations.Count(); |
|
95 LOG1(_L("\tnumber of implementations of converter plugin interface: %d"), count); |
|
96 // It is legal to have no converters. Some bearers may do conversion |
|
97 // internally. Others may have entirely state-dependent conversion. |
|
98 for ( TUint ii = 0 ; ii < count ; ++ii ) |
|
99 { |
|
100 CImplementationInformation* impl = implementations[ii]; |
|
101 ASSERT_DEBUG(impl); |
|
102 LOG(_L("\tloading converter with:")); |
|
103 LOG1(_L("\t\timplementation uid 0x%08x"), impl->ImplementationUid()); |
|
104 LOG1(_L("\t\tversion number %d"), impl->Version()); |
|
105 TBuf8<KMaxName> buf8; |
|
106 buf8.Copy(impl->DisplayName()); |
|
107 LOG1(_L8("\t\tdisplay name \"%S\""), &buf8); |
|
108 LOG1(_L("\t\tROM only %d"), impl->RomOnly()); |
|
109 LOG1(_L("\t\tROM based %d"), impl->RomBased()); |
|
110 |
|
111 CRemConConverterPlugin* conv = CRemConConverterPlugin::NewL(impl->ImplementationUid()); |
|
112 CleanupStack::PushL(conv); |
|
113 LEAVEIFERRORL(iConverters.Append(conv)); |
|
114 |
|
115 TInterfaceInfo info; |
|
116 info.iIf = reinterpret_cast<MRemConConverterInterface*>(conv->GetInterface(TUid::Uid(KRemConConverterInterface1))); |
|
117 // The converter plugins must currently support MRemConConverterInterface. |
|
118 ASSERT_DEBUG(info.iIf); |
|
119 info.iIfUid = TUid::Uid(KRemConConverterInterface1); |
|
120 info.iConverterUid = impl->ImplementationUid(); |
|
121 TInt err = iConverterIfs.Append(info); |
|
122 if ( err != KErrNone ) |
|
123 { |
|
124 iConverters.Remove(iConverters.Count() - 1); |
|
125 LEAVEIFERRORL(err); |
|
126 } |
|
127 CLEANUPSTACK_POP1(conv); |
|
128 } |
|
129 CleanupStack::PopAndDestroy(&implementations); |
|
130 } |
|
131 |
|
132 #ifdef __FLOG_ACTIVE |
|
133 void CConverterManager::LogConverters() const |
|
134 { |
|
135 const TUint count = iConverters.Count(); |
|
136 LOG1(_L("\tNumber of converters = %d"), count); |
|
137 for ( TUint ii = 0 ; ii < count ; ++ii ) |
|
138 { |
|
139 const CRemConConverterPlugin* const conv = iConverters[ii]; |
|
140 ASSERT_DEBUG(conv); |
|
141 LOG2(_L("\t\tconv %d [0x%08x]"), |
|
142 ii, |
|
143 conv); |
|
144 } |
|
145 } |
|
146 #endif // __FLOG_ACTIVE |
|
147 |
|
148 MRemConConverterInterface* CConverterManager::Converter(TUid aInterfaceUid, |
|
149 TUid aBearerUid) const |
|
150 { |
|
151 LOG_FUNC; |
|
152 LOG2(_L("\taInterfaceUid = 0x%08x, aBearerUid = 0x%08x"), aInterfaceUid, aBearerUid); |
|
153 |
|
154 MRemConConverterInterface* converter = NULL; |
|
155 |
|
156 const TUint count = iConverterIfs.Count(); |
|
157 for ( TUint ii = 0 ; ii < count ; ++ii ) |
|
158 { |
|
159 const TInterfaceInfo& tmp = iConverterIfs[ii]; |
|
160 ASSERT_DEBUG(tmp.iIf); |
|
161 if (tmp.iIf->SupportedUids(aInterfaceUid, aBearerUid)) |
|
162 { |
|
163 converter = tmp.iIf; |
|
164 break; |
|
165 } |
|
166 } |
|
167 |
|
168 LOG1(_L("\tconverter = 0x%08x"), converter); |
|
169 return converter; |
|
170 } |
|
171 |
|
172 MRemConConverterInterface* CConverterManager::Converter(const TDesC8& aInterfaceData, |
|
173 TUid aBearerUid) const |
|
174 { |
|
175 LOG_FUNC; |
|
176 |
|
177 MRemConConverterInterface* converter = NULL; |
|
178 |
|
179 const TUint count = iConverterIfs.Count(); |
|
180 for ( TUint ii = 0 ; ii < count ; ++ii ) |
|
181 { |
|
182 const TInterfaceInfo& tmp = iConverterIfs[ii]; |
|
183 ASSERT_DEBUG(tmp.iIf); |
|
184 if (tmp.iIf->SupportedInterface(aInterfaceData, aBearerUid)) |
|
185 { |
|
186 converter = tmp.iIf; |
|
187 break; |
|
188 } |
|
189 } |
|
190 |
|
191 LOG1(_L("\tconverter = 0x%08x"), converter); |
|
192 return converter; |
|
193 } |