|
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 // |
|
15 |
|
16 #include "csendasmtmmanager.h" |
|
17 |
|
18 #include <mtclreg.h> |
|
19 #include <mtclbase.h> |
|
20 #include <mtmuids.h> |
|
21 #include <csendasmessagetypes.h> |
|
22 |
|
23 #include "csendasserver.h" |
|
24 |
|
25 // constants |
|
26 const TInt KSendAsArrayGranularity = 8; // should be big enough to hold all standard mtms |
|
27 |
|
28 CSendAsMtmManager* CSendAsMtmManager::NewL(CSendAsServer& aServer) |
|
29 { |
|
30 CSendAsMtmManager* self = new(ELeave) CSendAsMtmManager(aServer); |
|
31 CleanupStack::PushL(self); |
|
32 self->ConstructL(); |
|
33 CleanupStack::Pop(self); |
|
34 return self; |
|
35 } |
|
36 |
|
37 CSendAsMtmManager::~CSendAsMtmManager() |
|
38 { |
|
39 // free resources |
|
40 iClientMtmArray.ResetAndDestroy(); |
|
41 iClientMtmArray.Close(); |
|
42 iMtmUidArray.Close(); |
|
43 delete iClientRegistry; |
|
44 } |
|
45 |
|
46 CSendAsMtmManager::CSendAsMtmManager(CSendAsServer& aServer) : |
|
47 iServer(aServer), iMtmUidArray(KSendAsArrayGranularity), |
|
48 iClientMtmArray(KSendAsArrayGranularity) |
|
49 { |
|
50 } |
|
51 |
|
52 void CSendAsMtmManager::ConstructL() |
|
53 { |
|
54 iClientRegistry = CClientMtmRegistry::NewL(iServer.GetMsvSessionL()); |
|
55 PopulateL(); |
|
56 } |
|
57 |
|
58 /** Populates the array of available MTMs capable of sending messages |
|
59 |
|
60 */ |
|
61 void CSendAsMtmManager::PopulateL() |
|
62 { |
|
63 TInt count = iClientRegistry->NumRegisteredMtmDlls(); |
|
64 for( TInt i=0; i<count; ++i ) |
|
65 { |
|
66 TBool addMtmInfo = EFalse; |
|
67 TUid mtmUid = iClientRegistry->MtmTypeUid(i); |
|
68 const CMtmDllInfo& dllInfo = iClientRegistry->RegisteredMtmDllInfo(mtmUid); |
|
69 if( dllInfo.CapabilitiesAvailable() ) |
|
70 { |
|
71 if( dllInfo.MessagingCapability() ) |
|
72 { |
|
73 addMtmInfo = ETrue; |
|
74 } |
|
75 } |
|
76 else |
|
77 { |
|
78 CBaseMtm* mtm = NULL; |
|
79 TRAPD(err, mtm = FindStoredMtmL(mtmUid)); |
|
80 if( err != KErrPermissionDenied ) |
|
81 { |
|
82 if( err == KErrNone ) |
|
83 { |
|
84 TInt ignored = 0; |
|
85 if( mtm->QueryCapability(KUidMtmQueryCanSendMsg, ignored) != KErrNotSupported ) |
|
86 { |
|
87 addMtmInfo = ETrue; |
|
88 } |
|
89 } |
|
90 else if( err != KErrNotFound ) |
|
91 { |
|
92 User::Leave(err); |
|
93 } |
|
94 } |
|
95 } |
|
96 if( addMtmInfo ) |
|
97 { |
|
98 iMtmUidArray.AppendL(mtmUid); |
|
99 } |
|
100 } |
|
101 } |
|
102 |
|
103 /** Requests creation of a Client-side MTM object for the specified MTM UID. |
|
104 |
|
105 @param aMtmUid |
|
106 The client MTM UID. |
|
107 |
|
108 @return |
|
109 CBaseMtm pointer to the created MTM. |
|
110 */ |
|
111 CBaseMtm* CSendAsMtmManager::GetClientMtmL(TUid aMtmUid) |
|
112 { |
|
113 return iClientRegistry->NewMtmL(aMtmUid); |
|
114 } |
|
115 |
|
116 RArray<TUid>& CSendAsMtmManager::GetMtmUidArray() |
|
117 { |
|
118 return iMtmUidArray; |
|
119 } |
|
120 |
|
121 CClientMtmRegistry* CSendAsMtmManager::GetClientMtmRegistry() |
|
122 { |
|
123 return iClientRegistry; |
|
124 } |
|
125 |
|
126 /** Searches for previously loaded MTM. |
|
127 |
|
128 The client MTM array is searched for MTM matching the requested UID. |
|
129 If the MTM is not found, an attempt is made to create it. |
|
130 |
|
131 @param aMtmUid |
|
132 The client MTM UID. |
|
133 |
|
134 @return |
|
135 CBaseMtm pointer to the requested MTM. |
|
136 */ |
|
137 CBaseMtm* CSendAsMtmManager::FindStoredMtmL(TUid aMtmUid) |
|
138 { |
|
139 // search mtm array for matching mtm by uid |
|
140 CBaseMtm* mtm = NULL; |
|
141 TInt count = iClientMtmArray.Count(); |
|
142 for( TInt i=0; i<count; ++i ) |
|
143 { |
|
144 mtm = iClientMtmArray[i]; |
|
145 if( mtm && mtm->Type() == aMtmUid ) |
|
146 { |
|
147 return mtm; |
|
148 } |
|
149 } |
|
150 |
|
151 // not found in mtm array so attempt to create it |
|
152 mtm = GetClientMtmL(aMtmUid); |
|
153 CleanupStack::PushL(mtm); |
|
154 |
|
155 // add to mtm array |
|
156 iClientMtmArray.AppendL(mtm); |
|
157 CleanupStack::Pop(mtm); |
|
158 return mtm; |
|
159 } |
|
160 |
|
161 /** Empties and repopulates the client MTM array. |
|
162 |
|
163 */ |
|
164 void CSendAsMtmManager::RefreshMtmUidArrayL() |
|
165 { |
|
166 // empty list of mtm uids |
|
167 iMtmUidArray.Reset(); |
|
168 // repopulate list |
|
169 PopulateL(); |
|
170 } |