00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017 #include "ComplexClientAndServer.h"
00018 #include "ComplexServer.h"
00019 #include <e32svr.h>
00020 #include <e32uid.h>
00021
00022
00023
00024
00025
00026
00030 CCountSession::CCountSession()
00031 {
00032 }
00033
00034
00048 void CCountSession::CreateL()
00049 {
00050
00051 iCountersObjectIndex=CObjectIx::NewL();
00052
00053
00054
00055 iContainer=((CCountServer*)Server())->NewContainerL();
00056 }
00057
00058
00066 void CCountSession::CloseSession()
00067 {
00068
00069 delete iCountersObjectIndex;
00070 iCountersObjectIndex = NULL;
00071
00072
00073 ((CCountServer*)Server())->RemoveContainer(iContainer);
00074 iContainer = NULL;
00075 }
00076
00077
00083 CCountSubSession* CCountSession::CounterFromHandle(const RMessage2& aMessage,TInt aHandle)
00084 {
00085 CCountSubSession* counter = (CCountSubSession*)iCountersObjectIndex->At(aHandle);
00086 if (counter == NULL)
00087 {
00088 PanicClient(aMessage, EBadSubsessionHandle);
00089 }
00090 return counter;
00091 }
00092
00093
00094
00104 void CCountSession::ServiceL(const RMessage2& aMessage)
00105 {
00106 TRAPD(err,DispatchMessageL(aMessage));
00107 aMessage.Complete(err);
00108 }
00109
00110
00117 void CCountSession::DispatchMessageL(const RMessage2& aMessage)
00118 {
00119
00120 switch (aMessage.Function())
00121 {
00122 case ECountServCreateSubSession:
00123 NewCounterL(aMessage);
00124 return;
00125 case ECountServCloseSession:
00126 CloseSession();
00127 return;
00128 case ECountServResourceCount:
00129 NumResourcesL(aMessage);
00130 return;
00131 }
00132
00133
00134
00135
00136
00137 CCountSubSession* counter=CounterFromHandle(aMessage,aMessage.Int3());
00138 switch (aMessage.Function())
00139 {
00140 case ECountServInitSubSession:
00141 counter->SetFromStringL(aMessage);
00142 return;
00143 case ECountServCloseSubSession:
00144 DeleteCounter(aMessage.Int3());
00145 return;
00146 case ECountServIncrease:
00147 counter->Increase();
00148 return;
00149 case ECountServIncreaseBy:
00150 counter->IncreaseBy(aMessage);
00151 return;
00152 case ECountServDecrease:
00153 counter->Decrease();
00154 return;
00155 case ECountServDecreaseBy:
00156 counter->DecreaseBy(aMessage);
00157 return;
00158 case ECountServReset:
00159 counter->Reset();
00160 return;
00161 case ECountServValue:
00162 counter->CounterValueL(aMessage);
00163 return;
00164 default:
00165 PanicClient(aMessage,EBadRequest);
00166 return;
00167 }
00168 }
00169
00170
00178 void CCountSession::NewCounterL(const RMessage2& aMessage)
00179 {
00180
00181 CCountSubSession* counter= new (ELeave) CCountSubSession(this);
00182
00183
00184
00185
00186 iContainer->AddL(counter);
00187
00188
00189
00190
00191 TInt handle=iCountersObjectIndex->AddL(counter);
00192
00193
00194
00195
00196
00197
00198
00199
00200
00201
00202
00203 TPckgBuf<TInt> handlePckg(handle);
00204 TRAPD(res,aMessage.WriteL(3,handlePckg));
00205 if (res!=KErrNone)
00206 {
00207 iCountersObjectIndex->Remove(handle);
00208 PanicClient(aMessage,EBadDescriptor);
00209 return;
00210 }
00211
00212
00213 iResourceCount++;
00214 }
00215
00216
00217
00218
00222 void CCountSession::DeleteCounter(TInt aHandle)
00223 {
00224
00225
00226
00227
00228
00229 iCountersObjectIndex->Remove(aHandle);
00230
00231 iResourceCount--;
00232 }
00233
00234
00235
00236
00237
00238 TInt CCountSession::CountResources()
00239 {
00240 return iResourceCount;
00241 }
00242
00243
00248 void CCountSession::NumResourcesL(const RMessage2& aMessage)
00249 {
00250 TPckgBuf<TInt> resourcesPckg(iResourceCount);
00251 aMessage.WriteL(0,resourcesPckg);
00252 }
00253
00254
00258 void CCountSession::PanicClient(const RMessage2& aMessage,TInt aPanic) const
00259 {
00260 _LIT(KTxtServer,"CountServ server");
00261 aMessage.Panic(KTxtServer,aPanic);
00262 }
00263