|
1 /* |
|
2 * Copyright (c) 2005 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: ?Description |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 |
|
20 // INCLUDE FILES |
|
21 #include "CAMMSTunerPresetsHandler.h" |
|
22 #include "TAMMSTunerPreset.h" |
|
23 |
|
24 #include <FMRadioEngineCRKeys.h> |
|
25 #include <s32mem.h> |
|
26 #include <jdebug.h> |
|
27 |
|
28 |
|
29 // CONSTANTS |
|
30 |
|
31 |
|
32 // ============================ MEMBER FUNCTIONS =============================== |
|
33 |
|
34 // ----------------------------------------------------------------------------- |
|
35 // CAMMSTunerPresetsHandler::CAMMSTunerPresetsHandler |
|
36 // C++ default constructor can NOT contain any code, that |
|
37 // might leave. |
|
38 // ----------------------------------------------------------------------------- |
|
39 // |
|
40 CAMMSTunerPresetsHandler::CAMMSTunerPresetsHandler() |
|
41 { |
|
42 } |
|
43 |
|
44 // ----------------------------------------------------------------------------- |
|
45 // CAMMSTunerPresetsHandler::ConstructL |
|
46 // Symbian 2nd phase constructor can leave. |
|
47 // ----------------------------------------------------------------------------- |
|
48 // |
|
49 void CAMMSTunerPresetsHandler::ConstructL() |
|
50 { |
|
51 iCentralRepository = CRepository::NewL(KCRUidFMRadioEngine); |
|
52 } |
|
53 |
|
54 // ----------------------------------------------------------------------------- |
|
55 // CAMMSTunerPresetsHandler::NewL |
|
56 // Two-phased constructor. |
|
57 // ----------------------------------------------------------------------------- |
|
58 // |
|
59 CAMMSTunerPresetsHandler* CAMMSTunerPresetsHandler::NewL() |
|
60 { |
|
61 CAMMSTunerPresetsHandler* self = new(ELeave) CAMMSTunerPresetsHandler; |
|
62 |
|
63 CleanupStack::PushL(self); |
|
64 self->ConstructL(); |
|
65 CleanupStack::Pop(); |
|
66 |
|
67 return self; |
|
68 } |
|
69 |
|
70 |
|
71 // Destructor |
|
72 CAMMSTunerPresetsHandler::~CAMMSTunerPresetsHandler() |
|
73 { |
|
74 delete iCentralRepository; |
|
75 } |
|
76 |
|
77 |
|
78 // ----------------------------------------------------------------------------- |
|
79 // CAMMSTunerPresetsHandler::GetPreset |
|
80 // ?implementation_description |
|
81 // (other items were commented in a header). |
|
82 // ----------------------------------------------------------------------------- |
|
83 // |
|
84 void CAMMSTunerPresetsHandler::GetPresetL(TInt aPreset, TAMMSTunerPreset &aTunerPreset) |
|
85 { |
|
86 // KFmRadioPresetChannel1 = The first preset channel's location in central repository |
|
87 TInt tempChannelIndex = KFmRadioPresetChannel1 + aPreset; |
|
88 |
|
89 HBufC8* buf = HBufC8::NewLC(sizeof(TAMMSTunerPreset)); |
|
90 TPtr8 bufPtr = buf->Des(); |
|
91 |
|
92 TInt err = iCentralRepository->Get(tempChannelIndex, bufPtr); |
|
93 if (err == KErrNone) |
|
94 { |
|
95 RDesReadStream inStream; |
|
96 inStream.Open(bufPtr); |
|
97 CleanupClosePushL(inStream); |
|
98 aTunerPreset.InternalizeL(inStream); |
|
99 CleanupStack::PopAndDestroy(&inStream); |
|
100 } |
|
101 else |
|
102 { |
|
103 User::Leave(err); |
|
104 } |
|
105 CleanupStack::PopAndDestroy(); // buf |
|
106 } |
|
107 |
|
108 // ----------------------------------------------------------------------------- |
|
109 // CAMMSTunerPresetsHandler::SavePreset |
|
110 // ?implementation_description |
|
111 // (other items were commented in a header). |
|
112 // ----------------------------------------------------------------------------- |
|
113 // |
|
114 void CAMMSTunerPresetsHandler::SavePresetL(TInt aPreset, TAMMSTunerPreset aTunerPreset) |
|
115 { |
|
116 // KFmRadioPresetChannel1 = The first preset channel's location in central repository |
|
117 TInt fieldNameIndex = KFmRadioPresetChannel1 + TUint32(aPreset); |
|
118 |
|
119 HBufC8* buf = HBufC8::NewLC(sizeof(TAMMSTunerPreset)); |
|
120 TPtr8 bufPtr = buf->Des(); |
|
121 |
|
122 RDesWriteStream outStream(bufPtr); |
|
123 CleanupClosePushL(outStream); |
|
124 aTunerPreset.ExternalizeL(outStream); |
|
125 outStream.CommitL(); |
|
126 CleanupStack::PopAndDestroy(&outStream); |
|
127 |
|
128 iCentralRepository->Set(fieldNameIndex, bufPtr); |
|
129 CleanupStack::PopAndDestroy(); //buf |
|
130 } |
|
131 |
|
132 |
|
133 // End of File |