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 |
#ifndef MESSAGEQUEUE_H
|
|
23 |
#define MESSAGEQUEUE_H
|
|
24 |
|
|
25 |
#include <e32base.h>
|
|
26 |
|
|
27 |
class CRemConMessage;
|
|
28 |
|
|
29 |
/**
|
|
30 |
A queue for RemCon messages (commands and responses).
|
|
31 |
Owns the messages.
|
|
32 |
*/
|
|
33 |
NONSHARABLE_CLASS(CMessageQueue) : public CBase
|
|
34 |
{
|
|
35 |
public:
|
|
36 |
/**
|
|
37 |
@return Ownership of a new CMessageQueue object.
|
|
38 |
*/
|
|
39 |
static CMessageQueue* NewL();
|
|
40 |
|
|
41 |
/**
|
|
42 |
Destructor.
|
|
43 |
*/
|
|
44 |
~CMessageQueue();
|
|
45 |
|
|
46 |
public:
|
|
47 |
/**
|
|
48 |
Accessor for a member iterator over the queue. The iterator is provided
|
|
49 |
set to the first item in the queue. The iterator is 'safe' (will not be
|
|
50 |
otherwise interfered with) until SetToFirst or the destructor is called.
|
|
51 |
@return Iterator.
|
|
52 |
*/
|
|
53 |
TSglQueIter<CRemConMessage>& SetToFirst();
|
|
54 |
|
|
55 |
/**
|
|
56 |
Appends the given item at the end of the queue.
|
|
57 |
@param aMsg New message.
|
|
58 |
*/
|
|
59 |
void Append(CRemConMessage& aMsg);
|
|
60 |
|
|
61 |
/**
|
|
62 |
Removes the given item from the queue and destroys it.
|
|
63 |
@param aMsg Message to be destroyed.
|
|
64 |
*/
|
|
65 |
void RemoveAndDestroy(CRemConMessage& aMsg);
|
|
66 |
|
|
67 |
/**
|
|
68 |
Removes and destroys all messages belonging to the given session.
|
|
69 |
@param aSessionId ID of session.
|
|
70 |
*/
|
|
71 |
void RemoveAndDestroy(TUint aSessionId);
|
|
72 |
|
|
73 |
/**
|
|
74 |
Removes the given item from the queue without destroying it.
|
|
75 |
@param aMsg Message to be removed.
|
|
76 |
*/
|
|
77 |
void Remove(CRemConMessage& aMsg);
|
|
78 |
|
|
79 |
/**
|
|
80 |
Returns the first item in the queue. The queue must not be empty.
|
|
81 |
@return First item in the queue.
|
|
82 |
*/
|
|
83 |
CRemConMessage& First();
|
|
84 |
|
|
85 |
/**
|
|
86 |
Returns a message with a specified transaction ID
|
|
87 |
@param Transaction ID of the required message
|
|
88 |
@return Pointer to the message, or NULL if it does not exist. Ownership is retained by the queue
|
|
89 |
*/
|
|
90 |
|
|
91 |
CRemConMessage* Message(TUint aTransactionId);
|
|
92 |
|
|
93 |
/**
|
|
94 |
@return Whether the queue is empty or not.
|
|
95 |
*/
|
|
96 |
inline TBool IsEmpty() const;
|
|
97 |
|
|
98 |
inline TSglQue<CRemConMessage>& Queue();
|
|
99 |
|
|
100 |
void LogQueue() const;
|
|
101 |
|
|
102 |
private:
|
|
103 |
CMessageQueue();
|
|
104 |
|
|
105 |
private: // owned
|
|
106 |
TSglQue<CRemConMessage> iQueue;
|
|
107 |
TSglQueIter<CRemConMessage> iIter;
|
|
108 |
// Used for logging purposes.
|
|
109 |
TUint iCount;
|
|
110 |
};
|
|
111 |
|
|
112 |
// Inlines
|
|
113 |
|
|
114 |
TBool CMessageQueue::IsEmpty() const
|
|
115 |
{
|
|
116 |
#ifdef __FLOG_ACTIVE
|
|
117 |
// Needs to be defined locally to prevent redefinition
|
|
118 |
_LIT8(KLogComponent, LOG_COMPONENT_REMCON_SERVER);
|
|
119 |
#endif
|
|
120 |
|
|
121 |
LOG_FUNC;
|
|
122 |
|
|
123 |
TBool ret = iQueue.IsEmpty();
|
|
124 |
LOG1(_L("\tret = %d"), ret);
|
|
125 |
|
|
126 |
return ret;
|
|
127 |
}
|
|
128 |
|
|
129 |
TSglQue<CRemConMessage>& CMessageQueue::Queue()
|
|
130 |
{
|
|
131 |
return iQueue;
|
|
132 |
}
|
|
133 |
|
|
134 |
#endif // MESSAGEQUEUE_H
|