uiservicetab/vimpstengine/src/cvimpstenginecontactmgmtextention.cpp
changeset 0 5e5d6b214f4f
child 14 9fdee5e1da30
equal deleted inserted replaced
-1:000000000000 0:5e5d6b214f4f
       
     1 /*
       
     2 * Copyright (c) 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: Implementation for CVIMPSTEngineContactMgmtExtention
       
    15 *
       
    16 */
       
    17 
       
    18 // INCLUDE FILES
       
    19 #include "cvimpstenginecontactmgmtextention.h"
       
    20 
       
    21 #include <ximpcontext.h>
       
    22 #include <ximprequestcompleteevent.h>
       
    23 #include <presentitygroups.h>
       
    24 #include <presentitygroupinfo.h>
       
    25 #include <presentitygroupmemberinfo.h>
       
    26 #include <ximpidentity.h>
       
    27 #include <ximpobjectfactory.h>
       
    28 #include <ximpstatus.h>
       
    29 
       
    30 #include "cvimpstenginerequestmapper.h"
       
    31 #include "cvimpstenginerequest.h"
       
    32 #include "tvimpstenums.h"
       
    33 
       
    34 
       
    35 #include "vimpstallerrors.h"
       
    36 #include "tvimpstconsts.h"
       
    37 #include "vimpstdebugtrace.h"
       
    38 
       
    39 // Constants
       
    40 _LIT( KListNameAllBuddy ,"buddylist" );
       
    41 
       
    42 
       
    43 // ================= MEMBER FUNCTIONS =======================
       
    44 // ---------------------------------------------------------
       
    45 // CVIMPSTEngineContactMgmtExtention::NewL
       
    46 // Two-phased constructor.
       
    47 // ---------------------------------------------------------
       
    48 CVIMPSTEngineContactMgmtExtention* CVIMPSTEngineContactMgmtExtention::NewL(
       
    49 							MXIMPContext& aPresenceCtx,
       
    50 							MPresentityGroups& aPresGroup,
       
    51 							CVIMPSTEngineRequestMapper& aRequestMapper)
       
    52     {
       
    53     TRACE( T_LIT("CVIMPSTEngineContactMgmtExtention::NewL start"));
       
    54     CVIMPSTEngineContactMgmtExtention* self = 
       
    55     			CVIMPSTEngineContactMgmtExtention::NewLC( aPresenceCtx,
       
    56     											aPresGroup,
       
    57     											aRequestMapper
       
    58     										    );
       
    59     CleanupStack::Pop( self );
       
    60    	TRACE( T_LIT("CVIMPSTEngineContactMgmtExtention::NewL end"));
       
    61     return self;
       
    62     }
       
    63 
       
    64 // ---------------------------------------------------------
       
    65 // CVIMPSTEngineContactMgmtExtention::NewLC
       
    66 // Two-phased constructor.
       
    67 // ---------------------------------------------------------
       
    68 CVIMPSTEngineContactMgmtExtention* CVIMPSTEngineContactMgmtExtention::NewLC(
       
    69 							MXIMPContext& aPresenceCtx,
       
    70 							MPresentityGroups& aPresGroup,
       
    71 							CVIMPSTEngineRequestMapper& aRequestMapper)
       
    72 	{
       
    73 	TRACE( T_LIT("CVIMPSTEngineContactMgmtExtention::NewLC start"));
       
    74 	CVIMPSTEngineContactMgmtExtention* self = new (ELeave) 
       
    75 					CVIMPSTEngineContactMgmtExtention(aPresenceCtx, aPresGroup,aRequestMapper);
       
    76 	CleanupStack::PushL( self );
       
    77 	
       
    78 	TRACE( T_LIT("CVIMPSTEngineContactMgmtExtention::NewLC end") );
       
    79 	return self;
       
    80 	}
       
    81     
       
    82 
       
    83 // ---------------------------------------------------------
       
    84 // CVIMPSTEngineContactMgmtExtention::CVIMPSTEngineContactMgmtExtention
       
    85 // ---------------------------------------------------------	
       
    86 CVIMPSTEngineContactMgmtExtention::CVIMPSTEngineContactMgmtExtention(
       
    87 											MXIMPContext& aPresenceCtx,
       
    88 											MPresentityGroups& aPresGroup,	
       
    89 											CVIMPSTEngineRequestMapper& aRequestMapper)
       
    90 	:
       
    91 	iPresenceCtx(aPresenceCtx),
       
    92 	iPresGroup(aPresGroup),
       
    93 	iRequestMapper(aRequestMapper),
       
    94 	iSupported(TVIMPSTEnums::ESupportUnKnown)
       
    95 	{
       
    96 		
       
    97 	}
       
    98 
       
    99 // ---------------------------------------------------------
       
   100 // CVIMPSTEngineContactMgmtExtention::~CVIMPSTEngineContactMgmtExtention
       
   101 // ---------------------------------------------------------
       
   102 CVIMPSTEngineContactMgmtExtention::~CVIMPSTEngineContactMgmtExtention()
       
   103     {
       
   104 	TRACE( T_LIT("CVIMPSTEngineContactMgmtExtention::~CVIMPSTEngineContactMgmtExtention start"));
       
   105 	TRACE( T_LIT("CVIMPSTEngineContactMgmtExtention::~CVIMPSTEngineContactMgmtExtention end"));
       
   106     }
       
   107 
       
   108 
       
   109 // -----------------------------------------------------------------------------
       
   110 // CVIMPSTEngineContactMgmtExtention::IsSupported()
       
   111 // -----------------------------------------------------------------------------
       
   112 //
       
   113 TVIMPSTEnums::FeatureSupport CVIMPSTEngineContactMgmtExtention::IsSupported() const 
       
   114 	{
       
   115 	return iSupported;
       
   116 	}
       
   117       	
       
   118 
       
   119 // -----------------------------------------------------------------------------
       
   120 // CVIMPSTEngineContactMgmtExtention::Type()
       
   121 // -----------------------------------------------------------------------------
       
   122 //
       
   123 TVIMPSTEnums::ExtentionType CVIMPSTEngineContactMgmtExtention::Type() const
       
   124 	{
       
   125 	return TVIMPSTEnums::EContactManagement;
       
   126 	}
       
   127 	
       
   128 
       
   129 // ---------------------------------------------------------
       
   130 // CVIMPSTEngineContactMgmtExtention::DeleteServerContactL
       
   131 // ---------------------------------------------------------
       
   132 TInt CVIMPSTEngineContactMgmtExtention::DeleteServerContactL( const TDesC& aContactListId,
       
   133 										   		   const TDesC& aUserId )
       
   134 	{
       
   135 	TRACE( T_LIT("CVIMPSTEngineContactMgmtExtention::DeleteServerContactL start"));
       
   136 	TRACE( T_LIT("CVIMPSTEngineContactMgmtExtention::DeleteServerContactL aContactListId = %s"),&aContactListId );
       
   137 	
       
   138 	// err is initialized to KErrNone, b'coz if adaptation or presence is not supported then,
       
   139 	// the request should not be sent to the server, this is a hack as the voip
       
   140 	// writes the adaptation uid into settings even if presence is not supported.
       
   141 	// bug has to be raised to voip.
       
   142 	
       
   143 	TInt err = KErrNone;
       
   144 	
       
   145 	if (iSupported == TVIMPSTEnums::ESupported)
       
   146 		{
       
   147 		//if there is no contact list id, contact is added to default contact list
       
   148         // here its "buddylist"
       
   149         HBufC* listId = HBufC::NewLC(KPropertyMaxLength); //  onto cleanup stack
       
   150         TPtr listIdPtr = listId->Des();
       
   151         if(0 == aContactListId.Length())
       
   152             {
       
   153             listIdPtr.Copy(KListNameAllBuddy);
       
   154             }
       
   155         else 
       
   156             {
       
   157             listIdPtr.Copy(aContactListId) ;  
       
   158 		    }
       
   159 		MXIMPIdentity* listIdentity = CreateIdentityLC( listIdPtr ) ;
       
   160 		MXIMPIdentity* userIdentity = CreateIdentityLC( aUserId ) ;
       
   161 	     
       
   162 	    //not sure whether we can pass NULL for listIdentity / userIdentity
       
   163 		//lets leave it to the adaptation.	
       
   164 		//so ignoring the NULL  for listIdentity, userIdentity
       
   165 	    TXIMPRequestId reqId = iPresGroup.RemovePresentityGroupMemberL( 
       
   166 	    									*listIdentity, *userIdentity );
       
   167 	       
       
   168 		iRequestMapper.CreateRequestL(reqId, ETrue, EVIMPSTXimpOperationDeleteContact);// waite here	
       
   169 			
       
   170 		// codescanner warning can be ignored as MXIMPIdentity doesn't allow to pass pointer
       
   171 		// to PopAnddestroy function. It gives panic
       
   172 		CleanupStack::PopAndDestroy(); //userIdentity
       
   173 		CleanupStack::PopAndDestroy(); //listIdentity
       
   174 		
       
   175 		CleanupStack::PopAndDestroy(); // listId;
       
   176 	    
       
   177 	    err = iReqResult;
       
   178 		}
       
   179 	TRACE( T_LIT("CVIMPSTEngineContactMgmtExtention::DeleteServerContactL end"));
       
   180 	return err;
       
   181 	}
       
   182 	
       
   183 
       
   184 // ---------------------------------------------------------
       
   185 // CVIMPSTEngineContactMgmtExtention::AddServerContactL
       
   186 // ---------------------------------------------------------
       
   187 TInt CVIMPSTEngineContactMgmtExtention::AddServerContactL(const TDesC& aContactList,
       
   188         									   const TDesC& aUserId,
       
   189         									   const TDesC& aNickname ,
       
   190         									   TBool aWaitToComplete /*= ETrue*/ )
       
   191 	{
       
   192 	
       
   193 	TRACE( T_LIT("CVIMPSTEngineContactMgmtExtention::AddServerContactL start"));
       
   194 	
       
   195 	// err is initialized to KErrNone, b'coz if adaptation or presence is not supported then,
       
   196 	// the request should not be sent to the server, this is a hack as the voip
       
   197 	// writes the adaptation uid into settings even if presence is not supported.
       
   198 	// bug has to be raised to voip.
       
   199 	TInt err = KErrNone;
       
   200 	
       
   201 	if (iSupported == TVIMPSTEnums::ESupported)
       
   202 		{
       
   203 		//if there is no contact list id, contact is added to default contact list
       
   204 		// here its "buddylist"
       
   205 		HBufC* listId = HBufC::NewLC(KPropertyMaxLength); //  onto cleanup stack
       
   206 		TPtr listIdPtr = listId->Des();
       
   207 		if(0 == aContactList.Length())
       
   208 		    {
       
   209 		    listIdPtr.Copy(KListNameAllBuddy);
       
   210 		    }
       
   211 		else 
       
   212 		    {
       
   213 		    listIdPtr.Copy(aContactList) ;  
       
   214 		    }
       
   215 		
       
   216 		HBufC* userId = HBufC::NewLC(KPropertyMaxLength); //  onto cleanup stack
       
   217 		TPtr userIdPtr = userId->Des();
       
   218 		
       
   219 		//domain name is checked on the ui and command process side.
       
   220 	    userIdPtr.Zero();
       
   221 	    userIdPtr.Append( aUserId );
       
   222 		   
       
   223 		// create identity
       
   224 		MXIMPIdentity* listIdentity = CreateIdentityLC( listIdPtr ) ;
       
   225 		MXIMPIdentity* userIdentity = CreateIdentityLC( userIdPtr ) ; //  onto cleanup stack
       
   226 
       
   227 		//not sure whether we can pass NULL for listIdentity / userIdentity
       
   228 		//lets leave it to the adaptation.
       
   229 		//so ignoring the NULL  for listIdentity, userIdentity
       
   230 		TXIMPRequestId reqId = iPresGroup.AddPresentityGroupMemberL(*listIdentity,
       
   231 														*userIdentity,
       
   232 														aNickname) ;
       
   233 	 
       
   234 		iRequestMapper.CreateRequestL(reqId, aWaitToComplete, EVIMPSTXimpOperationAddContact );
       
   235 		
       
   236 		// codescanner warning can be ignored as MXIMPIdentity doesn't allow to pass pointer
       
   237 		// to PopAnddestroy function. It gives panic
       
   238 		CleanupStack::PopAndDestroy(); //userIdentity
       
   239 		CleanupStack::PopAndDestroy(); //listIdentity
       
   240 		
       
   241 		CleanupStack::PopAndDestroy(); //userId
       
   242 		CleanupStack::PopAndDestroy(); // listId
       
   243 		
       
   244 		TRACE( T_LIT("CVIMPSTEngineContactMgmtExtention::AddServerContactL end"));
       
   245 		err = iReqResult;
       
   246 		}
       
   247 
       
   248 	return err;
       
   249 	}
       
   250 
       
   251 
       
   252 // ---------------------------------------------------------
       
   253 // CVIMPSTEngineContactMgmtExtention::CreateIdentityLC
       
   254 // ---------------------------------------------------------	 	
       
   255 MXIMPIdentity* CVIMPSTEngineContactMgmtExtention::CreateIdentityLC(const TDesC& aListId) 
       
   256 	{
       
   257 	TRACE( T_LIT("CVIMPSTEngineContactMgmtExtention::CreateIdentityLC start"));
       
   258 	
       
   259 	MXIMPObjectFactory& objFactory = iPresenceCtx.ObjectFactory();
       
   260 	MXIMPIdentity* newIdentity = objFactory.NewIdentityLC();
       
   261 	//no need to check for null as NewIdentityLC does not return null,
       
   262 	// if failed ot allocate memory it will leave with KErrNoMemory
       
   263 	newIdentity->SetIdentityL( aListId) ;
       
   264 	TRACE( T_LIT("CVIMPSTEngineContactMgmtExtention::CreateIdentityLC end"));
       
   265 	return newIdentity;
       
   266 	}	         	
       
   267 
       
   268 
       
   269 // ---------------------------------------------------------
       
   270 // CVIMPSTEngineContactMgmtExtention::HandleSessionContextEventL
       
   271 // ---------------------------------------------------------
       
   272 void CVIMPSTEngineContactMgmtExtention::HandleSessionContextEventL(const MXIMPContext& /*aContext*/,
       
   273                                              const MXIMPBase& aEvent,
       
   274                                              TXimpOperation aXimpOperation /*= EVIMPSTXimpOperationNoOperation*/ )
       
   275     {    
       
   276     
       
   277     TRACE( T_LIT("CVIMPSTEngineContactMgmtExtention::HandleSessionContextEventL start"));
       
   278     
       
   279     switch( aEvent.GetInterfaceId() )
       
   280         {
       
   281         case MXIMPRequestCompleteEvent::KInterfaceId:
       
   282         	{
       
   283             TRACE( T_LIT("InsideCallbackswitch::MXIMPRequestCompleteEvent"));
       
   284             if ( (EVIMPSTXimpOperationAddContact == aXimpOperation) 
       
   285              		|| (EVIMPSTXimpOperationDeleteContact == aXimpOperation) )
       
   286 	            {            
       
   287 	            const MXIMPRequestCompleteEvent* event =
       
   288 	                TXIMPGetInterface< const MXIMPRequestCompleteEvent >::From( 
       
   289 	                    aEvent, MXIMPBase::EPanicIfUnknown );
       
   290 	            
       
   291 	            iReqResult = event->CompletionResult().ResultCode();
       
   292 	            const TXIMPRequestId& reqId = event->RequestId();
       
   293 	            // Note:FindRequestId does not pass the ownership. hanece req
       
   294 	            // should not be deleted.
       
   295 	            CVIMPSTEngineRequest *req = iRequestMapper.FindRequestId( reqId );                
       
   296 	            
       
   297 	            if ( req )
       
   298 	                { 	                           
       
   299 	                req->StopWait() ;   
       
   300 	                iRequestMapper.RemoveRequestId(reqId);
       
   301 	                }
       
   302 	            }
       
   303             break;
       
   304             }
       
   305             
       
   306         default:
       
   307             {
       
   308             break;
       
   309             }
       
   310         }
       
   311    	TRACE( T_LIT("CVIMPSTEngineContactMgmtExtention::HandleSessionContextEventL end"));	
       
   312     }    
       
   313 
       
   314 //----------------------------------------------------------------------------
       
   315 // CVIMPSTEngineContactMgmtExtention::SetSupported()
       
   316 // -----------------------------------------------------------------------------
       
   317 //
       
   318 void  CVIMPSTEngineContactMgmtExtention::SetSupported(TVIMPSTEnums::FeatureSupport aSupported)
       
   319     {
       
   320     iSupported = aSupported;
       
   321     }
       
   322 
       
   323 // end of file