|
1 /* |
|
2 * Copyright (c) 2006 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: Plugin monitor |
|
15 * |
|
16 * An instance of CMPXPluginMonitor monitors plugins for the designated |
|
17 * plugin interface. When a plugin for that plugin interface is added or |
|
18 * removed from the system, CMPXPluginMonitor is notified. CMPXPluginMonitor |
|
19 notifies its client through MMPXPluginMonitorObserver if any changes of plugin. |
|
20 * |
|
21 * |
|
22 */ |
|
23 |
|
24 |
|
25 |
|
26 #include <bamdesca.h> |
|
27 #include <badesca.h> |
|
28 #include <uri16.h> |
|
29 #include <apgcli.h> |
|
30 |
|
31 #include <mpxlog.h> |
|
32 #include <mpxuser.h> |
|
33 #include "mpxpluginmonitor.h" |
|
34 |
|
35 |
|
36 // ============================ MEMBER FUNCTIONS ============================== |
|
37 // ---------------------------------------------------------------------------- |
|
38 // Two-phased constructor. |
|
39 // ---------------------------------------------------------------------------- |
|
40 // |
|
41 EXPORT_C CMPXPluginMonitor* CMPXPluginMonitor::NewL( |
|
42 const TUid& aInterfaceUid) |
|
43 { |
|
44 CMPXPluginMonitor* self = new(ELeave)CMPXPluginMonitor(aInterfaceUid); |
|
45 CleanupStack::PushL(self); |
|
46 self->ConstructL(); |
|
47 CleanupStack::Pop(self); |
|
48 return self; |
|
49 } |
|
50 |
|
51 // ---------------------------------------------------------------------------- |
|
52 // Constructor. |
|
53 // ---------------------------------------------------------------------------- |
|
54 // |
|
55 CMPXPluginMonitor::CMPXPluginMonitor( |
|
56 const TUid& aInterfaceUid) |
|
57 : CActive(EPriorityStandard), |
|
58 iInterfaceUid(aInterfaceUid) |
|
59 { |
|
60 CActiveScheduler::Add(this); |
|
61 } |
|
62 |
|
63 // ---------------------------------------------------------------------------- |
|
64 // 2nd phase constructor. |
|
65 // ---------------------------------------------------------------------------- |
|
66 // |
|
67 void CMPXPluginMonitor::ConstructL() |
|
68 { |
|
69 iECs = REComSession::OpenL(); |
|
70 iECs.NotifyOnChange(iStatus); |
|
71 SetActive(); |
|
72 } |
|
73 |
|
74 // ---------------------------------------------------------------------------- |
|
75 // Destructor. |
|
76 // ---------------------------------------------------------------------------- |
|
77 // |
|
78 EXPORT_C CMPXPluginMonitor::~CMPXPluginMonitor() |
|
79 { |
|
80 Cancel(); |
|
81 iObservers.Reset(); |
|
82 iObservers.Close(); |
|
83 iECs.Close(); |
|
84 REComSession::FinalClose(); |
|
85 } |
|
86 |
|
87 // ---------------------------------------------------------------------------- |
|
88 // CMPXPluginMonitor::AddObserverL |
|
89 // ---------------------------------------------------------------------------- |
|
90 // |
|
91 void CMPXPluginMonitor::AddObserverL(MMPXPluginMonitorObserver& aObs) |
|
92 { |
|
93 iObservers.AppendL(&aObs); |
|
94 } |
|
95 |
|
96 // ---------------------------------------------------------------------------- |
|
97 // CMPXPluginMonitor::RemoveObserverL |
|
98 // ---------------------------------------------------------------------------- |
|
99 // |
|
100 void CMPXPluginMonitor::RemoveObserverL(MMPXPluginMonitorObserver& aObs) |
|
101 { |
|
102 TInt i=iObservers.FindL(&aObs); |
|
103 iObservers.Remove(i); |
|
104 } |
|
105 |
|
106 // ---------------------------------------------------------------------------- |
|
107 // CMPXPluginMonitor::NotifyUnload |
|
108 // ---------------------------------------------------------------------------- |
|
109 // |
|
110 void CMPXPluginMonitor::NotifyUnload( |
|
111 const TUid& aPluginUid) |
|
112 { |
|
113 // notify client |
|
114 for (TInt i = iObservers.Count(); --i >= 0;) |
|
115 { |
|
116 iObservers[i]->HandlePluginUnload(aPluginUid); |
|
117 } |
|
118 } |
|
119 |
|
120 // ---------------------------------------------------------------------------- |
|
121 // Handles request completion event |
|
122 // ---------------------------------------------------------------------------- |
|
123 // |
|
124 void CMPXPluginMonitor::RunL() |
|
125 { |
|
126 MPX_DEBUG_THREAD("CMPXPluginMonitor::RunL"); |
|
127 MPX_DEBUG2("CMPXPluginMonitor::RunL interface id 0x%08x", iInterfaceUid.iUid); |
|
128 iECs.NotifyOnChange(iStatus); |
|
129 SetActive(); |
|
130 // notify client |
|
131 for (TInt i = iObservers.Count(); --i >= 0;) |
|
132 { |
|
133 iObservers[i]->PluginsChangedL(); |
|
134 } |
|
135 } |
|
136 |
|
137 // ---------------------------------------------------------------------------- |
|
138 // Handles a leave occurring in the request completion event handler RunL() |
|
139 // ---------------------------------------------------------------------------- |
|
140 // |
|
141 TInt CMPXPluginMonitor::RunError(TInt aError) |
|
142 { |
|
143 (void)aError; |
|
144 MPX_DEBUG_THREAD("CMPXPluginMonitor::RunError"); |
|
145 MPX_DEBUG3("CMPXPluginMonitor::RunError interface id 0x%08x, error", |
|
146 iInterfaceUid.iUid, aError); |
|
147 // Restart observer |
|
148 iECs.NotifyOnChange(iStatus); |
|
149 SetActive(); |
|
150 return KErrNone; |
|
151 } |
|
152 |
|
153 // ---------------------------------------------------------------------------- |
|
154 // Implements cancellation of an outstanding request. |
|
155 // ---------------------------------------------------------------------------- |
|
156 // |
|
157 void CMPXPluginMonitor::DoCancel() |
|
158 { |
|
159 MPX_DEBUG_THREAD("CMPXPluginMonitor::DoCancel"); |
|
160 MPX_DEBUG2("CMPXPluginMonitor::DoCancel interface id 0x%08x", iInterfaceUid.iUid); |
|
161 iECs.CancelNotifyOnChange(iStatus); |
|
162 } |
|
163 |
|
164 // End of file |