examples/Base/IPC/secureserver/secureserverccountsession.cpp

Go to the documentation of this file.
00001 /*
00002 Copyright (c) 2008-2010 Nokia Corporation and/or its subsidiary(-ies). All rights reserved.
00003 
00004 Redistribution and use in source and binary forms, with or without
00005 modification, are permitted provided that the following conditions are met:
00006 
00007 * Redistributions of source code must retain the above copyright notice, this
00008   list of conditions and the following disclaimer.
00009 * Redistributions in binary form must reproduce the above copyright notice,
00010   this list of conditions and the following disclaimer in the documentation
00011   and/or other materials provided with the distribution.
00012 * Neither the name of Nokia Corporation nor the names of its contributors
00013   may be used to endorse or promote products derived from this software
00014   without specific prior written permission.
00015 
00016 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
00017 AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
00018 IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
00019 DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
00020 FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
00021 DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
00022 SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
00023 CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
00024 OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
00025 OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
00026 
00027 Description: Contains the implementation of functions described in the CSecureServerSession class.  
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         // Check if the message is intended to the parent session.
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         // Check if the message is intended to a sub session.
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         // Create a sub session object and add it to the container index.
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         // For every new sub session created, increase the resource count.
00178         iResourceCount++;
00179         }
00180 
00185 void CSecureServerSession::DeleteCounter(TInt aHandle)
00186         {
00187         iCountersObjectIndex->Remove(aHandle);
00188         // For every new sub session deleted, decrease the resource count.
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         }

Generated by  doxygen 1.6.2