|
1 /* |
|
2 * Copyright (c) 2009 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: |
|
15 * |
|
16 */ |
|
17 |
|
18 #include "e32property.h" |
|
19 #include <e32cmn.h> |
|
20 |
|
21 static RArray<TUint> iIntProperty; |
|
22 static TInt iErrorCode = KErrNone; |
|
23 static RProperty::TPropertyCalledFunctions iCalledFunction = RProperty::ENone; |
|
24 static TName iString = KNullDesC(); |
|
25 static TInt iValue = KErrNotFound; |
|
26 |
|
27 |
|
28 _LIT( KMusTestPropertyReadDesc, "TEST" ); |
|
29 |
|
30 // Function definitions |
|
31 |
|
32 TInt RProperty::Define( TUid /*aCategory*/, TUint /*aKey*/, TInt /*aAttr*/,TInt /*aPreallocate=0*/ ) |
|
33 { |
|
34 iCalledFunction = RProperty::EDefine; |
|
35 return iErrorCode; |
|
36 } |
|
37 |
|
38 TInt RProperty::Delete( TUid /*aCategory*/, TUint aKey) |
|
39 { |
|
40 for(TInt i=0;i<iIntProperty.Count();i=i+2) |
|
41 { |
|
42 if( aKey == iIntProperty[i] ) |
|
43 { |
|
44 iIntProperty.Remove( i ); |
|
45 iIntProperty.Remove( i ); |
|
46 return KErrNone; |
|
47 } |
|
48 } |
|
49 |
|
50 return iErrorCode; |
|
51 } |
|
52 |
|
53 |
|
54 TInt RProperty::Get( TUid /*aCategory*/, TUint aKey, TInt& aVal) |
|
55 { |
|
56 if ( !iErrorCode ) |
|
57 { |
|
58 // if errorcode not set , then try to get value from array. |
|
59 TInt error = Get(aKey,aVal); |
|
60 if ( error != KErrNone ) |
|
61 { |
|
62 aVal = iValue; |
|
63 error = iValue == KErrNotFound ? error : KErrNone; |
|
64 } |
|
65 return error; |
|
66 } |
|
67 else |
|
68 { |
|
69 // if error code is set value doesnt matter. |
|
70 return iErrorCode; |
|
71 } |
|
72 } |
|
73 |
|
74 TInt RProperty::Get( TInt& aValue) |
|
75 { |
|
76 TInt error = iErrorCode; |
|
77 aValue = iPValue; |
|
78 return error; |
|
79 } |
|
80 |
|
81 TInt RProperty::Get( TUid /*aCategory*/, TUint /*aKey*/, TDes8& aValue) |
|
82 { |
|
83 // This is not widely used in Mush , so who cares in stub. |
|
84 aValue.Append( KMusTestPropertyReadDesc ); |
|
85 return iErrorCode; |
|
86 } |
|
87 |
|
88 TInt RProperty::Get( TUid /*aCategory*/, TUint /*aKey*/, TDes16& aValue ) |
|
89 { |
|
90 // This is not widely used in Mush , so who cares in stub. |
|
91 aValue = iString; |
|
92 return iErrorCode; |
|
93 } |
|
94 |
|
95 TInt RProperty::Set( TUid /*aCategory*/, TUint aKey, TInt aValue) |
|
96 { |
|
97 for(TInt i=0;i<iIntProperty.Count();i=i+2) |
|
98 { |
|
99 if( aKey == iIntProperty[i] ) |
|
100 { |
|
101 iIntProperty[i+1] = aValue; |
|
102 return KErrNone; |
|
103 } |
|
104 } |
|
105 |
|
106 TInt error = KErrNone; |
|
107 error = iIntProperty.Append(aKey); |
|
108 if (!error) |
|
109 { |
|
110 error = iIntProperty.Append(aValue); |
|
111 } |
|
112 return iErrorCode ? iErrorCode : error; |
|
113 } |
|
114 |
|
115 TInt RProperty::Set( TUid /*aCategory*/, TUint /*aKey*/, const TDesC8& /*aValue*/) |
|
116 { |
|
117 // This is not widely used in Mush , so who cares in stub. |
|
118 return iErrorCode; |
|
119 } |
|
120 |
|
121 TInt RProperty::Set( TUid /*aCategory*/, TUint /*aKey*/, const TDesC& aValue ) |
|
122 { |
|
123 // This is not widely used in Mush , so who cares in stub. |
|
124 iString = aValue; |
|
125 return iErrorCode; |
|
126 } |
|
127 |
|
128 |
|
129 TInt RProperty::Attach( TUid /*aCategory*/, TUint /*aKey*/) |
|
130 { |
|
131 return iErrorCode; |
|
132 } |
|
133 |
|
134 |
|
135 void RProperty::Cancel() |
|
136 { |
|
137 iCalledFunction = RProperty::ECancel; |
|
138 if ( iRequestStatus ) |
|
139 { |
|
140 User::RequestComplete( iRequestStatus, KErrCancel ); |
|
141 } |
|
142 iRequestStatus = NULL; |
|
143 } |
|
144 |
|
145 TInt RProperty::Set(TInt aValue) // Non-Static |
|
146 { |
|
147 iPValue = aValue; |
|
148 return iErrorCode; |
|
149 } |
|
150 |
|
151 |
|
152 void RProperty::Subscribe(TRequestStatus& aRequest) |
|
153 { |
|
154 aRequest = KRequestPending; |
|
155 iRequestStatus = &aRequest; |
|
156 |
|
157 } |
|
158 |
|
159 TInt RProperty::Get(TUint& aKey,TInt& aVal) |
|
160 { |
|
161 for(TInt i=0;i<iIntProperty.Count();i=i+2) |
|
162 { |
|
163 if( aKey == iIntProperty[i] ) |
|
164 { |
|
165 aVal = iIntProperty[i+1]; |
|
166 return KErrNone; |
|
167 } |
|
168 } |
|
169 return KErrNotFound; |
|
170 } |
|
171 |
|
172 /* |
|
173 * Stub helper function to set error codes |
|
174 */ |
|
175 void PropertyHelper::SetErrorCode(TInt aVal) |
|
176 { |
|
177 iErrorCode = aVal; |
|
178 } |
|
179 |
|
180 RProperty::TPropertyCalledFunctions PropertyHelper::GetCalledFunction() |
|
181 { |
|
182 return iCalledFunction; |
|
183 } |
|
184 |
|
185 void RProperty::Close() |
|
186 { |
|
187 Cancel(); |
|
188 } |
|
189 |
|
190 void PropertyHelper::Close() |
|
191 { |
|
192 iIntProperty.Close(); |
|
193 iErrorCode = KErrNone; |
|
194 iCalledFunction = RProperty::ENone; |
|
195 iString = KNullDesC(); |
|
196 iValue = KErrNotFound; |
|
197 } |
|
198 |
|
199 |