|
1 /* |
|
2 * Copyright (c) 2009 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 #ifndef SERVERCONNECTIONFACTORYBASE_H |
|
19 #define SERVERCONNECTIONFACTORYBASE_H |
|
20 |
|
21 #include <map> |
|
22 #include "serverconnectionfactory.h" |
|
23 #include "serverconnection.h" |
|
24 #include "scopedlocks.h" |
|
25 |
|
26 namespace java |
|
27 { |
|
28 namespace push |
|
29 { |
|
30 |
|
31 class PendingConnectionListener; |
|
32 |
|
33 /** |
|
34 * This class is internal helper class of ServerConnectionFactoryBase class. |
|
35 * This class contains data of one ServerConnection object. |
|
36 */ |
|
37 class SrvConnContainerData |
|
38 { |
|
39 public: |
|
40 |
|
41 enum ServerConnectionType_t |
|
42 { |
|
43 PUSH, //Push server connection which is listen by Push Controller |
|
44 NORMAL, //non-push server connection |
|
45 PUSH_LISTEN_BY_MIDLET //Push server connection listen by MIDlet. |
|
46 }; |
|
47 |
|
48 /** |
|
49 * @param aConn This class does not take ownership of this argument. |
|
50 */ |
|
51 SrvConnContainerData(ServerConnection* aConn,PendingConnectionListener* aListener, |
|
52 bool aIsActive,ServerConnectionType_t aType) |
|
53 :mSrvConn(aConn),mPendingConnListener(aListener),mIsActive(aIsActive),mConnType(aType) |
|
54 { |
|
55 } |
|
56 |
|
57 virtual ~SrvConnContainerData() |
|
58 { |
|
59 } |
|
60 |
|
61 ServerConnection* getConn() const |
|
62 { |
|
63 return mSrvConn; |
|
64 } |
|
65 |
|
66 void setPendingConnListener(PendingConnectionListener* aListener) |
|
67 { |
|
68 mPendingConnListener = aListener; |
|
69 } |
|
70 |
|
71 PendingConnectionListener* getPendingConnListener() const |
|
72 { |
|
73 return mPendingConnListener; |
|
74 } |
|
75 |
|
76 void setActive(bool aIsActive) |
|
77 { |
|
78 mIsActive = aIsActive; |
|
79 } |
|
80 bool isActive() const |
|
81 { |
|
82 return mIsActive; |
|
83 } |
|
84 |
|
85 void setConnType(ServerConnectionType_t aConnType) |
|
86 { |
|
87 mConnType = aConnType; |
|
88 } |
|
89 ServerConnectionType_t connType() const |
|
90 { |
|
91 return mConnType; |
|
92 } |
|
93 |
|
94 SrvConnContainerData(const SrvConnContainerData &x) |
|
95 { |
|
96 *this = x; |
|
97 } |
|
98 |
|
99 SrvConnContainerData &operator=(const SrvConnContainerData &x) |
|
100 { |
|
101 mSrvConn = x.mSrvConn; |
|
102 mPendingConnListener = x.mPendingConnListener; |
|
103 mIsActive = x.mIsActive; |
|
104 mConnType = x.mConnType; |
|
105 return *this; |
|
106 } |
|
107 |
|
108 private: |
|
109 |
|
110 //Datamembers. |
|
111 //This class does not take ownership of this datamember. |
|
112 ServerConnection* mSrvConn; |
|
113 PendingConnectionListener* mPendingConnListener; |
|
114 //Indicates whether incoming message has arrived to the connection. |
|
115 bool mIsActive; |
|
116 ServerConnectionType_t mConnType; |
|
117 }; |
|
118 |
|
119 /** |
|
120 * This class has "default" implementation of ServerConnectionFactory interface. |
|
121 * Probably this implementation is enough for most of protocols. I.e. it is recommened |
|
122 * to use this implementation if protocol does not have special reguirements for |
|
123 * implementation of ServerConnectionFactory. |
|
124 */ |
|
125 class ServerConnectionFactoryBase : public ServerConnectionFactory |
|
126 { |
|
127 |
|
128 public: |
|
129 |
|
130 OS_IMPORT ServerConnectionFactoryBase(); |
|
131 |
|
132 OS_IMPORT virtual ~ServerConnectionFactoryBase(); |
|
133 |
|
134 //Methods of ServerConnectionFactory interface. |
|
135 /** |
|
136 * See comments from ServerConnectionFactory::createPushServerConn() operation. |
|
137 */ |
|
138 OS_IMPORT virtual ServerConnection& createPushServerConn(const std::wstring& aUri, |
|
139 const std::wstring& aFilter, |
|
140 ConnectionListener* aListener, |
|
141 PendingConnectionListener* aPendingConnListener); |
|
142 |
|
143 /** |
|
144 * This operation creates ServerConnection if it is not already created. |
|
145 * @exception throws RuntimeException if type of the existing ServerConnection |
|
146 * object is PUSH_LISTEN_BY_MIDLET || PUSH and isMultipleSrvConnAllowed() |
|
147 * operation returns 'false'. |
|
148 */ |
|
149 OS_IMPORT virtual ServerConnection* create(const std::wstring& aUri); |
|
150 |
|
151 /** |
|
152 * Returns all connections which connection type is PUSH_LISTEN_BY_MIDLET || PUSH. |
|
153 */ |
|
154 OS_IMPORT virtual void getPushConnections(bool aAvailable,std::list<std::wstring>& aUriList); |
|
155 |
|
156 /** |
|
157 * See comments ServerConnectionFactory::closeAllConnections() operation. |
|
158 */ |
|
159 OS_IMPORT virtual void closeAllConnections(); |
|
160 |
|
161 /** |
|
162 * See comments ServerConnectionFactory::deletePushConnection() operation. |
|
163 */ |
|
164 OS_IMPORT virtual void deletePushConnection(const std::wstring& aUri); |
|
165 |
|
166 /** |
|
167 * See comments ServerConnectionFactory::getPushConnection() operation. |
|
168 */ |
|
169 OS_IMPORT virtual ServerConnection* getPushConnection(const std::wstring& aUri); |
|
170 |
|
171 /** |
|
172 * See comments ServerConnectionFactory::releaseConnection() operation. |
|
173 */ |
|
174 OS_IMPORT virtual void releaseConnection(const std::wstring& aUri); |
|
175 |
|
176 /** |
|
177 * Implementation class of the ServerConnection interface must update status whether |
|
178 * ServerConnection object has pending message(= message arrived but not yet read). |
|
179 * This information is needed for PushRegistry.listConnections() operation. MIDlet can |
|
180 * retrieve by this operation active but not handled connections. |
|
181 * @param aUri URI of the connection. |
|
182 * @param aPendingMsg Updating logic of pending message flag: |
|
183 * - Set it 'true' when message arrives to the connection. |
|
184 * - Set it 'false' when ServerConnection::open() operation has been called. |
|
185 */ |
|
186 OS_IMPORT void setPendingMsgFlag(const std::wstring& aUri,bool aPendingMsg); |
|
187 |
|
188 /** |
|
189 * This operation creates protocol specific ServerConnection object. Validation of |
|
190 * arguments must be done com.nokia.mj.impl.gcf.PushValidator java framework. |
|
191 * Note: This operation does not open push connection. |
|
192 * @param aUri ServerConnection URI. |
|
193 * @param aFilter Connection URL indicating which senders are allowed to cause |
|
194 * the MIDlet to be launched. |
|
195 * Value of this argument is empty string in the normal server connection case. |
|
196 * Note: START_APP_IN_LISTEN_MODE mode is used in the creation of normal server connection. |
|
197 * @throws PushException with following error codes: |
|
198 * COMMON_SRV_CONN_PLUGIN_ERROR: |
|
199 * reserved for other errors in the creation of ServerConnection object. |
|
200 */ |
|
201 virtual ServerConnection* createSrvConnObj(const std::wstring& aUri, |
|
202 const std::wstring& aFilter) = 0; |
|
203 |
|
204 /** |
|
205 * This method indicates whether multiple Connector.open() operation call is allowed |
|
206 * for a connection. Normally this is not allowed but e.g. for some new protocol it might |
|
207 * be allowed. |
|
208 */ |
|
209 virtual bool isMultipleSrvConnAllowed() = 0; |
|
210 |
|
211 protected: |
|
212 |
|
213 typedef std::map<std::wstring,SrvConnContainerData> SrvConnContainer_t; |
|
214 typedef std::map<std::wstring,SrvConnContainerData>::iterator SrvConnContainerIter_t; |
|
215 |
|
216 //Datamembers. |
|
217 SrvConnContainer_t mServerConnections; |
|
218 java::util::ScopedMutex mMutex; |
|
219 |
|
220 private: |
|
221 |
|
222 //Internal operations. |
|
223 bool deletePushConnection(SrvConnContainerIter_t& aIter); |
|
224 |
|
225 //Not implemented. |
|
226 ServerConnectionFactoryBase(const ServerConnectionFactoryBase &x); |
|
227 ServerConnectionFactoryBase &operator=(const ServerConnectionFactoryBase &x); |
|
228 |
|
229 }; |
|
230 |
|
231 }//end namespace push |
|
232 }//end namespace java |
|
233 |
|
234 #endif // SERVERCONNECTIONFACTORYBASE_H |