00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00022 #include "secureclientandserver.h"
00023 #include "secureserver.h"
00024
00028 CSecureServerSession::CSecureServerSession()
00029 {
00030 }
00031
00035 void CSecureServerSession::CreateL()
00036 {
00037 iCountersObjectIndex = CObjectIx::NewL();
00038 iContainer=((CSecureServer*)Server())->NewContainerL();
00039 }
00040
00045 void CSecureServerSession::CloseSession()
00046 {
00047 delete iCountersObjectIndex;
00048 iCountersObjectIndex = NULL;
00049 ((CSecureServer*)Server())->RemoveContainer(iContainer);
00050 iContainer = NULL;
00051 }
00052
00059 CSecureServerSubSession* CSecureServerSession::CounterFromHandle(const RMessage2& aMessage,TInt aHandle)
00060 {
00061 CSecureServerSubSession* counter = (CSecureServerSubSession*)iCountersObjectIndex->At(aHandle);
00062 if (counter == NULL)
00063 {
00064 PanicClient(aMessage, EBadSubsessionHandle);
00065 }
00066 return counter;
00067 }
00068
00077 void CSecureServerSession::ServiceL(const RMessage2& aMessage)
00078 {
00079
00080 switch (aMessage.Function())
00081 {
00082 case ESecureServerCreateSubSession:
00083 NewCounterL(aMessage);
00084 aMessage.Complete(KErrNone);
00085 return;
00086 case ESecureServerCloseSession:
00087 CloseSession();
00088 aMessage.Complete(KErrNone);
00089 return;
00090 case ESecureServerResourceCount:
00091 NumResourcesL(aMessage);
00092 aMessage.Complete(KErrNone);
00093 return;
00094 }
00095
00096 CSecureServerSubSession* counter=CounterFromHandle(aMessage,aMessage.Int3());
00097 switch (aMessage.Function())
00098 {
00099 case ESecureServerInitSubSession:
00100 counter->SetFromStringL(aMessage);
00101 aMessage.Complete(KErrNone);
00102 return;
00103 case ESecureServerCloseSubSession:
00104 DeleteCounter(aMessage.Int3());
00105 aMessage.Complete(KErrNone);
00106 return;
00107 case ESecureServerIncrease:
00108 counter->Increase();
00109 aMessage.Complete(KErrNone);
00110 return;
00111 case ESecureServerIncreaseBy:
00112 counter->IncreaseBy(aMessage);
00113 aMessage.Complete(KErrNone);
00114 return;
00115 case ESecureServerDecrease:
00116 counter->Decrease();
00117 aMessage.Complete(KErrNone);
00118 return;
00119 case ESecureServerDecreaseBy:
00120 counter->DecreaseBy(aMessage);
00121 aMessage.Complete(KErrNone);
00122 return;
00123 case ESecureServerReset:
00124 counter->Reset();
00125 aMessage.Complete(KErrNone);
00126 return;
00127 case ESecureServerValue:
00128 counter->CounterValueL(aMessage);
00129 aMessage.Complete(KErrNone);
00130 return;
00131 case ESecureServerSaveCounter:
00132 counter->SaveCounterValueL();
00133 aMessage.Complete(KErrNone);
00134 return;
00135 case ESecureServerSetCounterFromFile:
00136 counter->SetCounterValueFromFileL();
00137 aMessage.Complete(KErrNone);
00138 return;
00139 default:
00140 PanicClient(aMessage,EBadRequest);
00141 return;
00142 }
00143 }
00144
00149 void CSecureServerSession::NewCounterL(const RMessage2& aMessage)
00150 {
00151
00152 CSecureServerSubSession* counter = new (ELeave) CSecureServerSubSession(this);
00153 iContainer->AddL(counter);
00154
00155 TInt handle=iCountersObjectIndex->AddL(counter);
00156 TPckgBuf<TInt> handlePckg(handle);
00157 TRAPD(res,aMessage.WriteL(3,handlePckg));
00158 if (res!=KErrNone)
00159 {
00160 iCountersObjectIndex->Remove(handle);
00161 PanicClient(aMessage,EDescriptorNonNumeric);
00162 return;
00163 }
00164
00165 iResourceCount++;
00166 }
00167
00172 void CSecureServerSession::DeleteCounter(TInt aHandle)
00173 {
00174 iCountersObjectIndex->Remove(aHandle);
00175
00176 iResourceCount --;
00177 }
00178
00183 TInt CSecureServerSession::CountResources()
00184 {
00185 return iResourceCount;
00186 }
00187
00192 void CSecureServerSession::NumResourcesL(const RMessage2& aMessage)
00193 {
00194 TPckgBuf<TInt> resourcesPckg(iResourceCount);
00195 aMessage.WriteL(0,resourcesPckg);
00196 }
00197
00203 void CSecureServerSession::PanicClient(const RMessage2& aMessage,TInt aPanic) const
00204 {
00205 _LIT(KTxtServer,"SecureServer");
00206 aMessage.Panic(KTxtServer,aPanic);
00207 }