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 #include "ComplexClientAndServer.h"
00032 #include "ComplexServer.h"
00033 #include <e32svr.h>
00034 #include <e32uid.h>
00035
00036
00037
00038
00039
00040
00044 CCountSession::CCountSession()
00045 {
00046 }
00047
00048
00062 void CCountSession::CreateL()
00063 {
00064
00065 iCountersObjectIndex=CObjectIx::NewL();
00066
00067
00068
00069 iContainer=((CCountServer*)Server())->NewContainerL();
00070 }
00071
00072
00080 void CCountSession::CloseSession()
00081 {
00082
00083 delete iCountersObjectIndex;
00084 iCountersObjectIndex = NULL;
00085
00086
00087 ((CCountServer*)Server())->RemoveContainer(iContainer);
00088 iContainer = NULL;
00089 }
00090
00091
00097 CCountSubSession* CCountSession::CounterFromHandle(const RMessage2& aMessage,TInt aHandle)
00098 {
00099 CCountSubSession* counter = (CCountSubSession*)iCountersObjectIndex->At(aHandle);
00100 if (counter == NULL)
00101 {
00102 PanicClient(aMessage, EBadSubsessionHandle);
00103 }
00104 return counter;
00105 }
00106
00107
00108
00118 void CCountSession::ServiceL(const RMessage2& aMessage)
00119 {
00120 TRAPD(err,DispatchMessageL(aMessage));
00121 aMessage.Complete(err);
00122 }
00123
00124
00131 void CCountSession::DispatchMessageL(const RMessage2& aMessage)
00132 {
00133
00134 switch (aMessage.Function())
00135 {
00136 case ECountServCreateSubSession:
00137 NewCounterL(aMessage);
00138 return;
00139 case ECountServCloseSession:
00140 CloseSession();
00141 return;
00142 case ECountServResourceCount:
00143 NumResourcesL(aMessage);
00144 return;
00145 }
00146
00147
00148
00149
00150
00151 CCountSubSession* counter=CounterFromHandle(aMessage,aMessage.Int3());
00152 switch (aMessage.Function())
00153 {
00154 case ECountServInitSubSession:
00155 counter->SetFromStringL(aMessage);
00156 return;
00157 case ECountServCloseSubSession:
00158 DeleteCounter(aMessage.Int3());
00159 return;
00160 case ECountServIncrease:
00161 counter->Increase();
00162 return;
00163 case ECountServIncreaseBy:
00164 counter->IncreaseBy(aMessage);
00165 return;
00166 case ECountServDecrease:
00167 counter->Decrease();
00168 return;
00169 case ECountServDecreaseBy:
00170 counter->DecreaseBy(aMessage);
00171 return;
00172 case ECountServReset:
00173 counter->Reset();
00174 return;
00175 case ECountServValue:
00176 counter->CounterValueL(aMessage);
00177 return;
00178 default:
00179 PanicClient(aMessage,EBadRequest);
00180 return;
00181 }
00182 }
00183
00184
00192 void CCountSession::NewCounterL(const RMessage2& aMessage)
00193 {
00194
00195 CCountSubSession* counter= new (ELeave) CCountSubSession(this);
00196
00197
00198
00199
00200 iContainer->AddL(counter);
00201
00202
00203
00204
00205 TInt handle=iCountersObjectIndex->AddL(counter);
00206
00207
00208
00209
00210
00211
00212
00213
00214
00215
00216
00217 TPckgBuf<TInt> handlePckg(handle);
00218 TRAPD(res,aMessage.WriteL(3,handlePckg));
00219 if (res!=KErrNone)
00220 {
00221 iCountersObjectIndex->Remove(handle);
00222 PanicClient(aMessage,EBadDescriptor);
00223 return;
00224 }
00225
00226
00227 iResourceCount++;
00228 }
00229
00230
00231
00232
00236 void CCountSession::DeleteCounter(TInt aHandle)
00237 {
00238
00239
00240
00241
00242
00243 iCountersObjectIndex->Remove(aHandle);
00244
00245 iResourceCount--;
00246 }
00247
00248
00249
00250
00251
00252 TInt CCountSession::CountResources()
00253 {
00254 return iResourceCount;
00255 }
00256
00257
00262 void CCountSession::NumResourcesL(const RMessage2& aMessage)
00263 {
00264 TPckgBuf<TInt> resourcesPckg(iResourceCount);
00265 aMessage.WriteL(0,resourcesPckg);
00266 }
00267
00268
00272 void CCountSession::PanicClient(const RMessage2& aMessage,TInt aPanic) const
00273 {
00274 _LIT(KTxtServer,"CountServ server");
00275 aMessage.Panic(KTxtServer,aPanic);
00276 }
00277