|
1 /* |
|
2 * Copyright (c) 2005-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 * Implementation of Test structured data class for sharing between process |
|
16 * Initialises the member variable with zero |
|
17 * |
|
18 */ |
|
19 |
|
20 |
|
21 |
|
22 /** |
|
23 @file TestSharedData.cpp |
|
24 */ |
|
25 void CTestSharedData::Construct() |
|
26 { |
|
27 // Initialise the data member |
|
28 for (TInt index = 0; index < KMaxSharedDataLength; index++) |
|
29 { |
|
30 iText[index] = 0; |
|
31 } |
|
32 } |
|
33 |
|
34 /** |
|
35 * Copies the data input to the shared TText member for sharing |
|
36 * @param aVal - Descriptor containing the string to be set to the member data |
|
37 */ |
|
38 void CTestSharedData::SetText(TDesC& aVal) |
|
39 { |
|
40 TInt length = aVal.Length(); |
|
41 if (length < KMaxSharedDataLength) |
|
42 { |
|
43 for (TInt index = 0; index < length; index++) |
|
44 { |
|
45 iText[index] = *(aVal.Mid(index,1).Ptr()); |
|
46 } |
|
47 for (TInt nullIndex = length; nullIndex < KMaxSharedDataLength; nullIndex++) |
|
48 { |
|
49 iText[nullIndex] = 0; |
|
50 } |
|
51 } |
|
52 else |
|
53 { |
|
54 User::Panic(_L("OutOfMemory"), KErrNoMemory); |
|
55 } |
|
56 } |
|
57 |
|
58 /** |
|
59 * Appends the data input to the shared TText for sharing |
|
60 * @param aVal - Descriptor containing the string to be appended to the member data |
|
61 */ |
|
62 void CTestSharedData::AppendText(TDesC& aVal) |
|
63 { |
|
64 TInt appendLength = aVal.Length(); |
|
65 TInt originalLength = User::StringLength(iText);; |
|
66 TInt length = originalLength + appendLength; |
|
67 if (length < KMaxSharedDataLength) |
|
68 { |
|
69 TInt midLocation = 0; |
|
70 for (TInt index = originalLength; index < length; index++) |
|
71 { |
|
72 iText[index] = *(aVal.Mid(midLocation,1).Ptr()); |
|
73 midLocation++; |
|
74 } |
|
75 for (TInt nullIndex = length; nullIndex < KMaxSharedDataLength; nullIndex++) |
|
76 { |
|
77 iText[nullIndex] = 0; |
|
78 } |
|
79 } |
|
80 else |
|
81 { |
|
82 User::Panic(_L("OutOfMemory"), KErrNoMemory); |
|
83 } |
|
84 } |
|
85 |
|
86 /** |
|
87 * Copies the value within member data to the descriptor reference passed in |
|
88 * @param aVal - Reference Descriptor which gets set with member data value |
|
89 */ |
|
90 void CTestSharedData::GetText(TDes& aVal) |
|
91 { |
|
92 TInt length = User::StringLength(iText); |
|
93 TInt bufferLength = aVal.MaxLength(); |
|
94 if (bufferLength < length) |
|
95 { |
|
96 User::Panic(_L("OutOfMemory"), KErrNoMemory); |
|
97 } |
|
98 |
|
99 aVal.Zero(); |
|
100 for (TInt index = 0; index < length; index++) |
|
101 { |
|
102 aVal.Append(iText[index]); |
|
103 } |
|
104 } |