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 "messagequeue.h"
|
|
23 |
#include "utils.h"
|
|
24 |
#include "remconmessage.h"
|
|
25 |
|
|
26 |
#ifdef __FLOG_ACTIVE
|
|
27 |
_LIT8(KLogComponent, LOG_COMPONENT_REMCON_SERVER);
|
|
28 |
#endif
|
|
29 |
|
|
30 |
#ifdef _DEBUG
|
|
31 |
PANICCATEGORY("msgqueue");
|
|
32 |
#endif
|
|
33 |
|
|
34 |
CMessageQueue* CMessageQueue::NewL()
|
|
35 |
{
|
|
36 |
LOG_STATIC_FUNC
|
|
37 |
return new(ELeave) CMessageQueue();
|
|
38 |
}
|
|
39 |
|
|
40 |
CMessageQueue::CMessageQueue()
|
|
41 |
: iQueue(_FOFF(CRemConMessage, iLink)),
|
|
42 |
iIter(iQueue)
|
|
43 |
{
|
|
44 |
LOG_FUNC
|
|
45 |
}
|
|
46 |
|
|
47 |
CMessageQueue::~CMessageQueue()
|
|
48 |
{
|
|
49 |
LOG_FUNC;
|
|
50 |
LogQueue();
|
|
51 |
|
|
52 |
iIter.SetToFirst();
|
|
53 |
CRemConMessage* msg;
|
|
54 |
while ( ( msg = iIter++ ) != NULL )
|
|
55 |
{
|
|
56 |
iQueue.Remove(*msg);
|
|
57 |
--iCount;
|
|
58 |
delete msg;
|
|
59 |
}
|
|
60 |
|
|
61 |
LogQueue();
|
|
62 |
}
|
|
63 |
|
|
64 |
TSglQueIter<CRemConMessage>& CMessageQueue::SetToFirst()
|
|
65 |
{
|
|
66 |
LOG_FUNC;
|
|
67 |
|
|
68 |
iIter.SetToFirst();
|
|
69 |
|
|
70 |
return iIter;
|
|
71 |
}
|
|
72 |
|
|
73 |
void CMessageQueue::Append(CRemConMessage& aMsg)
|
|
74 |
{
|
|
75 |
LOG_FUNC;
|
|
76 |
LogQueue();
|
|
77 |
|
|
78 |
iQueue.AddLast(aMsg);
|
|
79 |
++iCount;
|
|
80 |
|
|
81 |
LogQueue();
|
|
82 |
}
|
|
83 |
|
|
84 |
void CMessageQueue::RemoveAndDestroy(CRemConMessage& aMsg)
|
|
85 |
{
|
|
86 |
LOG_FUNC;
|
|
87 |
LOG1(_L("\t&aMsg = [0x%08x]"), &aMsg);
|
|
88 |
|
|
89 |
Remove(aMsg);
|
|
90 |
delete &aMsg;
|
|
91 |
}
|
|
92 |
|
|
93 |
void CMessageQueue::RemoveAndDestroy(TUint aSessionId)
|
|
94 |
{
|
|
95 |
LOG_FUNC;
|
|
96 |
LOG1(_L("\taSessionId = %d"), aSessionId);
|
|
97 |
|
|
98 |
TSglQueIter<CRemConMessage> iter(iQueue);
|
|
99 |
CRemConMessage* msg;
|
|
100 |
while ( ( msg = iter++ ) != NULL )
|
|
101 |
{
|
|
102 |
if ( msg->SessionId() == aSessionId )
|
|
103 |
{
|
|
104 |
RemoveAndDestroy(*msg);
|
|
105 |
}
|
|
106 |
}
|
|
107 |
}
|
|
108 |
|
|
109 |
void CMessageQueue::Remove(CRemConMessage& aMsg)
|
|
110 |
{
|
|
111 |
LOG_FUNC;
|
|
112 |
LOG1(_L("\t&aMsg = [0x%08x]"), &aMsg);
|
|
113 |
LogQueue();
|
|
114 |
|
|
115 |
iQueue.Remove(aMsg);
|
|
116 |
--iCount;
|
|
117 |
|
|
118 |
LogQueue();
|
|
119 |
}
|
|
120 |
|
|
121 |
CRemConMessage& CMessageQueue::First()
|
|
122 |
{
|
|
123 |
LOG_FUNC;
|
|
124 |
|
|
125 |
CRemConMessage* msg = iQueue.First();
|
|
126 |
ASSERT_DEBUG(msg);
|
|
127 |
return *msg;
|
|
128 |
}
|
|
129 |
|
|
130 |
CRemConMessage* CMessageQueue::Message(TUint aTransactionId)
|
|
131 |
{
|
|
132 |
LOG_FUNC;
|
|
133 |
LOG1(_L("\taTransactionId = %d"), aTransactionId);
|
|
134 |
|
|
135 |
TSglQueIter<CRemConMessage> iter(iQueue);
|
|
136 |
CRemConMessage* msg;
|
|
137 |
CRemConMessage* ret = NULL;
|
|
138 |
|
|
139 |
while ( ( msg = iter++ ) != NULL )
|
|
140 |
{
|
|
141 |
if ( msg->TransactionId() == aTransactionId )
|
|
142 |
{
|
|
143 |
ret = msg;
|
|
144 |
break;
|
|
145 |
}
|
|
146 |
}
|
|
147 |
return ret;
|
|
148 |
}
|
|
149 |
|
|
150 |
void CMessageQueue::LogQueue() const
|
|
151 |
{
|
|
152 |
#ifdef __FLOG_ACTIVE
|
|
153 |
|
|
154 |
LOG2(_L("\tthis = 0x%08x, iCount = %d"), this, iCount);
|
|
155 |
|
|
156 |
// Make our own local iterator so we don't interfere with one the client
|
|
157 |
// may be relying on.
|
|
158 |
TSglQueIter<CRemConMessage> iter(const_cast<CMessageQueue*>(this)->iQueue);
|
|
159 |
CRemConMessage* msg;
|
|
160 |
while ( ( msg = iter++ ) != NULL )
|
|
161 |
{
|
|
162 |
LOG4(_L("\t\tmsg [0x%08x], Addr.BearerUid = 0x%08x, MsgType = %d, InterfaceUid = 0x%08x,"),
|
|
163 |
msg,
|
|
164 |
msg->Addr().BearerUid(),
|
|
165 |
msg->MsgType(),
|
|
166 |
msg->InterfaceUid()
|
|
167 |
);
|
|
168 |
LOG3(_L("\t\tOperationId = 0x%02x, SessionId = %d, TransactionId = %d"),
|
|
169 |
msg->OperationId(),
|
|
170 |
msg->SessionId(),
|
|
171 |
msg->TransactionId()
|
|
172 |
);
|
|
173 |
// This logging code left in for maintenance.
|
|
174 |
//LOG1(_L("\t\tOperationData = \"%S\""), &msg->OperationData());
|
|
175 |
}
|
|
176 |
|
|
177 |
#endif // __FLOG_ACTIVE
|
|
178 |
}
|