|
1 /* |
|
2 * Copyright (c) 2007-2007 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 #include "logger.h" |
|
20 #include "socketserverconnection.h" |
|
21 #include "socketserverconnectionfactory.h" |
|
22 #include "serverconnectionfactorybase.h" |
|
23 #include "socketserverconnection.h" |
|
24 |
|
25 |
|
26 #if defined(__SYMBIAN32__) && defined(__WINSCW__) |
|
27 #include <pls.h> |
|
28 #else |
|
29 static SocketServerConnectionFactory* sSocSrvConnFac = 0; |
|
30 #endif |
|
31 |
|
32 |
|
33 /* |
|
34 * returns a pointer of SocketServerConnectionFactory to the push controller |
|
35 * so that it can invoke this class when a incoming push event arrives |
|
36 * for this connection |
|
37 */ |
|
38 |
|
39 #ifdef __SYMBIAN32__ |
|
40 ServerConnectionFactory& getServerConnectionFactory() |
|
41 { |
|
42 #else |
|
43 extern "C" ServerConnectionFactory& getServerConnectionFactory() |
|
44 { |
|
45 #endif |
|
46 //CONTEXT_REMOVAL |
|
47 #if defined(__SYMBIAN32__) && defined(__WINSCW__) |
|
48 TUid uid = TUid::Uid(0xE0000079); |
|
49 SocketServerConnectionFactory* socSrvConnFac = Pls<SocketServerConnectionFactory>(uid); |
|
50 return *socSrvConnFac; |
|
51 #else |
|
52 if (sSocSrvConnFac == 0) |
|
53 { |
|
54 sSocSrvConnFac = new SocketServerConnectionFactory(); |
|
55 } |
|
56 return *sSocSrvConnFac; |
|
57 #endif |
|
58 } |
|
59 |
|
60 OS_EXPORT SocketServerConnectionFactory& SocketServerConnectionFactory::getFactory() |
|
61 { |
|
62 JELOG2(ESOCKET); |
|
63 LOG(ESOCKET,EInfo,"+SocketServerConnectionFactory::getFactory() "); |
|
64 ServerConnectionFactory& scf = ::getServerConnectionFactory(); |
|
65 return reinterpret_cast<SocketServerConnectionFactory&>(scf); |
|
66 } |
|
67 |
|
68 /** |
|
69 * Construcot |
|
70 */ |
|
71 OS_EXPORT SocketServerConnectionFactory::SocketServerConnectionFactory() |
|
72 { |
|
73 JELOG2(ESOCKET); |
|
74 } |
|
75 |
|
76 /** |
|
77 * Destrucor |
|
78 */ |
|
79 OS_EXPORT SocketServerConnectionFactory::~SocketServerConnectionFactory() |
|
80 { |
|
81 JELOG2(ESOCKET); |
|
82 } |
|
83 |
|
84 /** |
|
85 * This operation creates protocol specific ServerConnection object |
|
86 * @param aUri ServerConnection URI. |
|
87 * @param aFilter Connection URL indicating which senders are allowed to cause |
|
88 * the MIDlet to be launched. |
|
89 * Value of this argument is empty string in the normal server connection case. |
|
90 */ |
|
91 OS_EXPORT ServerConnection* SocketServerConnectionFactory::createSrvConnObj(const std::wstring& aUri, const std::wstring& aFilter) |
|
92 { |
|
93 return new SocketServerConnection(aUri,aFilter); |
|
94 } |
|
95 |
|
96 /* |
|
97 * This method indicates whether multiple Connector.open() operation call is allowed |
|
98 * for a connection. |
|
99 */ |
|
100 OS_EXPORT bool SocketServerConnectionFactory::isMultipleSrvConnAllowed() |
|
101 { |
|
102 return false; |
|
103 } |
|
104 |
|
105 /* overriding create() method, to handle special case of allowing more than 1 connection socket://: type of url |
|
106 called from midlet */ |
|
107 |
|
108 OS_EXPORT ServerConnection* SocketServerConnectionFactory::create(const std::wstring& aUri) |
|
109 { |
|
110 JELOG2(ESOCKET); |
|
111 LOG(ESOCKET,EInfo,"SocketServerConnectionFactory::create()"); |
|
112 |
|
113 // ScopedLock lockObj(mMutex); |
|
114 if (aUri.length() == 10) // "socket://:" dynamic port url first time return push object |
|
115 { |
|
116 LOG(ESOCKET,EInfo,"SocketServerConnectionFactory::create() - dynamic url"); |
|
117 SrvConnContainerIter_t iter = mServerConnections.find(aUri); |
|
118 if (iter == mServerConnections.end()) |
|
119 { |
|
120 // std::auto_ptr<ServerConnection> newSrvConn(createSrvConnObj(aUri,L"")); |
|
121 // SrvConnContainerData newDataObj(newSrvConn.release(),0,false,SrvConnContainerData::NORMAL); |
|
122 // mServerConnections.insert(std::pair<std::wstring,SrvConnContainerData>(aUri,newDataObj)); |
|
123 // SocketServerConnection * dsc = (SocketServerConnection*)newDataObj.getConn(); |
|
124 // dsc->setPushEnabled(); |
|
125 // return dsc; |
|
126 LOG(ESOCKET,EInfo,"SocketServerConnectionFactory::create() - dynamic url, normal server connection"); |
|
127 SocketServerConnection * socketserver = new SocketServerConnection(); |
|
128 return reinterpret_cast<ServerConnection *>(socketserver); |
|
129 |
|
130 } |
|
131 else |
|
132 { |
|
133 if (SrvConnContainerData::PUSH == iter->second.connType()) |
|
134 { |
|
135 LOG(ESOCKET,EInfo,"SocketServerConnectionFactory::create() - dynamic url, this url is already registered for push"); |
|
136 iter->second.setConnType(SrvConnContainerData::PUSH_LISTEN_BY_MIDLET); |
|
137 return reinterpret_cast<ServerConnection *>(iter->second.getConn()); |
|
138 } |
|
139 else |
|
140 { |
|
141 LOG(ESOCKET,EInfo,"SocketServerConnectionFactory::create() - dynamic url, not registered with push db, so return normal server connection"); |
|
142 SocketServerConnection * socketserver = new SocketServerConnection(); |
|
143 return reinterpret_cast<ServerConnection *>(socketserver); |
|
144 } |
|
145 } |
|
146 } |
|
147 else |
|
148 { |
|
149 return ServerConnectionFactoryBase::create(aUri); |
|
150 } |
|
151 } |