|
1 /* |
|
2 * Copyright (c) 2006 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: Sensor server property queue. |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 |
|
20 #include "sensrvdefines.h" |
|
21 #include "sensrvtrace.h" |
|
22 #include "sensrvpropertyqueue.h" |
|
23 |
|
24 // --------------------------------------------------------------------------- |
|
25 // 2-phase constructor |
|
26 // --------------------------------------------------------------------------- |
|
27 // |
|
28 CSensrvPropertyQueue* CSensrvPropertyQueue::NewL() |
|
29 { |
|
30 COMPONENT_TRACE( ( _L( "Sensor Server - CSensrvPropertyQueue::NewL()" ) ) ); |
|
31 |
|
32 CSensrvPropertyQueue* self = new( ELeave ) CSensrvPropertyQueue(); |
|
33 CleanupStack::PushL(self); |
|
34 self->ConstructL(); |
|
35 CleanupStack::Pop(self); |
|
36 |
|
37 COMPONENT_TRACE( ( _L( "Sensor Server - CSensrvPropertyQueue::NewL - return 0x%x" ), self ) ); |
|
38 |
|
39 return self; |
|
40 } |
|
41 |
|
42 // --------------------------------------------------------------------------- |
|
43 // C++ constructor |
|
44 // --------------------------------------------------------------------------- |
|
45 // |
|
46 CSensrvPropertyQueue::CSensrvPropertyQueue() |
|
47 : iPropertyPtrList(_FOFF(TLinkablePropertyPtr,iLink)), |
|
48 iPropertyPtrIter(iPropertyPtrList) |
|
49 { |
|
50 COMPONENT_TRACE( ( _L( "Sensor Server - CSensrvPropertyQueue::CSensrvPropertyQueue()" ) ) ); |
|
51 |
|
52 // Nothing to do |
|
53 |
|
54 COMPONENT_TRACE( ( _L( "Sensor Server - CSensrvPropertyQueue::CSensrvPropertyQueue - return" ) ) ); |
|
55 } |
|
56 |
|
57 // --------------------------------------------------------------------------- |
|
58 // 2nd phase of construction |
|
59 // --------------------------------------------------------------------------- |
|
60 // |
|
61 void CSensrvPropertyQueue::ConstructL() |
|
62 { |
|
63 COMPONENT_TRACE( ( _L( "Sensor Server - CSensrvPropertyQueue::ConstructL()" ) ) ); |
|
64 |
|
65 iHeap = &User::Heap(); |
|
66 |
|
67 COMPONENT_TRACE( ( _L( "Sensor Server - CSensrvPropertyQueue::ConstructL - return" ) ) ); |
|
68 } |
|
69 |
|
70 |
|
71 // --------------------------------------------------------------------------- |
|
72 // Destructor |
|
73 // --------------------------------------------------------------------------- |
|
74 // |
|
75 CSensrvPropertyQueue::~CSensrvPropertyQueue() |
|
76 { |
|
77 COMPONENT_TRACE( ( _L( "Sensor Server - CSensrvPropertyQueue::~CSensrvPropertyQueue()" ) ) ); |
|
78 |
|
79 RemoveAll(); |
|
80 |
|
81 // iHeap is not owned |
|
82 |
|
83 COMPONENT_TRACE( ( _L( "Sensor Server - CSensrvPropertyQueue::~CSensrvPropertyQueue - return" ) ) ); |
|
84 } |
|
85 |
|
86 |
|
87 // --------------------------------------------------------------------------- |
|
88 // Adds property to the end of the queue |
|
89 // --------------------------------------------------------------------------- |
|
90 // |
|
91 TInt CSensrvPropertyQueue::Append( const TSensrvProperty& aProperty ) |
|
92 { |
|
93 COMPONENT_TRACE( ( _L( "Sensor Server - CSensrvPropertyQueue::Append(Property ID:%d)" ), aProperty.GetPropertyId() ) ); |
|
94 |
|
95 TInt err(KErrNone); |
|
96 |
|
97 // Allocate linkable transaction pointer in same heap as queue |
|
98 TLinkablePropertyPtr* newPtr = reinterpret_cast<TLinkablePropertyPtr*>(iHeap->Alloc(sizeof(TLinkablePropertyPtr))); |
|
99 |
|
100 if (newPtr) |
|
101 { |
|
102 Mem::Copy(&(newPtr->iProperty), &aProperty, sizeof(TSensrvProperty)); |
|
103 iPropertyPtrList.AddLast(*newPtr); |
|
104 } |
|
105 else |
|
106 { |
|
107 ERROR_TRACE( ( _L( "Sensor Server - CCSensrvPropertyQueue::Append - ERROR: No memory to add item" ) ) ); |
|
108 err = KErrNoMemory; |
|
109 } |
|
110 |
|
111 COMPONENT_TRACE( ( _L( "Sensor Server - CSensrvPropertyQueue::Append - return %d" ), err ) ); |
|
112 |
|
113 return err; |
|
114 } |
|
115 |
|
116 // --------------------------------------------------------------------------- |
|
117 // Gets the first property |
|
118 // --------------------------------------------------------------------------- |
|
119 // |
|
120 TSensrvProperty* CSensrvPropertyQueue::First() |
|
121 { |
|
122 COMPONENT_TRACE( ( _L( "Sensor Server - CSensrvPropertyQueue::First()" ) ) ); |
|
123 |
|
124 TSensrvProperty* property = NULL; |
|
125 if (!iPropertyPtrList.IsEmpty()) |
|
126 { |
|
127 TLinkablePropertyPtr* ptr = iPropertyPtrList.First(); |
|
128 |
|
129 if( ptr ) |
|
130 { |
|
131 property = &(ptr->iProperty); |
|
132 } |
|
133 } |
|
134 |
|
135 COMPONENT_TRACE( ( _L( "Sensor Server - CSensrvPropertyQueue::First - return %d" ), property ) ); |
|
136 |
|
137 return property; |
|
138 } |
|
139 |
|
140 // --------------------------------------------------------------------------- |
|
141 // Remove the first property |
|
142 // --------------------------------------------------------------------------- |
|
143 // |
|
144 void CSensrvPropertyQueue::RemoveFirst() |
|
145 { |
|
146 COMPONENT_TRACE( ( _L( "Sensor Server - CSensrvPropertyQueue::RemoveFirst()" ) ) ); |
|
147 |
|
148 if (!iPropertyPtrList.IsEmpty()) |
|
149 { |
|
150 TLinkablePropertyPtr* ptr = iPropertyPtrList.First(); |
|
151 |
|
152 if( ptr ) |
|
153 { |
|
154 iPropertyPtrList.Remove(*ptr); |
|
155 |
|
156 // Pointers are allocated directly on heap, so free them directly also just to be on safe side. |
|
157 if (iHeap) |
|
158 { |
|
159 iHeap->Free(ptr); |
|
160 ptr = NULL; |
|
161 } |
|
162 } |
|
163 } |
|
164 |
|
165 COMPONENT_TRACE( ( _L( "Sensor Server - CSensrvPropertyQueue::RemoveFirst - return" ) ) ); |
|
166 } |
|
167 |
|
168 // --------------------------------------------------------------------------- |
|
169 // Remove all properties from queue |
|
170 // --------------------------------------------------------------------------- |
|
171 // |
|
172 void CSensrvPropertyQueue::RemoveAll() |
|
173 { |
|
174 COMPONENT_TRACE( ( _L( "Sensor Server - CSensrvPropertyQueue::RemoveAll()" ) ) ); |
|
175 |
|
176 if (!iPropertyPtrList.IsEmpty()) |
|
177 { |
|
178 TLinkablePropertyPtr* ptr = NULL; |
|
179 iPropertyPtrIter.SetToFirst(); |
|
180 |
|
181 while ((ptr = iPropertyPtrIter++) != NULL) |
|
182 { |
|
183 iPropertyPtrList.Remove(*ptr); |
|
184 iHeap->Free(ptr); |
|
185 ptr = NULL; |
|
186 }; |
|
187 } |
|
188 |
|
189 iPropertyPtrList.Reset(); |
|
190 } |
|
191 |
|
192 |
|
193 |