|
1 // Copyright (c) 2005-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 @internalTechnology |
|
19 */ |
|
20 |
|
21 #include "ItfInfoConfigExt.h" |
|
22 #include <comms-infras/metatype.h> |
|
23 |
|
24 using namespace Meta; |
|
25 |
|
26 START_ATTRIBUTE_TABLE(TItfInfoConfigExt, KIpProtoConfigExtUid, EItfInfoConfigExt) |
|
27 // No attributes registered as no serialisation takes place. |
|
28 END_ATTRIBUTE_TABLE() |
|
29 |
|
30 START_ATTRIBUTE_TABLE(XInterfaceNames, KIpProtoConfigExtUid, EInterfaceName) |
|
31 // No attributes registered as no serialisation takes place. |
|
32 END_ATTRIBUTE_TABLE() |
|
33 |
|
34 const TUint KMaxInterfaceNames = 10; |
|
35 |
|
36 XInterfaceNames* XInterfaceNames::NewL() |
|
37 { |
|
38 XInterfaceNames* self = new(ELeave) XInterfaceNames(); |
|
39 |
|
40 CleanupStack::PushL(self); |
|
41 self->ConstructL(); |
|
42 CleanupStack::Pop(self); |
|
43 |
|
44 return self; |
|
45 } |
|
46 |
|
47 void XInterfaceNames::ConstructL() |
|
48 { |
|
49 iInterfaceNames.ReserveL(KMaxInterfaceNames); |
|
50 User::LeaveIfError(iLock.CreateLocal()); |
|
51 } |
|
52 |
|
53 XInterfaceNames::~XInterfaceNames() |
|
54 { |
|
55 iInterfaceNames.Close(); |
|
56 iLock.Close(); |
|
57 } |
|
58 |
|
59 /** |
|
60 Retrieves an interface name from the store. |
|
61 |
|
62 @param aIndex The index of the interface name to retrieve. |
|
63 @param aInterfaceName The buffer to be populated with the name of the interface. |
|
64 */ |
|
65 TInt XInterfaceNames::InterfaceName(TUint aIndex, TInterfaceName& aInterfaceName) |
|
66 { |
|
67 iLock.Wait(); |
|
68 { |
|
69 if(aIndex >= iInterfaceNames.Count() || aIndex >= KMaxInterfaceNames) |
|
70 { |
|
71 iLock.Signal(); |
|
72 return KErrArgument; |
|
73 } |
|
74 aInterfaceName = iInterfaceNames[aIndex].iName; |
|
75 } |
|
76 iLock.Signal(); |
|
77 |
|
78 return KErrNone; |
|
79 } |
|
80 |
|
81 /** |
|
82 Adds an interface name to the store. |
|
83 |
|
84 @param aInterfaceName The name of the interface. |
|
85 @leave A system-wide error code if the interface name could not be stored. |
|
86 */ |
|
87 void XInterfaceNames::AddInterfaceNameL(const TAny* aOwner, const TInterfaceName& aInterfaceName) |
|
88 { |
|
89 TInt ret = KErrNone; |
|
90 |
|
91 iLock.Wait(); |
|
92 { |
|
93 if(iInterfaceNames.Count() >= KMaxInterfaceNames) |
|
94 { |
|
95 iLock.Signal(); |
|
96 User::Leave(KErrOverflow); |
|
97 } |
|
98 |
|
99 ret = iInterfaceNames.Append(TNameAndOwner(aOwner, aInterfaceName)); |
|
100 } |
|
101 iLock.Signal(); |
|
102 |
|
103 User::LeaveIfError(ret); |
|
104 } |
|
105 |
|
106 /** |
|
107 Removes all interfacesName entries matching the supplied owner. |
|
108 |
|
109 @param aOwner The owner of the entry |
|
110 */ |
|
111 void XInterfaceNames::RemoveInterfaceName(const TAny* aOwner) |
|
112 { |
|
113 iLock.Wait(); |
|
114 { |
|
115 for(TUint i=0;i<iInterfaceNames.Count();i++) |
|
116 { |
|
117 if(iInterfaceNames[i].iOwner == aOwner) |
|
118 { |
|
119 iInterfaceNames.Remove(i); |
|
120 } |
|
121 } |
|
122 } |
|
123 iLock.Signal(); |
|
124 } |