51
|
1 |
// Copyright (c) 2004-2009 Nokia Corporation and/or its subsidiary(-ies).
|
|
2 |
// All rights reserved.
|
|
3 |
// This component and the accompanying materials are made available
|
|
4 |
// under the terms of "Eclipse Public License v1.0"
|
|
5 |
// which accompanies this distribution, and is available
|
|
6 |
// at the URL "http://www.eclipse.org/legal/epl-v10.html".
|
|
7 |
//
|
|
8 |
// Initial Contributors:
|
|
9 |
// Nokia Corporation - initial contribution.
|
|
10 |
//
|
|
11 |
// Contributors:
|
|
12 |
//
|
|
13 |
// Description:
|
|
14 |
//
|
|
15 |
|
|
16 |
/**
|
|
17 |
@file
|
|
18 |
@internalComponent
|
|
19 |
*/
|
|
20 |
|
|
21 |
#include <bluetooth/logger.h>
|
|
22 |
#include "connections.h"
|
|
23 |
#include "utils.h"
|
|
24 |
|
|
25 |
#ifdef __FLOG_ACTIVE
|
|
26 |
_LIT8(KLogComponent, LOG_COMPONENT_REMCON_SERVER);
|
|
27 |
#endif
|
|
28 |
|
|
29 |
#ifdef _DEBUG
|
|
30 |
PANICCATEGORY("connectns");
|
|
31 |
#endif
|
|
32 |
|
|
33 |
CConnections* CConnections::NewL()
|
|
34 |
{
|
|
35 |
LOG_STATIC_FUNC
|
|
36 |
return new(ELeave) CConnections();
|
|
37 |
}
|
|
38 |
|
|
39 |
CConnections::CConnections()
|
|
40 |
: iConnections(_FOFF(TRemConAddress, iLink)),
|
|
41 |
iIter(iConnections)
|
|
42 |
{
|
|
43 |
LOG_FUNC
|
|
44 |
}
|
|
45 |
|
|
46 |
CConnections::~CConnections()
|
|
47 |
{
|
|
48 |
LOG_FUNC;
|
|
49 |
LogConnections();
|
|
50 |
|
|
51 |
iIter.SetToFirst();
|
|
52 |
TRemConAddress* addr;
|
|
53 |
while ( ( addr = iIter++ ) != NULL )
|
|
54 |
{
|
|
55 |
iConnections.Remove(*addr);
|
|
56 |
delete addr;
|
|
57 |
}
|
|
58 |
|
|
59 |
LogConnections();
|
|
60 |
}
|
|
61 |
|
|
62 |
CConnections* CConnections::CopyL(CConnections& aItem)
|
|
63 |
{
|
|
64 |
CConnections* const self = NewL();
|
|
65 |
CleanupStack::PushL(self);
|
|
66 |
|
|
67 |
TSglQueIter<TRemConAddress> iter(aItem.iConnections);
|
|
68 |
TRemConAddress* orig;
|
|
69 |
while ( ( orig = iter++ ) != NULL )
|
|
70 |
{
|
|
71 |
TRemConAddress* const newAddr = new(ELeave) TRemConAddress;
|
|
72 |
newAddr->BearerUid() = orig->BearerUid();
|
|
73 |
newAddr->Addr() = orig->Addr();
|
|
74 |
self->Append(*newAddr);
|
|
75 |
}
|
|
76 |
|
|
77 |
CLEANUPSTACK_POP1(self);
|
|
78 |
return self;
|
|
79 |
}
|
|
80 |
|
|
81 |
TSglQueIter<TRemConAddress>& CConnections::SetToFirst() const
|
|
82 |
{
|
|
83 |
LOG_FUNC;
|
|
84 |
|
|
85 |
TSglQueIter<TRemConAddress>& ncIter = const_cast<CConnections*>(this)->iIter;
|
|
86 |
|
|
87 |
ncIter.SetToFirst();
|
|
88 |
|
|
89 |
return ncIter;
|
|
90 |
}
|
|
91 |
|
|
92 |
void CConnections::Append(TRemConAddress& aAddr)
|
|
93 |
{
|
|
94 |
LOG_FUNC;
|
|
95 |
LogConnections();
|
|
96 |
|
|
97 |
// Add the connection to the array of remotes. In debug, check it isn't
|
|
98 |
// already known. This is a programming error somewhere, possibly the
|
|
99 |
// bearer informing us of a new connection twice.
|
|
100 |
#ifdef _DEBUG
|
|
101 |
TSglQueIter<TRemConAddress> iter(iConnections);
|
|
102 |
TRemConAddress* addr;
|
|
103 |
while ( ( addr = iter++ ) != NULL )
|
|
104 |
{
|
|
105 |
ASSERT_DEBUG( !(*addr == aAddr) );
|
|
106 |
}
|
|
107 |
#endif // _DEBUG
|
|
108 |
|
|
109 |
iConnections.AddLast(aAddr);
|
|
110 |
|
|
111 |
LogConnections();
|
|
112 |
}
|
|
113 |
|
|
114 |
|
|
115 |
void CConnections::Remove(TRemConAddress& aAddr)
|
|
116 |
{
|
|
117 |
LOG_FUNC;
|
|
118 |
LogConnections();
|
|
119 |
|
|
120 |
// Remove the connection from the array of remotes. In debug, check it's
|
|
121 |
// already known.
|
|
122 |
#ifdef _DEBUG
|
|
123 |
TBool found = EFalse;
|
|
124 |
TSglQueIter<TRemConAddress> iter(iConnections);
|
|
125 |
TRemConAddress* addr;
|
|
126 |
while ( ( addr = iter++ ) != NULL )
|
|
127 |
{
|
|
128 |
if ( *addr == aAddr )
|
|
129 |
{
|
|
130 |
found = ETrue;
|
|
131 |
}
|
|
132 |
}
|
|
133 |
ASSERT_DEBUG(found);
|
|
134 |
#endif // _DEBUG
|
|
135 |
|
|
136 |
iConnections.Remove(aAddr);
|
|
137 |
|
|
138 |
LogConnections();
|
|
139 |
}
|
|
140 |
|
|
141 |
TBool CConnections::Find(const TRemConAddress& aAddr) const
|
|
142 |
{
|
|
143 |
LOG_FUNC;
|
|
144 |
LOG1(_L("\taAddr.BearerUid() = 0x%08x"), aAddr.BearerUid());
|
|
145 |
LogConnections();
|
|
146 |
|
|
147 |
TBool found = EFalse;
|
|
148 |
TSglQueIter<TRemConAddress> iter(const_cast<CConnections*>(this)->iConnections);
|
|
149 |
TRemConAddress* addr;
|
|
150 |
while ( ( addr = iter++ ) != NULL )
|
|
151 |
{
|
|
152 |
if ( *addr == aAddr )
|
|
153 |
{
|
|
154 |
found = ETrue;
|
|
155 |
break;
|
|
156 |
}
|
|
157 |
}
|
|
158 |
|
|
159 |
LOG1(_L("\tfound = %d"), found);
|
|
160 |
return found;
|
|
161 |
}
|
|
162 |
|
|
163 |
void CConnections::LogConnections() const
|
|
164 |
{
|
|
165 |
#ifdef __FLOG_ACTIVE
|
|
166 |
|
|
167 |
const TUint count = Count();
|
|
168 |
LOG1(_L("\tNumber of remotes = %d"), count);
|
|
169 |
TSglQueIter<TRemConAddress> iter(const_cast<CConnections*>(this)->iConnections);
|
|
170 |
TRemConAddress* addr;
|
|
171 |
while ( ( addr = iter++ ) != NULL )
|
|
172 |
{
|
|
173 |
LOG3(_L("\t\tremote [0x%08x], BearerUid = 0x%08x, Addr.Length = %d"),
|
|
174 |
addr,
|
|
175 |
addr->BearerUid(),
|
|
176 |
addr->Addr().Length()
|
|
177 |
);
|
|
178 |
}
|
|
179 |
|
|
180 |
#endif // __FLOG_ACTIVE
|
|
181 |
}
|