|
1 /* |
|
2 * Copyright (c) 2008 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 is the implementation of application class |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 #include <e32std.h> |
|
20 #include <e32uid.h> |
|
21 #include <e32svr.h> |
|
22 #include <ecom/ecom.h> |
|
23 #include <ecom/implementationinformation.h> |
|
24 |
|
25 #include "hidinterfaces.h" |
|
26 #include "decode.h" |
|
27 #include "layout.h" |
|
28 #include "library.h" |
|
29 #include "debug.h" |
|
30 |
|
31 |
|
32 CLayoutLibrary* CLayoutLibrary::NewL() |
|
33 { |
|
34 CLayoutLibrary* self = new (ELeave) CLayoutLibrary; |
|
35 |
|
36 // No two phase construction required |
|
37 |
|
38 return self; |
|
39 } |
|
40 |
|
41 CLayoutLibrary::CLayoutLibrary() |
|
42 : iId(0), iLoaded(EFalse), iLayout(0) |
|
43 { |
|
44 // Nothing else to do |
|
45 } |
|
46 |
|
47 CLayoutLibrary::~CLayoutLibrary() |
|
48 { |
|
49 TRACE_INFO( (_L("[HID]\t~CLayoutLibrary() 0x%08x"), this)); |
|
50 delete iLayout; |
|
51 if (iLoaded) |
|
52 { |
|
53 iLoaded = EFalse; |
|
54 iId = 0; |
|
55 } |
|
56 REComSession::FinalClose(); |
|
57 } |
|
58 |
|
59 // ---------------------------------------------------------------------- |
|
60 |
|
61 TInt CLayoutLibrary::SetLayout(TInt aId) |
|
62 { |
|
63 TInt err = KErrNone; |
|
64 TBool foundLayout = EFalse; |
|
65 |
|
66 // Implementation info array |
|
67 RImplInfoPtrArray implInfoArray; |
|
68 |
|
69 TRACE_INFO( (_L("[HID]\tCLayoutLibrary::SetLayout: id=%d"), aId)); |
|
70 |
|
71 if( aId == iId ) |
|
72 { |
|
73 TRACE_INFO( (_L("[HID]\tCLayoutLibrary::SetLayout: Same layout id=%d, don't load twice"), aId)); |
|
74 return KErrNone; |
|
75 } |
|
76 |
|
77 // Plain ignore is enough. If listing leaves, the array is just empty. |
|
78 TRAP_IGNORE( REComSession::ListImplementationsL( KHidLayoutPluginInterfaceUid, implInfoArray ) ); |
|
79 |
|
80 TRACE_INFO( (_L("[HID]\tCLayoutLibrary::SetLayout: %d plugins listed"),implInfoArray.Count() )); |
|
81 |
|
82 if ( 0 == implInfoArray.Count()) |
|
83 { |
|
84 TRACE_INFO( (_L("[HID]\tCLayoutLibrary::SetLayout: No Drivers found"))); |
|
85 err = KErrNotFound; |
|
86 } |
|
87 else |
|
88 { |
|
89 for (TInt i=0; i<implInfoArray.Count() && !foundLayout; i++) |
|
90 { |
|
91 // parse implementation UID |
|
92 CImplementationInformation* info = implInfoArray[ i ]; |
|
93 TUid implUid = info->ImplementationUid(); |
|
94 TRACE_INFO( (_L("[HID]\tCLayoutLibrary::SetLayout: load plugin 0x%08x"),implUid )); |
|
95 // load driver |
|
96 // Trap so other drivers will be enumerated even if |
|
97 // this fails: |
|
98 CHidLayoutPluginInterface* plugin = NULL; |
|
99 TRAPD( err, |
|
100 plugin = CHidLayoutPluginInterface::NewL( implUid ); |
|
101 TRACE_INFO( (_L("[HID]\tCLayoutLibrary::SetLayout: plugin loaded"))); |
|
102 ); |
|
103 |
|
104 if( err == KErrNone) |
|
105 { |
|
106 CKeyboardLayout* layout = reinterpret_cast<CKeyboardLayout*>(plugin); |
|
107 if (aId == layout->LayoutId()) |
|
108 { |
|
109 TRACE_INFO( (_L("[HID]\tCLayoutLibrary::SetLayout: Found layout %d!"), aId)); |
|
110 foundLayout = ETrue; |
|
111 // Swap the current layout object: |
|
112 CKeyboardLayout* tmpLayout = iLayout; |
|
113 iLayout = layout; |
|
114 iId = aId; |
|
115 iLoaded = ETrue; |
|
116 TRACE_INFO( (_L("[HID]\tCLayoutLibrary::SetLayout: delete old layout"))); |
|
117 delete tmpLayout; |
|
118 } |
|
119 else |
|
120 { |
|
121 TRACE_INFO( (_L("[HID]\tCLayoutLibrary::SetLayout: wrong layout, delete plugin"))); |
|
122 delete plugin; |
|
123 } |
|
124 } |
|
125 else |
|
126 { |
|
127 TRACE_INFO( (_L("[HID]\tCLayoutLibrary::SetLayout: plugin creation failed"))); |
|
128 } |
|
129 }// end of for loop |
|
130 } |
|
131 |
|
132 if( !foundLayout ) |
|
133 { |
|
134 TRACE_INFO( (_L("[HID]\tCLayoutLibrary::SetLayout: NO PLUGIN FOUND"))); |
|
135 } |
|
136 TRACE_INFO( (_L("[HID]\tCLayoutLibrary::SetLayout: Plugin listing ready, delete info array"))); |
|
137 implInfoArray.ResetAndDestroy(); |
|
138 implInfoArray.Close(); |
|
139 return err; |
|
140 } |
|
141 |
|
142 // End of file |
|
143 |