00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036 #include "ClientServer.h"
00037
00038
00039 #include "SimpleClient.h"
00040 #include "CommonFramework.h"
00041
00042
00043 const TUint kDefaultMessageSlots=4;
00044
00045
00046
00047
00048
00049
00050 RCountServSession::RCountServSession()
00051 {
00052 }
00053
00054
00064 TInt RCountServSession::Connect()
00065 {
00066 TInt r=StartThread(iServerThread);
00067 if (r==KErrNone)
00068 r=CreateSession(KCountServerName,Version(),kDefaultMessageSlots);
00069 return(r);
00070 }
00071
00072
00076 TVersion RCountServSession::Version(void) const
00077 {
00078 return(TVersion(KCountServMajorVersionNumber,KCountServMinorVersionNumber,KCountServBuildVersionNumber));
00079 }
00080
00081
00086 TInt RCountServSession::SetFromString(const TDesC& aString)
00087 {
00088 TIpcArgs args(&aString);
00089 return SendReceive(ECountServSetFromString, args);
00090 }
00091
00092
00096 void RCountServSession::Increase()
00097 {
00098 SendReceive(ECountServIncrease);
00099 }
00100
00101
00106 void RCountServSession::IncreaseBy(TInt anInt)
00107 {
00108 TIpcArgs args(anInt);
00109 SendReceive(ECountServIncreaseBy, args);
00110 }
00111
00112
00116 void RCountServSession::Decrease()
00117 {
00118 SendReceive(ECountServDecrease);
00119 }
00120
00121
00126 void RCountServSession::DecreaseBy(TInt anInt)
00127 {
00128 TIpcArgs args(anInt);
00129 SendReceive(ECountServDecreaseBy, args);
00130 }
00131
00135 void RCountServSession::Reset()
00136 {
00137 SendReceive(ECountServReset);
00138 }
00139
00140
00146 TInt RCountServSession::CounterValue()
00147 {
00148 TInt res=0;
00149 TPckgBuf<TInt> pckg;
00150
00151
00152 TIpcArgs args(&pckg);
00153 SendReceive(ECountServValue, args);
00154
00155
00156 res = pckg();
00157 return res;
00158 }
00159
00160
00167 TInt RCountServSession::UnsupportedRequest()
00168 {
00169 return SendReceive(ECountServUnsupportedRequest);
00170 }
00171
00175 void RCountServSession::BadRequest()
00176 {
00177 SendReceive(9999);
00178 }
00179
00180
00181
00185 void RCountServSession::Close()
00186 {
00187 RSessionBase::Close();
00188 iServerThread.Close();
00189 }
00190
00191
00192
00193
00201 LOCAL_C void doExampleL()
00202 {
00203 _LIT(KTxtTestingCountServer,"Testing the count server \n\n");
00204 _LIT(KTxtInitCounterWith,"\nInitialize the counter with : ");
00205 _LIT(KTxtInitCounterFailed,"\nSetting the counter from string failed: non-numeric character detected\n");
00206 _LIT(KTxtGetCounterValue,"\nGetting the counter value back from the server: %d \n");
00207
00208
00209
00210 console->Printf(KTxtTestingCountServer);
00211
00212
00213 RCountServSession ss;
00214
00215
00216
00217
00218 User::LeaveIfError(ss.Connect());
00219
00220
00221 console->Printf(KTxtInitCounterWith);
00222
00223
00224
00225 _LIT(KTxtIllegalString,"22h4");
00226 console->Printf(KTxtIllegalString);
00227 TInt ret = ss.SetFromString(KTxtIllegalString);
00228 if (ret==ENonNumericString)
00229 {
00230 console->Printf(KTxtInitCounterFailed);
00231 }
00232
00233
00234 console->Printf(KTxtInitCounterWith);
00235 _LIT(KTxtLegalString,"224");
00236 console->Printf(KTxtLegalString);
00237 ret = ss.SetFromString(KTxtLegalString);
00238 if (ret==ENonNumericString)
00239 {
00240 console->Printf(KTxtInitCounterFailed);
00241 }
00242
00243
00244
00245 ret = ss.CounterValue();
00246 console->Printf(KTxtGetCounterValue, ret);
00247
00248
00249 _LIT(KTxt1,"\nIncrease counter (default 1)..");
00250 console->Printf(KTxt1);
00251 ss.Increase();
00252 ret = ss.CounterValue();
00253 console->Printf(KTxtGetCounterValue, ret);
00254
00255
00256 _LIT(KTxt2,"\nIncrease counter by 2..");
00257 console->Printf(KTxt2);
00258 ss.IncreaseBy(2);
00259 ret = ss.CounterValue();
00260 console->Printf(KTxtGetCounterValue, ret);
00261
00262
00263 _LIT(KTxt3,"\nDecrease counter(default 1)..");
00264 console->Printf(KTxt3);
00265 ss.Decrease();
00266 ret = ss.CounterValue();
00267 console->Printf(KTxtGetCounterValue, ret);
00268
00269
00270 _LIT(KTxt4,"\nIncrease counter by 7..");
00271 console->Printf(KTxt4);
00272 ss.IncreaseBy(7);
00273 ret = ss.CounterValue();
00274 console->Printf(KTxtGetCounterValue, ret);
00275
00276
00277 _LIT(KTxt5,"\nIncrease counter(default 1)..");
00278 console->Printf(KTxt5);
00279 ss.Increase();
00280 ret = ss.CounterValue();
00281 console->Printf(KTxtGetCounterValue, ret);
00282
00283
00284 _LIT(KTxt6,"\nDecrease counter by 3..");
00285 console->Printf(KTxt6);
00286 ss.DecreaseBy(3);
00287 ret = ss.CounterValue();
00288 console->Printf(KTxtGetCounterValue, ret);
00289
00290
00291 _LIT(KTxt7,"\nReseting counter value to 0..");
00292 console->Printf(KTxt7);
00293 ss.Reset();
00294 ret = ss.CounterValue();
00295 console->Printf(KTxtGetCounterValue, ret);
00296
00297
00298
00299 _LIT(KTxt8,"\nAbout to call the unsupported function Stop()..");
00300 console->Printf(KTxt8);
00301 ret = ss.UnsupportedRequest();
00302 _LIT(KTxt9,"\nSorry, UnsupportedRequest() is not supported\n");
00303 if (ret==KErrNotSupported)
00304 {
00305 console->Printf(KTxt9);
00306 }
00307
00308
00309
00310
00311
00312
00313
00314
00315 ss.Close();
00316 }