00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021 #include "ClientServer.h"
00022
00023
00024 #include "SimpleClient.h"
00025 #include "CommonFramework.h"
00026
00027
00028 const TUint kDefaultMessageSlots=4;
00029
00030
00031
00032
00033
00034
00035 RCountServSession::RCountServSession()
00036 {
00037 }
00038
00039
00049 TInt RCountServSession::Connect()
00050 {
00051 TInt r=StartThread(iServerThread);
00052 if (r==KErrNone)
00053 r=CreateSession(KCountServerName,Version(),kDefaultMessageSlots);
00054 return(r);
00055 }
00056
00057
00061 TVersion RCountServSession::Version(void) const
00062 {
00063 return(TVersion(KCountServMajorVersionNumber,KCountServMinorVersionNumber,KCountServBuildVersionNumber));
00064 }
00065
00066
00071 TInt RCountServSession::SetFromString(const TDesC& aString)
00072 {
00073 TIpcArgs args(&aString);
00074 return SendReceive(ECountServSetFromString, args);
00075 }
00076
00077
00081 void RCountServSession::Increase()
00082 {
00083 SendReceive(ECountServIncrease);
00084 }
00085
00086
00091 void RCountServSession::IncreaseBy(TInt anInt)
00092 {
00093 TIpcArgs args(anInt);
00094 SendReceive(ECountServIncreaseBy, args);
00095 }
00096
00097
00101 void RCountServSession::Decrease()
00102 {
00103 SendReceive(ECountServDecrease);
00104 }
00105
00106
00111 void RCountServSession::DecreaseBy(TInt anInt)
00112 {
00113 TIpcArgs args(anInt);
00114 SendReceive(ECountServDecreaseBy, args);
00115 }
00116
00120 void RCountServSession::Reset()
00121 {
00122 SendReceive(ECountServReset);
00123 }
00124
00125
00131 TInt RCountServSession::CounterValue()
00132 {
00133 TInt res=0;
00134 TPckgBuf<TInt> pckg;
00135
00136
00137 TIpcArgs args(&pckg);
00138 SendReceive(ECountServValue, args);
00139
00140
00141 res = pckg();
00142 return res;
00143 }
00144
00145
00152 TInt RCountServSession::UnsupportedRequest()
00153 {
00154 return SendReceive(ECountServUnsupportedRequest);
00155 }
00156
00160 void RCountServSession::BadRequest()
00161 {
00162 SendReceive(9999);
00163 }
00164
00165
00166
00170 void RCountServSession::Close()
00171 {
00172 RSessionBase::Close();
00173 iServerThread.Close();
00174 }
00175
00176
00177
00178
00186 LOCAL_C void doExampleL()
00187 {
00188 _LIT(KTxtTestingCountServer,"Testing the count server \n\n");
00189 _LIT(KTxtInitCounterWith,"\nInitialize the counter with : ");
00190 _LIT(KTxtInitCounterFailed,"\nSetting the counter from string failed: non-numeric character detected\n");
00191 _LIT(KTxtGetCounterValue,"\nGetting the counter value back from the server: %d \n");
00192
00193
00194
00195 console->Printf(KTxtTestingCountServer);
00196
00197
00198 RCountServSession ss;
00199
00200
00201
00202
00203 User::LeaveIfError(ss.Connect());
00204
00205
00206 console->Printf(KTxtInitCounterWith);
00207
00208
00209
00210 _LIT(KTxtIllegalString,"22h4");
00211 console->Printf(KTxtIllegalString);
00212 TInt ret = ss.SetFromString(KTxtIllegalString);
00213 if (ret==ENonNumericString)
00214 {
00215 console->Printf(KTxtInitCounterFailed);
00216 }
00217
00218
00219 console->Printf(KTxtInitCounterWith);
00220 _LIT(KTxtLegalString,"224");
00221 console->Printf(KTxtLegalString);
00222 ret = ss.SetFromString(KTxtLegalString);
00223 if (ret==ENonNumericString)
00224 {
00225 console->Printf(KTxtInitCounterFailed);
00226 }
00227
00228
00229
00230 ret = ss.CounterValue();
00231 console->Printf(KTxtGetCounterValue, ret);
00232
00233
00234 _LIT(KTxt1,"\nIncrease counter (default 1)..");
00235 console->Printf(KTxt1);
00236 ss.Increase();
00237 ret = ss.CounterValue();
00238 console->Printf(KTxtGetCounterValue, ret);
00239
00240
00241 _LIT(KTxt2,"\nIncrease counter by 2..");
00242 console->Printf(KTxt2);
00243 ss.IncreaseBy(2);
00244 ret = ss.CounterValue();
00245 console->Printf(KTxtGetCounterValue, ret);
00246
00247
00248 _LIT(KTxt3,"\nDecrease counter(default 1)..");
00249 console->Printf(KTxt3);
00250 ss.Decrease();
00251 ret = ss.CounterValue();
00252 console->Printf(KTxtGetCounterValue, ret);
00253
00254
00255 _LIT(KTxt4,"\nIncrease counter by 7..");
00256 console->Printf(KTxt4);
00257 ss.IncreaseBy(7);
00258 ret = ss.CounterValue();
00259 console->Printf(KTxtGetCounterValue, ret);
00260
00261
00262 _LIT(KTxt5,"\nIncrease counter(default 1)..");
00263 console->Printf(KTxt5);
00264 ss.Increase();
00265 ret = ss.CounterValue();
00266 console->Printf(KTxtGetCounterValue, ret);
00267
00268
00269 _LIT(KTxt6,"\nDecrease counter by 3..");
00270 console->Printf(KTxt6);
00271 ss.DecreaseBy(3);
00272 ret = ss.CounterValue();
00273 console->Printf(KTxtGetCounterValue, ret);
00274
00275
00276 _LIT(KTxt7,"\nReseting counter value to 0..");
00277 console->Printf(KTxt7);
00278 ss.Reset();
00279 ret = ss.CounterValue();
00280 console->Printf(KTxtGetCounterValue, ret);
00281
00282
00283
00284 _LIT(KTxt8,"\nAbout to call the unsupported function Stop()..");
00285 console->Printf(KTxt8);
00286 ret = ss.UnsupportedRequest();
00287 _LIT(KTxt9,"\nSorry, UnsupportedRequest() is not supported\n");
00288 if (ret==KErrNotSupported)
00289 {
00290 console->Printf(KTxt9);
00291 }
00292
00293
00294
00295
00296
00297
00298
00299
00300 ss.Close();
00301 }