imstutils/imconversationview/imcvuiengine/src/cimcvenginecontextobserver.cpp
branchRCL_3
changeset 28 3104fc151679
parent 27 2b7283837edb
child 29 9a48e301e94b
equal deleted inserted replaced
27:2b7283837edb 28:3104fc151679
     1 /*
       
     2 * Copyright (c) 2007-2008 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:  single context observer implementation
       
    15 *
       
    16 */
       
    17 
       
    18 #include "cimcvenginecontextobserver.h"
       
    19 
       
    20 #include <ximpidentity.h>
       
    21 #include <ximpstatus.h>
       
    22 #include <ximpcontextstateevent.h>
       
    23 #include <ximprequestcompleteevent.h>
       
    24 #include <presentitypresenceevent.h>
       
    25 #include <presentitygrouplistevent.h>
       
    26 #include <presentitygroupinfo.h>
       
    27 #include <presentitygroupcontentevent.h>
       
    28 #include <presentitygroupmemberinfo.h>
       
    29 #include <ximpcontextstate.h>
       
    30 #include "imcvuiliterals.h"
       
    31 #include "mimcvenginenewmessagehandler.h"
       
    32 #include "imcvlogger.h"
       
    33 #include <imerrors.hrh>
       
    34 // ============================ MEMBER FUNCTIONS ==============================
       
    35 
       
    36 // ---------------------------------------------------------
       
    37 // CIMCVEngineContextObserver::NewL
       
    38 // two phase construction
       
    39 // ---------------------------------------------------------
       
    40 CIMCVEngineContextObserver* CIMCVEngineContextObserver::NewL()
       
    41     {
       
    42     IM_CV_LOGS(TXT("CIMCVEngineContextObserver::NewL() start") );
       
    43     CIMCVEngineContextObserver* self = 
       
    44     					CIMCVEngineContextObserver::NewLC();
       
    45     CleanupStack::Pop( self );
       
    46     IM_CV_LOGS(TXT("CIMCVEngineContextObserver::NewL() end") );
       
    47     return self;
       
    48     }
       
    49 
       
    50 // ---------------------------------------------------------
       
    51 // CIMCVEngineContextObserver::NewLC
       
    52 // two phase construction
       
    53 // ---------------------------------------------------------
       
    54 CIMCVEngineContextObserver* CIMCVEngineContextObserver::NewLC()
       
    55     {
       
    56     IM_CV_LOGS(TXT("CIMCVEngineContextObserver::NewLC() start") );
       
    57     CIMCVEngineContextObserver* self = new 
       
    58     					(ELeave) CIMCVEngineContextObserver();
       
    59     CleanupStack::PushL( self );
       
    60     self->ConstructL();
       
    61     IM_CV_LOGS(TXT("CIMCVEngineContextObserver::NewLC() end") );
       
    62     return self;
       
    63     }
       
    64 
       
    65 // ---------------------------------------------------------
       
    66 // CIMCVEngineContextObserver::ConstructL
       
    67 // two phase construction
       
    68 // ---------------------------------------------------------    
       
    69 void CIMCVEngineContextObserver::ConstructL()
       
    70 	{
       
    71 	}
       
    72 
       
    73 // ---------------------------------------------------------
       
    74 // CIMCVEngineContextObserver::~CIMCVEngineContextObserver
       
    75 // destructor
       
    76 // ---------------------------------------------------------
       
    77 CIMCVEngineContextObserver::~CIMCVEngineContextObserver()
       
    78     {
       
    79     IM_CV_LOGS(TXT("CIMCVEngineContextObserver::~CIMCVEngineContextObserver() start") );
       
    80      if(iWait.IsStarted() )
       
    81 	    {
       
    82 	    iWait.AsyncStop();	
       
    83 	    }
       
    84 	IM_CV_LOGS(TXT("CIMCVEngineContextObserver::~CIMCVEngineContextObserver() end") );
       
    85     }
       
    86 
       
    87 // ---------------------------------------------------------
       
    88 // CIMCVEngineContextObserver::CIMCVEngineContextObserver
       
    89 // ---------------------------------------------------------
       
    90 CIMCVEngineContextObserver::CIMCVEngineContextObserver() :
       
    91 iCurrentReqType(EReqUnknown)
       
    92     {
       
    93     IM_CV_LOGS(TXT("CIMCVEngineContextObserver::CIMCVEngineContextObserver() start") );
       
    94     IM_CV_LOGS(TXT("CIMCVEngineContextObserver::CIMCVEngineContextObserver() end") );
       
    95     }
       
    96 
       
    97 // ===========================================================================
       
    98 // FROM MPRFWximpCONTEXTOBSERVER
       
    99 // ===========================================================================
       
   100 //
       
   101 // ---------------------------------------------------------
       
   102 // CIMCVEngineContextObserver::HandleximpContextEvent
       
   103 // ---------------------------------------------------------
       
   104 void CIMCVEngineContextObserver::HandlePresenceContextEvent( 
       
   105     const MXIMPContext& /*aContext*/,
       
   106     const MXIMPBase& aEvent )
       
   107     {
       
   108   	IM_CV_LOGS(TXT("CIMCVEngineContextObserver::HandlePresenceContextEvent() start") );
       
   109     const TInt32 eventType = aEvent.GetInterfaceId();
       
   110     
       
   111     switch( eventType )
       
   112         {
       
   113         case MXIMPRequestCompleteEvent::KInterfaceId:
       
   114 			{
       
   115             const MXIMPRequestCompleteEvent* event =
       
   116                 TXIMPGetInterface< const MXIMPRequestCompleteEvent >::From( aEvent, MXIMPBase::EPanicIfUnknown );
       
   117 
       
   118             TXIMPRequestId reqId = event->RequestId();
       
   119             
       
   120             const MXIMPStatus& status = event->CompletionResult();
       
   121 			
       
   122             TInt err = status.ResultCode();
       
   123             //Login request has been issued            
       
   124             if ((iCurrentXIMPReq == reqId) && (ELoginReq == iCurrentReqType))
       
   125 	            {
       
   126 				//Login is an synchronous call	            
       
   127 	            if ( iWait.IsStarted() )
       
   128 					{
       
   129 					iWait.AsyncStop();	
       
   130 					}
       
   131 				if(KErrNone == err )
       
   132 	                {	                
       
   133 	                iLoggedIn = ETrue;	                		                
       
   134 	                }
       
   135                 else
       
   136 	                {	                
       
   137 	                iLoggedIn = EFalse;	                
       
   138 	                } 	            
       
   139 				
       
   140 				iCurrentReqType = EReqUnknown;	
       
   141 				if(iSessionObserver)
       
   142 					{
       
   143 					TRAP_IGNORE( iSessionObserver->HandleConnectionEventL( ELoggedIn, KErrNone ) );  				
       
   144 					}				                	
       
   145 	            }
       
   146 	        //Logout request has been issued    
       
   147 			else if ((iCurrentXIMPReq == reqId) && (ELogoutReq == iCurrentReqType))  
       
   148 				{
       
   149 				//Login is an synchronous call	            
       
   150 	            if ( iWait.IsStarted() )
       
   151 					{
       
   152 					iWait.AsyncStop();	
       
   153 					}
       
   154 				iLoggedIn = EFalse;	
       
   155 				iCurrentReqType = EReqUnknown;	
       
   156 				if(iSessionObserver)
       
   157 					{
       
   158 					TRAP_IGNORE( iSessionObserver->HandleConnectionEventL(ELoggedOut, KErrNone ) );  				
       
   159 					}			
       
   160 				}
       
   161 			//SendMessage request has been issued	
       
   162 			else
       
   163 				{
       
   164 				// for message delivery report
       
   165 			    if( iSessionObserver && iLoggedIn )
       
   166 				    {
       
   167 				    TRAP_IGNORE( iSessionObserver->HandleDeliveryReportL(reqId, status.ResultCode() ) );	
       
   168 				    }	
       
   169 				}
       
   170             break;
       
   171             }
       
   172             
       
   173         case MXIMPContextStateEvent::KInterfaceId:
       
   174         	{        	
       
   175         	// what do we do with context state event
       
   176         	// state of the context can be associated with the 
       
   177         	const MXIMPContextStateEvent* ctxtStateEvent = 
       
   178             TXIMPGetInterface< const MXIMPContextStateEvent >::From( aEvent, 
       
   179                                                                      MXIMPBase::EPanicIfUnknown );
       
   180             const MXIMPStatus* fwStatus = ctxtStateEvent->StateChangeReason();
       
   181             const MXIMPContextState& cState = ctxtStateEvent->ContextState();
       
   182             MXIMPContextState::TState state = cState.ContextState();          
       
   183             
       
   184             if (MXIMPContextState::EInactive == state  )
       
   185 				{
       
   186 				//No request of Login/Logout has been issued by CV
       
   187 				//Hence this might be a server initiated disconnect
       
   188 				//handle properly
       
   189 			 	if( (iSessionObserver) && (EReqUnknown == iCurrentReqType) )
       
   190 					{
       
   191 					TRAP_IGNORE( iSessionObserver->HandleConnectionEventL(EForcedLoggedOut, KImErrServiceForceClosedSession ) );  
       
   192 					}
       
   193 			
       
   194 				}
       
   195              break;
       
   196         	}
       
   197        default:
       
   198         	{
       
   199         		
       
   200         	break;
       
   201 			}
       
   202         }
       
   203     IM_CV_LOGS(TXT("CIMCVEngineContextObserver::HandlePresenceContextEvent() end") );
       
   204     }
       
   205     
       
   206 
       
   207 // ---------------------------------------------------------
       
   208 // CIMCVEngineContextObserver::GetCompletedReqResult
       
   209 // 
       
   210 // ---------------------------------------------------------
       
   211 void CIMCVEngineContextObserver::GetConnectedSessionL(MXIMPContext& aContext, TInt aServiceId, TUid aProtocolUid)
       
   212 	{
       
   213 	IM_CV_LOGS(TXT("CIMCVEngineContextObserver::GetConnectedSessionL() start") );
       
   214 	//TUid protocolUid = TUid::Uid( KProtocolUidTelepathy );
       
   215 	if ( (!iLoggedIn) && (EReqUnknown == iCurrentReqType) )
       
   216 	    {
       
   217 	    //iOngoingOperation = TIMCVStateEnums::EIMCVLogging;
       
   218 	    iCurrentXIMPReq = aContext.BindToL( aProtocolUid, aServiceId ) ;
       
   219 	    iCurrentReqType = ELoginReq;
       
   220 
       
   221 	    if( !iWait.IsStarted() )
       
   222 	        {
       
   223 	        // Code scanner warning "active object called without checking 
       
   224 	        // whether it is active or cancelling it first" ignored because
       
   225 	        // CActiveSchedulerWait is not an active object
       
   226 	        iWait.Start(); // CSI: 10 # See above
       
   227 	        }
       
   228 
       
   229 	    //iOngoingOperation = TIMCVStateEnums::EIMCVUnknown;
       
   230 	    }
       
   231 	IM_CV_LOGS(TXT("CIMCVEngineContextObserver::GetConnectedSessionL() end") );
       
   232 	
       
   233 	}
       
   234 // ---------------------------------------------------------
       
   235 // CIMCVEngineContextObserver::GetCompletedReqResult
       
   236 // 
       
   237 // ---------------------------------------------------------
       
   238 void CIMCVEngineContextObserver::ReleaseConnectionL(MXIMPContext& aContext)
       
   239 	{
       
   240 	IM_CV_LOGS(TXT("CIMCVEngineContextObserver::ReleaseConnectionL() start") );
       
   241 	if ( (iLoggedIn) && (EReqUnknown == iCurrentReqType) )
       
   242 	    {
       
   243 	    //iOngoingOperation = TIMCVStateEnums::EIMCVLoggingOut;
       
   244 	    iCurrentXIMPReq = aContext.UnbindL() ;
       
   245 	    iCurrentReqType = ELogoutReq;
       
   246 	    if( !iWait.IsStarted() )
       
   247 	        {
       
   248 	        // Code scanner warning "active object called without checking 
       
   249 	        // whether it is active or cancelling it first" ignored because
       
   250 	        // CActiveSchedulerWait is not an active object
       
   251 	        iWait.Start(); // CSI: 10 # See above	
       
   252 	        }
       
   253 	    }
       
   254     IM_CV_LOGS(TXT("CIMCVEngineContextObserver::ReleaseConnectionL() end") );
       
   255    
       
   256 	}
       
   257 	
       
   258 // ---------------------------------------------------------
       
   259 // CIMCVEngineContextObserver::IsLoggedIn
       
   260 // 
       
   261 // ---------------------------------------------------------
       
   262 TBool CIMCVEngineContextObserver::IsLoggedIn() const
       
   263 	{
       
   264 	return 	iLoggedIn;
       
   265 	}
       
   266 // ---------------------------------------------------------
       
   267 // CIMCVEngineContextObserver::RegisterObserver
       
   268 // 
       
   269 // ---------------------------------------------------------	
       
   270 void CIMCVEngineContextObserver::RegisterObserver(MIMCVEngineServiceSessionHandler* aObserver)  
       
   271 	{
       
   272 	IM_CV_LOGS(TXT("CIMCVEngineContextObserver::RegisterObserver() start") );
       
   273 	iSessionObserver = 	aObserver;
       
   274 	IM_CV_LOGS(TXT("CIMCVEngineContextObserver::RegisterObserver() end") );
       
   275 	}
       
   276 // ---------------------------------------------------------
       
   277 // CIMCVEngineContextObserver::UnRegisterObserver
       
   278 // 
       
   279 // ---------------------------------------------------------		
       
   280 void CIMCVEngineContextObserver::UnRegisterObserver(MIMCVEngineServiceSessionHandler* /*aObserver*/)  
       
   281 	{
       
   282 	IM_CV_LOGS(TXT("CIMCVEngineContextObserver::UnRegisterObserver() start") );
       
   283 	// do not call delete 
       
   284 	// not owned by this class
       
   285 	iSessionObserver = NULL;
       
   286 	IM_CV_LOGS(TXT("CIMCVEngineContextObserver::UnRegisterObserver() end") );
       
   287 	}
       
   288 // ---------------------------------------------------------
       
   289 // CIMCVEngine::SetLoggedIn()
       
   290 // ---------------------------------------------------------
       
   291 //
       
   292 void CIMCVEngineContextObserver::SetLoggedIn(TBool aState) 
       
   293 	{
       
   294 	iLoggedIn = aState;
       
   295 	}	
       
   296 		
       
   297 // end of file
       
   298