clock/clockengines/clockserver/server/src/clockserversession.cpp
changeset 18 c198609911f9
equal deleted inserted replaced
0:f979ecb2b13e 18:c198609911f9
       
     1 /*
       
     2 * Copyright (c) 2009 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:   The source file of the CClkSrvSession class.
       
    15 *
       
    16 */
       
    17 
       
    18 // System includes
       
    19 
       
    20 // User includes
       
    21 #include "clockserver.h"
       
    22 #include "clockserversession.h"
       
    23 #include "clockservercmds.h"
       
    24 #include "clockserverimpl.h"
       
    25 #include "clock_debug.h"
       
    26 #include "clocktimesourceinterface.hrh"
       
    27 
       
    28 // Constants
       
    29 const TInt KZerothArgument( 0 );
       
    30 const TInt KFirstArgument( 1 );
       
    31 
       
    32 // ---------------------------------------------------------
       
    33 // CClkSrvSession::CClkSrvSession
       
    34 // rest of the details are commented in the header
       
    35 // ---------------------------------------------------------
       
    36 //
       
    37 CClkSrvSession::CClkSrvSession( CClkSrvImpl* aClkSrvImpl ) : CSession2(), iClkSrvImpl( aClkSrvImpl )
       
    38 	{
       
    39 	__PRINTS( "CClkSrvSession::CClkSrvSession - Entry" );
       
    40 	
       
    41 	// No implementation yet
       
    42 	
       
    43 	__PRINTS( "CClkSrvSession::CClkSrvSession - Exit" );
       
    44 	}
       
    45 	
       
    46 // ---------------------------------------------------------
       
    47 // CClkSrvSession::~CClkSrvSession
       
    48 // rest of the details are commented in the header
       
    49 // ---------------------------------------------------------
       
    50 //
       
    51 CClkSrvSession::~CClkSrvSession()
       
    52 	{
       
    53 	__PRINTS( "CClkSrvSession::~CClkSrvSession - Entry" );
       
    54 	
       
    55 	if( NULL != iSessionLink.iNext )
       
    56         {
       
    57         iSessionLink.Deque();
       
    58         }
       
    59 
       
    60 	__PRINTS( "CClkSrvSession::~CClkSrvSession - Exit" );
       
    61 	
       
    62 	}
       
    63 	
       
    64 // ---------------------------------------------------------
       
    65 // CClkSrvSession::ServiceL
       
    66 // rest of the details are commented in the header
       
    67 // ---------------------------------------------------------
       
    68 //
       
    69 void CClkSrvSession::ServiceL( const RMessage2& aMessage )
       
    70 	{
       
    71 	__PRINTS( "CClkSrvSession::ServiceL - Entry" );
       
    72 	
       
    73 	TInt returnValue( KErrNone );
       
    74 	
       
    75 	iMessageComplete = ETrue;
       
    76 	
       
    77 	// Do the actual service
       
    78 	TRAPD( error, returnValue = DoServiceL( aMessage ) );
       
    79     
       
    80     if( iMessageComplete || ( KErrNone > error ) )
       
    81     	{
       
    82     	// Set the message as completed.
       
    83     	aMessage.Complete( ( error == KErrNone ) ? returnValue : error );
       
    84     	}
       
    85         
       
    86     __PRINTS( "CClkSrvSession::ServiceL - Exit" );
       
    87 	}
       
    88 	
       
    89 // ---------------------------------------------------------
       
    90 // CClkSrvSession::DoServiceL
       
    91 // rest of the details are commented in the header
       
    92 // ---------------------------------------------------------
       
    93 //
       
    94 TInt CClkSrvSession::DoServiceL( const RMessage2& aMessage )
       
    95 	{
       
    96 	__PRINTS( "CClkSrvSession::DoServiceL - Entry" );
       
    97 	
       
    98 	TInt returnValue( KErrNone );
       
    99 	
       
   100 	// Switch on the type of service request.
       
   101 	switch( aMessage.Function() )
       
   102         {
       
   103         case EClkSrvActivateProtocol:
       
   104         	{
       
   105         	returnValue = DoActivateProtocolL( aMessage );
       
   106         	}
       
   107             break;
       
   108             
       
   109         case EClkSrvIsProtocolActive:
       
   110         	{
       
   111 			returnValue = DoCheckProtocolActiveL( aMessage );
       
   112         	}
       
   113             break;
       
   114             
       
   115         case EClkSrvDeactivateProtocol:
       
   116         	{
       
   117         	returnValue = DoDeActivateProtocolL( aMessage );
       
   118         	}
       
   119             break;
       
   120             
       
   121         case EClkSrvGetProtocolInfo:
       
   122         	{
       
   123         	returnValue = DoGetProtocolInfoL( aMessage );
       
   124         	}
       
   125         	break;
       
   126         	
       
   127         case EClkSrvGetCurrentMcc:
       
   128         	{
       
   129         	returnValue = DoGetCurrentMccL( aMessage );
       
   130         	}
       
   131         	break;
       
   132         	
       
   133         case EClkSrvGetCurrentTimeZoneId:
       
   134         	{
       
   135         	returnValue = DoGetCurrentTimeZoneIdL( aMessage );
       
   136         	}
       
   137         	break;
       
   138         	
       
   139         case EClkSrvNotifyOnChange:
       
   140         	{
       
   141         	DoNotifyOnChange( aMessage );
       
   142         	}
       
   143         	break;
       
   144         	
       
   145         case EClkSrvCancelNotifyOnChange:
       
   146             {
       
   147         	NotifyAboutChange( EComponentNone, KErrNone, KErrCancel );
       
   148         	}
       
   149         	break;
       
   150         	
       
   151         case EClkSrvIsAutoTimeUpdadeOn:
       
   152             {
       
   153             returnValue = DoCheckAutoTimeUpdateOn( aMessage );
       
   154             }
       
   155             break;
       
   156         	
       
   157 		default:
       
   158 			{
       
   159 			returnValue = KErrNotSupported;
       
   160 			}         
       
   161 			break;
       
   162         }
       
   163     
       
   164 	__PRINTS( "CClkSrvSession::DoServiceL - Exit" );
       
   165 	
       
   166 	return returnValue;
       
   167 	}
       
   168 
       
   169 // ---------------------------------------------------------
       
   170 // CClkSrvSession::LinkOffset()
       
   171 // rest of the details are commented in the header
       
   172 // ---------------------------------------------------------
       
   173 //	
       
   174 TInt CClkSrvSession::LinkOffset()
       
   175 	{
       
   176 	__PRINTS( "CClkSrvSession::LinkOffset - Entry" );
       
   177 	
       
   178 	__PRINTS( "CClkSrvSession::LinkOffset - Exit" );
       
   179 	
       
   180 	return _FOFF( CClkSrvSession, iSessionLink );
       
   181 	}
       
   182 	
       
   183 // ---------------------------------------------------------
       
   184 // CClkSrvSession::DoActivateProtocol()
       
   185 // rest of the details are commented in the header
       
   186 // ---------------------------------------------------------
       
   187 //	
       
   188 TInt CClkSrvSession::DoActivateProtocolL( const RMessage2& /*aMessage*/ )
       
   189 	{
       
   190 	__PRINTS( "CClkSrvSession::DoActivateProtocolL - Entry" );
       
   191 	
       
   192 	// Activate all the protocols.
       
   193 	TInt returnVal = iClkSrvImpl->ActivateAllProtocolsL();
       
   194 	
       
   195 	__PRINTS( "CClkSrvSession::DoActivateProtocolL - Exit" );
       
   196 	
       
   197 	return returnVal;
       
   198 	}
       
   199 
       
   200 // ---------------------------------------------------------
       
   201 // CClkSrvSession::DoCheckProtocolActive()
       
   202 // rest of the details are commented in the header
       
   203 // ---------------------------------------------------------
       
   204 //	
       
   205 TInt CClkSrvSession::DoCheckProtocolActiveL( const RMessage2& aMessage )
       
   206 	{
       
   207 	__PRINTS( "CClkSrvSession::DoCheckProtocolActiveL - Entry" );
       
   208 	
       
   209 	TBool protocolActive( EFalse );
       
   210 	
       
   211 	// Check if protocol is active.
       
   212 	TInt returnVal = iClkSrvImpl->IsProtocolActive( protocolActive, aMessage.Int0() );
       
   213 	
       
   214 	if( KErrNone == returnVal )
       
   215 		{
       
   216 		TPckgBuf< TBool > packageBuf( protocolActive );
       
   217 		
       
   218 		// Return the value.
       
   219 		aMessage.WriteL( KFirstArgument, packageBuf, NULL );
       
   220 		}
       
   221 	
       
   222 	__PRINTS( "CClkSrvSession::DoCheckProtocolActiveL - Exit" );
       
   223 	
       
   224 	return returnVal;
       
   225 	}
       
   226 
       
   227 // ---------------------------------------------------------
       
   228 // CClkSrvSession::DoDeActivateProtocol()
       
   229 // rest of the details are commented in the header
       
   230 // ---------------------------------------------------------
       
   231 //	
       
   232 TInt CClkSrvSession::DoDeActivateProtocolL( const RMessage2& /*aMessage*/ )
       
   233 	{
       
   234 	__PRINTS( "CClkSrvSession::DoDeActivateProtocol - Entry" );
       
   235 	
       
   236 	// Deactivate all the protocols.
       
   237 	TInt returnVal = iClkSrvImpl->DeActivateAllProtocolsL();
       
   238 	
       
   239 	__PRINTS( "CClkSrvSession::DoDeActivateProtocol - Exit" );
       
   240 	
       
   241 	return returnVal;
       
   242 	}
       
   243 
       
   244 // ---------------------------------------------------------
       
   245 // CClkSrvSession::DoGetProtocolInfoL()
       
   246 // rest of the details are commented in the header
       
   247 // ---------------------------------------------------------
       
   248 //
       
   249 TInt CClkSrvSession::DoGetProtocolInfoL( const RMessage2& aMessage )
       
   250 	{
       
   251 	__PRINTS( "CClkSrvSession::DoGetProtocolInfoL - Entry" );
       
   252 	
       
   253 	STimeAttributes timeInformation;
       
   254 		
       
   255 	// Ask the implementation for the time information.
       
   256 	TInt returnVal = iClkSrvImpl->GetProtocolInformationL( timeInformation );
       
   257 
       
   258 	if( KErrNone == returnVal )
       
   259 		{
       
   260 		TPckg< STimeAttributes > packageBuf( timeInformation );
       
   261 
       
   262 		// Write the result.
       
   263 		aMessage.WriteL( KFirstArgument, packageBuf, NULL );
       
   264 		}
       
   265 	
       
   266 	__PRINTS( "CClkSrvSession::DoGetProtocolInfoL - Exit" );
       
   267 	
       
   268 	return returnVal;
       
   269 	}
       
   270 
       
   271 // ---------------------------------------------------------
       
   272 // CClkSrvSession::DoGetCurrentMccL()
       
   273 // rest of the details are commented in the header
       
   274 // ---------------------------------------------------------
       
   275 //
       
   276 TInt CClkSrvSession::DoGetCurrentMccL( const RMessage2& aMessage )
       
   277 	{
       
   278 	__PRINTS( "CClkSrvSession::DoGetCurrentMccL - Entry" );
       
   279 	
       
   280 	TInt currentMcc( 0 ); 
       
   281 	
       
   282 	// Ask the implementation for the mcc.
       
   283 	TInt returnVal = iClkSrvImpl->GetCurrentMccL( currentMcc );
       
   284 	
       
   285 	if( KErrNone == returnVal )
       
   286 		{
       
   287 		TPckg< TInt > packageBuf( currentMcc );
       
   288 		
       
   289 		// Write the result
       
   290 		aMessage.WriteL( KZerothArgument, packageBuf, NULL );
       
   291 		}
       
   292 	
       
   293 	__PRINTS( "CClkSrvSession::DoGetCurrentMccL - Exit" );
       
   294 	
       
   295 	return returnVal;
       
   296 	}
       
   297 
       
   298 // ---------------------------------------------------------
       
   299 // CClkSrvSession::DoGetCurrentMccL()
       
   300 // rest of the details are commented in the header
       
   301 // ---------------------------------------------------------
       
   302 //
       
   303 TInt CClkSrvSession::DoGetCurrentTimeZoneIdL( const RMessage2& aMessage )
       
   304 	{
       
   305 	__PRINTS( "CClkSrvSession::DoGetCurrentTimeZoneIdL - Entry" );
       
   306 	
       
   307 	TInt currentTimeZoneId( -1 );
       
   308 	
       
   309 	TInt returnVal = iClkSrvImpl->GetCurrentTimeZoneIdL( currentTimeZoneId );
       
   310 	
       
   311 	__PRINT( "currentTimeZoneId in DoGetCurrentTimeZoneIdL : %d", currentTimeZoneId );
       
   312 	
       
   313 	if( KErrNone == returnVal )
       
   314 		{
       
   315 		TPckg< TInt > packageBuf( currentTimeZoneId );
       
   316 		
       
   317 		// Write the result
       
   318 		aMessage.WriteL( KZerothArgument, packageBuf, NULL );
       
   319 		}
       
   320 	
       
   321 	__PRINTS( "CClkSrvSession::DoGetCurrentTimeZoneIdL - Exit" );
       
   322 	
       
   323 	return returnVal;
       
   324 	}
       
   325 
       
   326 // ---------------------------------------------------------
       
   327 // CClkSrvSession::DoNotifyOnChange()
       
   328 // rest of the details are commented in the header
       
   329 // ---------------------------------------------------------
       
   330 //	
       
   331 void CClkSrvSession::DoNotifyOnChange( const RMessage2& aMessage )
       
   332 	{
       
   333 	__PRINTS( "CClkSrvSession::DoNotifyOnChange - Entry" );
       
   334 	
       
   335 	// First store the message for notification later.
       
   336 	SetNotifyMessagePtr( aMessage );
       
   337 	
       
   338 	if( FirstNotifyRequest() )
       
   339         {
       
   340         NotifyAboutChange( EComponentNone, 0, KErrNone );
       
   341         }
       
   342         
       
   343     iMessageComplete = EFalse;
       
   344 	
       
   345 	__PRINTS( "CClkSrvSession::DoNotifyOnChange - Exit" );
       
   346 	}
       
   347 
       
   348 // ---------------------------------------------------------
       
   349 // CClkSrvSession::DoCheckAutoTimeUpdateOn
       
   350 // rest of the details are commented in the header
       
   351 // ---------------------------------------------------------
       
   352 //  
       
   353 TInt CClkSrvSession::DoCheckAutoTimeUpdateOn( const RMessage2& aMessage )
       
   354     {
       
   355     __PRINTS( "CClkSrvSession::DoCheckAutoTimeUpdateOn - Entry" );
       
   356         
       
   357     TBool autoTimeUpdateOn( EFalse );
       
   358 
       
   359     // Check if any protocol is active.
       
   360     TInt returnVal = iClkSrvImpl->IsAutoTimeUpdateOn( autoTimeUpdateOn );
       
   361 
       
   362     if( KErrNone == returnVal )
       
   363         {
       
   364         TPckgBuf< TBool > packageBuf( autoTimeUpdateOn );
       
   365 
       
   366         // Return the value.
       
   367         aMessage.WriteL( KZerothArgument, packageBuf, NULL );
       
   368         }
       
   369 
       
   370     __PRINTS( "CClkSrvSession::DoCheckAutoTimeUpdateOn - Exit" );
       
   371 
       
   372     return returnVal;
       
   373     }
       
   374 	
       
   375 // ---------------------------------------------------------
       
   376 // CClkSrvSession::SetNotifyMessagePtr()
       
   377 // rest of the details are commented in the header
       
   378 // ---------------------------------------------------------
       
   379 //
       
   380 void CClkSrvSession::SetNotifyMessagePtr( const RMessage2& aMessage )
       
   381     {
       
   382     __PRINTS( "CClkSrvSession::SetNotifyMessagePtr - Entry" );
       
   383     
       
   384     // __ASSERT_ALWAYS( NotifyPending() == EFalse, PanicClient( aMessage, ENitzMdlNotifyPending ) );
       
   385     
       
   386     // Store the message for notifying later.
       
   387     iNotifyChangeMsg = aMessage;
       
   388     
       
   389     // Reset the flags.
       
   390     iMsgPendingFlags = 0;
       
   391     // Change the state to msg pending.
       
   392     iMsgPendingFlags |= ENotifyMsgPending;
       
   393     
       
   394     __PRINTS( "CClkSrvSession::SetNotifyMessagePtr - Exit" );
       
   395     }	
       
   396 	
       
   397 // ---------------------------------------------------------
       
   398 // CClkSrvSession::NotifyAboutChange()
       
   399 // rest of the details are commented in the header
       
   400 // ---------------------------------------------------------
       
   401 //
       
   402 void CClkSrvSession::NotifyAboutChange( TInt32 aWhatChanged, TInt32 aWhoChanged, TInt aNotification )
       
   403     {
       
   404     __PRINTS( "CClkSrvSession::NotifyAboutChange - Entry" );
       
   405     
       
   406     if( NotifyPending() )
       
   407         {
       
   408         __PRINTS( "CClkSrvSession::NotifyAboutChange - Notification was pending" );
       
   409         
       
   410         // Reset the flags.
       
   411         iMsgPendingFlags &= ~( ENotifyMsgPending );
       
   412         
       
   413         TPckg< TInt32 > whatChangedPkg( aWhatChanged );
       
   414         TPckg< TInt32 > whoChangedPkg( aWhoChanged );
       
   415         
       
   416         // Write the result
       
   417         TRAP_IGNORE( iNotifyChangeMsg.WriteL( KZerothArgument, whatChangedPkg ) );
       
   418         
       
   419         __PRINTS( "CClkSrvSession::NotifyAboutChange - 0th WriteL didn't leave" );
       
   420         
       
   421         TRAP_IGNORE( iNotifyChangeMsg.WriteL( KFirstArgument, whoChangedPkg ) );
       
   422         
       
   423         __PRINTS( "CClkSrvSession::NotifyAboutChange - 1st WriteL didn't leave" );
       
   424         
       
   425         // Mark the message as complete.
       
   426         iNotifyChangeMsg.Complete( aNotification );
       
   427         }
       
   428     
       
   429     __PRINTS( "CClkSrvSession::NotifyAboutChange - Notification was not pending" );
       
   430     
       
   431     __PRINTS( "CClkSrvSession::NotifyAboutChange - Exit" );
       
   432     }
       
   433 
       
   434 // ---------------------------------------------------------
       
   435 // CClkSrvSession::FirstNotifyRequest()
       
   436 // rest of the details are commented in the header
       
   437 // ---------------------------------------------------------
       
   438 //
       
   439 TBool CClkSrvSession::FirstNotifyRequest() const
       
   440     {
       
   441     __PRINTS( "CClkSrvSession::FirstNotifyRequest - Entry" );
       
   442     
       
   443     __PRINTS( "CClkSrvSession::FirstNotifyRequest - Exit" );
       
   444     
       
   445     return ( iMsgPendingFlags & EFirstChangeMsg );
       
   446     }
       
   447 
       
   448 // ---------------------------------------------------------
       
   449 // CClkSrvSession::FirstNotifyRequest()
       
   450 // rest of the details are commented in the header
       
   451 // ---------------------------------------------------------
       
   452 //
       
   453 TBool CClkSrvSession::NotifyPending() const
       
   454     {
       
   455     __PRINTS( "CClkSrvSession::NotifyPending - Entry" );
       
   456     
       
   457     __PRINT( "Notification Pending?: %d", iMsgPendingFlags & ENotifyMsgPending );
       
   458     
       
   459     __PRINTS( "CClkSrvSession::NotifyPending - Exit" );
       
   460     
       
   461     return ( iMsgPendingFlags & ENotifyMsgPending );
       
   462     }
       
   463     	
       
   464 // End of file