|
1 /* |
|
2 * Copyright (c) 2002 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: |
|
15 * Bio control factory |
|
16 * |
|
17 */ |
|
18 |
|
19 |
|
20 |
|
21 // INCLUDE FILES |
|
22 |
|
23 #include "MsgBioControlFactory.h" // for CMsgBioControlFactory |
|
24 #include "msgbiocontrolObserver.h" // for MMsgBioControlObserver |
|
25 #include "MsgEditorUtils.pan" // for panics and error codes |
|
26 #include "MsgBioUids.h" |
|
27 |
|
28 #include <s32file.h> // for CFileStore |
|
29 #include <biodb.h> // for CBIODatabase |
|
30 #include <e32uid.h> // for uids |
|
31 #include <msvapi.h> // MTM server API |
|
32 #include <msgbiocontrol.h> |
|
33 #include <data_caging_path_literals.hrh> |
|
34 #include "MsgEditorUtilsLog.h" |
|
35 |
|
36 // LOCAL CONSTANTS AND MACROS |
|
37 |
|
38 const TInt KEntryPointOrdinalNumber = 1; // Ordinal for NewL |
|
39 |
|
40 typedef CMsgBioControl* (*TNewControlL)(MMsgBioControlObserver& aObserver, |
|
41 CMsvSession* aSession, |
|
42 TMsvId aId, |
|
43 TMsgBioMode aEditorOrViewerMode, |
|
44 const RFile* aFile); |
|
45 |
|
46 // MEMBER FUNCTIONS |
|
47 |
|
48 EXPORT_C CMsgBioControlFactory* CMsgBioControlFactory::NewL() |
|
49 { |
|
50 LOG("CMsgBioControlFactory::NewL begin"); |
|
51 CMsgBioControlFactory* self = new(ELeave) CMsgBioControlFactory(); |
|
52 CleanupStack::PushL(self); |
|
53 self->ConstructL(); |
|
54 CleanupStack::Pop(); |
|
55 LOG("CMsgBioControlFactory::NewL end"); |
|
56 return self; |
|
57 } |
|
58 |
|
59 EXPORT_C CMsgBioControlFactory::~CMsgBioControlFactory() |
|
60 { |
|
61 iControlDllLibrary.Close(); |
|
62 iFs.Close(); |
|
63 } |
|
64 |
|
65 EXPORT_C CMsgBioControl* CMsgBioControlFactory::CreateControlL( |
|
66 MMsgBioControlObserver& aBioControlObserver, |
|
67 const TUid& aBioMsgType, |
|
68 TMsgBioMode aEditorOrViewerMode, |
|
69 TMsvId aId, |
|
70 CMsvSession* aSession) //ownership not transferred |
|
71 { |
|
72 __ASSERT_ALWAYS( ( aId && aSession && |
|
73 ( (aEditorOrViewerMode == EMsgBioEditorMode) || |
|
74 (aEditorOrViewerMode == EMsgBioViewerMode) ) ), |
|
75 Panic(EMEUErrArgument) ); |
|
76 |
|
77 return DoCreateControlL( |
|
78 aBioControlObserver, |
|
79 aBioMsgType, |
|
80 aEditorOrViewerMode, |
|
81 aId, |
|
82 aSession, |
|
83 NULL /* file handle */ ); |
|
84 } |
|
85 |
|
86 EXPORT_C CMsgBioControl* CMsgBioControlFactory::CreateControlL( |
|
87 MMsgBioControlObserver& aBioControlObserver, |
|
88 const TUid& aBioMsgType, |
|
89 TMsgBioMode aEditorOrViewerMode, |
|
90 const RFile& aFile) |
|
91 { |
|
92 __ASSERT_ALWAYS( ( ( (aEditorOrViewerMode == EMsgBioEditorMode) || |
|
93 (aEditorOrViewerMode == EMsgBioViewerMode) ) ), |
|
94 Panic(EMEUErrArgument) ); |
|
95 |
|
96 TMsvId nullMsvId = NULL; |
|
97 return DoCreateControlL( |
|
98 aBioControlObserver, |
|
99 aBioMsgType, |
|
100 aEditorOrViewerMode, |
|
101 nullMsvId, |
|
102 NULL, // of type CMsvSession* |
|
103 &aFile); |
|
104 } |
|
105 |
|
106 CMsgBioControlFactory::CMsgBioControlFactory() |
|
107 { |
|
108 } |
|
109 |
|
110 void CMsgBioControlFactory::ConstructL() |
|
111 { |
|
112 User::LeaveIfError(iFs.Connect()); |
|
113 } |
|
114 |
|
115 CMsgBioControl* CMsgBioControlFactory::DoCreateControlL( |
|
116 MMsgBioControlObserver& aBioControlObserver, |
|
117 const TUid& aBioMsgType, |
|
118 TMsgBioMode aEditorOrViewerMode, |
|
119 TMsvId aId, |
|
120 CMsvSession* aSession, |
|
121 const RFile* aFile) |
|
122 { |
|
123 LOG("CMsgBioControlFactory::DoCreateControlL begin"); |
|
124 if(aBioMsgType.iUid == 0) |
|
125 { |
|
126 User::Leave(KMsgBioMessageTypeNotDefined); |
|
127 } |
|
128 |
|
129 CBIODatabase* bioDatabase = CBIODatabase::NewL(iFs); |
|
130 CleanupStack::PushL(bioDatabase); |
|
131 |
|
132 TPtrC controlName; |
|
133 TRAPD(err,controlName.Set(bioDatabase->GetBioControlNameL(aBioMsgType))); |
|
134 |
|
135 if(err == KErrNotFound) |
|
136 User::Leave(KErrNotFound); |
|
137 |
|
138 TFileName fullname(NULL); |
|
139 fullname.Append( controlName ); |
|
140 |
|
141 CleanupStack::PopAndDestroy(bioDatabase); |
|
142 |
|
143 __ASSERT_ALWAYS( iControlDllLibrary.Handle() == 0, |
|
144 Panic(EMEUOnlyOneLibraryAllowed)); |
|
145 |
|
146 User::LeaveIfError(iControlDllLibrary.Load(fullname)); |
|
147 |
|
148 TLibraryFunction libFunc = iControlDllLibrary.Lookup( |
|
149 KEntryPointOrdinalNumber); |
|
150 if (libFunc == NULL) // Check that we found the entry point |
|
151 { |
|
152 User::Leave(KMsgBadLibraryEntryPoint); |
|
153 } |
|
154 |
|
155 // Create a function pointer to NewL |
|
156 TNewControlL pFunc = reinterpret_cast<TNewControlL>( libFunc ); |
|
157 |
|
158 CMsgBioControl* control = NULL; |
|
159 TRAPD(ret, control = ((*pFunc)( |
|
160 aBioControlObserver, |
|
161 aSession, |
|
162 aId, |
|
163 aEditorOrViewerMode, |
|
164 aFile))); |
|
165 if ((ret != KErrNone) || (control == NULL)) |
|
166 { |
|
167 iControlDllLibrary.Close(); |
|
168 User::Leave(ret); |
|
169 } |
|
170 LOG("CMsgBioControlFactory::DoCreateControlL end"); |
|
171 return control; |
|
172 } |
|
173 // End of file |