|
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: |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 #ifndef PUSHSERVERCONNPLUGINMANAGER_H |
|
20 #define PUSHSERVERCONNPLUGINMANAGER_H |
|
21 |
|
22 #include <memory> |
|
23 #include <list> |
|
24 #include <map> |
|
25 #include <string> |
|
26 #include <exception> |
|
27 |
|
28 #include "dynamiclibloader.h" |
|
29 #include "scopedlocks.h" |
|
30 #include "serverconnectionfactory.h" |
|
31 #include "serverconnection.h" |
|
32 #include "connectionlistener.h" |
|
33 #include "pushregdata.h" |
|
34 |
|
35 |
|
36 namespace java |
|
37 { |
|
38 namespace push |
|
39 { |
|
40 |
|
41 class PushControllerErrorHandlerInterface |
|
42 { |
|
43 public: |
|
44 |
|
45 virtual ~PushControllerErrorHandlerInterface() {} |
|
46 |
|
47 /** |
|
48 * This operation sends IPC_PR_ALL_CONNS_FAILED msg |
|
49 * to PushRegistryPlugin. |
|
50 * @throws This operation does not throw exceptions. |
|
51 */ |
|
52 virtual void sendAllConnsFailedMsg() = 0; |
|
53 |
|
54 /** |
|
55 * This operation informs Runtime to close itself. |
|
56 * @throws This operation does not throw exceptions. |
|
57 */ |
|
58 virtual void closeRuntime() = 0; |
|
59 |
|
60 }; |
|
61 |
|
62 class ConnManagedInterface |
|
63 { |
|
64 public: |
|
65 |
|
66 virtual ~ConnManagedInterface() {} |
|
67 |
|
68 /** |
|
69 * This method sends IPC_PR_CONN_COMPLETED comms message to PushRegistryPlugin |
|
70 * when push connection, registered/unregistered by other MIDlet, has been completed. |
|
71 * @param aUri URI of the managed connection. |
|
72 */ |
|
73 virtual void connCompleted(const std::wstring& aUri) = 0; |
|
74 |
|
75 }; |
|
76 |
|
77 /** |
|
78 * This class contains Server Connection Plugin data. Reserved only for internal usage. |
|
79 */ |
|
80 class ServerConnectionPluginData |
|
81 { |
|
82 public: |
|
83 |
|
84 /** |
|
85 * @param aSrvConnLibAccess This class does not take ownership of this object. |
|
86 */ |
|
87 ServerConnectionPluginData(java::util::DynamicLibLoader* aSrvConnLibAccess, |
|
88 java::push::ServerConnectionFactory& aServerConnFactory) |
|
89 : mSrvConnLibAccess(aSrvConnLibAccess),mServerConnFactory(aServerConnFactory) |
|
90 { |
|
91 } |
|
92 |
|
93 virtual ~ServerConnectionPluginData() |
|
94 { |
|
95 } |
|
96 |
|
97 ServerConnectionPluginData(const ServerConnectionPluginData& x) |
|
98 : mSrvConnLibAccess(x.mSrvConnLibAccess),mServerConnFactory(x.mServerConnFactory) |
|
99 { |
|
100 } |
|
101 |
|
102 java::util::DynamicLibLoader* mSrvConnLibAccess; |
|
103 java::push::ServerConnectionFactory& mServerConnFactory; |
|
104 |
|
105 private: |
|
106 //Not implemented. |
|
107 ServerConnectionPluginData &operator=(const ServerConnectionPluginData&); |
|
108 }; |
|
109 |
|
110 /** |
|
111 * This class caches Server Connection Plugins. This class provides functionality to start |
|
112 * listening push connections, register and unregister new dynamic push registrations and |
|
113 * getting information from Server Connections. |
|
114 */ |
|
115 class PushServerConnPluginManager |
|
116 { |
|
117 public: |
|
118 |
|
119 typedef std::list<PushRegData> UriList_t; |
|
120 typedef std::list<PushRegData>::iterator UriListIter_t; |
|
121 |
|
122 /** |
|
123 * @param aListener This class does not take ownership into this argument. |
|
124 * @param aPendingConnListener This class does not take ownership into this argument. |
|
125 */ |
|
126 PushServerConnPluginManager(ConnectionListener* aListener, |
|
127 PendingConnectionListener* aPendingConnListener, |
|
128 ConnManagedInterface* aConnManagedInterface); |
|
129 |
|
130 virtual ~PushServerConnPluginManager(); |
|
131 |
|
132 /** |
|
133 * This operation is used to open push connections to listen arriving messages. |
|
134 * This operation loads Server Connection Plugins, creates ServerConnection objects and |
|
135 * calls ServerConnection.open() operation for each URI. |
|
136 * @param aUriList Push connection URIs. |
|
137 * @param aThrowException indicates whether this operation throws an exception |
|
138 * if creation/opening a connection fails. |
|
139 * @throws PushException with following error codes: |
|
140 * INVALID_URI: |
|
141 * Uri passed as argument is not valid. |
|
142 * COMMON_SRV_CONN_PLUGIN_ERROR: |
|
143 * creation of ServerConnection object failed. |
|
144 * INIT_OF_ALL_PUSH_CONNS_FAILED: |
|
145 initialization of all operations fails |
|
146 * LibraryLoaderException with following error codes: |
|
147 * OPENING_LIBRARY_FAILED: |
|
148 * if opening a Server Connection Plugin failed. |
|
149 * E.g. in the situation where certain protocol is not supported. |
|
150 * CANNOT_FIND_FUNCTION_FAILURE: |
|
151 * if function function by "getServerConnectionFactory" name is not found |
|
152 * from ServerConnection Plugin. |
|
153 */ |
|
154 void startListen(UriList_t& aUriList,bool aThrowException,bool aCallConnectionHandled); |
|
155 |
|
156 /** |
|
157 * This operation is used to update push connnections. This operation creates and |
|
158 * opens new push connections or closes and deletes/sets to "non-push" existing push connections. |
|
159 * @param aUriList Push connection URIs. |
|
160 * @param aErrorHandler error handler object. |
|
161 * @throws If error occurs in the update this operation send same exceptions as |
|
162 * startListen(UriList_t& aUriList) operation. |
|
163 * In the unregistering case this operation does not throw exceptions. |
|
164 */ |
|
165 void updatePushRegs(UriList_t& aUriList,PushControllerErrorHandlerInterface& aErrorHandler); |
|
166 |
|
167 /** |
|
168 * This operation populates aUriList output argument with active or all push |
|
169 * connection URIs of the MIDlet depending value of the aAvailable argument. |
|
170 * @param aAvailable 'true' means that only active push connections are returned. |
|
171 * Active push connection means connection where msg has been arrived. |
|
172 * 'false' means that all push connections of the MIDlet is returned. |
|
173 * @param aUriList Output argument. Push connection URIs are populated into this list. |
|
174 * @throws This operation does not throw exceptions. |
|
175 */ |
|
176 void listConnections(bool aAvailable,std::list<std::wstring>& aUriList); |
|
177 |
|
178 /** |
|
179 * This operation returns push ServerConnection object. |
|
180 * @throws PushException with following error codes: |
|
181 * SRV_CONN_NOT_FOUND: |
|
182 * ServerConnectionFactory object by URI is not found or if ServerConnection |
|
183 * by URI is not found. |
|
184 * INVALID_URI: |
|
185 * Scheme cannot be resolved from the URI. |
|
186 */ |
|
187 ServerConnection& getPushConnection(const std::wstring& aUri); |
|
188 |
|
189 /** |
|
190 * Changed dynamic push registration to normal ServerConnection in the Server Connection Plugin. |
|
191 * This operation does not do anything if ServerConnection by URI is not found. |
|
192 * @throws PushException with following error codes: |
|
193 * INVALID_URI: |
|
194 * Scheme cannot be resolved from the URI. |
|
195 */ |
|
196 void unregisterDynamicPushConn(const std::wstring& aUri); |
|
197 |
|
198 /** |
|
199 * Push ServerConnection can be set to failed by this operation in the case where |
|
200 * ServerConnection calls error() operation. |
|
201 * @param aUri Push connection URI. |
|
202 * @return int Returns number of successful push ServerConnections. |
|
203 */ |
|
204 int setConnFailed(const std::wstring& aUri); |
|
205 |
|
206 /** |
|
207 * Deletes ServerConnection from the ServerConnectionFactory. |
|
208 * This can be used e.g. in the error situation to remove already created |
|
209 * ServerConnection objects. |
|
210 * @param aUri Push connection URI. |
|
211 * @throws This operation does not thrown exception. |
|
212 */ |
|
213 void deletePushServerConn(const std::wstring& aUri); |
|
214 |
|
215 /** |
|
216 * This operation checks that connection is not accepted by an another |
|
217 * application. This operation must be called when push connection is registered |
|
218 * dynamically to other MIDlet in the suite. |
|
219 * @param aUri Push connection URI. |
|
220 * @return true if URI is valid and push connection can be registered. |
|
221 * @throws This operation does not throw exceptions. |
|
222 */ |
|
223 bool isValidPushUri(const std::wstring& aUri); |
|
224 |
|
225 private: |
|
226 |
|
227 //Datamembers. |
|
228 typedef std::map<std::wstring,ServerConnectionPluginData> SrvConnContainer_t; |
|
229 typedef std::map<std::wstring,ServerConnectionPluginData>::iterator SrvConnContainerIter_t; |
|
230 SrvConnContainer_t mSrvConnContainer; |
|
231 |
|
232 typedef std::map<std::wstring,bool> SuccessPushConnList_t; |
|
233 typedef std::map<std::wstring,bool>::iterator SuccessPushConnListIter_t; |
|
234 SuccessPushConnList_t mSuccessPushConnList; |
|
235 |
|
236 //This class does not take ownershhip of the object. |
|
237 ConnectionListener* mConnListener; |
|
238 java::util::ScopedMutex mMutex; |
|
239 //This class does not take ownershhip of the object. |
|
240 PendingConnectionListener* mPendingConnListener; |
|
241 //This class does not take ownershhip of the object. |
|
242 ConnManagedInterface* mConnManagedInterface; |
|
243 |
|
244 //Internal operations. |
|
245 ServerConnectionFactory* getDllFromContainer(const std::wstring& aScheme); |
|
246 ServerConnectionFactory& loadAndStoreDll(const std::wstring& aUri, |
|
247 std::wstring& aOutScheme); |
|
248 void createAndOpenConn(const PushRegData& aData,const std::wstring& aScheme); |
|
249 std::wstring resolveScheme(const std::wstring& aUri) const; |
|
250 std::string resolveDllName(const std::wstring& aScheme) const; |
|
251 int getNumOfSuccessfulPushConns(); |
|
252 void findAndDeleteUnregPushConns(std::list<std::wstring>& aExistingUriList, |
|
253 UriList_t& aNewUriListFromStorage, |
|
254 PushControllerErrorHandlerInterface& aErrorHandler); |
|
255 void findAndAddNewPushConns(std::list<std::wstring>& aExistingUriList, |
|
256 UriList_t& aNewUriListFromStorage); |
|
257 |
|
258 //Not implemented. |
|
259 PushServerConnPluginManager(const PushServerConnPluginManager &x); |
|
260 PushServerConnPluginManager &operator=(const PushServerConnPluginManager &x); |
|
261 |
|
262 }; |
|
263 |
|
264 }//end namespace push |
|
265 }//end namespace java |
|
266 |
|
267 #endif // PUSHSERVERCONNPLUGINMANAGER_H |