|
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 #include "logger.h" |
|
20 #include "btl2cappushserverconnection.h" |
|
21 #include "btl2capserverconnectionfactory.h" |
|
22 |
|
23 using namespace java::util; |
|
24 using namespace java::push; |
|
25 using namespace std; |
|
26 using namespace java::bluetooth; |
|
27 |
|
28 #if defined(__SYMBIAN32__) && defined(__WINSCW__) |
|
29 #include <pls.h> |
|
30 #else |
|
31 static BtL2CapServerConnectionFactory* sL2CapSrvConnFac = 0; |
|
32 #endif |
|
33 |
|
34 #ifdef __SYMBIAN32__ |
|
35 ServerConnectionFactory& getServerConnectionFactory() |
|
36 { |
|
37 #else |
|
38 extern "C" ServerConnectionFactory& getServerConnectionFactory() |
|
39 { |
|
40 #endif |
|
41 JELOG2(EJavaBluetooth); |
|
42 |
|
43 //CONTEXT_REMOVAL |
|
44 #if defined(__SYMBIAN32__) && defined(__WINSCW__) |
|
45 TUid uid = TUid::Uid(0xE0000053); |
|
46 BtL2CapServerConnectionFactory* retObj = |
|
47 Pls<BtL2CapServerConnectionFactory>(uid); |
|
48 return *retObj; |
|
49 #else |
|
50 if (sL2CapSrvConnFac == 0) |
|
51 { |
|
52 sL2CapSrvConnFac = new BtL2CapServerConnectionFactory(); |
|
53 } |
|
54 return *sL2CapSrvConnFac; |
|
55 #endif |
|
56 } |
|
57 |
|
58 |
|
59 OS_EXPORT |
|
60 BtL2CapServerConnectionFactory& BtL2CapServerConnectionFactory::getFactory() |
|
61 { |
|
62 JELOG2(EJavaBluetooth); |
|
63 ServerConnectionFactory& scf = ::getServerConnectionFactory(); |
|
64 return reinterpret_cast<BtL2CapServerConnectionFactory&>(scf); |
|
65 } |
|
66 |
|
67 /** |
|
68 * |
|
69 */ |
|
70 OS_EXPORT BtL2CapServerConnectionFactory::BtL2CapServerConnectionFactory() |
|
71 { |
|
72 JELOG2(EJavaBluetooth); |
|
73 } |
|
74 |
|
75 /** |
|
76 * |
|
77 */ |
|
78 OS_EXPORT BtL2CapServerConnectionFactory::~BtL2CapServerConnectionFactory() |
|
79 { |
|
80 JELOG2(EJavaBluetooth); |
|
81 |
|
82 } |
|
83 |
|
84 /** |
|
85 * |
|
86 */ |
|
87 OS_EXPORT ServerConnection* BtL2CapServerConnectionFactory::createSrvConnObj( |
|
88 const std::wstring& aUri, const std::wstring& aFilter) |
|
89 { |
|
90 JELOG2(EJavaBluetooth); |
|
91 |
|
92 // If launched by push, URI and Filter are already valid. No need to check. |
|
93 // Function Server also needs to be passed during construction. |
|
94 return new L2CapPushServerConnection(aUri, aFilter); |
|
95 } |
|
96 |
|
97 /** |
|
98 * The create method is overrided to support bluetooth specific behaviour |
|
99 * of create . |
|
100 */ |
|
101 OS_EXPORT ServerConnection* BtL2CapServerConnectionFactory::create( |
|
102 const std::wstring& aUri) |
|
103 { |
|
104 JELOG2(EJavaBluetooth); |
|
105 L2CapPushServerConnection * server = NULL; |
|
106 SrvConnContainerIter_t iter = mServerConnections.find(aUri); |
|
107 if (iter == mServerConnections.end()) |
|
108 { |
|
109 // If no server connection object is created before for the given uri |
|
110 // then create and return the server connection |
|
111 std::auto_ptr<ServerConnection> newSrvConn(createSrvConnObj(aUri, L"")); |
|
112 SrvConnContainerData newDataObj(newSrvConn.release(), 0, false, |
|
113 SrvConnContainerData::NORMAL); |
|
114 mServerConnections.insert(std::pair<std::wstring,SrvConnContainerData> |
|
115 (aUri,newDataObj)); |
|
116 server = (L2CapPushServerConnection*)newDataObj.getConn(); |
|
117 server->setCreatedByPush(); |
|
118 } |
|
119 else if (SrvConnContainerData::PUSH_LISTEN_BY_MIDLET == iter->second.connType() |
|
120 || SrvConnContainerData::NORMAL == iter->second.connType()) |
|
121 { |
|
122 // If a server connection is already created for the given uri |
|
123 // and it is handled by application then create a new instance |
|
124 // of server connection |
|
125 server = new L2CapPushServerConnection(aUri, L""); |
|
126 } |
|
127 else |
|
128 { |
|
129 // If a server connection is already created for the given uri |
|
130 // and it is handled by push framework then return the same |
|
131 // instance of server connection to the application |
|
132 iter->second.setConnType(SrvConnContainerData::PUSH_LISTEN_BY_MIDLET); |
|
133 server = (L2CapPushServerConnection*)(*iter).second.getConn(); |
|
134 server->setCreatedByPush(); |
|
135 } |
|
136 return server; |
|
137 } |
|
138 |
|
139 OS_EXPORT bool BtL2CapServerConnectionFactory::isMultipleSrvConnAllowed() |
|
140 { |
|
141 return false; |
|
142 } |
|
143 |
|
144 |
|
145 |