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