|
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: This is the implementation of application class |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 #include "hiddescriptorlist.h" |
|
20 #include "hiddescriptor.h" |
|
21 #include "bthidserver.pan" |
|
22 |
|
23 const TInt KArrayGranularity = 2; |
|
24 |
|
25 CHidDescriptorList::CHidDescriptorList() |
|
26 { |
|
27 } |
|
28 |
|
29 CHidDescriptorList::~CHidDescriptorList() |
|
30 { |
|
31 if (iDescriptorList) |
|
32 { |
|
33 // Clean up. |
|
34 iDescriptorList->ResetAndDestroy(); |
|
35 delete iDescriptorList; |
|
36 } |
|
37 } |
|
38 |
|
39 TInt CHidDescriptorList::DescriptorCount() const |
|
40 { |
|
41 if (iDescriptorList) |
|
42 { |
|
43 return iDescriptorList->Count(); |
|
44 } |
|
45 else |
|
46 { |
|
47 return 0; |
|
48 } |
|
49 } |
|
50 |
|
51 const CHidDescriptor& CHidDescriptorList::operator[](TInt aIndex) const |
|
52 { |
|
53 __ASSERT_ALWAYS(iDescriptorList && |
|
54 0 <= aIndex && aIndex < iDescriptorList->Count(), |
|
55 User::Panic(KBTHIDServer, EBadRequest)); |
|
56 |
|
57 return (*iDescriptorList->At(aIndex)); |
|
58 } |
|
59 |
|
60 void CHidDescriptorList::AddDescriptorL(const CHidDescriptor* aDesc) |
|
61 { |
|
62 if (iDescriptorList) |
|
63 { |
|
64 iDescriptorList->AppendL(aDesc); |
|
65 } |
|
66 else |
|
67 { |
|
68 iDescriptorList = new (ELeave) CArrayPtrFlat<const CHidDescriptor> ( |
|
69 KArrayGranularity); |
|
70 iDescriptorList->AppendL(aDesc); |
|
71 } |
|
72 } |
|
73 |
|
74 TInt CHidDescriptorList::DiskSize() const |
|
75 { |
|
76 // We always write out the number of descriptors which is an int. |
|
77 TInt size = 4; |
|
78 |
|
79 // Add on the size of all descriptors |
|
80 if (iDescriptorList) |
|
81 { |
|
82 TInt count = iDescriptorList->Count(); |
|
83 |
|
84 for (TInt i = 0; i < count; i++) |
|
85 { |
|
86 const CHidDescriptor* tmp = ((*iDescriptorList)[i]); |
|
87 size += tmp->DiskSize(); |
|
88 } |
|
89 } |
|
90 |
|
91 return size; |
|
92 } |
|
93 |
|
94 void CHidDescriptorList::ExternalizeL(RWriteStream& aStream) const |
|
95 { |
|
96 // NOTE!! When changing this function, also check DiskSize |
|
97 |
|
98 if (iDescriptorList) |
|
99 { |
|
100 TInt count = iDescriptorList->Count(); |
|
101 |
|
102 aStream.WriteInt32L(count); |
|
103 for (TInt i = 0; i < count; i++) |
|
104 { |
|
105 const CHidDescriptor* tmp = ((*iDescriptorList)[i]); |
|
106 aStream << *tmp; |
|
107 } |
|
108 } |
|
109 else |
|
110 { |
|
111 aStream.WriteInt32L(0); |
|
112 } |
|
113 } |
|
114 |
|
115 void CHidDescriptorList::InternalizeL(RReadStream& aStream) |
|
116 { |
|
117 // Read in the number of descriptors |
|
118 TInt count = aStream.ReadInt32L(); |
|
119 |
|
120 if (count > 0) |
|
121 { |
|
122 // Create the array to hold the CHidDescriptor. |
|
123 iDescriptorList = new (ELeave) CArrayPtrFlat<const CHidDescriptor> ( |
|
124 KArrayGranularity); |
|
125 |
|
126 // Load each descriptor in and add it to the list |
|
127 for (TInt i = 0; i < count; i++) |
|
128 { |
|
129 CHidDescriptor *temp = CHidDescriptor::NewLC(aStream); |
|
130 iDescriptorList->AppendL(temp); |
|
131 CleanupStack::Pop(); // temp |
|
132 } |
|
133 } |
|
134 } |
|
135 |