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
00035 #include "secureclientandserver.h"
00036 #include "secureserver.h"
00037
00041 CSecureServerSession::CSecureServerSession()
00042 {
00043 }
00044
00048 void CSecureServerSession::CreateL()
00049 {
00050 iCountersObjectIndex = CObjectIx::NewL();
00051 iContainer=((CSecureServer*)Server())->NewContainerL();
00052 }
00053
00058 void CSecureServerSession::CloseSession()
00059 {
00060 delete iCountersObjectIndex;
00061 iCountersObjectIndex = NULL;
00062 ((CSecureServer*)Server())->RemoveContainer(iContainer);
00063 iContainer = NULL;
00064 }
00065
00072 CSecureServerSubSession* CSecureServerSession::CounterFromHandle(const RMessage2& aMessage,TInt aHandle)
00073 {
00074 CSecureServerSubSession* counter = (CSecureServerSubSession*)iCountersObjectIndex->At(aHandle);
00075 if (counter == NULL)
00076 {
00077 PanicClient(aMessage, EBadSubsessionHandle);
00078 }
00079 return counter;
00080 }
00081
00090 void CSecureServerSession::ServiceL(const RMessage2& aMessage)
00091 {
00092
00093 switch (aMessage.Function())
00094 {
00095 case ESecureServerCreateSubSession:
00096 NewCounterL(aMessage);
00097 aMessage.Complete(KErrNone);
00098 return;
00099 case ESecureServerCloseSession:
00100 CloseSession();
00101 aMessage.Complete(KErrNone);
00102 return;
00103 case ESecureServerResourceCount:
00104 NumResourcesL(aMessage);
00105 aMessage.Complete(KErrNone);
00106 return;
00107 }
00108
00109 CSecureServerSubSession* counter=CounterFromHandle(aMessage,aMessage.Int3());
00110 switch (aMessage.Function())
00111 {
00112 case ESecureServerInitSubSession:
00113 counter->SetFromStringL(aMessage);
00114 aMessage.Complete(KErrNone);
00115 return;
00116 case ESecureServerCloseSubSession:
00117 DeleteCounter(aMessage.Int3());
00118 aMessage.Complete(KErrNone);
00119 return;
00120 case ESecureServerIncrease:
00121 counter->Increase();
00122 aMessage.Complete(KErrNone);
00123 return;
00124 case ESecureServerIncreaseBy:
00125 counter->IncreaseBy(aMessage);
00126 aMessage.Complete(KErrNone);
00127 return;
00128 case ESecureServerDecrease:
00129 counter->Decrease();
00130 aMessage.Complete(KErrNone);
00131 return;
00132 case ESecureServerDecreaseBy:
00133 counter->DecreaseBy(aMessage);
00134 aMessage.Complete(KErrNone);
00135 return;
00136 case ESecureServerReset:
00137 counter->Reset();
00138 aMessage.Complete(KErrNone);
00139 return;
00140 case ESecureServerValue:
00141 counter->CounterValueL(aMessage);
00142 aMessage.Complete(KErrNone);
00143 return;
00144 case ESecureServerSaveCounter:
00145 counter->SaveCounterValueL();
00146 aMessage.Complete(KErrNone);
00147 return;
00148 case ESecureServerSetCounterFromFile:
00149 counter->SetCounterValueFromFileL();
00150 aMessage.Complete(KErrNone);
00151 return;
00152 default:
00153 PanicClient(aMessage,EBadRequest);
00154 return;
00155 }
00156 }
00157
00162 void CSecureServerSession::NewCounterL(const RMessage2& aMessage)
00163 {
00164
00165 CSecureServerSubSession* counter = new (ELeave) CSecureServerSubSession(this);
00166 iContainer->AddL(counter);
00167
00168 TInt handle=iCountersObjectIndex->AddL(counter);
00169 TPckgBuf<TInt> handlePckg(handle);
00170 TRAPD(res,aMessage.WriteL(3,handlePckg));
00171 if (res!=KErrNone)
00172 {
00173 iCountersObjectIndex->Remove(handle);
00174 PanicClient(aMessage,EDescriptorNonNumeric);
00175 return;
00176 }
00177
00178 iResourceCount++;
00179 }
00180
00185 void CSecureServerSession::DeleteCounter(TInt aHandle)
00186 {
00187 iCountersObjectIndex->Remove(aHandle);
00188
00189 iResourceCount --;
00190 }
00191
00196 TInt CSecureServerSession::CountResources()
00197 {
00198 return iResourceCount;
00199 }
00200
00205 void CSecureServerSession::NumResourcesL(const RMessage2& aMessage)
00206 {
00207 TPckgBuf<TInt> resourcesPckg(iResourceCount);
00208 aMessage.WriteL(0,resourcesPckg);
00209 }
00210
00216 void CSecureServerSession::PanicClient(const RMessage2& aMessage,TInt aPanic) const
00217 {
00218 _LIT(KTxtServer,"SecureServer");
00219 aMessage.Panic(KTxtServer,aPanic);
00220 }