diff -r f345bda72bc4 -r 43e37759235e Symbian3/Examples/guid-6013a680-57f9-415b-8851-c4fa63356636/secureserverccountsession_8cpp_source.html --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/Symbian3/Examples/guid-6013a680-57f9-415b-8851-c4fa63356636/secureserverccountsession_8cpp_source.html Tue Mar 30 16:16:55 2010 +0100 @@ -0,0 +1,175 @@ + + +
+ +00001 // Copyright (c) 2008-2009 Nokia Corporation and/or its subsidiary(-ies). +00002 // All rights reserved. +00003 // This component and the accompanying materials are made available +00004 // under the terms of "Eclipse Public License v1.0" +00005 // which accompanies this distribution, and is available +00006 // at the URL "http://www.eclipse.org/legal/epl-v10.html". +00007 // +00008 // Initial Contributors: +00009 // Nokia Corporation - initial contribution. +00010 // +00011 // Contributors: +00012 // +00013 // Description: +00014 // Contains the implementation of functions described in the CSecureServerSession class. +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 // Check if the message is intended to the parent session. +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 // Check if the message is intended to a sub session. +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 // Create a sub session object and add it to the container index. +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 // For every new sub session created, increase the resource count. +00165 iResourceCount++; +00166 } +00167 +00172 void CSecureServerSession::DeleteCounter(TInt aHandle) +00173 { +00174 iCountersObjectIndex->Remove(aHandle); +00175 // For every new sub session deleted, decrease the resource count. +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 } +