Symbian3/Examples/guid-6013a680-57f9-415b-8851-c4fa63356636/centrepexample_8cpp-source.html
week 10 bug fix submission: Bug 1892, Bug 1897, Bug 1319. Also 3 or 4 documents were found to contain code blocks with SFL, which has been fixed. Partial fix for broken links, links to Forum Nokia, and the 'Symbian platform' terminology issues.
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html><head><meta http-equiv="Content-Type" content="text/html;charset=UTF-8">
<title>TB10.1 Example Applications: examples/SysLibs/CentRepExample/centrepexample.cpp Source File</title>
<link href="doxygen.css" rel="stylesheet" type="text/css">
<link href="tabs.css" rel="stylesheet" type="text/css">
</head><body>
<!-- Generated by Doxygen 1.5.3 -->
<h1>examples/SysLibs/CentRepExample/centrepexample.cpp</h1><a href="centrepexample_8cpp.html">Go to the documentation of this file.</a><div class="fragment"><pre class="fragment"><a name="l00001"></a>00001 <span class="comment">// Copyright (c) 2006-2009 Nokia Corporation and/or its subsidiary(-ies).</span>
<a name="l00002"></a>00002 <span class="comment">// All rights reserved.</span>
<a name="l00003"></a>00003 <span class="comment">// This component and the accompanying materials are made available</span>
<a name="l00004"></a>00004 <span class="comment">// under the terms of "Eclipse Public License v1.0"</span>
<a name="l00005"></a>00005 <span class="comment">// which accompanies this distribution, and is available</span>
<a name="l00006"></a>00006 <span class="comment">// at the URL "http://www.eclipse.org/legal/epl-v10.html".</span>
<a name="l00007"></a>00007 <span class="comment">//</span>
<a name="l00008"></a>00008 <span class="comment">// Initial Contributors:</span>
<a name="l00009"></a>00009 <span class="comment">// Nokia Corporation - initial contribution.</span>
<a name="l00010"></a>00010 <span class="comment">//</span>
<a name="l00011"></a>00011 <span class="comment">// Contributors:</span>
<a name="l00012"></a>00012 <span class="comment">//</span>
<a name="l00013"></a>00013 <span class="comment">// Description:</span>
<a name="l00014"></a>00014 <span class="comment">// This example program demonstrates the use of the Central Repository. </span>
<a name="l00015"></a>00015 <span class="comment">// The code demonstrates how to open this repository, read its settings, </span>
<a name="l00016"></a>00016 <span class="comment">// change them, perform read-write operations in a transaction, </span>
<a name="l00017"></a>00017 <span class="comment">// find settings, restore default settings, request change notifications </span>
<a name="l00018"></a>00018 <span class="comment">// and delete settings.</span>
<a name="l00019"></a>00019 <span class="comment">// The program requires that before it is run a data file representing</span>
<a name="l00020"></a>00020 <span class="comment">// a repository is present in the private\10202be9 directory on the</span>
<a name="l00021"></a>00021 <span class="comment">// emulator.</span>
<a name="l00022"></a>00022 <span class="comment">// The example defines an example repository in the E80000AD.txt file.</span>
<a name="l00023"></a>00023 <span class="comment">// This text file can be installed directly, but it is recommended</span>
<a name="l00024"></a>00024 <span class="comment">// that repository files are first converted to binary format using the </span>
<a name="l00025"></a>00025 <span class="comment">// CentRepConv tool.</span>
<a name="l00026"></a>00026 <span class="comment">// To do this: </span>
<a name="l00027"></a>00027 <span class="comment">// - Copy E80000AD.txt file to the epoc32\winscw\c location on your kit.</span>
<a name="l00028"></a>00028 <span class="comment">// - Start a command line prompt, cd to epoc32\RELEASE\WINSCW\UDEB, and run the</span>
<a name="l00029"></a>00029 <span class="comment">// command CentRepConv C:\E80000AD.txt </span>
<a name="l00030"></a>00030 <span class="comment">// - This then displays that the file has been converted to the new binary file </span>
<a name="l00031"></a>00031 <span class="comment">// E80000AD.cre. </span>
<a name="l00032"></a>00032 <span class="comment">// - Copy this file to the epoc32\RELEASE\WINSCW\UDEB\Z\private\10202be9</span>
<a name="l00033"></a>00033 <span class="comment">// directory on your kit.</span>
<a name="l00034"></a>00034 <span class="comment">//</span>
<a name="l00035"></a>00035
<a name="l00036"></a>00036
<a name="l00037"></a>00037
<a name="l00041"></a>00041 <span class="preprocessor">#include "<a class="code" href="centrepexample_8h.html">centrepexample.h</a>"</span>
<a name="l00042"></a>00042 <span class="preprocessor">#include <e32cons.h></span>
<a name="l00043"></a>00043 <span class="preprocessor">#include "<a class="code" href="_sys_libs_2_cent_rep_example_2asyncwaiter_8h.html">asyncwaiter.h</a>"</span>
<a name="l00044"></a>00044
<a name="l00045"></a>00045 _LIT(KTitle, <span class="stringliteral">"Central repository example"</span>);
<a name="l00046"></a>00046 _LIT(KTextPressAKey, <span class="stringliteral">"\n\nPress any key to step through the example"</span>);
<a name="l00047"></a>00047 _LIT(KExit,<span class="stringliteral">"\nPress any key to exit the application "</span>);
<a name="l00048"></a>00048 _LIT(KPressAKey,<span class="stringliteral">"\nPress any key to continue \n"</span>);
<a name="l00049"></a>00049 _LIT(KErr,<span class="stringliteral">"\nThe repository file has not been set up. Please see the instructions in centrepexample.cpp for how to do this"</span>);
<a name="l00050"></a>00050
<a name="l00051"></a>00051 _LIT(KOpen,<span class="stringliteral">"\n\nOpening the repository and displaying some initial settings"</span>);
<a name="l00052"></a>00052 _LIT(KChangeSet,<span class="stringliteral">"\nChanging some settings in the repository"</span>);
<a name="l00053"></a>00053 _LIT(KReadSet,<span class="stringliteral">"\nReading the changed settings"</span>);
<a name="l00054"></a>00054 _LIT(KTransact,<span class="stringliteral">"\n\nPerforming read and write transactions"</span>);
<a name="l00055"></a>00055 _LIT(KDelete,<span class="stringliteral">"\n\nCreating integer and real number settings and deleting them"</span>);
<a name="l00056"></a>00056 _LIT(KMove,<span class="stringliteral">"\n\nMoving the key to target position"</span>);
<a name="l00057"></a>00057 _LIT(KReset,<span class="stringliteral">"\nResetting settings to default values, and getting notifications that the changes have occurred"</span>);
<a name="l00058"></a>00058 _LIT(KFind,<span class="stringliteral">"\nFinding settings for simple and structured data"</span>);
<a name="l00059"></a>00059 _LIT(KNonExisting,<span class="stringliteral">"\n\nValue of new setting is %d"</span>);
<a name="l00060"></a>00060 _LIT(KInt,<span class="stringliteral">"\nValue of setting with key x01 is %d"</span>);
<a name="l00061"></a>00061 _LIT(KReal,<span class="stringliteral">"\nValue of setting with key x02 is %f"</span>);
<a name="l00062"></a>00062 _LIT(KInteg,<span class="stringliteral">"\nValue of setting with key x06 is %d \n"</span>);
<a name="l00063"></a>00063 _LIT(KIntBefore,<span class="stringliteral">"\nValue of setting with key x01 before reset is %d"</span>);
<a name="l00064"></a>00064 _LIT(KIntAfter,<span class="stringliteral">"\nValue of setting with key x01 after reset is %d"</span>);
<a name="l00065"></a>00065 _LIT(KIdsFound,<span class="stringliteral">"\nFound %d settings"</span>);
<a name="l00066"></a>00066 _LIT(KStringName,<span class="stringliteral">"Another string"</span>);
<a name="l00067"></a>00067 _LIT(KString1_UpdatedValue, <span class="stringliteral">"Value of setting with key x05 is %s"</span>);
<a name="l00068"></a>00068
<a name="l00069"></a>00069 <span class="keyword">static</span> <span class="keyword">const</span> TUid KUidRepository = { 0xE80000AD };
<a name="l00070"></a><a class="code" href="centrepexample_8cpp.html#841be22d434bc6f5e7cde00b629124ba">00070</a> <span class="keyword">const</span> TUint32 <a class="code" href="centrepexample_8cpp.html#841be22d434bc6f5e7cde00b629124ba">KNonExistentSetting</a> = 0x10;
<a name="l00071"></a><a class="code" href="centrepexample_8cpp.html#b51e13a40abcd0929cdb185e3420131b">00071</a> <span class="keyword">const</span> TUint32 <a class="code" href="centrepexample_8cpp.html#b51e13a40abcd0929cdb185e3420131b">KInt1</a> = 0x01;
<a name="l00072"></a><a class="code" href="centrepexample_8cpp.html#8c89e8423be52fd1bc368cf5543196e9">00072</a> <span class="keyword">const</span> TUint32 <a class="code" href="centrepexample_8cpp.html#8c89e8423be52fd1bc368cf5543196e9">KInt3</a> = 0x06;
<a name="l00073"></a><a class="code" href="centrepexample_8cpp.html#b5338c35514ac188dafdba0e9083fa14">00073</a> <span class="keyword">const</span> TUint32 <a class="code" href="centrepexample_8cpp.html#b5338c35514ac188dafdba0e9083fa14">KReal1</a> = 0x02;
<a name="l00074"></a><a class="code" href="centrepexample_8cpp.html#9cac7b725e3b7db4f0996569491a8754">00074</a> <span class="keyword">const</span> TUint32 <a class="code" href="centrepexample_8cpp.html#9cac7b725e3b7db4f0996569491a8754">KString1</a> = 0x05;
<a name="l00075"></a><a class="code" href="centrepexample_8cpp.html#26522c5a6e5b261136ca16173dc58921">00075</a> <span class="keyword">const</span> TInt <a class="code" href="centrepexample_8cpp.html#26522c5a6e5b261136ca16173dc58921">KInt1_InitialValue</a> = 1;
<a name="l00076"></a><a class="code" href="centrepexample_8cpp.html#72c6ed80162c86177f369a50d3015a47">00076</a> <span class="keyword">const</span> TInt <a class="code" href="centrepexample_8cpp.html#72c6ed80162c86177f369a50d3015a47">KInt1_UpdatedValue</a> = 73;
<a name="l00077"></a><a class="code" href="centrepexample_8cpp.html#6283fcdef4584a1fdfc129c9588fccaf">00077</a> <span class="keyword">const</span> TReal <a class="code" href="centrepexample_8cpp.html#6283fcdef4584a1fdfc129c9588fccaf">KReal1_InitialValue</a> = 14.91;
<a name="l00078"></a><a class="code" href="centrepexample_8cpp.html#d2a0ec821823376147d2f52e9668cdf2">00078</a> <span class="keyword">const</span> TReal <a class="code" href="centrepexample_8cpp.html#d2a0ec821823376147d2f52e9668cdf2">KReal1_UpdatedValue</a> = 72.8;
<a name="l00079"></a><a class="code" href="centrepexample_8cpp.html#af75a270116ff145ce1037613fbc2465">00079</a> <span class="keyword">const</span> TUint32 <a class="code" href="centrepexample_8cpp.html#af75a270116ff145ce1037613fbc2465">KMoveTarget</a> = 0x30;
<a name="l00080"></a>00080
<a name="l00086"></a><a class="code" href="class_c_cent_rep_example.html#6761078f15ec4f9085cb01402f8444a2">00086</a> <a class="code" href="class_c_cent_rep_example.html">CCentRepExample</a>* <a class="code" href="class_c_cent_rep_example.html#6761078f15ec4f9085cb01402f8444a2">CCentRepExample::NewLC</a>()
<a name="l00087"></a>00087 {
<a name="l00088"></a>00088 <a class="code" href="class_c_cent_rep_example.html">CCentRepExample</a>* rep = <span class="keyword">new</span>(ELeave) <a class="code" href="class_c_cent_rep_example.html">CCentRepExample</a>();
<a name="l00089"></a>00089 CleanupStack::PushL(rep);
<a name="l00090"></a>00090 rep-><a class="code" href="class_c_cent_rep_example.html#0276f57ca244bbd219f2ad21749c7bcd">ConstructL</a>();
<a name="l00091"></a>00091 <span class="keywordflow">return</span> rep;
<a name="l00092"></a>00092 }
<a name="l00093"></a>00093
<a name="l00097"></a>00097 CCentRepExample::CCentRepExample()
<a name="l00098"></a>00098 {
<a name="l00099"></a>00099 }
<a name="l00100"></a>00100
<a name="l00101"></a>00101 <span class="keywordtype">void</span> CCentRepExample::ConstructL()
<a name="l00102"></a>00102 {
<a name="l00103"></a>00103
<a name="l00104"></a>00104 iConsole = Console::NewL(KTitle,TSize(KConsFullScreen,KConsFullScreen));
<a name="l00105"></a>00105 iConsole->Printf ( KTextPressAKey );
<a name="l00106"></a>00106 iConsole->Getch ();
<a name="l00107"></a>00107 }
<a name="l00108"></a>00108
<a name="l00112"></a><a class="code" href="class_c_cent_rep_example.html#971b2383437b99571ed67451d76c9e58">00112</a> <a class="code" href="class_c_cent_rep_example.html#971b2383437b99571ed67451d76c9e58">CCentRepExample::~CCentRepExample</a>()
<a name="l00113"></a>00113 {
<a name="l00114"></a>00114 iConsole->Printf(KExit);
<a name="l00115"></a>00115 iConsole->Getch();
<a name="l00116"></a>00116
<a name="l00117"></a>00117 <span class="keyword">delete</span> iConsole;
<a name="l00118"></a>00118 <span class="keyword">delete</span> iRepository;
<a name="l00119"></a>00119 }
<a name="l00120"></a>00120
<a name="l00121"></a>00121
<a name="l00128"></a><a class="code" href="class_c_cent_rep_example.html#513576b361a857b6cdc737672179a612">00128</a> <span class="keywordtype">void</span> <a class="code" href="class_c_cent_rep_example.html#513576b361a857b6cdc737672179a612">CCentRepExample::ResetL</a>()
<a name="l00129"></a>00129 {
<a name="l00130"></a>00130 CRepository* repository = NULL;
<a name="l00131"></a>00131 TRAPD(err, repository = CRepository::NewL(KUidRepository););
<a name="l00132"></a>00132 CleanupStack::PushL(repository);
<a name="l00133"></a>00133 <span class="comment">// test if an error has occurred because the repository</span>
<a name="l00134"></a>00134 <span class="comment">// has not been set up: see instructions at the top</span>
<a name="l00135"></a>00135 <span class="comment">// of this file if this occurs.</span>
<a name="l00136"></a>00136 <span class="keywordflow">if</span> (err == KErrNotFound)
<a name="l00137"></a>00137 {
<a name="l00138"></a>00138 iConsole->Printf(KErr);
<a name="l00139"></a>00139 }
<a name="l00140"></a>00140 User::LeaveIfError(err);
<a name="l00141"></a>00141 User::LeaveIfError(err = repository->Reset());
<a name="l00142"></a>00142 CleanupStack::PopAndDestroy(repository);
<a name="l00143"></a>00143 }
<a name="l00144"></a>00144
<a name="l00151"></a><a class="code" href="class_c_cent_rep_example.html#9c9e68c292232731fe5e5608251a05e2">00151</a> <span class="keywordtype">void</span> <a class="code" href="class_c_cent_rep_example.html#9c9e68c292232731fe5e5608251a05e2">CCentRepExample::OpenRepositoryL</a>()
<a name="l00152"></a>00152 {
<a name="l00153"></a>00153 TInt i, k;
<a name="l00154"></a>00154 TReal j;
<a name="l00155"></a>00155 TBuf<50> tooShort;
<a name="l00156"></a>00156 iConsole->Printf(KOpen);
<a name="l00157"></a>00157 iRepository = CRepository::NewL(KUidRepository);
<a name="l00158"></a>00158
<a name="l00159"></a>00159 User::LeaveIfError(iRepository->Get(<a class="code" href="centrepexample_8cpp.html#b51e13a40abcd0929cdb185e3420131b">KInt1</a>, i));
<a name="l00160"></a>00160 iConsole->Printf(KInt,i);
<a name="l00161"></a>00161
<a name="l00162"></a>00162 User::LeaveIfError(iRepository->Get(<a class="code" href="centrepexample_8cpp.html#b5338c35514ac188dafdba0e9083fa14">KReal1</a>, j));
<a name="l00163"></a>00163 iConsole->Printf(KReal,j);
<a name="l00164"></a>00164
<a name="l00165"></a>00165 User::LeaveIfError(iRepository->Get(<a class="code" href="centrepexample_8cpp.html#8c89e8423be52fd1bc368cf5543196e9">KInt3</a>, k));
<a name="l00166"></a>00166 iConsole->Printf(KInteg,k);
<a name="l00167"></a>00167
<a name="l00168"></a>00168 User::LeaveIfError(iRepository->Get(<a class="code" href="centrepexample_8cpp.html#9cac7b725e3b7db4f0996569491a8754">KString1</a>, tooShort));
<a name="l00169"></a>00169 iConsole->Printf(KString1_UpdatedValue,tooShort.PtrZ());
<a name="l00170"></a>00170
<a name="l00171"></a>00171 iConsole->Printf(KPressAKey);
<a name="l00172"></a>00172 iConsole->Getch();
<a name="l00173"></a>00173
<a name="l00174"></a>00174 }
<a name="l00175"></a>00175
<a name="l00181"></a><a class="code" href="class_c_cent_rep_example.html#4e0ebe8e6bff9c146211cca8748d5739">00181</a> <span class="keywordtype">void</span> <a class="code" href="class_c_cent_rep_example.html#4e0ebe8e6bff9c146211cca8748d5739">CCentRepExample::ChangeSettingsL</a>()
<a name="l00182"></a>00182 {
<a name="l00183"></a>00183 iConsole->Printf(KChangeSet);
<a name="l00184"></a>00184 User::LeaveIfError(iRepository->Set(<a class="code" href="centrepexample_8cpp.html#841be22d434bc6f5e7cde00b629124ba">KNonExistentSetting</a>, 10));
<a name="l00185"></a>00185
<a name="l00186"></a>00186 User::LeaveIfError(iRepository->Set(<a class="code" href="centrepexample_8cpp.html#b51e13a40abcd0929cdb185e3420131b">KInt1</a>, <a class="code" href="centrepexample_8cpp.html#72c6ed80162c86177f369a50d3015a47">KInt1_UpdatedValue</a>));
<a name="l00187"></a>00187
<a name="l00188"></a>00188 User::LeaveIfError(iRepository->Set(<a class="code" href="centrepexample_8cpp.html#b5338c35514ac188dafdba0e9083fa14">KReal1</a>, <a class="code" href="centrepexample_8cpp.html#6283fcdef4584a1fdfc129c9588fccaf">KReal1_InitialValue</a>));
<a name="l00189"></a>00189
<a name="l00190"></a>00190 User::LeaveIfError(iRepository->Set(<a class="code" href="centrepexample_8cpp.html#8c89e8423be52fd1bc368cf5543196e9">KInt3</a>, <a class="code" href="centrepexample_8cpp.html#26522c5a6e5b261136ca16173dc58921">KInt1_InitialValue</a>));
<a name="l00191"></a>00191
<a name="l00192"></a>00192 User::LeaveIfError(iRepository->Set(<a class="code" href="centrepexample_8cpp.html#9cac7b725e3b7db4f0996569491a8754">KString1</a>, KStringName));
<a name="l00193"></a>00193
<a name="l00194"></a>00194 }
<a name="l00195"></a>00195
<a name="l00201"></a><a class="code" href="class_c_cent_rep_example.html#b96ba0baa8204931f40a32834f1849f3">00201</a> <span class="keywordtype">void</span> <a class="code" href="class_c_cent_rep_example.html#b96ba0baa8204931f40a32834f1849f3">CCentRepExample::ReadSettingsL</a>()
<a name="l00202"></a>00202 {
<a name="l00203"></a>00203 TInt m, i, k;
<a name="l00204"></a>00204 TReal j;
<a name="l00205"></a>00205 TBuf<50> tooShort;
<a name="l00206"></a>00206 iConsole->Printf(KReadSet);
<a name="l00207"></a>00207
<a name="l00208"></a>00208 User::LeaveIfError(iRepository->Get(<a class="code" href="centrepexample_8cpp.html#841be22d434bc6f5e7cde00b629124ba">KNonExistentSetting</a>, m));
<a name="l00209"></a>00209
<a name="l00210"></a>00210 iConsole->Printf(KNonExisting,m);
<a name="l00211"></a>00211
<a name="l00212"></a>00212 User::LeaveIfError(iRepository->Get(<a class="code" href="centrepexample_8cpp.html#b51e13a40abcd0929cdb185e3420131b">KInt1</a>, i));
<a name="l00213"></a>00213
<a name="l00214"></a>00214 iConsole->Printf(KInt,i);
<a name="l00215"></a>00215
<a name="l00216"></a>00216 User::LeaveIfError(iRepository->Get(<a class="code" href="centrepexample_8cpp.html#b5338c35514ac188dafdba0e9083fa14">KReal1</a>, j));
<a name="l00217"></a>00217
<a name="l00218"></a>00218 iConsole->Printf(KReal,j);
<a name="l00219"></a>00219
<a name="l00220"></a>00220 User::LeaveIfError(iRepository->Get(<a class="code" href="centrepexample_8cpp.html#8c89e8423be52fd1bc368cf5543196e9">KInt3</a>, k));
<a name="l00221"></a>00221
<a name="l00222"></a>00222 iConsole->Printf(KInteg,k);
<a name="l00223"></a>00223
<a name="l00224"></a>00224 User::LeaveIfError(iRepository->Get(<a class="code" href="centrepexample_8cpp.html#9cac7b725e3b7db4f0996569491a8754">KString1</a>, tooShort));
<a name="l00225"></a>00225
<a name="l00226"></a>00226 iConsole->Printf(KString1_UpdatedValue,tooShort.PtrZ());
<a name="l00227"></a>00227
<a name="l00228"></a>00228 iConsole->Printf(KPressAKey);
<a name="l00229"></a>00229 iConsole->Getch();
<a name="l00230"></a>00230
<a name="l00231"></a>00231 }
<a name="l00232"></a>00232
<a name="l00240"></a><a class="code" href="class_c_cent_rep_example.html#4d89eb968ca8b89aff9b363e73a4fa38">00240</a> <span class="keywordtype">void</span> <a class="code" href="class_c_cent_rep_example.html#4d89eb968ca8b89aff9b363e73a4fa38">CCentRepExample::FindSettingsL</a>()
<a name="l00241"></a>00241 {
<a name="l00242"></a>00242 RArray<TUint32> foundIds;
<a name="l00243"></a>00243
<a name="l00244"></a>00244 <span class="comment">// Finds all the settings that exist and match the specification </span>
<a name="l00245"></a>00245 <span class="comment">//given by partialKey and mask. </span>
<a name="l00246"></a>00246 iConsole->Printf(KFind);
<a name="l00247"></a>00247
<a name="l00248"></a>00248 <span class="comment">// These values will instruct Find to return the all settings keys which </span>
<a name="l00249"></a>00249 <span class="comment">//match the pattern 000001XXh where X indicates a ‘don’t care’ state.</span>
<a name="l00250"></a>00250
<a name="l00251"></a>00251 User::LeaveIfError(iRepository->FindL(0x100 <span class="comment">/*partialKey*/</span>, 0xF00<span class="comment">/*mask*/</span>, foundIds));
<a name="l00252"></a>00252
<a name="l00253"></a>00253 iConsole->Printf(KIdsFound,foundIds.Count());
<a name="l00254"></a>00254 foundIds.Reset();
<a name="l00255"></a>00255
<a name="l00256"></a>00256 <span class="comment">// Finds all the settings that contain a given integer and </span>
<a name="l00257"></a>00257 <span class="comment">//match the specification given by partialKey and mask. </span>
<a name="l00258"></a>00258
<a name="l00259"></a>00259 User::LeaveIfError(iRepository->FindEqL(0x00<span class="comment">/*partialKey*/</span>, 0x00<span class="comment">/*mask*/</span>,<a class="code" href="centrepexample_8cpp.html#26522c5a6e5b261136ca16173dc58921">KInt1_InitialValue</a> <span class="comment">/*integer value*/</span>, foundIds));
<a name="l00260"></a>00260
<a name="l00261"></a>00261 iConsole->Printf(KIdsFound,foundIds.Count());
<a name="l00262"></a>00262 foundIds.Reset();
<a name="l00263"></a>00263
<a name="l00264"></a>00264 <span class="comment">// Finds all the settings that contain the given floating point value </span>
<a name="l00265"></a>00265 <span class="comment">//and match the specification given by partialKey and mask. </span>
<a name="l00266"></a>00266 User::LeaveIfError(iRepository->FindEqL(0x00, 0x00,<a class="code" href="centrepexample_8cpp.html#6283fcdef4584a1fdfc129c9588fccaf">KReal1_InitialValue</a><span class="comment">/*Real value*/</span>, foundIds));
<a name="l00267"></a>00267
<a name="l00268"></a>00268 iConsole->Printf(KIdsFound,foundIds.Count());
<a name="l00269"></a>00269 foundIds.Reset();
<a name="l00270"></a>00270
<a name="l00271"></a>00271 <span class="comment">// Finds all the settings that contain a given string value </span>
<a name="l00272"></a>00272 <span class="comment">//and match the specification given by partialKey and mask. </span>
<a name="l00273"></a>00273
<a name="l00274"></a>00274 User::LeaveIfError(iRepository->FindEqL(0x00, 0x00, KStringName<span class="comment">/*string*/</span>, foundIds));
<a name="l00275"></a>00275
<a name="l00276"></a>00276 iConsole->Printf(KIdsFound,foundIds.Count());
<a name="l00277"></a>00277 foundIds.Reset();
<a name="l00278"></a>00278
<a name="l00279"></a>00279 <span class="comment">// Finds all the settings that match the specification given </span>
<a name="l00280"></a>00280 <span class="comment">// by partialKey and mask, but are either not integer values or </span>
<a name="l00281"></a>00281 <span class="comment">//do not have the given value. </span>
<a name="l00282"></a>00282
<a name="l00283"></a>00283 User::LeaveIfError(iRepository->FindNeqL(0x00<span class="comment">/*partial key*/</span>, 0x00<span class="comment">/*mask*/</span>, <a class="code" href="centrepexample_8cpp.html#72c6ed80162c86177f369a50d3015a47">KInt1_UpdatedValue</a>, foundIds));
<a name="l00284"></a>00284
<a name="l00285"></a>00285 iConsole->Printf(KIdsFound,foundIds.Count());
<a name="l00286"></a>00286 foundIds.Reset();
<a name="l00287"></a>00287
<a name="l00288"></a>00288 <span class="comment">// Finds all the settings that match the specification given by </span>
<a name="l00289"></a>00289 <span class="comment">//partialKey and mask, but are either not floating point values </span>
<a name="l00290"></a>00290 <span class="comment">//or do not have the given value.</span>
<a name="l00291"></a>00291
<a name="l00292"></a>00292 User::LeaveIfError(iRepository->FindNeqL(0x100, 0x0F0, <a class="code" href="centrepexample_8cpp.html#d2a0ec821823376147d2f52e9668cdf2">KReal1_UpdatedValue</a>, foundIds));
<a name="l00293"></a>00293
<a name="l00294"></a>00294 iConsole->Printf(KIdsFound,foundIds.Count());
<a name="l00295"></a>00295 foundIds.Reset();
<a name="l00296"></a>00296
<a name="l00297"></a>00297 }
<a name="l00303"></a><a class="code" href="class_c_cent_rep_example.html#5b2b3b4cdba5336eec39b703458c9971">00303</a> <span class="keywordtype">void</span> <a class="code" href="class_c_cent_rep_example.html#5b2b3b4cdba5336eec39b703458c9971">CCentRepExample::ResetAndNotifyL</a>()
<a name="l00304"></a>00304 {
<a name="l00305"></a>00305 TInt x;
<a name="l00306"></a>00306
<a name="l00307"></a>00307 <span class="comment">// Ensure KInt1 is set to a different value to its initial value</span>
<a name="l00308"></a>00308 <span class="comment">// First change to setting should cause notification</span>
<a name="l00309"></a>00309 iConsole->Printf(KReset);
<a name="l00310"></a>00310
<a name="l00311"></a>00311 User::LeaveIfError(iRepository->Set(<a class="code" href="centrepexample_8cpp.html#b51e13a40abcd0929cdb185e3420131b">KInt1</a>, <a class="code" href="centrepexample_8cpp.html#26522c5a6e5b261136ca16173dc58921">KInt1_InitialValue</a>+10));
<a name="l00312"></a>00312
<a name="l00313"></a>00313
<a name="l00314"></a>00314 User::LeaveIfError(iRepository->Get(<a class="code" href="centrepexample_8cpp.html#b51e13a40abcd0929cdb185e3420131b">KInt1</a>, x));
<a name="l00315"></a>00315
<a name="l00316"></a>00316 iConsole->Printf(KIntBefore, x);
<a name="l00317"></a>00317
<a name="l00318"></a>00318 <a class="code" href="class_c_async_waiter.html">CAsyncWaiter</a>* waiter = <a class="code" href="class_c_async_waiter.html#dbceb921d2500fa11395669bf1cbbccf">CAsyncWaiter::NewL</a>();
<a name="l00319"></a>00319 CleanupStack::PushL(waiter);
<a name="l00320"></a>00320
<a name="l00321"></a>00321 User::LeaveIfError(iRepository->NotifyRequest(<a class="code" href="centrepexample_8cpp.html#b51e13a40abcd0929cdb185e3420131b">KInt1</a>, waiter->iStatus));
<a name="l00322"></a>00322
<a name="l00323"></a>00323 <span class="comment">// Get a notification on a reset as well</span>
<a name="l00324"></a>00324
<a name="l00325"></a>00325 User::LeaveIfError(iRepository->Reset(<a class="code" href="centrepexample_8cpp.html#b51e13a40abcd0929cdb185e3420131b">KInt1</a>));
<a name="l00326"></a>00326
<a name="l00327"></a>00327 <span class="comment">// Check we got a notification</span>
<a name="l00328"></a>00328 waiter-><a class="code" href="class_c_async_waiter.html#43b19982f387f3f74bd9bd6c80051c38">StartAndWait</a>();
<a name="l00329"></a>00329 User::LeaveIfError(waiter-><a class="code" href="class_c_async_waiter.html#74c5f6ce2438095e08e3c349a297280b">Result</a>());
<a name="l00330"></a>00330
<a name="l00331"></a>00331 <span class="comment">// Check KInt1 now has the right value</span>
<a name="l00332"></a>00332 User::LeaveIfError(iRepository->Get(<a class="code" href="centrepexample_8cpp.html#b51e13a40abcd0929cdb185e3420131b">KInt1</a>, x));
<a name="l00333"></a>00333 iConsole->Printf(KIntAfter, x);
<a name="l00334"></a>00334
<a name="l00335"></a>00335 CleanupStack::PopAndDestroy(waiter);
<a name="l00336"></a>00336 }
<a name="l00337"></a>00337
<a name="l00342"></a><a class="code" href="class_c_cent_rep_example.html#88cdab03335c7b3d261cbf84592b38d4">00342</a> <span class="keywordtype">void</span> <a class="code" href="class_c_cent_rep_example.html#88cdab03335c7b3d261cbf84592b38d4">CCentRepExample::MoveSettingsL</a>()
<a name="l00343"></a>00343 {
<a name="l00344"></a>00344 TUint32 keyInfo;
<a name="l00345"></a>00345
<a name="l00346"></a>00346 iConsole->Printf(KMove);
<a name="l00347"></a>00347 iConsole->Printf(KPressAKey);
<a name="l00348"></a>00348 iConsole->Getch();
<a name="l00349"></a>00349 <span class="comment">// Move the key to the target position</span>
<a name="l00350"></a>00350 User::LeaveIfError(iRepository->Move(<a class="code" href="centrepexample_8cpp.html#8c89e8423be52fd1bc368cf5543196e9">KInt3</a>, <a class="code" href="centrepexample_8cpp.html#af75a270116ff145ce1037613fbc2465">KMoveTarget</a>, 0xFFFFFFFF,
<a name="l00351"></a>00351 keyInfo));
<a name="l00352"></a>00352 }
<a name="l00353"></a>00353
<a name="l00358"></a><a class="code" href="class_c_cent_rep_example.html#f6321df74160a46e24b176883973d7f5">00358</a> <span class="keywordtype">void</span> <a class="code" href="class_c_cent_rep_example.html#f6321df74160a46e24b176883973d7f5">CCentRepExample::TransactionFuncL</a>()
<a name="l00359"></a>00359 {
<a name="l00360"></a>00360 TUint32 keyId;
<a name="l00361"></a>00361 TInt intVal;
<a name="l00362"></a>00362
<a name="l00363"></a>00363 iConsole->Printf(KTransact);
<a name="l00364"></a>00364
<a name="l00365"></a>00365 <span class="comment">// Attempts to start a read write transaction.</span>
<a name="l00366"></a>00366 User::LeaveIfError(iRepository->StartTransaction(CRepository::EReadWriteTransaction));
<a name="l00367"></a>00367
<a name="l00368"></a>00368 <span class="comment">// Calls FailTransaction if activated by a Leave or PopAndDestroy.</span>
<a name="l00369"></a>00369 iRepository->CleanupCancelTransactionPushL();
<a name="l00370"></a>00370
<a name="l00371"></a>00371 <span class="comment">// Creating the variable KNewInt at 0x16</span>
<a name="l00372"></a>00372 <span class="keyword">const</span> TUint32 KNewInt = 0x16;
<a name="l00373"></a>00373 <span class="keyword">const</span> TInt KIntValue = 1201;
<a name="l00374"></a>00374 intVal = KIntValue +33;
<a name="l00375"></a>00375
<a name="l00376"></a>00376 <span class="comment">// Perform some write operations.</span>
<a name="l00377"></a>00377 <span class="comment">// Creating KNewInt with the value KIntValue.</span>
<a name="l00378"></a>00378 User::LeaveIfError(iRepository->Create(KNewInt, KIntValue));
<a name="l00379"></a>00379 <span class="comment">// Setting KNewInt to the new value</span>
<a name="l00380"></a>00380 User::LeaveIfError(iRepository->Set(KNewInt,intVal));
<a name="l00381"></a>00381
<a name="l00382"></a>00382 <span class="comment">// Persistence of all values read and written during the transaction </span>
<a name="l00383"></a>00383 <span class="comment">// is only guaranteed after a successful return from CommitTransaction.</span>
<a name="l00384"></a>00384 User::LeaveIfError(iRepository->CommitTransaction(keyId));
<a name="l00385"></a>00385
<a name="l00386"></a>00386 <span class="comment">// Read the data written.</span>
<a name="l00387"></a>00387 User::LeaveIfError(iRepository->Get(KNewInt, intVal));
<a name="l00388"></a>00388
<a name="l00389"></a>00389 <span class="comment">// Deleting the data after reading it.</span>
<a name="l00390"></a>00390 User::LeaveIfError(iRepository->Delete(KNewInt));
<a name="l00391"></a>00391 CleanupStack::Pop();
<a name="l00392"></a>00392
<a name="l00393"></a>00393 CRepository* repository1;
<a name="l00394"></a>00394 User::LeaveIfNull(repository1 = CRepository::NewLC(KUidRepository));
<a name="l00395"></a>00395
<a name="l00396"></a>00396 <span class="comment">// Begin read transaction for repository1</span>
<a name="l00397"></a>00397 User::LeaveIfError(repository1->StartTransaction(CRepository::EReadTransaction));
<a name="l00398"></a>00398
<a name="l00399"></a>00399 CRepository* repository2;
<a name="l00400"></a>00400 User::LeaveIfNull(repository2 = CRepository::NewLC(KUidRepository));
<a name="l00401"></a>00401
<a name="l00402"></a>00402 <span class="comment">// Should be able to start another read transaction (Multiple read transactions)</span>
<a name="l00403"></a>00403 User::LeaveIfError(repository2->StartTransaction(CRepository::EReadTransaction));
<a name="l00404"></a>00404
<a name="l00405"></a>00405 <span class="comment">// Perform some gets using the open transactions and repositories</span>
<a name="l00406"></a>00406 <span class="comment">// Read operation</span>
<a name="l00407"></a>00407 User::LeaveIfError(repository1->Get(<a class="code" href="centrepexample_8cpp.html#b51e13a40abcd0929cdb185e3420131b">KInt1</a>, intVal));
<a name="l00408"></a>00408 <span class="comment">// Ensure transaction cancelled if following code Leaves:</span>
<a name="l00409"></a>00409 repository1->CleanupCancelTransactionPushL();
<a name="l00410"></a>00410
<a name="l00411"></a>00411 <span class="comment">// Commit the transaction </span>
<a name="l00412"></a>00412 User::LeaveIfError(repository1->CommitTransaction(keyId));
<a name="l00413"></a>00413 CleanupStack::Pop();
<a name="l00414"></a>00414
<a name="l00415"></a>00415 <span class="comment">// Calls FailTransaction if activated by a Leave or PopAndDestroy.</span>
<a name="l00416"></a>00416 repository2->CleanupCancelTransactionPushL();
<a name="l00417"></a>00417 User::LeaveIfError(repository2->Get(<a class="code" href="centrepexample_8cpp.html#b51e13a40abcd0929cdb185e3420131b">KInt1</a>, intVal));
<a name="l00418"></a>00418 User::LeaveIfError(repository2->CommitTransaction(keyId));
<a name="l00419"></a>00419
<a name="l00420"></a>00420 <span class="comment">// Pop the transaction</span>
<a name="l00421"></a>00421 CleanupStack::Pop();
<a name="l00422"></a>00422 CleanupStack::PopAndDestroy(2,repository1);
<a name="l00423"></a>00423
<a name="l00424"></a>00424
<a name="l00425"></a>00425 }
<a name="l00426"></a>00426
<a name="l00431"></a><a class="code" href="class_c_cent_rep_example.html#f1334cf942baf9af3ac1d53f71af4419">00431</a> <span class="keywordtype">void</span> <a class="code" href="class_c_cent_rep_example.html#f1334cf942baf9af3ac1d53f71af4419">CCentRepExample::DeleteL</a>()
<a name="l00432"></a>00432 {
<a name="l00433"></a>00433 TInt x;
<a name="l00434"></a>00434 TReal y;
<a name="l00435"></a>00435
<a name="l00436"></a>00436 iConsole->Printf(KDelete);
<a name="l00437"></a>00437
<a name="l00438"></a>00438 User::LeaveIfError(iRepository->Get(<a class="code" href="centrepexample_8cpp.html#26522c5a6e5b261136ca16173dc58921">KInt1_InitialValue</a>, x));
<a name="l00439"></a>00439 User::LeaveIfError(iRepository->Get(<a class="code" href="centrepexample_8cpp.html#b5338c35514ac188dafdba0e9083fa14">KReal1</a>, y));
<a name="l00440"></a>00440 User::LeaveIfError(iRepository->Delete(<a class="code" href="centrepexample_8cpp.html#26522c5a6e5b261136ca16173dc58921">KInt1_InitialValue</a>));
<a name="l00441"></a>00441 User::LeaveIfError(iRepository->Delete(<a class="code" href="centrepexample_8cpp.html#af75a270116ff145ce1037613fbc2465">KMoveTarget</a>));
<a name="l00442"></a>00442 User::LeaveIfError(iRepository->Delete(<a class="code" href="centrepexample_8cpp.html#b5338c35514ac188dafdba0e9083fa14">KReal1</a>));
<a name="l00443"></a>00443 }
<a name="l00444"></a>00444
<a name="l00445"></a><a class="code" href="centrepexample_8cpp.html#689e0bf9aa924a1d7dc108665d44736c">00445</a> LOCAL_C <span class="keywordtype">void</span> <a class="code" href="circularbuffer_8cpp.html#5fb473d4ee18739183215b04dcad6e12">MainL</a>()
<a name="l00446"></a>00446 {
<a name="l00447"></a>00447 <span class="comment">// Create an Active Scheduler to handle asychronous calls</span>
<a name="l00448"></a>00448 CActiveScheduler* scheduler = <span class="keyword">new</span> (ELeave) CActiveScheduler;
<a name="l00449"></a>00449 CleanupStack::PushL(scheduler);
<a name="l00450"></a>00450 CActiveScheduler::Install( scheduler );
<a name="l00451"></a>00451 <a class="code" href="class_c_cent_rep_example.html">CCentRepExample</a> * app = <a class="code" href="class_c_cent_rep_example.html#6761078f15ec4f9085cb01402f8444a2">CCentRepExample ::NewLC</a>();
<a name="l00452"></a>00452
<a name="l00453"></a>00453 <span class="comment">// Reset the repository</span>
<a name="l00454"></a>00454 app-><a class="code" href="class_c_cent_rep_example.html#513576b361a857b6cdc737672179a612">ResetL</a>();
<a name="l00455"></a>00455
<a name="l00456"></a>00456 <span class="comment">// Open the repository</span>
<a name="l00457"></a>00457 app-><a class="code" href="class_c_cent_rep_example.html#9c9e68c292232731fe5e5608251a05e2">OpenRepositoryL</a>();
<a name="l00458"></a>00458
<a name="l00459"></a>00459 <span class="comment">// Change the existing settings</span>
<a name="l00460"></a>00460 app-><a class="code" href="class_c_cent_rep_example.html#4e0ebe8e6bff9c146211cca8748d5739">ChangeSettingsL</a>();
<a name="l00461"></a>00461
<a name="l00462"></a>00462 <span class="comment">// Read the changed settings</span>
<a name="l00463"></a>00463 app-><a class="code" href="class_c_cent_rep_example.html#b96ba0baa8204931f40a32834f1849f3">ReadSettingsL</a>();
<a name="l00464"></a>00464
<a name="l00465"></a>00465 <span class="comment">// Find the settings using FindL, FindEqL and FindNeqL</span>
<a name="l00466"></a>00466 app-><a class="code" href="class_c_cent_rep_example.html#4d89eb968ca8b89aff9b363e73a4fa38">FindSettingsL</a>();
<a name="l00467"></a>00467
<a name="l00468"></a>00468 <span class="comment">// Move settings</span>
<a name="l00469"></a>00469 app-><a class="code" href="class_c_cent_rep_example.html#88cdab03335c7b3d261cbf84592b38d4">MoveSettingsL</a>();
<a name="l00470"></a>00470
<a name="l00471"></a>00471 <span class="comment">// Reset settings to default values and get notification</span>
<a name="l00472"></a>00472 app-><a class="code" href="class_c_cent_rep_example.html#5b2b3b4cdba5336eec39b703458c9971">ResetAndNotifyL</a>();
<a name="l00473"></a>00473
<a name="l00474"></a>00474 <span class="comment">// Perform multiple operations in a transaction</span>
<a name="l00475"></a>00475 app-><a class="code" href="class_c_cent_rep_example.html#f6321df74160a46e24b176883973d7f5">TransactionFuncL</a>();
<a name="l00476"></a>00476
<a name="l00477"></a>00477 <span class="comment">// Delete settings</span>
<a name="l00478"></a>00478 app-><a class="code" href="class_c_cent_rep_example.html#f1334cf942baf9af3ac1d53f71af4419">DeleteL</a>();
<a name="l00479"></a>00479
<a name="l00480"></a>00480 CleanupStack::PopAndDestroy(2); <span class="comment">//app, scheduler</span>
<a name="l00481"></a>00481
<a name="l00482"></a>00482 }
<a name="l00483"></a>00483
<a name="l00484"></a><a class="code" href="centrepexample_8cpp.html#0f358e9c4355138f629b8c4f37310295">00484</a> GLDEF_C TInt <a class="code" href="dbllist_8cpp.html#0f358e9c4355138f629b8c4f37310295">E32Main</a>()
<a name="l00485"></a>00485 {
<a name="l00486"></a>00486 __UHEAP_MARK;
<a name="l00487"></a>00487 CTrapCleanup* cleanup = CTrapCleanup::New();
<a name="l00488"></a>00488 <span class="keywordflow">if</span>(cleanup == NULL)
<a name="l00489"></a>00489 {
<a name="l00490"></a>00490 <span class="keywordflow">return</span> KErrNoMemory;
<a name="l00491"></a>00491 }
<a name="l00492"></a>00492 TRAPD(err, <a class="code" href="circularbuffer_8cpp.html#5fb473d4ee18739183215b04dcad6e12">MainL</a>());
<a name="l00493"></a>00493 <span class="keywordflow">if</span>(err != KErrNone)
<a name="l00494"></a>00494 {
<a name="l00495"></a>00495 User::Panic(_L(<span class="stringliteral">"Failed to complete"</span>),err);
<a name="l00496"></a>00496 }
<a name="l00497"></a>00497
<a name="l00498"></a>00498 <span class="keyword">delete</span> cleanup;
<a name="l00499"></a>00499 __UHEAP_MARKEND;
<a name="l00500"></a>00500 <span class="keywordflow">return</span> KErrNone;
<a name="l00501"></a>00501 }
</pre></div><hr size="1"><address style="text-align: right;"><small>Generated on Thu Jan 21 10:33:00 2010 for TB10.1 Example Applications by
<a href="http://www.doxygen.org/index.html">
<img src="doxygen.png" alt="doxygen" align="middle" border="0"></a> 1.5.3 </small></address>
</body>
</html>