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