locationcentre/lcserver/src/lcserversession.cpp
branchRCL_3
changeset 16 4721bd00d3da
parent 14 3a25f69541ff
child 21 e15b7f06eba6
equal deleted inserted replaced
14:3a25f69541ff 16:4721bd00d3da
     1 /*
       
     2 * Copyright (c) 2007 Nokia Corporation and/or its subsidiary(-ies). 
       
     3 * All rights reserved.
       
     4 * This component and the accompanying materials are made available
       
     5 * under the terms of "Eclipse Public License v1.0"
       
     6 * which accompanies this distribution, and is available
       
     7 * at the URL "http://www.eclipse.org/legal/epl-v10.html".
       
     8 *
       
     9 * Initial Contributors:
       
    10 * Nokia Corporation - initial contribution.
       
    11 *
       
    12 * Contributors:
       
    13 *
       
    14 * Description:  Location Centre Server side session object.
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 // SYSTEM INCLUDES
       
    20 #include <s32mem.h>
       
    21 
       
    22 // USER INCLUDES
       
    23 #include "lcserversession.h"
       
    24 #include "lcserver.h"
       
    25 #include "lcipcparams.h"
       
    26 #include "lcserverinterface.h"
       
    27 #include "lcserverengine.h"
       
    28 #include "lcdebug.h"
       
    29 
       
    30 // ----- Member funtions for CLcServerSession ---------------------------------
       
    31 
       
    32 // ---------------------------------------------------------------------------
       
    33 // CLcServerSession::CLcServerSession
       
    34 // ---------------------------------------------------------------------------
       
    35 //
       
    36 CLcServerSession::CLcServerSession( CLcServer&        aLcServer,
       
    37                                     CLcServerEngine&  aLcServerEngine )
       
    38     :iLcServer( aLcServer ),
       
    39     iEngine( aLcServerEngine )
       
    40     {
       
    41     // C++ Default constructor. No allocations or functions which can Leave
       
    42     // should be called from here.
       
    43     }
       
    44          
       
    45 // ---------------------------------------------------------------------------
       
    46 // CLcServerSession::~CLcServerSession
       
    47 // ---------------------------------------------------------------------------
       
    48 //
       
    49 CLcServerSession::~CLcServerSession()
       
    50     {
       
    51     // C++ Destructor. Free all resources associated with this class.
       
    52     
       
    53     // Complete the Observer method with KErrServerTerminated if it exists
       
    54     if ( iNotificationOutStanding )
       
    55         {
       
    56         iObserverMessage.Complete( KErrServerTerminated );
       
    57         }
       
    58         
       
    59     // Decrement the count only if it has been incremented in the Construction
       
    60     if( iDecrementSession )
       
    61         {
       
    62         iLcServer.DecrementSessions();
       
    63         }
       
    64     }
       
    65         
       
    66 // ---------------------------------------------------------------------------
       
    67 // CLcServerSession* CLcServerSession::NewL
       
    68 // ---------------------------------------------------------------------------
       
    69 //
       
    70 CLcServerSession* CLcServerSession::NewL( CLcServer&        aLcServer,
       
    71                                           CLcServerEngine&  aLcServerEngine )
       
    72     {
       
    73     CLcServerSession* self = NewLC( aLcServer, aLcServerEngine );
       
    74     CleanupStack::Pop( self );
       
    75     return self;         
       
    76     }
       
    77 
       
    78 // ---------------------------------------------------------------------------
       
    79 // CLcServerSession* CLcServerSession::NewLC
       
    80 // ---------------------------------------------------------------------------
       
    81 //
       
    82 CLcServerSession* CLcServerSession::NewLC( CLcServer&        aLcServer,
       
    83                                            CLcServerEngine&  aLcServerEngine )
       
    84     {
       
    85     // Symbian Two phased constructor. Leaves the object on the Clean-up
       
    86     // stack.
       
    87     CLcServerSession* self = 
       
    88                         new ( ELeave )CLcServerSession( aLcServer,
       
    89                                                         aLcServerEngine );
       
    90     CleanupStack::PushL( self );
       
    91     self->ConstructL();
       
    92     return self;         
       
    93     }
       
    94 
       
    95 // ---------------------------------------------------------------------------
       
    96 // void CLcService::ConstructL
       
    97 // ---------------------------------------------------------------------------
       
    98 //
       
    99 void CLcServerSession::ConstructL()
       
   100     {
       
   101     
       
   102     // Increment the server's increment session routine.
       
   103     iLcServer.IncrementSessions();
       
   104   
       
   105     // Set the flag to mark that the number of sessions have been incremented.
       
   106     // This flag is set at the end of the contruction process to ensure that
       
   107     // we dont decrement the count in the destructor unless we have actually
       
   108     // incremented it. This is necessary because there is a possibility that
       
   109     // the ConstructL leaves before incrementing the count.
       
   110     iDecrementSession = ETrue;    
       
   111     }  
       
   112 
       
   113 // ---------------------------------------------------------------------------
       
   114 // void CLcServerSession::RegistryUpdated
       
   115 // ---------------------------------------------------------------------------
       
   116 //
       
   117 void CLcServerSession::RegistryUpdated()
       
   118     {
       
   119     DEBUG( "+ CLcServerSession::RegistryUpdated")
       
   120     
       
   121     // If the Observer has been set, then complete the Observer
       
   122     // request with KErrNone.
       
   123     if ( iNotificationOutStanding )
       
   124         {
       
   125         DEBUG3("Notify Client", 0, 0, 0 );
       
   126         
       
   127         iObserverMessage.Complete( KErrNone );
       
   128         }
       
   129     else
       
   130         {
       
   131         DEBUG3("Notify Lost", 0, 0, 0 );
       
   132         iNotifyPending = ETrue;
       
   133         }        
       
   134     iNotificationOutStanding = EFalse;
       
   135     
       
   136     DEBUG( "- CLcServerSession::RegistryUpdated")
       
   137     }
       
   138     
       
   139 // ---------------------------------------------------------------------------
       
   140 // void CLcServerSession::ServiceL
       
   141 // ---------------------------------------------------------------------------
       
   142 //
       
   143 void CLcServerSession::ServiceL( const RMessage2& aMessage )
       
   144     {
       
   145     DEBUG( "+ CLcServerSession::ServiceL")
       
   146     
       
   147     switch( aMessage.Function())
       
   148         {
       
   149         case ERegisterObserver:
       
   150             {
       
   151             DEBUG( "Message : ERegisterObserver")
       
   152             
       
   153             // If an Observer message exists then this is a Duplicate request
       
   154             // which is not accepted.
       
   155             if ( iNotificationOutStanding )
       
   156                 {
       
   157                 DEBUG3("Notify Already there", 0, 0, 0 );
       
   158                 aMessage.Complete( KErrAlreadyExists );
       
   159                 }
       
   160             else if ( iNotifyPending )
       
   161                 {
       
   162                 DEBUG3("Notify Immediately", 0, 0, 0 );
       
   163                 aMessage.Complete( KErrNone );
       
   164                 iNotifyPending = EFalse;
       
   165                 }
       
   166             else
       
   167                 {
       
   168                 DEBUG3("Notify Later", 0, 0, 0 );
       
   169                 // The Client application has requested for an Observer to
       
   170                 // notify about any changes to the Location Centre Registry.
       
   171                 // Store the message object.
       
   172                 iObserverMessage = aMessage;
       
   173                 iNotificationOutStanding = ETrue;                
       
   174                 }            
       
   175             break;
       
   176             }
       
   177         case ERemoveObserver:
       
   178             {
       
   179             DEBUG( "Message : ERemoveObserver")
       
   180                                 	
       
   181             // If the Observer has been set, then complete the Observer
       
   182             // request with KErrCancel.
       
   183             if ( iNotificationOutStanding )
       
   184                 {
       
   185                 iObserverMessage.Complete( KErrCancel );
       
   186                 }
       
   187             iNotificationOutStanding = EFalse;
       
   188 
       
   189             // Complete the current request with KErrNone
       
   190             aMessage.Complete( KErrNone );
       
   191             
       
   192             break;
       
   193             }
       
   194         case ELcFilteredAppsBufferLength:
       
   195         case ELcFilteredApps:
       
   196         case ELcSpecifiedAppsBufferLength:
       
   197         case ELcSpecifiedApps:
       
   198         case ELcAppInfoLength:
       
   199         case ELcAppInfo:
       
   200             {
       
   201             TInt desLength = aMessage.GetDesLength( 0 );
       
   202             if ( desLength < KErrNone )
       
   203                 {
       
   204                 User::Leave( desLength );
       
   205                 }
       
   206              
       
   207             if ( desLength >= KMaxTInt/2 )
       
   208                 {
       
   209                 User::Leave( KErrArgument );
       
   210                 }
       
   211                 
       
   212             // These messages are not handled here but only in the Engine
       
   213             // class. Hence, pass it onto the Engine class for handling.
       
   214             iEngine.DoServiceL( aMessage );   
       
   215             break;
       
   216             }
       
   217         default:
       
   218             {
       
   219             aMessage.Complete( KErrNotSupported );
       
   220             }
       
   221         }
       
   222         
       
   223     DEBUG( "- CLcServerSession::ServiceL")
       
   224     }
       
   225 
       
   226 // ---------------------------------------------------------------------------
       
   227 // void CLcServerSession::ServiceError
       
   228 // ---------------------------------------------------------------------------
       
   229 //
       
   230 void CLcServerSession::ServiceError( const RMessage2& aMessage, 
       
   231                                            TInt       aError )
       
   232     {
       
   233     DEBUG( "+ CLcServerSession::ServiceError")
       
   234     
       
   235     aMessage.Complete( aError );
       
   236     
       
   237     DEBUG( "- CLcServerSession::ServiceError")
       
   238     }
       
   239                                                                                              
       
   240 // End of File