00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00023 #include "secureclientandserver.h"
00024 #include "secureclient.h"
00025
00026 LOCAL_D CConsoleBase* console;
00027
00028 void DoExampleL()
00029 {
00030 console->Printf(KTxtTestingCountServer);
00031
00032
00033 RSecureSession countserv;
00034 User::LeaveIfError(countserv.Connect());
00035
00036
00037 RSecureSubSession counterA;
00038 counterA.Open(countserv);
00039
00040
00041 console->Printf(KTxtInitCounterAWith);
00042 console->Printf(KTxtOption);
00043 TUint8 inpOption = console->Getch();
00044 if(inpOption == '1')
00045 {
00046
00047 counterA.SetCounterFromFileL();
00048 console->Printf(KTxtInitFromFile,counterA.CounterValueL());
00049 }
00050 else
00051 {
00052
00053 _LIT(KTxtValueString,"a2");
00054 console->Printf(KTxtValueString);
00055
00056 TInt err = counterA.SetFromString(KTxtValueString);
00057 if (err == ENonNumericString)
00058 {
00059
00060 console->Printf(KTxtInitCounterFailed);
00061 }
00062 else
00063 {
00064
00065 console->Printf(KTxtInitCounterSucceeded);
00066 }
00067 }
00068 RSecureSubSession counterB;
00069
00070
00071 counterB.Open(countserv);
00072
00073
00074 console->Printf(KTxtInitCounterBWith);
00075 console->Printf(KTxtOption);
00076 inpOption = console->Getch();
00077 if(inpOption == '1')
00078 {
00079
00080 counterB.SetCounterFromFileL();
00081 console->Printf(KTxtInitFromFile,counterB.CounterValueL());
00082 }
00083 else
00084 {
00085
00086 _LIT(KTxtLegalString,"100");
00087 console->Printf(KTxtLegalString);
00088
00089 TInt err = counterB.SetFromString(KTxtLegalString);
00090 if (err == ENonNumericString)
00091 {
00092
00093 console->Printf(KTxtInitCounterFailed);
00094 }
00095 else
00096 {
00097
00098
00099 console->Printf(KTxtInitCounterSucceeded);
00100 }
00101 }
00102
00103
00104 console->Printf(KMsgPressAnyKey);
00105 console->Getch();
00106 console->ClearScreen();
00107
00108
00109 console->Printf(KTxtGetCounterAValue,counterA.CounterValueL());
00110 console->Printf(KTxtGetCounterBValue,counterB.CounterValueL());
00111
00112
00113 console->Printf(KMsgPressAnyKey);
00114 console->Getch();
00115 console->ClearScreen();
00116
00117
00118 _LIT(KTxt1,"\nIncrease counterA by default value (i.e. 1)..\n");
00119 console->Printf(KTxt1);
00120 counterA.Increase();
00121 console->Printf(KTxtGetCounterAValue,counterA.CounterValueL());
00122
00123
00124 _LIT(KTxt2,"\nIncrease counterA by 2..\n");
00125 console->Printf(KTxt2);
00126
00127
00128 counterA.IncreaseByL(2);
00129 console->Printf(KTxtGetCounterAValue,counterA.CounterValueL());
00130
00131
00132 _LIT(KTxt3,"\nIncrease counterB by default value (i.e. 1)..\n");
00133 console->Printf(KTxt3);
00134 counterB.Increase();
00135 console->Printf(KTxtGetCounterBValue,counterB.CounterValueL());
00136
00137
00138 _LIT(KTxt4,"\nIncrease counterA by 17..\n");
00139 console->Printf(KTxt4);
00140
00141 counterA.IncreaseByL(17);
00142 console->Printf(KTxtGetCounterAValue,counterA.CounterValueL());
00143
00144
00145 console->Printf(KMsgPressAnyKey);
00146 console->Getch();
00147 console->ClearScreen();
00148
00149
00150 _LIT(KTxt5,"\nIncrease counterB by 5..\n");
00151 console->Printf(KTxt5);
00152 counterB.IncreaseByL(5);
00153 console->Printf(KTxtGetCounterBValue,counterB.CounterValueL());
00154
00155
00156 _LIT(KTxt6,"\nDecrease counterA..\n");
00157 console->Printf(KTxt6);
00158 counterA.Decrease();
00159 console->Printf(KTxtGetCounterAValue,counterA.CounterValueL());
00160
00161
00162 _LIT(KTxt7,"\nDecrease counterB by 3..\n");
00163 console->Printf(KTxt7);
00164 console->Printf(KTxtGetCounterBValue,counterB.CounterValueL());
00165
00166
00167 counterB.DecreaseByL(3);
00168
00169
00170 _LIT(KTxt8,"\nResource count is.. %d \n");
00171 console->Printf(KTxt8,countserv.ResourceCountL());
00172
00173
00174 console->Printf(KTxtSaveToFile);
00175 TUint8 sel = console->Getch();
00176 if(sel == 'a')
00177 {
00178
00179 console->Printf(KTxtSelectCounter,sel);
00180 console->Printf(KTxtSaveCounter);
00181
00182 counterA.SaveCounterL();
00183 }
00184 else if(sel == 'b')
00185 {
00186
00187 console->Printf(KTxtSelectCounter,sel);
00188 console->Printf(KTxtSaveCounter);
00189
00190 counterB.SaveCounterL();
00191 }
00192
00193
00194 _LIT(KTxt9,"\nClosing counterA and then CounterB..\n");
00195 console->Printf(KTxt9);
00196 counterA.Close();
00197 counterB.Close();
00198 countserv.Close();
00199 }
00200
00201 GLDEF_C TInt E32Main()
00202 {
00203 __UHEAP_MARK;
00204 CTrapCleanup* cleanup = CTrapCleanup::New();
00205
00206 TRAPD(createError, console = Console::NewL(KTextConsoleTitle, TSize(KConsFullScreen,KConsFullScreen)));
00207 if (createError)
00208 return createError;
00209
00210 TRAPD(mainError, DoExampleL());
00211 if (mainError)
00212 console->Printf(KTextFailed, mainError);
00213 console->Printf(KTextPressAnyKey);
00214 console->Getch();
00215
00216 delete console;
00217 delete cleanup;
00218 __UHEAP_MARKEND;
00219 return KErrNone;
00220 }