imservices/ossprotocoladaptation/tsrc/ossadapmt/src/ossadapmtBlocks.cpp
branchRCL_3
changeset 14 7797b2f86d2b
parent 13 b6f2a363adf7
child 16 cfe5eb8bb9ca
equal deleted inserted replaced
13:b6f2a363adf7 14:7797b2f86d2b
     1 /*
       
     2 * Copyright (c) 2002 - 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:  ossadapmtBlocks.cpp
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 
       
    20 // [INCLUDE FILES] - do not remove
       
    21 #include <e32svr.h>
       
    22 #include <StifParser.h>
       
    23 #include <StifTestInterface.h>
       
    24 #include "ossadapmt.h"
       
    25 #include <ximpidentity.h>
       
    26 #include <ximpclient.h>
       
    27 #include <ximpcontext.h>
       
    28 #include <ximpobjectfactory.h>
       
    29 #include <ximpcontextobserver.h>
       
    30 #include <ximpcontextstateevent.h>
       
    31 #include <ximpprotocolinfo.h>
       
    32 #include <ximpfeatureinfo.h>
       
    33 #include <ximpserviceinfo.h>
       
    34 #include "uscontextobserver.h"
       
    35 #include <presencefeatures.h>
       
    36 #include <imfeatures.h>
       
    37 #include <presentitygroups.h>
       
    38 #include <imconversation.h>
       
    39 #include <imobjectfactory.h>
       
    40 #include <imconversationinfo.h>
       
    41 #include "cuserafter.h"
       
    42 #include <presencepublishing.h>
       
    43 #include <presencewatching.h>
       
    44 #include <presenceinfofilter.h>
       
    45 #include <presenceinfo.h>
       
    46 #include <presenceobjectfactory.h>
       
    47 #include <servicepresenceinfo.h>
       
    48 #include <personpresenceinfo.h>
       
    49 #include <presenceinfofield.h>
       
    50 #include <presenceinfofieldcollection.h>
       
    51 #include <presenceinfofieldvalueenum.h>
       
    52 #include <presenceinfofieldvaluetext.h>
       
    53 #include <presenceinfofieldvaluebinary.h>
       
    54 #include <presenceauthorization.h>
       
    55 #include <utf.h>
       
    56 #include <search.h>
       
    57 #include <searchfeature.h>
       
    58 #include <searchobjectfactory.h>
       
    59 #include <searchelement.h>
       
    60 //#include "immessageinfoimp.h"
       
    61 const TInt KProtocolUid = 0x101FB3E7; // 0x10282EE9;
       
    62 _LIT8( KInstantMessaging, "instant-messaging");
       
    63 
       
    64 // StatusText attribute value tags
       
    65 _LIT8( KStatusTextfield, "StatusText");
       
    66 
       
    67 // Online Status attribute value tags
       
    68 _LIT8( KOnlineStatusfield, "OnlineStatus" );
       
    69 _LIT ( KMsgId, "MessageID1" );
       
    70 _LIT( KContact1, "meco5555@gmail.com");
       
    71 
       
    72 // EXTERNAL DATA STRUCTURES
       
    73 //extern  ?external_data;
       
    74 
       
    75 // EXTERNAL FUNCTION PROTOTYPES
       
    76 //extern ?external_function( ?arg_type,?arg_type );
       
    77 
       
    78 // CONSTANTS
       
    79 //const ?type ?constant_var = ?constant;
       
    80 
       
    81 // MACROS
       
    82 //#define ?macro ?macro_def
       
    83 
       
    84 // LOCAL CONSTANTS AND MACROS
       
    85 //const ?type ?constant_var = ?constant;
       
    86 //#define ?macro_name ?macro_def
       
    87 
       
    88 // MODULE DATA STRUCTURES
       
    89 //enum ?declaration
       
    90 //typedef ?declaration
       
    91 
       
    92 // LOCAL FUNCTION PROTOTYPES
       
    93 //?type ?function_name( ?arg_type, ?arg_type );
       
    94 
       
    95 // FORWARD DECLARATIONS
       
    96 //class ?FORWARD_CLASSNAME;
       
    97 
       
    98 // ============================= LOCAL FUNCTIONS ===============================
       
    99 
       
   100 // -----------------------------------------------------------------------------
       
   101 // ?function_name ?description.
       
   102 // ?description
       
   103 // Returns: ?value_1: ?description
       
   104 //          ?value_n: ?description_line1
       
   105 //                    ?description_line2
       
   106 // -----------------------------------------------------------------------------
       
   107 //
       
   108 /*
       
   109 ?type ?function_name(
       
   110     ?arg_type arg,  // ?description
       
   111     ?arg_type arg)  // ?description
       
   112     {
       
   113 
       
   114     ?code  // ?comment
       
   115 
       
   116     // ?comment
       
   117     ?code
       
   118     }
       
   119 */
       
   120 
       
   121 // ============================ MEMBER FUNCTIONS ===============================
       
   122 
       
   123 // -----------------------------------------------------------------------------
       
   124 // Cossadapmt::Delete
       
   125 // Delete here all resources allocated and opened from test methods.
       
   126 // Called from destructor.
       
   127 // -----------------------------------------------------------------------------
       
   128 //
       
   129 void Cossadapmt::Delete()
       
   130 	{
       
   131 
       
   132 	}
       
   133 
       
   134 // -----------------------------------------------------------------------------
       
   135 // Cossadapmt::RunMethodL
       
   136 // Run specified method. Contains also table of test mothods and their names.
       
   137 // -----------------------------------------------------------------------------
       
   138 //
       
   139 TInt Cossadapmt::RunMethodL (
       
   140     CStifItemParser& aItem )
       
   141 	{
       
   142 
       
   143 	static TStifFunctionInfo const KFunctions[] =
       
   144 		{
       
   145 		// Copy this line for every implemented function.
       
   146 		// First string is the function name used in TestScripter script file.
       
   147 		// Second is the actual implementation member function.
       
   148 		ENTRY ( "SecondSearchL",Cossadapmt::SecondSearchL ), 
       
   149 		ENTRY ( "Login", Cossadapmt::LoginL ),
       
   150 		ENTRY ( "Login_InvalidData", Cossadapmt::Login_InvalidDataL ),
       
   151 		ENTRY ( "AcceptnotificationRequest", Cossadapmt::AcceptnotificationRequestL ),
       
   152 		ENTRY ( "Login_Logout_sequential", Cossadapmt::LoginLogout_LoginLogoutL ),
       
   153 		ENTRY ( "Login_8Hrs_Logout", Cossadapmt::Login8HrsLogoutL ),
       
   154 		ENTRY ( "Unbind", Cossadapmt::UnBindL ),
       
   155 		ENTRY ( "GetContacts", Cossadapmt::GetContactsL ),
       
   156 		ENTRY ( "Add_conatct", Cossadapmt::AddConatctL ),
       
   157 		ENTRY ( "Add_Blank_Conatct", Cossadapmt::AddBlankConatctL ),
       
   158 		ENTRY ( "Add_Blank_Conatct1", Cossadapmt::AddBlankConatct1L ),
       
   159 		ENTRY ( "Delete_conatct", Cossadapmt::DeleteConatctL ),
       
   160 		ENTRY ( "Delete_Blank_Conatct", Cossadapmt::DeleteBlankConatctL ),
       
   161 		ENTRY ( "Sendmessage", Cossadapmt::SendMessageL ),
       
   162 		ENTRY ( "Sendemptymessage", Cossadapmt::SendEmptyMessageL ),
       
   163 		ENTRY ( "Send_ten_messages", Cossadapmt::SendTenMessageL ),
       
   164 		ENTRY ( "Send_twenty_messages", Cossadapmt::SendTwentyMessageL ),
       
   165 		ENTRY ( "Sendmessage_multiplecontacts", Cossadapmt::SendMessage_MultipleContactsL ),
       
   166 		ENTRY ( "Receivemessage", Cossadapmt::ReceiveMessageL ),
       
   167 		ENTRY ( "Receiveemptymessage", Cossadapmt::ReceiveEmptyMessageL ),
       
   168 		ENTRY ( "Receive_ten_messages", Cossadapmt::ReceiveTenMessageL ),
       
   169 		ENTRY ( "Receive_twenty_message", Cossadapmt::ReceiveTwentyMessageL ),
       
   170 		ENTRY ( "Publish_ownpresence", Cossadapmt::PublishOwnPresenceL ),
       
   171 		ENTRY ( "Publish_ownpresence_emptytext", Cossadapmt::PublishOwnPresenceEmptyTextL ),
       
   172 		ENTRY ( "RejectAddnotificationRequest", Cossadapmt::RejectAddnotificationRequestL ),
       
   173 		ENTRY ( "ImOperations_Coverage", Cossadapmt::ImOperationsCoverageL ),
       
   174 		
       
   175 		ENTRY ( "SimpleSearchL", Cossadapmt::SimpleSearchL ),
       
   176 		ENTRY ( "MultipleSearchL", Cossadapmt::MultipleSearchL ),
       
   177 		ENTRY ( "NoResultSearchL", Cossadapmt::NoResultSearchL ),
       
   178 		ENTRY ( "ManyResultsSearchL", Cossadapmt::ManyResultsSearchL ),
       
   179 		ENTRY ( "BlankSearchL", Cossadapmt::BlankSearchL ),
       
   180 		ENTRY ( "MaxCharSearchL", Cossadapmt::MaxCharSearchL ),
       
   181 		ENTRY ( "SpecialCharSearchL", Cossadapmt::SpecialCharSearchL ),
       
   182 		ENTRY ( "SearchEmailIDL",Cossadapmt::SearchEmailIDL ),
       
   183 		ENTRY ( "SearchAndAddToIML",Cossadapmt::SearchAndAddToIML ), 
       
   184 		ENTRY ( "GetSearchKeyEnumL",Cossadapmt::GetSearchKeyEnumL ), 
       
   185 		ENTRY ( "GetSearchKeyLabelL",Cossadapmt::GetSearchKeyLabelL ), 
       
   186 		ENTRY ( "GetSearchKeyEnumNLabelL",Cossadapmt::GetSearchKeyEnumNLabelL ), 
       
   187         ENTRY ( "SetAvtar",Cossadapmt::SetAvtarL ), 
       
   188 		//ADD NEW ENTRY HERE
       
   189 		// [test cases entries] - Do not remove
       
   190 
       
   191 		};
       
   192 
       
   193 	const TInt count = sizeof ( KFunctions ) /
       
   194 	                   sizeof ( TStifFunctionInfo );
       
   195 
       
   196 	return RunInternalL ( KFunctions, count, aItem );
       
   197 
       
   198 	}
       
   199 
       
   200 
       
   201 
       
   202 // -----------------------------------------------------------------------------
       
   203 // Cossadapmt::SearchL
       
   204 // Search test method function.
       
   205 // (other items were commented in a header).
       
   206 // -----------------------------------------------------------------------------
       
   207 //
       
   208 TInt Cossadapmt::SearchL ( CStifItemParser& aItem, TSearch aSearchType )
       
   209 	{
       
   210 
       
   211 
       
   212 
       
   213 	//Initialize XIMP client
       
   214 	TOssAdapMtLogger::Log ( _L ( "Cossadapmt::LoginL() start" ) );
       
   215 
       
   216 	MXIMPClient* ximpClient = MXIMPClient::NewClientL();
       
   217 	CleanupDeletePushL ( ximpClient );
       
   218 	TOssAdapMtLogger::Log ( _L ( "Cossadapmt::MXIMPClient::NewClientL() start" ) );
       
   219 
       
   220 	//Create new sink to receive presence context events
       
   221 	CUSContextObserver* eventObserver = CUSContextObserver::NewLC();
       
   222 
       
   223 	//Create new presence context
       
   224 	MXIMPContext* presecenCtx = ximpClient->NewPresenceContextLC();
       
   225 	TOssAdapMtLogger::Log ( _L ( "Cossadapmt::ximpClient->NewPresenceContextLC() called" ) );
       
   226 	presecenCtx->RegisterObserverL ( *eventObserver );
       
   227 
       
   228    	
       
   229     //read data from cfg file
       
   230     TPtrC               username;
       
   231     TPtrC               password;
       
   232 	TInt                serviceId;
       
   233 
       
   234 
       
   235 	MSearchFeature* srFeature = NULL;
       
   236 	srFeature = MSearchFeature::NewL ( presecenCtx );
       
   237 //	CleanupStack::PushL( srFeature );
       
   238 	
       
   239 	MSearch& srch=srFeature->Search();
       
   240 	MSearchObjectFactory& searchObjFact=srFeature->SearchObjectFactory();
       
   241 
       
   242 
       
   243 	aItem.GetNextString ( username );
       
   244 	aItem.GetNextString ( password );
       
   245 	aItem.GetNextInt ( serviceId );
       
   246 
       
   247 	TUid protocolUid = TUid::Uid ( KProtocolUid );
       
   248 
       
   249 	//Bind context to desired presence service
       
   250 	TXIMPRequestId req = presecenCtx->BindToL ( protocolUid,
       
   251 	                     username,
       
   252 	                     password,
       
   253 	                     serviceId );
       
   254 	TOssAdapMtLogger::Log ( _L ( "Cossadapmt::presecenCtx->BindToL() called" ) );
       
   255 	//Wait with CActiveSchedulerWait the binding to complete
       
   256 	//If binding fails, it is handled with leave
       
   257 	eventObserver->WaitOpToCompleteL ( req );
       
   258 	
       
   259 //------------------------------------------Fetch Start------------------------------------------
       
   260 	MPresenceFeatures* presenceFeatures = NULL;
       
   261 	presenceFeatures = MPresenceFeatures::NewL ( presecenCtx );
       
   262 	CleanupDeletePushL ( presenceFeatures );
       
   263 	MXIMPIdentity* newGroupId = presecenCtx->ObjectFactory().NewIdentityLC();
       
   264 	MPresentityGroups& groups = presenceFeatures->PresentityGroups() ;
       
   265 	MXIMPIdentity* newmemberId = presecenCtx->ObjectFactory().NewIdentityLC();
       
   266 
       
   267 	TOssAdapMtLogger::Log ( _L ( "presentity groups object created" ) );
       
   268 	_LIT ( KDummyListId, "list" );
       
   269 	HBufC16* iListId;
       
   270 	iListId = KDummyListId().AllocL();
       
   271 	iListId->Des().Fold();
       
   272 	newGroupId->SetIdentityL ( *iListId );
       
   273 	delete iListId;
       
   274 	iListId = NULL;
       
   275 
       
   276 
       
   277 	req = groups.SubscribePresentityGroupContentL ( *newGroupId );
       
   278 
       
   279 	TOssAdapMtLogger::Log ( _L ( "Cossadapmt::groups.SubscribePresentityGroupListL() called" ) );
       
   280 
       
   281 	eventObserver->WaitOpToCompleteL ( req );
       
   282 
       
   283 	CUserAfter::AfterL ( 1000000 );
       
   284 
       
   285 //------------------------------------------Fetch End------------------------------------------
       
   286 
       
   287 
       
   288 	MXIMPIdentity* searchId = presecenCtx->ObjectFactory().NewIdentityLC();
       
   289     searchId->SetIdentityL(_L("SEARCH"));
       
   290     
       
   291     MXIMPIdentity* firstId = presecenCtx->ObjectFactory().NewIdentityLC();
       
   292     
       
   293     
       
   294     MSearchElement* srchElement1=searchObjFact.NewSearchElementLC();
       
   295     
       
   296     
       
   297     MXIMPIdentity* secondId = presecenCtx->ObjectFactory().NewIdentityLC();
       
   298     
       
   299     
       
   300     MSearchElement* srchElement2=searchObjFact.NewSearchElementLC();
       
   301     
       
   302     
       
   303     RPointerArray< MSearchElement > searchList;
       
   304     CleanupClosePushL( searchList );
       
   305     
       
   306 	switch ( aSearchType ) 
       
   307 		{
       
   308 		
       
   309 		case EGetSearchKeyEnum:
       
   310 			{
       
   311 			
       
   312 			req = srch.GetSearchKeysL();
       
   313 			eventObserver->WaitOpToCompleteL ( req );
       
   314 			
       
   315 			firstId->SetIdentityL(_L("james"));
       
   316 			srchElement1->SetRequestL( *firstId, EUserFirstName );
       
   317 			
       
   318 			searchList.Append(srchElement1);
       
   319 			
       
   320 			req=srch.SearchL(*searchId,searchList,10 );				
       
   321 			break;
       
   322 			
       
   323 			}
       
   324 		
       
   325 		
       
   326 		case EGetSearchKeyLabel:
       
   327 			{
       
   328 			
       
   329 			req = srch.GetSearchKeysL();
       
   330 			eventObserver->WaitOpToCompleteL ( req );
       
   331 			
       
   332 			MXIMPIdentity* label = presecenCtx->ObjectFactory().NewIdentityLC();
       
   333 			label->SetIdentityL( _L( "Family Name" ) );
       
   334 			
       
   335 			secondId->SetIdentityL(_L("BOND"));
       
   336 			
       
   337 		    srchElement2->SetRequestL( *secondId, *label );
       
   338 		    
       
   339 			searchList.Append( srchElement1 );
       
   340 			searchList.Append( srchElement2 ); 
       
   341 		    
       
   342 		    req=srch.SearchL(*searchId,searchList,10 );
       
   343 		    
       
   344 		    CleanupStack::PopAndDestroy ();
       
   345 		    
       
   346 			break;		
       
   347 			
       
   348 			}
       
   349 		
       
   350 		
       
   351 		case EGetSearchKeyEnumNLabel:
       
   352 			{
       
   353 			
       
   354 			req = srch.GetSearchKeysL();
       
   355 			eventObserver->WaitOpToCompleteL ( req );
       
   356 			
       
   357 			
       
   358 			firstId->SetIdentityL(_L("james"));
       
   359 			srchElement1->SetRequestL( *firstId, EUserFirstName );
       
   360 			
       
   361 			secondId->SetIdentityL(_L("BOND"));
       
   362 			
       
   363 			MXIMPIdentity* label = presecenCtx->ObjectFactory().NewIdentityLC();
       
   364 			label->SetIdentityL( _L( "Family Name" ) );
       
   365 			
       
   366 		    srchElement2->SetRequestL( *secondId, *label );
       
   367 		    
       
   368 			searchList.Append( srchElement1 );
       
   369 			searchList.Append( srchElement2 ); 
       
   370 		    
       
   371 		    req=srch.SearchL(*searchId,searchList,10 );
       
   372 		    
       
   373 		    CleanupStack::PopAndDestroy ();
       
   374 		    
       
   375 			break;		
       
   376 			}
       
   377 		
       
   378 		
       
   379 		case ESimpleSearch :
       
   380 			{
       
   381 			
       
   382 			req = srch.GetSearchKeysL();
       
   383 			eventObserver->WaitOpToCompleteL ( req );
       
   384 			
       
   385 			firstId->SetIdentityL(_L("james"));
       
   386 			srchElement1->SetRequestL( *firstId, EUserFirstName );
       
   387 			
       
   388 			searchList.Append(srchElement1);
       
   389 			
       
   390 			req=srch.SearchL(*searchId,searchList,10 );
       
   391 			
       
   392 			break;	
       
   393 			}
       
   394 		
       
   395 		
       
   396 		case EMultipleSearch :
       
   397 			{
       
   398 			
       
   399 			req = srch.GetSearchKeysL();
       
   400 			eventObserver->WaitOpToCompleteL ( req );
       
   401 			
       
   402 			
       
   403 			firstId->SetIdentityL(_L("james"));
       
   404 			srchElement1->SetRequestL( *firstId, EUserFirstName );
       
   405 			
       
   406 			secondId->SetIdentityL(_L("BOND"));
       
   407 			
       
   408 			MXIMPIdentity* label = presecenCtx->ObjectFactory().NewIdentityLC();
       
   409 			label->SetIdentityL( _L( "Family Name" ) );
       
   410 			
       
   411 		    srchElement2->SetRequestL( *secondId, *label );
       
   412 		    
       
   413 			searchList.Append( srchElement1 );
       
   414 			searchList.Append( srchElement2 ); 
       
   415 		    
       
   416 		    req=srch.SearchL(*searchId,searchList,10 );
       
   417 		    
       
   418 		    CleanupStack::PopAndDestroy ();
       
   419 		    		
       
   420 			break;	
       
   421 			}
       
   422 		
       
   423 		
       
   424 		case ESearchNoResults :
       
   425 			{
       
   426 			firstId->SetIdentityL(_L("Santhosh"));
       
   427 			srchElement1->SetRequestL( *firstId, EUserFirstName );
       
   428 			
       
   429 			secondId->SetIdentityL(_L("I C"));
       
   430 		    srchElement2->SetRequestL( *secondId, EUserLastName );
       
   431 		    
       
   432 			searchList.Append( srchElement1 );
       
   433 			searchList.Append( srchElement2 ); 
       
   434 		    
       
   435 		    req=srch.SearchL(*searchId,searchList,10 );
       
   436 			break;	
       
   437 			}
       
   438 	
       
   439 		
       
   440 		case ESearchManyResults :
       
   441 			{
       
   442 			firstId->SetIdentityL(_L("a"));
       
   443 			srchElement1->SetRequestL( *firstId, EUserFirstName );
       
   444 			
       
   445 			searchList.Append(srchElement1);
       
   446 			
       
   447 			req=srch.SearchL(*searchId,searchList,10 );
       
   448 			
       
   449 			break;	
       
   450 			}
       
   451 		
       
   452 		
       
   453 		case ESearchBlank :
       
   454 			{
       
   455 			firstId->SetIdentityL(_L(""));
       
   456 			srchElement1->SetRequestL( *firstId, EUserFirstName );
       
   457 			
       
   458 			searchList.Append(srchElement1);
       
   459 			
       
   460 			req=srch.SearchL(*searchId,searchList,10 );	
       
   461 			break;
       
   462 			}
       
   463 		
       
   464 		
       
   465 		
       
   466 		case ESearchMaxChars :
       
   467 			{
       
   468 			firstId->SetIdentityL( _L( "fbg agh ggd sad ghda gh dhg hgasdg dh jggd gsdg g \
       
   469 			kjdg g gsd gfhsdg fhasgd hasdh ghfgahfg hgsdg dg gdgsgkj" ) );
       
   470 			srchElement1->SetRequestL( *firstId, EUserFirstName );
       
   471 			
       
   472 			searchList.Append( srchElement1 );
       
   473 			
       
   474 			req=srch.SearchL( *searchId,searchList,10 );
       
   475 			break;	
       
   476 			}
       
   477 		
       
   478 		
       
   479 		case ESearchSpecialChars :
       
   480 			{
       
   481 			firstId->SetIdentityL( _L( "*%#@$%^#%^&^^%)(" ) );
       
   482 			srchElement1->SetRequestL( *firstId, EUserFirstName );
       
   483 			
       
   484 			searchList.Append( srchElement1 );
       
   485 			
       
   486 			req=srch.SearchL( *searchId,searchList,10 );
       
   487 			
       
   488 			break;	
       
   489 			}
       
   490 		case  ESearchEmailid:
       
   491 			{
       
   492 			firstId->SetIdentityL( _L( "wordjames@chat.gizmoproject.com" ) );
       
   493 			srchElement1->SetRequestL( *firstId, EUserFirstName );
       
   494 			
       
   495 			searchList.Append( srchElement1 );
       
   496 			
       
   497 			req=srch.SearchL( *searchId,searchList,10 );
       
   498 			break;	
       
   499 			} 
       
   500 			
       
   501 		case  ESearchAndAddToIm:
       
   502 			{
       
   503 			firstId->SetIdentityL( _L( "sharath" ) );
       
   504 			srchElement1->SetRequestL( *firstId, EUserFirstName );
       
   505 			
       
   506 			searchList.Append( srchElement1 );
       
   507 			
       
   508 			req=srch.SearchL( *searchId,searchList,10 );
       
   509 			//Wait for search to complete
       
   510 			eventObserver->WaitOpToCompleteL( req );
       
   511 			CUserAfter::AfterL ( 5000000 );
       
   512 			
       
   513 			//And then call the AddToContactList
       
   514 			RFs fs;
       
   515 			RFile file;
       
   516 			TBuf8<100> buf;
       
   517 			User::LeaveIfError( fs.Connect() );
       
   518 			User::LeaveIfError( file.Open( fs, KAddContactFileName, EFileRead ) );
       
   519 			file.Read( buf );
       
   520 			file.Close();
       
   521 			fs.Close();
       
   522 			TBuf16<100> h_buf;
       
   523 			CnvUtfConverter::ConvertToUnicodeFromUtf8( h_buf, 
       
   524 											buf );
       
   525 //-------------------Adding Contact Start-----------------------------------------			
       
   526 			
       
   527 			newmemberId->SetIdentityL ( h_buf );
       
   528 			
       
   529 			req = groups.AddPresentityGroupMemberL(
       
   530 			                    *newGroupId,
       
   531 			                    *newmemberId,
       
   532 			                    KNullDesC()) ;	
       
   533 
       
   534 			//eventObserver->WaitOpToCompleteL ( req );
       
   535 			//CUserAfter::AfterL ( 5000000 );
       
   536 			//Wait at the below eventObserver->WaitOpToCompleteL( req );
       
   537 			
       
   538 			
       
   539 //-------------------Adding Contact End-----------------------------------------						
       
   540 			break;	
       
   541 			}
       
   542 		case ESecondSearch:
       
   543 			{
       
   544 			
       
   545 			firstId->SetIdentityL(_L("sharath"));
       
   546 			srchElement1->SetRequestL( *firstId, EUserFirstName );
       
   547 			
       
   548 			searchList.Append(srchElement1);
       
   549 			
       
   550 			req=srch.SearchL(*searchId,searchList,10 );
       
   551 			
       
   552 			eventObserver->WaitOpToCompleteL( req );
       
   553 					
       
   554 			CUserAfter::AfterL(100000);
       
   555 			searchList.Reset();
       
   556 			
       
   557 			//Second Search
       
   558 			secondId->SetIdentityL(_L("Jeppu"));
       
   559 			srchElement1->SetRequestL( *secondId, EUserLastName );
       
   560 			
       
   561 			searchList.Append(srchElement1);
       
   562 			
       
   563 			req=srch.SearchL(*searchId,searchList,10 );
       
   564 			
       
   565 			break;
       
   566 			}
       
   567 					
       
   568 		}
       
   569     
       
   570     CleanupStack::PopAndDestroy (); //newmemberId
       
   571 	CleanupStack::PopAndDestroy ();//newGroupId
       
   572 	CleanupStack::PopAndDestroy ();//presenceFeatures
       
   573     
       
   574 	CleanupStack::PopAndDestroy (); //
       
   575 	CleanupStack::PopAndDestroy ();
       
   576 	CleanupStack::PopAndDestroy ();
       
   577 	
       
   578 	CleanupStack::PopAndDestroy ();
       
   579 	CleanupStack::PopAndDestroy ();
       
   580 	
       
   581 	CleanupStack::PopAndDestroy ();
       
   582 
       
   583 	eventObserver->WaitOpToCompleteL( req );
       
   584 	//Unbind the context and wait completion
       
   585     req = presecenCtx->UnbindL();
       
   586     eventObserver->WaitOpToCompleteL( req );
       
   587 	TOssAdapMtLogger::Log ( _L ( "Cossadapmt::WaitOpToCompleteL() end" ) );
       
   588 
       
   589 //	CleanupStack::PopAndDestroy ();//Search feature plugin 
       
   590 	CleanupStack::PopAndDestroy ( 3 ); //presecenCtx,eventObserver,ximpClient
       
   591 	TOssAdapMtLogger::Log ( _L ( "Cossadapmt::SearchL() End" ) );
       
   592 	return KErrNone;
       
   593 
       
   594 	}
       
   595 // -----------------------------------------------------------------------------
       
   596 // Cossadapmt::GetSearchKeyEnum
       
   597 // (other items were commented in a header).
       
   598 // -----------------------------------------------------------------------------
       
   599 //
       
   600 TInt Cossadapmt::GetSearchKeyEnumL( CStifItemParser& aItem )
       
   601 	{
       
   602 	return SearchL ( aItem, EGetSearchKeyEnum );	
       
   603 	}
       
   604 
       
   605 // -----------------------------------------------------------------------------
       
   606 // Cossadapmt::GetSearchKeyLabel
       
   607 // (other items were commented in a header).
       
   608 // -----------------------------------------------------------------------------
       
   609 //
       
   610 TInt Cossadapmt::GetSearchKeyLabelL( CStifItemParser& aItem )
       
   611 	{
       
   612 	return SearchL ( aItem, EGetSearchKeyLabel );	
       
   613 	}
       
   614 
       
   615 // -----------------------------------------------------------------------------
       
   616 // Cossadapmt::GetSearchKeyEnumNLabel
       
   617 // (other items were commented in a header).
       
   618 // -----------------------------------------------------------------------------
       
   619 //	
       
   620 TInt Cossadapmt::GetSearchKeyEnumNLabelL( CStifItemParser& aItem )
       
   621 	{
       
   622 	return SearchL ( aItem, EGetSearchKeyEnumNLabel );	
       
   623 	}
       
   624 
       
   625 // -----------------------------------------------------------------------------
       
   626 // Cossadapmt::SearchAndAddToIML
       
   627 // (other items were commented in a header).
       
   628 // -----------------------------------------------------------------------------
       
   629 //
       
   630 
       
   631 TInt Cossadapmt::SecondSearchL( CStifItemParser& aItem )
       
   632 	{
       
   633 	return SearchL ( aItem, ESecondSearch );
       
   634 	}
       
   635 
       
   636 
       
   637 // -----------------------------------------------------------------------------
       
   638 // Cossadapmt::SearchAndAddToIML
       
   639 // (other items were commented in a header).
       
   640 // -----------------------------------------------------------------------------
       
   641 //
       
   642 
       
   643 TInt Cossadapmt::SearchAndAddToIML( CStifItemParser& aItem )
       
   644 	{
       
   645 	return SearchL ( aItem, ESearchAndAddToIm );
       
   646 	}
       
   647 
       
   648 // -----------------------------------------------------------------------------
       
   649 // Cossadapmt::SimpleSearchL
       
   650 // (other items were commented in a header).
       
   651 // -----------------------------------------------------------------------------
       
   652 //
       
   653 
       
   654 TInt Cossadapmt::SimpleSearchL( CStifItemParser& aItem )
       
   655 	{
       
   656 	return SearchL ( aItem, ESimpleSearch );
       
   657 	}
       
   658 // -----------------------------------------------------------------------------
       
   659 // Cossadapmt::MultipleSearchL
       
   660 // (other items were commented in a header).
       
   661 // -----------------------------------------------------------------------------
       
   662 //	
       
   663 TInt Cossadapmt::MultipleSearchL( CStifItemParser& aItem )
       
   664 	{
       
   665 	return SearchL ( aItem, EMultipleSearch );	
       
   666 	}
       
   667 // -----------------------------------------------------------------------------
       
   668 // Cossadapmt::NoResultSearchL
       
   669 // (other items were commented in a header).
       
   670 // -----------------------------------------------------------------------------
       
   671 //
       
   672 TInt Cossadapmt::NoResultSearchL( CStifItemParser& aItem )
       
   673 	{
       
   674 	return SearchL ( aItem, ESearchNoResults );	
       
   675 	}
       
   676 // -----------------------------------------------------------------------------
       
   677 // Cossadapmt::ManyResultsSearchL
       
   678 // (other items were commented in a header).
       
   679 // -----------------------------------------------------------------------------
       
   680 //
       
   681 TInt Cossadapmt::ManyResultsSearchL( CStifItemParser& aItem )
       
   682 	{
       
   683 	return SearchL ( aItem, ESearchManyResults );	
       
   684 	}
       
   685 // -----------------------------------------------------------------------------
       
   686 // Cossadapmt::BlankSearchL.
       
   687 // (other items were commented in a header).
       
   688 // -----------------------------------------------------------------------------
       
   689 //
       
   690 TInt Cossadapmt::BlankSearchL( CStifItemParser& aItem )
       
   691 	{
       
   692 	return SearchL ( aItem, ESearchBlank );	
       
   693 	}
       
   694 // -----------------------------------------------------------------------------
       
   695 // Cossadapmt::MaxCharSearchL
       
   696 // (other items were commented in a header).
       
   697 // -----------------------------------------------------------------------------
       
   698 //
       
   699 TInt Cossadapmt::MaxCharSearchL( CStifItemParser& aItem )
       
   700 	{
       
   701 	return SearchL ( aItem, ESearchMaxChars );	
       
   702 	}
       
   703 // -----------------------------------------------------------------------------
       
   704 // Cossadapmt::SpecialCharSearchL
       
   705 // (other items were commented in a header).
       
   706 // -----------------------------------------------------------------------------
       
   707 //	
       
   708 TInt Cossadapmt::SpecialCharSearchL( CStifItemParser& aItem )
       
   709 	{
       
   710 	return SearchL ( aItem, ESearchSpecialChars );	
       
   711 	}
       
   712 // -----------------------------------------------------------------------------
       
   713 // Cossadapmt::SearchEmailIDL
       
   714 // (other items were commented in a header).
       
   715 // -----------------------------------------------------------------------------
       
   716 //	
       
   717 TInt Cossadapmt::SearchEmailIDL( CStifItemParser& aItem )
       
   718 	{
       
   719 	return SearchL ( aItem, ESearchEmailid );	
       
   720 	}
       
   721 // -----------------------------------------------------------------------------
       
   722 // Cossadapmt::LoginL
       
   723 // Login test method function.
       
   724 // (other items were commented in a header).
       
   725 // -----------------------------------------------------------------------------
       
   726 //
       
   727 TInt Cossadapmt::LoginL ( CStifItemParser& aItem )
       
   728 	{
       
   729 
       
   730 
       
   731 
       
   732 	//Initialize XIMP client
       
   733 	TOssAdapMtLogger::Log ( _L ( "Cossadapmt::LoginL() start" ) );
       
   734 
       
   735 	MXIMPClient* ximpClient = MXIMPClient::NewClientL();
       
   736 	CleanupDeletePushL ( ximpClient );
       
   737 	TOssAdapMtLogger::Log ( _L ( "Cossadapmt::MXIMPClient::NewClientL() start" ) );
       
   738 
       
   739 	//Create new sink to receive presence context events
       
   740 	CUSContextObserver* eventObserver = CUSContextObserver::NewLC();
       
   741 
       
   742 	//Create new presence context
       
   743 	MXIMPContext* presecenCtx = ximpClient->NewPresenceContextLC();
       
   744 	TOssAdapMtLogger::Log ( _L ( "Cossadapmt::ximpClient->NewPresenceContextLC() called" ) );
       
   745 	presecenCtx->RegisterObserverL ( *eventObserver );
       
   746 
       
   747     //read data from cfg file
       
   748     TPtrC               username;
       
   749     TPtrC               password;
       
   750 	TInt                serviceId;
       
   751 
       
   752 	aItem.GetNextString ( username );
       
   753 	aItem.GetNextString ( password );
       
   754 	aItem.GetNextInt ( serviceId );
       
   755 
       
   756 	TUid protocolUid = TUid::Uid ( KProtocolUid );
       
   757 
       
   758 	//Bind context to desired presence service
       
   759 	TXIMPRequestId req = presecenCtx->BindToL ( protocolUid,
       
   760 	                     username,
       
   761 	                     password,
       
   762 	                     serviceId );
       
   763 	TOssAdapMtLogger::Log ( _L ( "Cossadapmt::presecenCtx->BindToL() called" ) );
       
   764 	//Wait with CActiveSchedulerWait the binding to complete
       
   765 	//If binding fails, it is handled with leave
       
   766 	eventObserver->WaitOpToCompleteL ( req );
       
   767 
       
   768 
       
   769 	//Unbind the context and wait completion
       
   770     req = presecenCtx->UnbindL();
       
   771     eventObserver->WaitOpToCompleteL( req );
       
   772 	TOssAdapMtLogger::Log ( _L ( "Cossadapmt::WaitOpToCompleteL() end" ) );
       
   773 
       
   774 	CleanupStack::PopAndDestroy ( 3 ); //presecenCtx,eventObserver,ximpClient
       
   775 	TOssAdapMtLogger::Log ( _L ( "Cossadapmt::LoginL() End" ) );
       
   776 	return KErrNone;
       
   777 
       
   778 	}
       
   779 // -----------------------------------------------------------------------------
       
   780 // Cossadapmt::Login_InvalidDataL
       
   781 // Login test method function.
       
   782 // (other items were commented in a header).
       
   783 // -----------------------------------------------------------------------------
       
   784 //
       
   785 TInt Cossadapmt::Login_InvalidDataL ( CStifItemParser& aItem )
       
   786 	{
       
   787 
       
   788 
       
   789 
       
   790 	//Initialize XIMP client
       
   791 	TOssAdapMtLogger::Log ( _L ( "Cossadapmt::Login_InvalidDataL() start" ) );
       
   792 
       
   793 	MXIMPClient* ximpClient = MXIMPClient::NewClientL();
       
   794 	CleanupDeletePushL ( ximpClient );
       
   795 	TOssAdapMtLogger::Log ( _L ( "Cossadapmt::MXIMPClient::NewClientL() start" ) );
       
   796 
       
   797 	//Create new sink to receive presence context events
       
   798 	CUSContextObserver* eventObserver = CUSContextObserver::NewLC();
       
   799 
       
   800 	//Create new presence context
       
   801 	MXIMPContext* presecenCtx = ximpClient->NewPresenceContextLC();
       
   802 	TOssAdapMtLogger::Log ( _L ( "Cossadapmt::ximpClient->NewPresenceContextLC() called" ) );
       
   803 	presecenCtx->RegisterObserverL ( *eventObserver );
       
   804 
       
   805     //read data from cfg file
       
   806     TPtrC               username;
       
   807     TPtrC               password;
       
   808 	TInt                serviceId;
       
   809 
       
   810 	aItem.GetNextString ( username );
       
   811 	aItem.GetNextString ( password );
       
   812 	aItem.GetNextInt ( serviceId );
       
   813 
       
   814 	TUid protocolUid = TUid::Uid ( KProtocolUid );
       
   815 
       
   816 	//Bind context to desired presence service
       
   817 	TXIMPRequestId req = presecenCtx->BindToL ( protocolUid,
       
   818 	                     username,
       
   819 	                     password,
       
   820 	                     serviceId );
       
   821 	TOssAdapMtLogger::Log ( _L ( "Cossadapmt::presecenCtx->BindToL() called" ) );
       
   822 	//Wait with CActiveSchedulerWait the binding to complete
       
   823 	//If binding fails, it is handled with leave
       
   824 	eventObserver->WaitOpToCompleteL ( req );
       
   825 
       
   826 	CleanupStack::PopAndDestroy ( 3 ); //presecenCtx,eventObserver,ximpClient
       
   827 	TOssAdapMtLogger::Log ( _L ( "Cossadapmt::Login_InvalidDataL() End" ) );
       
   828 	return KErrNone;
       
   829 
       
   830 	}
       
   831 // -----------------------------------------------------------------------------
       
   832 // Cossadapmt::Login8HrsLogoutL
       
   833 // Login test method function.
       
   834 // (other items were commented in a header).
       
   835 // -----------------------------------------------------------------------------
       
   836 //
       
   837 TInt Cossadapmt::Login8HrsLogoutL ( CStifItemParser& aItem )
       
   838 	{
       
   839 
       
   840 
       
   841 
       
   842 	//Initialize XIMP client
       
   843 	TOssAdapMtLogger::Log ( _L ( "Cossadapmt::Login8HrsLogoutL() start" ) );
       
   844 
       
   845 	MXIMPClient* ximpClient = MXIMPClient::NewClientL();
       
   846 	CleanupDeletePushL ( ximpClient );
       
   847 	TOssAdapMtLogger::Log ( _L ( "Cossadapmt::MXIMPClient::NewClientL() start" ) );
       
   848 
       
   849 	//Create new sink to receive presence context events
       
   850 	CUSContextObserver* eventObserver = CUSContextObserver::NewLC();
       
   851 
       
   852 	//Create new presence context
       
   853 	MXIMPContext* presecenCtx = ximpClient->NewPresenceContextLC();
       
   854 	TOssAdapMtLogger::Log ( _L ( "Cossadapmt::ximpClient->NewPresenceContextLC() called" ) );
       
   855 	presecenCtx->RegisterObserverL ( *eventObserver );
       
   856 
       
   857 
       
   858     //read data from cfg file
       
   859     TPtrC               username;
       
   860     TPtrC               password;
       
   861 	TInt                serviceId;
       
   862 
       
   863 	aItem.GetNextString ( username );
       
   864 	aItem.GetNextString ( password );
       
   865 	aItem.GetNextInt ( serviceId );
       
   866 
       
   867 	TUid protocolUid = TUid::Uid ( KProtocolUid );
       
   868 
       
   869 	//Bind context to desired presence service
       
   870 	TXIMPRequestId req = presecenCtx->BindToL ( protocolUid,
       
   871 	                     username,
       
   872 	                     password,
       
   873 	                     serviceId );
       
   874 	TOssAdapMtLogger::Log ( _L ( "Cossadapmt::presecenCtx->BindToL() called" ) );
       
   875 	//Wait with CActiveSchedulerWait the binding to complete
       
   876 	//If binding fails, it is handled with leave
       
   877 	eventObserver->WaitOpToCompleteL ( req );
       
   878 	CUserAfter::After8HrsL ();
       
   879 
       
   880 	//Unbind the context and wait completion
       
   881     req = presecenCtx->UnbindL();
       
   882     eventObserver->WaitOpToCompleteL( req );
       
   883 	TOssAdapMtLogger::Log ( _L ( "Cossadapmt::WaitOpToCompleteL() end" ) );
       
   884 
       
   885 	CleanupStack::PopAndDestroy ( 3 ); //presecenCtx,eventObserver,ximpClient
       
   886 	TOssAdapMtLogger::Log ( _L ( "Cossadapmt::Login8HrsLogoutL() End" ) );
       
   887 	return KErrNone;
       
   888 
       
   889 	}
       
   890 	
       
   891 // -----------------------------------------------------------------------------
       
   892 // Cossadapmt::LoginLogout_LoginLogoutL
       
   893 // Login test method function.
       
   894 // (other items were commented in a header).
       
   895 // -----------------------------------------------------------------------------
       
   896 //
       
   897 TInt Cossadapmt::LoginLogout_LoginLogoutL ( CStifItemParser& aItem )
       
   898 	{
       
   899 
       
   900 
       
   901 
       
   902 	//Initialize XIMP client
       
   903 	TOssAdapMtLogger::Log ( _L ( "Cossadapmt::LoginLogout_Log() start" ) );
       
   904 
       
   905 	MXIMPClient* ximpClient = MXIMPClient::NewClientL();
       
   906 	CleanupDeletePushL ( ximpClient );
       
   907 	TOssAdapMtLogger::Log ( _L ( "Cossadapmt::MXIMPClient::NewClientL() start" ) );
       
   908 
       
   909 	//Create new sink to receive presence context events
       
   910 	CUSContextObserver* eventObserver = CUSContextObserver::NewLC();
       
   911 
       
   912 	//Create new presence context
       
   913 	MXIMPContext* presecenCtx = ximpClient->NewPresenceContextLC();
       
   914 	TOssAdapMtLogger::Log ( _L ( "Cossadapmt::ximpClient->NewPresenceContextLC() called" ) );
       
   915 	presecenCtx->RegisterObserverL ( *eventObserver );
       
   916     //read data from cfg file
       
   917     TPtrC               username;
       
   918     TPtrC               password;
       
   919 	TInt                serviceId;
       
   920 
       
   921 	aItem.GetNextString ( username );
       
   922 	aItem.GetNextString ( password );
       
   923 	aItem.GetNextInt ( serviceId );
       
   924 
       
   925 	TUid protocolUid = TUid::Uid ( KProtocolUid );
       
   926 
       
   927 	//Bind context to desired presence service
       
   928 	TXIMPRequestId req = presecenCtx->BindToL ( protocolUid,
       
   929 	                     username,
       
   930 	                     password,
       
   931 	                     serviceId );
       
   932 	TOssAdapMtLogger::Log ( _L ( "Cossadapmt::presecenCtx->BindToL() called - Sequence 1" ) );
       
   933 	//Wait with CActiveSchedulerWait the binding to complete
       
   934 	//If binding fails, it is handled with leave
       
   935 	eventObserver->WaitOpToCompleteL ( req );
       
   936 
       
   937 	//Unbind the context and wait completion
       
   938     req = presecenCtx->UnbindL();
       
   939     eventObserver->WaitOpToCompleteL( req );
       
   940 	TOssAdapMtLogger::Log ( _L ( "Cossadapmt::WaitOpToCompleteL() end- Sequence 1 complete" ) );
       
   941 	
       
   942 
       
   943 /// Login --- Logout  - Sequence 2
       
   944 	//Bind context to desired presence service
       
   945 	req = presecenCtx->BindToL ( protocolUid,
       
   946 	                     username,
       
   947 	                     password,
       
   948 	                     serviceId );
       
   949 	TOssAdapMtLogger::Log ( _L ( "Cossadapmt::presecenCtx->BindToL() called  - Sequence 2" ) );
       
   950 	//Wait with CActiveSchedulerWait the binding to complete
       
   951 	//If binding fails, it is handled with leave
       
   952 	eventObserver->WaitOpToCompleteL ( req );
       
   953 
       
   954 	//Unbind the context and wait completion
       
   955     req = presecenCtx->UnbindL();
       
   956     eventObserver->WaitOpToCompleteL( req );
       
   957 	TOssAdapMtLogger::Log ( _L ( "Cossadapmt::WaitOpToCompleteL() end - Sequence 2 complete" ) );
       
   958 
       
   959 
       
   960 	CleanupStack::PopAndDestroy ( 3 ); //presecenCtx,eventObserver,ximpClient
       
   961 	TOssAdapMtLogger::Log ( _L ( "Cossadapmt::LoginLogout_Log() End" ) );
       
   962 	return KErrNone;
       
   963 
       
   964 	}
       
   965 	
       
   966 
       
   967 // -----------------------------------------------------------------------------
       
   968 // Cossadapmt::GetContactsL
       
   969 // Fetch contacts test method function.
       
   970 // (other items were commented in a header).
       
   971 // -----------------------------------------------------------------------------
       
   972 //
       
   973 TInt Cossadapmt::GetContactsL ( CStifItemParser& aItem )
       
   974 	{
       
   975 
       
   976 	//Initialize XIMP client
       
   977 	TOssAdapMtLogger::Log ( _L ( "Cossadapmt::GetContactsL() start" ) );
       
   978 
       
   979 	MXIMPClient* ximpClient = MXIMPClient::NewClientL();
       
   980 	CleanupDeletePushL ( ximpClient );
       
   981 	TOssAdapMtLogger::Log ( _L ( "Cossadapmt::MXIMPClient::NewClientL() start" ) );
       
   982 
       
   983 	//Create new sink to receive presence context events
       
   984 	CUSContextObserver* eventObserver = CUSContextObserver::NewLC();
       
   985 
       
   986 	//Create new presence context
       
   987 	MXIMPContext* presecenCtx = ximpClient->NewPresenceContextLC();
       
   988 	TOssAdapMtLogger::Log ( _L ( "Cossadapmt::ximpClient->NewPresenceContextLC() called" ) );
       
   989 	presecenCtx->RegisterObserverL ( *eventObserver );
       
   990 	MPresenceFeatures* presenceFeatures = NULL;
       
   991 	presenceFeatures = MPresenceFeatures::NewL ( presecenCtx );
       
   992 	CleanupDeletePushL ( presenceFeatures );
       
   993 	TOssAdapMtLogger::Log ( _L ( "Loading presence plugin Done" ) );
       
   994 	MXIMPObjectFactory& objFactory = presecenCtx->ObjectFactory();
       
   995 	MXIMPIdentity* newGroupId = objFactory.NewIdentityLC();
       
   996 	MPresentityGroups& groups = presenceFeatures->PresentityGroups() ;
       
   997 
       
   998 	TOssAdapMtLogger::Log ( _L ( "presentity groups object created" ) );
       
   999 	_LIT ( KDummyListId, "list" );
       
  1000 	HBufC16* iListId;
       
  1001 	iListId = KDummyListId().AllocL();
       
  1002 	iListId->Des().Fold();
       
  1003 	newGroupId->SetIdentityL ( *iListId );
       
  1004 	delete iListId;
       
  1005 	iListId = NULL;
       
  1006 
       
  1007     //read data from cfg file
       
  1008     TPtrC               username;
       
  1009     TPtrC               password;
       
  1010 	TInt                serviceId;
       
  1011 
       
  1012 	aItem.GetNextString ( username );
       
  1013 	aItem.GetNextString ( password );
       
  1014 	aItem.GetNextInt ( serviceId );
       
  1015 
       
  1016 	TUid protocolUid = TUid::Uid ( KProtocolUid );
       
  1017 
       
  1018 	//Bind context to desired presence service
       
  1019 	TXIMPRequestId req = presecenCtx->BindToL ( protocolUid,
       
  1020 	                     username,
       
  1021 	                     password,
       
  1022 	                     serviceId );
       
  1023 
       
  1024 	TOssAdapMtLogger::Log ( _L ( "Cossadapmt::presecenCtx->BindToL() called" ) );
       
  1025 	//Wait with CActiveSchedulerWait the binding to complete
       
  1026 	//If binding fails, it is handled with leave
       
  1027 	eventObserver->WaitOpToCompleteL ( req );
       
  1028 
       
  1029 	
       
  1030 	req = groups.SubscribePresentityGroupContentL ( *newGroupId );
       
  1031 
       
  1032 	TOssAdapMtLogger::Log ( _L ( "Cossadapmt::groups.SubscribePresentityGroupListL() called" ) );
       
  1033 
       
  1034 	eventObserver->WaitOpToCompleteL ( req );
       
  1035 
       
  1036 	CUserAfter::AfterL ( 1000000 );
       
  1037 	//Unbind the context and wait completion
       
  1038 	req = presecenCtx->UnbindL();
       
  1039 	TOssAdapMtLogger::Log ( _L ( "Cossadapmt::presecenCtx->UnbindL() called" ) );
       
  1040 
       
  1041 	eventObserver->WaitOpToCompleteL ( req );
       
  1042 	TOssAdapMtLogger::Log ( _L ( "Cossadapmt::WaitOpToCompleteL() end" ) );
       
  1043 
       
  1044 	CleanupStack::PopAndDestroy ( 5 );//newGroupId,presenceFeatures,presecenCtx,eventObserver,ximpClient
       
  1045 	TOssAdapMtLogger::Log ( _L ( "Cossadapmt::GetContactsL() end" ) );
       
  1046 
       
  1047 	return KErrNone;
       
  1048 
       
  1049 	}
       
  1050 // -----------------------------------------------------------------------------
       
  1051 // Cossadapmt::AddConatctL
       
  1052 // AddConatctL contacts test method function.
       
  1053 // (other items were commented in a header).
       
  1054 // -----------------------------------------------------------------------------
       
  1055 //
       
  1056 TInt Cossadapmt::AddConatctL ( CStifItemParser& aItem )
       
  1057 	{
       
  1058 
       
  1059 	//Initialize XIMP client
       
  1060 	TOssAdapMtLogger::Log ( _L ( "Cossadapmt::AddContactsL() start" ) );
       
  1061 
       
  1062 	MXIMPClient* ximpClient = MXIMPClient::NewClientL();
       
  1063 	CleanupDeletePushL ( ximpClient );
       
  1064 	TOssAdapMtLogger::Log ( _L ( "Cossadapmt::MXIMPClient::NewClientL() start" ) );
       
  1065 
       
  1066 	//Create new sink to receive presence context events
       
  1067 	CUSContextObserver* eventObserver = CUSContextObserver::NewLC();
       
  1068 
       
  1069 	//Create new presence context
       
  1070 	MXIMPContext* presecenCtx = ximpClient->NewPresenceContextLC();
       
  1071 	TOssAdapMtLogger::Log ( _L ( "Cossadapmt::ximpClient->NewPresenceContextLC() called" ) );
       
  1072 	presecenCtx->RegisterObserverL ( *eventObserver );
       
  1073 	MPresenceFeatures* presenceFeatures = NULL;
       
  1074 	presenceFeatures = MPresenceFeatures::NewL ( presecenCtx );
       
  1075 	CleanupDeletePushL ( presenceFeatures );
       
  1076 	TOssAdapMtLogger::Log ( _L ( "Loading presence plugin Done" ) );
       
  1077 	MXIMPObjectFactory& objFactory = presecenCtx->ObjectFactory();
       
  1078 	MXIMPIdentity* newGroupId = objFactory.NewIdentityLC();
       
  1079 	MPresentityGroups& groups = presenceFeatures->PresentityGroups() ;
       
  1080 	MXIMPIdentity* newmemberId = objFactory.NewIdentityLC();
       
  1081 
       
  1082 	TOssAdapMtLogger::Log ( _L ( "presentity groups object created" ) );
       
  1083 	_LIT ( KDummyListId, "list" );
       
  1084 	HBufC16* iListId;
       
  1085 	iListId = KDummyListId().AllocL();
       
  1086 	iListId->Des().Fold();
       
  1087 	newGroupId->SetIdentityL ( *iListId );
       
  1088 	delete iListId;
       
  1089 	iListId = NULL;
       
  1090 
       
  1091     //read data from cfg file
       
  1092     TPtrC               username;
       
  1093     TPtrC               password;
       
  1094 	TInt                serviceId;
       
  1095     TPtrC               contact;
       
  1096     
       
  1097 	aItem.GetNextString ( username );
       
  1098 	aItem.GetNextString ( password );
       
  1099 	aItem.GetNextInt ( serviceId );
       
  1100 	aItem.GetNextString ( contact );
       
  1101 
       
  1102 	TUid protocolUid = TUid::Uid ( KProtocolUid );
       
  1103 
       
  1104 	//Bind context to desired presence service
       
  1105 	TXIMPRequestId req = presecenCtx->BindToL ( protocolUid,
       
  1106 	                     username,
       
  1107 	                     password,
       
  1108 	                     serviceId );
       
  1109 	TOssAdapMtLogger::Log ( _L ( "Cossadapmt::presecenCtx->BindToL() called" ) );
       
  1110 	//Wait with CActiveSchedulerWait the binding to complete
       
  1111 	//If binding fails, it is handled with leave
       
  1112 	eventObserver->WaitOpToCompleteL ( req );
       
  1113 
       
  1114 	req = groups.SubscribePresentityGroupContentL ( *newGroupId );
       
  1115 
       
  1116 	TOssAdapMtLogger::Log ( _L ( "Cossadapmt::groups.SubscribePresentityGroupListL() called" ) );
       
  1117 
       
  1118 	eventObserver->WaitOpToCompleteL ( req );
       
  1119 
       
  1120 	CUserAfter::AfterL ( 1000000 );
       
  1121 	
       
  1122 	 newmemberId->SetIdentityL ( contact );
       
  1123 	
       
  1124 	req = groups.AddPresentityGroupMemberL(
       
  1125 	                    *newGroupId,
       
  1126 	                    *newmemberId,
       
  1127 	                    KNullDesC()) ;	
       
  1128 
       
  1129 	eventObserver->WaitOpToCompleteL ( req );
       
  1130 	CUserAfter::AfterL ( 5000000 );
       
  1131 	 CleanupStack::PopAndDestroy();//newmemberId
       
  1132 	//Unbind the context and wait completion
       
  1133 	req = presecenCtx->UnbindL();
       
  1134 	TOssAdapMtLogger::Log ( _L ( "Cossadapmt::presecenCtx->UnbindL() called" ) );
       
  1135 
       
  1136 	eventObserver->WaitOpToCompleteL ( req );
       
  1137 	TOssAdapMtLogger::Log ( _L ( "Cossadapmt::WaitOpToCompleteL() end" ) );
       
  1138 
       
  1139 	CleanupStack::PopAndDestroy ( 5 );//newGroupId,presenceFeatures,presecenCtx,eventObserver,ximpClient
       
  1140 	TOssAdapMtLogger::Log ( _L ( "Cossadapmt::AddContactsL() end" ) );
       
  1141 
       
  1142 	return KErrNone;
       
  1143 
       
  1144 	}
       
  1145 // -----------------------------------------------------------------------------
       
  1146 // Cossadapmt::AddBlankConatctL
       
  1147 // AddConatctL contacts test method function.
       
  1148 // (other items were commented in a header).
       
  1149 // -----------------------------------------------------------------------------
       
  1150 //
       
  1151 TInt Cossadapmt::AddBlankConatctL ( CStifItemParser& aItem )
       
  1152 	{
       
  1153 
       
  1154 	//Initialize XIMP client
       
  1155 	TOssAdapMtLogger::Log ( _L ( "Cossadapmt::AddBlankConatctL() start" ) );
       
  1156 
       
  1157 	MXIMPClient* ximpClient = MXIMPClient::NewClientL();
       
  1158 	CleanupDeletePushL ( ximpClient );
       
  1159 	TOssAdapMtLogger::Log ( _L ( "Cossadapmt::MXIMPClient::NewClientL() start" ) );
       
  1160 
       
  1161 	//Create new sink to receive presence context events
       
  1162 	CUSContextObserver* eventObserver = CUSContextObserver::NewLC();
       
  1163 
       
  1164 	//Create new presence context
       
  1165 	MXIMPContext* presecenCtx = ximpClient->NewPresenceContextLC();
       
  1166 	TOssAdapMtLogger::Log ( _L ( "Cossadapmt::ximpClient->NewPresenceContextLC() called" ) );
       
  1167 	presecenCtx->RegisterObserverL ( *eventObserver );
       
  1168 	MPresenceFeatures* presenceFeatures = NULL;
       
  1169 	presenceFeatures = MPresenceFeatures::NewL ( presecenCtx );
       
  1170 	CleanupDeletePushL ( presenceFeatures );
       
  1171 	TOssAdapMtLogger::Log ( _L ( "Loading presence plugin Done" ) );
       
  1172 	MXIMPObjectFactory& objFactory = presecenCtx->ObjectFactory();
       
  1173 	MXIMPIdentity* newGroupId = objFactory.NewIdentityLC();
       
  1174 	MPresentityGroups& groups = presenceFeatures->PresentityGroups() ;
       
  1175 	MXIMPIdentity* newmemberId = objFactory.NewIdentityLC();
       
  1176 
       
  1177 	TOssAdapMtLogger::Log ( _L ( "presentity groups object created" ) );
       
  1178 	_LIT ( KDummyListId, "list" );
       
  1179 	HBufC16* iListId;
       
  1180 	iListId = KDummyListId().AllocL();
       
  1181 	iListId->Des().Fold();
       
  1182 	newGroupId->SetIdentityL ( *iListId );
       
  1183 	delete iListId;
       
  1184 	iListId = NULL;
       
  1185 
       
  1186     //read data from cfg file
       
  1187     TPtrC               username;
       
  1188     TPtrC               password;
       
  1189 	TInt                serviceId;
       
  1190     
       
  1191 	aItem.GetNextString ( username );
       
  1192 	aItem.GetNextString ( password );
       
  1193 	aItem.GetNextInt ( serviceId );
       
  1194 
       
  1195 	TUid protocolUid = TUid::Uid ( KProtocolUid );
       
  1196 
       
  1197 	//Bind context to desired presence service
       
  1198 	TXIMPRequestId req = presecenCtx->BindToL ( protocolUid,
       
  1199 	                     username,
       
  1200 	                     password,
       
  1201 	                     serviceId );
       
  1202 	TOssAdapMtLogger::Log ( _L ( "Cossadapmt::presecenCtx->BindToL() called" ) );
       
  1203 	//Wait with CActiveSchedulerWait the binding to complete
       
  1204 	//If binding fails, it is handled with leave
       
  1205 	eventObserver->WaitOpToCompleteL ( req );
       
  1206 
       
  1207 	
       
  1208 	req = groups.SubscribePresentityGroupContentL ( *newGroupId );
       
  1209 
       
  1210 	TOssAdapMtLogger::Log ( _L ( "Cossadapmt::groups.SubscribePresentityGroupListL() called" ) );
       
  1211 
       
  1212 	eventObserver->WaitOpToCompleteL ( req );
       
  1213 
       
  1214 	CUserAfter::AfterL ( 1000000 );
       
  1215 	_LIT ( KBlankContact, "" );
       
  1216 	 newmemberId->SetIdentityL ( KBlankContact );
       
  1217 	 
       
  1218 	
       
  1219 	req = groups.AddPresentityGroupMemberL(
       
  1220 	                    *newGroupId,
       
  1221 	                    *newmemberId,
       
  1222 	                    KNullDesC()) ;	
       
  1223 
       
  1224 	eventObserver->WaitOpToCompleteL ( req );
       
  1225 	//Unbind the context and wait completion
       
  1226 	req = presecenCtx->UnbindL();
       
  1227 	TOssAdapMtLogger::Log ( _L ( "Cossadapmt::presecenCtx->UnbindL() called" ) );
       
  1228 
       
  1229 	eventObserver->WaitOpToCompleteL ( req );
       
  1230 	TOssAdapMtLogger::Log ( _L ( "Cossadapmt::WaitOpToCompleteL() end" ) );
       
  1231 	CleanupStack::PopAndDestroy();
       
  1232 	CleanupStack::PopAndDestroy ( 5 );//newGroupId,presenceFeatures,presecenCtx,eventObserver,ximpClient
       
  1233 	TOssAdapMtLogger::Log ( _L ( "Cossadapmt::AddBlankConatctL() end" ) );
       
  1234 
       
  1235 	return KErrNone;
       
  1236 
       
  1237 	}
       
  1238 // -----------------------------------------------------------------------------
       
  1239 // Cossadapmt::AddBlankConatct1L
       
  1240 // AddConatctL contacts test method function.
       
  1241 // (other items were commented in a header).
       
  1242 // -----------------------------------------------------------------------------
       
  1243 //
       
  1244 TInt Cossadapmt::AddBlankConatct1L ( CStifItemParser& aItem )
       
  1245 	{
       
  1246 
       
  1247 	//Initialize XIMP client
       
  1248 	TOssAdapMtLogger::Log ( _L ( "Cossadapmt::AddBlankConatctL() start" ) );
       
  1249 
       
  1250 	MXIMPClient* ximpClient = MXIMPClient::NewClientL();
       
  1251 	CleanupDeletePushL ( ximpClient );
       
  1252 	TOssAdapMtLogger::Log ( _L ( "Cossadapmt::MXIMPClient::NewClientL() start" ) );
       
  1253 
       
  1254 	//Create new sink to receive presence context events
       
  1255 	CUSContextObserver* eventObserver = CUSContextObserver::NewLC();
       
  1256 
       
  1257 	//Create new presence context
       
  1258 	MXIMPContext* presecenCtx = ximpClient->NewPresenceContextLC();
       
  1259 	TOssAdapMtLogger::Log ( _L ( "Cossadapmt::ximpClient->NewPresenceContextLC() called" ) );
       
  1260 	presecenCtx->RegisterObserverL ( *eventObserver );
       
  1261 	MPresenceFeatures* presenceFeatures = NULL;
       
  1262 	presenceFeatures = MPresenceFeatures::NewL ( presecenCtx );
       
  1263 	CleanupDeletePushL ( presenceFeatures );
       
  1264 	TOssAdapMtLogger::Log ( _L ( "Loading presence plugin Done" ) );
       
  1265 	MXIMPObjectFactory& objFactory = presecenCtx->ObjectFactory();
       
  1266 	MXIMPIdentity* newGroupId = objFactory.NewIdentityLC();
       
  1267 	MPresentityGroups& groups = presenceFeatures->PresentityGroups() ;
       
  1268 	MXIMPIdentity* newmemberId = objFactory.NewIdentityLC();
       
  1269 
       
  1270 	TOssAdapMtLogger::Log ( _L ( "presentity groups object created" ) );
       
  1271 	_LIT ( KDummyListId, "list" );
       
  1272 	HBufC16* iListId;
       
  1273 	iListId = KDummyListId().AllocL();
       
  1274 	iListId->Des().Fold();
       
  1275 	newGroupId->SetIdentityL ( *iListId );
       
  1276 	delete iListId;
       
  1277 	iListId = NULL;
       
  1278 
       
  1279     //read data from cfg file
       
  1280     TPtrC               username;
       
  1281     TPtrC               password;
       
  1282 	TInt                serviceId;
       
  1283     
       
  1284 	aItem.GetNextString ( username );
       
  1285 	aItem.GetNextString ( password );
       
  1286 	aItem.GetNextInt ( serviceId );
       
  1287 
       
  1288 	TUid protocolUid = TUid::Uid ( KProtocolUid );
       
  1289 
       
  1290 	//Bind context to desired presence service
       
  1291 	TXIMPRequestId req = presecenCtx->BindToL ( protocolUid,
       
  1292 	                     username,
       
  1293 	                     password,
       
  1294 	                     serviceId );
       
  1295 	TOssAdapMtLogger::Log ( _L ( "Cossadapmt::presecenCtx->BindToL() called" ) );
       
  1296 	//Wait with CActiveSchedulerWait the binding to complete
       
  1297 	//If binding fails, it is handled with leave
       
  1298 	eventObserver->WaitOpToCompleteL ( req );
       
  1299 
       
  1300 	
       
  1301 	req = groups.SubscribePresentityGroupContentL ( *newGroupId );
       
  1302 
       
  1303 	TOssAdapMtLogger::Log ( _L ( "Cossadapmt::groups.SubscribePresentityGroupListL() called" ) );
       
  1304 
       
  1305 	eventObserver->WaitOpToCompleteL ( req );
       
  1306 
       
  1307 	CUserAfter::AfterL ( 1000000 );
       
  1308 	_LIT ( KBlankContact, "" );
       
  1309 	 newmemberId->SetIdentityL ( KBlankContact );
       
  1310 	
       
  1311 	req = groups.AddPresentityGroupMemberL(
       
  1312 	                    *newGroupId,
       
  1313 	                    *newmemberId,
       
  1314 	                    KNullDesC()) ;	
       
  1315 
       
  1316 	eventObserver->WaitOpToCompleteL ( req );
       
  1317 	CleanupStack::PopAndDestroy();  //newmemberId
       
  1318 	//Unbind the context and wait completion
       
  1319 	req = presecenCtx->UnbindL();
       
  1320 	TOssAdapMtLogger::Log ( _L ( "Cossadapmt::presecenCtx->UnbindL() called" ) );
       
  1321 
       
  1322 	eventObserver->WaitOpToCompleteL ( req );
       
  1323 	TOssAdapMtLogger::Log ( _L ( "Cossadapmt::WaitOpToCompleteL() end" ) );
       
  1324 
       
  1325 	CleanupStack::PopAndDestroy ( 5 );//newGroupId,presenceFeatures,presecenCtx,eventObserver,ximpClient
       
  1326 	TOssAdapMtLogger::Log ( _L ( "Cossadapmt::AddBlankConatctL() end" ) );
       
  1327 
       
  1328 	return KErrNone;
       
  1329 
       
  1330 	}	
       
  1331 // -----------------------------------------------------------------------------
       
  1332 // Cossadapmt::DeleteConatctL
       
  1333 // DeleteConatctL contacts test method function.
       
  1334 // (other items were commented in a header).
       
  1335 // -----------------------------------------------------------------------------
       
  1336 //
       
  1337 TInt Cossadapmt::DeleteConatctL ( CStifItemParser& aItem )
       
  1338 	{
       
  1339 
       
  1340 	//Initialize XIMP client
       
  1341 	TOssAdapMtLogger::Log ( _L ( "Cossadapmt::DeleteConatctL() start" ) );
       
  1342 
       
  1343 	MXIMPClient* ximpClient = MXIMPClient::NewClientL();
       
  1344 	CleanupDeletePushL ( ximpClient );
       
  1345 	TOssAdapMtLogger::Log ( _L ( "Cossadapmt::MXIMPClient::NewClientL() start" ) );
       
  1346 
       
  1347 	//Create new sink to receive presence context events
       
  1348 	CUSContextObserver* eventObserver = CUSContextObserver::NewLC();
       
  1349 
       
  1350 	//Create new presence context
       
  1351 	MXIMPContext* presecenCtx = ximpClient->NewPresenceContextLC();
       
  1352 	TOssAdapMtLogger::Log ( _L ( "Cossadapmt::ximpClient->NewPresenceContextLC() called" ) );
       
  1353 	presecenCtx->RegisterObserverL ( *eventObserver );
       
  1354 	MPresenceFeatures* presenceFeatures = NULL;
       
  1355 	presenceFeatures = MPresenceFeatures::NewL ( presecenCtx );
       
  1356 	CleanupDeletePushL ( presenceFeatures );
       
  1357 	TOssAdapMtLogger::Log ( _L ( "Loading presence plugin Done" ) );
       
  1358 	MXIMPObjectFactory& objFactory = presecenCtx->ObjectFactory();
       
  1359 	MXIMPIdentity* newGroupId = objFactory.NewIdentityLC();
       
  1360 	MPresentityGroups& groups = presenceFeatures->PresentityGroups() ;
       
  1361 	MXIMPIdentity* newmemberId = objFactory.NewIdentityLC();
       
  1362 
       
  1363 	TOssAdapMtLogger::Log ( _L ( "presentity groups object created" ) );
       
  1364 	_LIT ( KDummyListId, "list" );
       
  1365 	HBufC16* iListId;
       
  1366 	iListId = KDummyListId().AllocL();
       
  1367 	iListId->Des().Fold();
       
  1368 	newGroupId->SetIdentityL ( *iListId );
       
  1369 	delete iListId;
       
  1370 	iListId = NULL;
       
  1371 
       
  1372     //read data from cfg file
       
  1373     TPtrC               username;
       
  1374     TPtrC               password;
       
  1375 	TInt                serviceId;
       
  1376     TPtrC               contact;
       
  1377 
       
  1378 	aItem.GetNextString ( username );
       
  1379 	aItem.GetNextString ( password );
       
  1380 	aItem.GetNextInt ( serviceId );
       
  1381 	aItem.GetNextString ( contact );
       
  1382 
       
  1383 	TUid protocolUid = TUid::Uid ( KProtocolUid );
       
  1384 
       
  1385 	//Bind context to desired presence service
       
  1386 	TXIMPRequestId req = presecenCtx->BindToL ( protocolUid,
       
  1387 	                     username,
       
  1388 	                     password,
       
  1389 	                     serviceId );
       
  1390 	TOssAdapMtLogger::Log ( _L ( "Cossadapmt::presecenCtx->BindToL() called" ) );
       
  1391 	//Wait with CActiveSchedulerWait the binding to complete
       
  1392 	//If binding fails, it is handled with leave
       
  1393 	eventObserver->WaitOpToCompleteL ( req );
       
  1394 
       
  1395 	
       
  1396 	req = groups.SubscribePresentityGroupContentL ( *newGroupId );
       
  1397 
       
  1398 	TOssAdapMtLogger::Log ( _L ( "Cossadapmt::groups.SubscribePresentityGroupListL() called" ) );
       
  1399 
       
  1400 	eventObserver->WaitOpToCompleteL ( req );
       
  1401 
       
  1402 	CUserAfter::AfterL ( 1000000 );
       
  1403 	
       
  1404 	newmemberId->SetIdentityL ( contact );
       
  1405 	
       
  1406 	req = groups.RemovePresentityGroupMemberL(
       
  1407 	                    *newGroupId,
       
  1408 	                    *newmemberId) ;	
       
  1409 
       
  1410 	eventObserver->WaitOpToCompleteL ( req );
       
  1411 	CleanupStack::PopAndDestroy();//newmemberId
       
  1412 	//Unbind the context and wait completion
       
  1413 	req = presecenCtx->UnbindL();
       
  1414 	TOssAdapMtLogger::Log ( _L ( "Cossadapmt::presecenCtx->UnbindL() called" ) );
       
  1415 
       
  1416 	eventObserver->WaitOpToCompleteL ( req );
       
  1417 	TOssAdapMtLogger::Log ( _L ( "Cossadapmt::WaitOpToCompleteL() end" ) );
       
  1418 
       
  1419 	CleanupStack::PopAndDestroy ( 5 );//newGroupId,presenceFeatures,presecenCtx,eventObserver,ximpClient
       
  1420 	TOssAdapMtLogger::Log ( _L ( "Cossadapmt::DeleteConatctL() end" ) );
       
  1421 
       
  1422 	return KErrNone;
       
  1423 
       
  1424 	}
       
  1425 // -----------------------------------------------------------------------------
       
  1426 // Cossadapmt::DeleteBlankConatctL
       
  1427 // DeleteConatctL contacts test method function.
       
  1428 // (other items were commented in a header).
       
  1429 // -----------------------------------------------------------------------------
       
  1430 //
       
  1431 TInt Cossadapmt::DeleteBlankConatctL ( CStifItemParser& aItem )
       
  1432 	{
       
  1433 
       
  1434 	//Initialize XIMP client
       
  1435 	TOssAdapMtLogger::Log ( _L ( "Cossadapmt::DeleteBlankConatctL() start" ) );
       
  1436 
       
  1437 	MXIMPClient* ximpClient = MXIMPClient::NewClientL();
       
  1438 	CleanupDeletePushL ( ximpClient );
       
  1439 	TOssAdapMtLogger::Log ( _L ( "Cossadapmt::MXIMPClient::NewClientL() start" ) );
       
  1440 
       
  1441 	//Create new sink to receive presence context events
       
  1442 	CUSContextObserver* eventObserver = CUSContextObserver::NewLC();
       
  1443 
       
  1444 	//Create new presence context
       
  1445 	MXIMPContext* presecenCtx = ximpClient->NewPresenceContextLC();
       
  1446 	TOssAdapMtLogger::Log ( _L ( "Cossadapmt::ximpClient->NewPresenceContextLC() called" ) );
       
  1447 	presecenCtx->RegisterObserverL ( *eventObserver );
       
  1448 	MPresenceFeatures* presenceFeatures = NULL;
       
  1449 	presenceFeatures = MPresenceFeatures::NewL ( presecenCtx );
       
  1450 	CleanupDeletePushL ( presenceFeatures );
       
  1451 	TOssAdapMtLogger::Log ( _L ( "Loading presence plugin Done" ) );
       
  1452 	MXIMPObjectFactory& objFactory = presecenCtx->ObjectFactory();
       
  1453 	MXIMPIdentity* newGroupId = objFactory.NewIdentityLC();
       
  1454 	MPresentityGroups& groups = presenceFeatures->PresentityGroups() ;
       
  1455 	MXIMPIdentity* newmemberId = objFactory.NewIdentityLC();
       
  1456 
       
  1457 	TOssAdapMtLogger::Log ( _L ( "presentity groups object created" ) );
       
  1458 	_LIT ( KDummyListId, "list" );
       
  1459 	HBufC16* iListId;
       
  1460 	iListId = KDummyListId().AllocL();
       
  1461 	iListId->Des().Fold();
       
  1462 	newGroupId->SetIdentityL ( *iListId );
       
  1463 	delete iListId;
       
  1464 	iListId = NULL;
       
  1465 
       
  1466     //read data from cfg file
       
  1467     TPtrC               username;
       
  1468     TPtrC               password;
       
  1469 	TInt                serviceId;
       
  1470 
       
  1471 	aItem.GetNextString ( username );
       
  1472 	aItem.GetNextString ( password );
       
  1473 	aItem.GetNextInt ( serviceId );
       
  1474 
       
  1475 	TUid protocolUid = TUid::Uid ( KProtocolUid );
       
  1476 
       
  1477 	//Bind context to desired presence service
       
  1478 	TXIMPRequestId req = presecenCtx->BindToL ( protocolUid,
       
  1479 	                     username,
       
  1480 	                     password,
       
  1481 	                     serviceId );
       
  1482 	TOssAdapMtLogger::Log ( _L ( "Cossadapmt::presecenCtx->BindToL() called" ) );
       
  1483 	//Wait with CActiveSchedulerWait the binding to complete
       
  1484 	//If binding fails, it is handled with leave
       
  1485 	eventObserver->WaitOpToCompleteL ( req );
       
  1486 
       
  1487 	
       
  1488 	req = groups.SubscribePresentityGroupContentL ( *newGroupId );
       
  1489 
       
  1490 	TOssAdapMtLogger::Log ( _L ( "Cossadapmt::groups.SubscribePresentityGroupListL() called" ) );
       
  1491 
       
  1492 	eventObserver->WaitOpToCompleteL ( req );
       
  1493 
       
  1494 	CUserAfter::AfterL ( 1000000 );
       
  1495 	_LIT ( KBlankContact, "" );
       
  1496 	newmemberId->SetIdentityL (KBlankContact);
       
  1497 	
       
  1498 	req = groups.RemovePresentityGroupMemberL(
       
  1499 	                    *newGroupId,
       
  1500 	                    *newmemberId) ;	
       
  1501 
       
  1502 	eventObserver->WaitOpToCompleteL ( req );
       
  1503 	CleanupStack::PopAndDestroy();  //newmemberId	
       
  1504 	//Unbind the context and wait completion
       
  1505 	req = presecenCtx->UnbindL();
       
  1506 	TOssAdapMtLogger::Log ( _L ( "Cossadapmt::presecenCtx->UnbindL() called" ) );
       
  1507 
       
  1508 	eventObserver->WaitOpToCompleteL ( req );
       
  1509 	TOssAdapMtLogger::Log ( _L ( "Cossadapmt::WaitOpToCompleteL() end" ) );
       
  1510 
       
  1511 	CleanupStack::PopAndDestroy ( 5 );//newGroupId,presenceFeatures,presecenCtx,eventObserver,ximpClient
       
  1512 	TOssAdapMtLogger::Log ( _L ( "Cossadapmt::DeleteBlankConatctL() end" ) );
       
  1513 
       
  1514 	return KErrNone;
       
  1515 
       
  1516 	}
       
  1517 // -----------------------------------------------------------------------------
       
  1518 // Cossadapmt::UnBindL
       
  1519 // UnBind test method function.
       
  1520 // (other items were commented in a header).
       
  1521 // -----------------------------------------------------------------------------
       
  1522 //
       
  1523 TInt Cossadapmt::UnBindL ( CStifItemParser& aItem )
       
  1524 	{
       
  1525 
       
  1526 	//Initialize XIMP client
       
  1527 	TOssAdapMtLogger::Log ( _L ( "Cossadapmt::UnBindL() start" ) );
       
  1528 
       
  1529 	MXIMPClient* ximpClient = MXIMPClient::NewClientL();
       
  1530 	CleanupDeletePushL ( ximpClient );
       
  1531 	TOssAdapMtLogger::Log ( _L ( "Cossadapmt::MXIMPClient::NewClientL() start" ) );
       
  1532 
       
  1533 	//Create new sink to receive presence context events
       
  1534 	CUSContextObserver* eventObserver = CUSContextObserver::NewLC();
       
  1535 
       
  1536 	//Create new presence context
       
  1537 	MXIMPContext* presecenCtx = ximpClient->NewPresenceContextLC();
       
  1538 	TOssAdapMtLogger::Log ( _L ( "Cossadapmt::ximpClient->NewPresenceContextLC() called" ) );
       
  1539 	presecenCtx->RegisterObserverL ( *eventObserver );
       
  1540 
       
  1541     //read data from cfg file
       
  1542     TPtrC               username;
       
  1543     TPtrC               password;
       
  1544 	TInt                serviceId;
       
  1545 
       
  1546 	aItem.GetNextString ( username );
       
  1547 	aItem.GetNextString ( password );
       
  1548 	aItem.GetNextInt ( serviceId );
       
  1549 
       
  1550 	TUid protocolUid = TUid::Uid ( KProtocolUid );
       
  1551 
       
  1552 	//Bind context to desired presence service
       
  1553 	TXIMPRequestId req = presecenCtx->BindToL ( protocolUid,
       
  1554 	                     username,
       
  1555 	                     password,
       
  1556 	                     serviceId );
       
  1557                      
       
  1558 	TOssAdapMtLogger::Log ( _L ( "Cossadapmt::presecenCtx->BindToL() called" ) );
       
  1559 	//Wait with CActiveSchedulerWait the binding to complete
       
  1560 	//If binding fails, it is handled with leave
       
  1561 	eventObserver->WaitOpToCompleteL ( req );
       
  1562 
       
  1563 
       
  1564 	//Unbind the context and wait completion
       
  1565 	req = presecenCtx->UnbindL();
       
  1566 	eventObserver->WaitOpToCompleteL( req );
       
  1567 	TOssAdapMtLogger::Log ( _L ( "Cossadapmt::WaitOpToCompleteL() end" ) );
       
  1568 
       
  1569 
       
  1570 	CleanupStack::Pop ( 3 ); //presecenCtx,eventObserver,ximpClient
       
  1571 	TOssAdapMtLogger::Log ( _L ( "Cossadapmt::UnBindL() End" ) );
       
  1572 	return KErrNone;
       
  1573 
       
  1574 
       
  1575 	}
       
  1576 
       
  1577 // -----------------------------------------------------------------------------
       
  1578 // Cossadapmt::SendMessageL
       
  1579 // SendMessage test method function.
       
  1580 // (other items were commented in a header).
       
  1581 // -----------------------------------------------------------------------------
       
  1582 //
       
  1583 TInt Cossadapmt::SendMessageL ( CStifItemParser& aItem )
       
  1584 	{
       
  1585 
       
  1586 	//Initialize XIMP client
       
  1587 	TOssAdapMtLogger::Log ( _L ( "Cossadapmt::SendMessageL() start" ) );
       
  1588 	MXIMPClient* ximpClient = MXIMPClient::NewClientL();
       
  1589 	CleanupDeletePushL ( ximpClient );
       
  1590 	TOssAdapMtLogger::Log ( _L ( "Cossadapmt::MXIMPClient::NewClientL() start" ) );
       
  1591 	//Create new sink to receive presence context events
       
  1592 	CUSContextObserver* eventObserver = CUSContextObserver::NewLC();
       
  1593 	//Create new presence context
       
  1594 	MXIMPContext* presecenCtx = ximpClient->NewPresenceContextLC();
       
  1595 	//Bind context to desired presence service
       
  1596 	presecenCtx->RegisterObserverL ( *eventObserver );
       
  1597 	MPresenceFeatures* presenceFeatures = NULL;
       
  1598 	presenceFeatures = MPresenceFeatures::NewL ( presecenCtx );
       
  1599 	CleanupDeletePushL ( presenceFeatures );
       
  1600 
       
  1601     //read data from cfg file
       
  1602     TPtrC               username;
       
  1603     TPtrC               password;
       
  1604 	TInt                serviceId;
       
  1605     TPtrC               message;
       
  1606     TPtrC               recipient;
       
  1607 
       
  1608 	aItem.GetNextString ( username );
       
  1609 	aItem.GetNextString ( password );
       
  1610 	aItem.GetNextInt ( serviceId );
       
  1611 	aItem.GetNextString ( message );
       
  1612 	aItem.GetNextString ( recipient );
       
  1613 
       
  1614 	TUid protocolUid = TUid::Uid ( KProtocolUid );
       
  1615 
       
  1616 	//Bind context to desired presence service
       
  1617 	TXIMPRequestId req = presecenCtx->BindToL ( protocolUid,
       
  1618 	                     username,
       
  1619 	                     password,
       
  1620 	                     serviceId );
       
  1621 	TOssAdapMtLogger::Log ( _L ( "Cossadapmt::ximpClient->NewPresenceContextLC() called\n" ) );
       
  1622 	eventObserver->WaitOpToCompleteL ( req );
       
  1623 	MXIMPObjectFactory& objFactory = presecenCtx->ObjectFactory();
       
  1624 	MXIMPIdentity* newGroupId = objFactory.NewIdentityLC();
       
  1625 	MPresentityGroups& groups = presenceFeatures->PresentityGroups() ;
       
  1626 
       
  1627 	TOssAdapMtLogger::Log ( _L ( "presentity groups object created" ) );
       
  1628 	_LIT ( KDummyListId, "" );
       
  1629 	HBufC16* iListId;
       
  1630 	iListId = KDummyListId().AllocL();
       
  1631 	iListId->Des().Fold();
       
  1632 	newGroupId->SetIdentityL ( *iListId );
       
  1633 	delete iListId;
       
  1634 	iListId = NULL;
       
  1635 	req = groups.SubscribePresentityGroupContentL ( *newGroupId );
       
  1636 
       
  1637 	TOssAdapMtLogger::Log ( _L ( "Cossadapmt::groups.SubscribePresentityGroupListL() called" ) );
       
  1638 
       
  1639 	eventObserver->WaitOpToCompleteL ( req );
       
  1640    CleanupStack::PopAndDestroy(2); //newGroupId,presenceFeatures
       
  1641 
       
  1642 	CUserAfter::AfterL ( 1000000 );
       
  1643 	//Bind context to desired presence service
       
  1644 	MImFeatures* imFeatures = NULL;
       
  1645 	imFeatures = MImFeatures::NewL ( presecenCtx );
       
  1646 	CleanupDeletePushL ( imFeatures );
       
  1647 	TOssAdapMtLogger::Log ( _L ( "Cossadapmt::imFeatures created\n" ) );
       
  1648 	MImConversation& imconversation = imFeatures->ImConversation();
       
  1649 	TOssAdapMtLogger::Log ( _L ( "Cossadapmt::imconversation created\n" ) );
       
  1650 	MImConversationInfo *aImMessage = NULL;
       
  1651 	aImMessage = imFeatures->ImObjectFactory().NewImConversationInfoLC();
       
  1652 	MXIMPIdentity* identity = objFactory.NewIdentityLC();
       
  1653 	identity->SetIdentityL ( KMsgId );
       
  1654 	aImMessage->SetMessageIdL ( identity );
       
  1655 	aImMessage->SetTextMessageL ( message );
       
  1656 	CDesCArrayFlat* aRecipients = new ( ELeave ) CDesCArrayFlat ( 2 );
       
  1657 	CleanupStack::PushL ( aRecipients );  
       
  1658 	aRecipients->AppendL ( recipient );//userid's
       
  1659 	aImMessage->SetRecipientL ( aRecipients );
       
  1660 	TOssAdapMtLogger::Log ( _L ( "Cossadapmt::before sendmessage called\n" ) );
       
  1661 
       
  1662 	req = imconversation.SendMessageL ( *aImMessage );
       
  1663 	eventObserver->WaitOpToCompleteL ( req );
       
  1664 	CleanupStack::Pop ( 3 );//identity,aRecipients,aImMessage
       
  1665 	//Unbind the context and wait completion
       
  1666 	CUserAfter::AfterL ( 2000000 );
       
  1667   	req = presecenCtx->UnbindL();
       
  1668   	eventObserver->WaitOpToCompleteL( req );
       
  1669 
       
  1670 	TOssAdapMtLogger::Log ( _L ( "Cossadapmt::message sent\n " ) );
       
  1671 	CleanupStack::PopAndDestroy(4); //imFeatures,presecenCtx,eventObserver,ximpClient,
       
  1672 	TOssAdapMtLogger::Log ( _L ( "Cossadapmt::SendMessageL() end" ) );
       
  1673 
       
  1674 	return KErrNone;
       
  1675 
       
  1676 	}
       
  1677 // -----------------------------------------------------------------------------
       
  1678 // Cossadapmt::SendEmptyMessageL
       
  1679 // SendMessage test method function.
       
  1680 // (other items were commented in a header).
       
  1681 // -----------------------------------------------------------------------------
       
  1682 //
       
  1683 TInt Cossadapmt::SendEmptyMessageL ( CStifItemParser& aItem )
       
  1684 	{
       
  1685 
       
  1686 	//Initialize XIMP client
       
  1687 	TOssAdapMtLogger::Log ( _L ( "Cossadapmt::SendEmptyMessageL() start" ) );
       
  1688 	MXIMPClient* ximpClient = MXIMPClient::NewClientL();
       
  1689 	CleanupDeletePushL ( ximpClient );
       
  1690 	TOssAdapMtLogger::Log ( _L ( "Cossadapmt::MXIMPClient::NewClientL() start" ) );
       
  1691 	//Create new sink to receive presence context events
       
  1692 	CUSContextObserver* eventObserver = CUSContextObserver::NewLC();
       
  1693 	//Create new presence context
       
  1694 	MXIMPContext* presecenCtx = ximpClient->NewPresenceContextLC();
       
  1695 	//Bind context to desired presence service
       
  1696 	presecenCtx->RegisterObserverL ( *eventObserver );
       
  1697 	MPresenceFeatures* presenceFeatures = NULL;
       
  1698 	presenceFeatures = MPresenceFeatures::NewL ( presecenCtx );
       
  1699 	CleanupDeletePushL ( presenceFeatures );
       
  1700 
       
  1701     //read data from cfg file
       
  1702     TPtrC               username;
       
  1703     TPtrC               password;
       
  1704 	TInt                serviceId;
       
  1705     TPtrC               recipient;
       
  1706 
       
  1707 	aItem.GetNextString ( username );
       
  1708 	aItem.GetNextString ( password );
       
  1709 	aItem.GetNextInt ( serviceId );
       
  1710 	aItem.GetNextString ( recipient );
       
  1711 
       
  1712 	TUid protocolUid = TUid::Uid ( KProtocolUid );
       
  1713 
       
  1714 	//Bind context to desired presence service
       
  1715 	TXIMPRequestId req = presecenCtx->BindToL ( protocolUid,
       
  1716 	                     username,
       
  1717 	                     password,
       
  1718 	                     serviceId );
       
  1719 	TOssAdapMtLogger::Log ( _L ( "Cossadapmt::ximpClient->NewPresenceContextLC() called\n" ) );
       
  1720 	eventObserver->WaitOpToCompleteL ( req );
       
  1721 	MXIMPObjectFactory& objFactory = presecenCtx->ObjectFactory();
       
  1722 	MXIMPIdentity* newGroupId = objFactory.NewIdentityLC();
       
  1723 	MPresentityGroups& groups = presenceFeatures->PresentityGroups() ;
       
  1724 
       
  1725 	TOssAdapMtLogger::Log ( _L ( "presentity groups object created" ) );
       
  1726 	_LIT ( KDummyListId, "" );
       
  1727 	_LIT ( KEmptyMessage, "" );
       
  1728 	HBufC16* iListId;
       
  1729 	iListId = KDummyListId().AllocL();
       
  1730 	iListId->Des().Fold();
       
  1731 	newGroupId->SetIdentityL ( *iListId );
       
  1732 	delete iListId;
       
  1733 	iListId = NULL;
       
  1734 	req = groups.SubscribePresentityGroupContentL ( *newGroupId );
       
  1735 
       
  1736 	TOssAdapMtLogger::Log ( _L ( "Cossadapmt::groups.SubscribePresentityGroupListL() called" ) );
       
  1737 
       
  1738 	eventObserver->WaitOpToCompleteL ( req );
       
  1739    CleanupStack::PopAndDestroy(2); //newGroupId,presenceFeatures
       
  1740 
       
  1741 	CUserAfter::AfterL ( 1000000 );
       
  1742 	//Bind context to desired presence service
       
  1743 	MImFeatures* imFeatures = NULL;
       
  1744 	imFeatures = MImFeatures::NewL ( presecenCtx );
       
  1745 	CleanupDeletePushL ( imFeatures );
       
  1746 	TOssAdapMtLogger::Log ( _L ( "Cossadapmt::imFeatures created\n" ) );
       
  1747 	MImConversation& imconversation = imFeatures->ImConversation();
       
  1748 	TOssAdapMtLogger::Log ( _L ( "Cossadapmt::imconversation created\n" ) );
       
  1749 	MImConversationInfo *aImMessage = NULL;
       
  1750 	aImMessage = imFeatures->ImObjectFactory().NewImConversationInfoLC();
       
  1751 	MXIMPIdentity* identity = objFactory.NewIdentityLC();
       
  1752 	identity->SetIdentityL ( KMsgId );
       
  1753 	aImMessage->SetMessageIdL ( identity );
       
  1754 	aImMessage->SetTextMessageL ( KEmptyMessage );
       
  1755 	CDesCArrayFlat* aRecipients = new ( ELeave ) CDesCArrayFlat ( 2 );
       
  1756 	CleanupStack::PushL ( aRecipients );  
       
  1757 	aRecipients->AppendL ( recipient );//userid's
       
  1758 	aImMessage->SetRecipientL ( aRecipients );
       
  1759 	TOssAdapMtLogger::Log ( _L ( "Cossadapmt::before sendmessage called\n" ) );
       
  1760 
       
  1761 	req = imconversation.SendMessageL ( *aImMessage );
       
  1762 	eventObserver->WaitOpToCompleteL ( req );
       
  1763 	CleanupStack::Pop ( 3 );//identity,aRecipients,aImMessage
       
  1764 	//Unbind the context and wait completion
       
  1765   	req = presecenCtx->UnbindL();
       
  1766   	eventObserver->WaitOpToCompleteL( req );
       
  1767 
       
  1768 	TOssAdapMtLogger::Log ( _L ( "Cossadapmt::message sent\n " ) );
       
  1769 	CleanupStack::PopAndDestroy(4); //imFeatures,presecenCtx,eventObserver,ximpClient,
       
  1770 	TOssAdapMtLogger::Log ( _L ( "Cossadapmt::SendEmptyMessageL() end" ) );
       
  1771 
       
  1772 	return KErrNone;
       
  1773 
       
  1774 	}	
       
  1775 
       
  1776 // -----------------------------------------------------------------------------
       
  1777 // Cossadapmt::SendTenMessageL
       
  1778 // SendMessage test method function.
       
  1779 // (other items were commented in a header).
       
  1780 // -----------------------------------------------------------------------------
       
  1781 //
       
  1782 TInt Cossadapmt::SendTenMessageL ( CStifItemParser& aItem )
       
  1783 	{
       
  1784 
       
  1785 	//Initialize XIMP client
       
  1786 	TOssAdapMtLogger::Log ( _L ( "Cossadapmt::SendTenMessageL() start" ) );
       
  1787 	MXIMPClient* ximpClient = MXIMPClient::NewClientL();
       
  1788 	CleanupDeletePushL ( ximpClient );
       
  1789 	TOssAdapMtLogger::Log ( _L ( "Cossadapmt::MXIMPClient::NewClientL() start" ) );
       
  1790 	//Create new sink to receive presence context events
       
  1791 	CUSContextObserver* eventObserver = CUSContextObserver::NewLC();
       
  1792 	//Create new presence context
       
  1793 	MXIMPContext* presecenCtx = ximpClient->NewPresenceContextLC();
       
  1794 	//Bind context to desired presence service
       
  1795 	presecenCtx->RegisterObserverL ( *eventObserver );
       
  1796 	MPresenceFeatures* presenceFeatures = NULL;
       
  1797 	presenceFeatures = MPresenceFeatures::NewL ( presecenCtx );
       
  1798 	CleanupDeletePushL ( presenceFeatures );
       
  1799 
       
  1800     //read data from cfg file
       
  1801     TPtrC               username;
       
  1802     TPtrC               password;
       
  1803 	TInt                serviceId;
       
  1804     TPtrC               message;
       
  1805     TPtrC               recipient;
       
  1806 
       
  1807 	aItem.GetNextString ( username );
       
  1808 	aItem.GetNextString ( password );
       
  1809 	aItem.GetNextInt ( serviceId );
       
  1810 	aItem.GetNextString ( message );
       
  1811 	aItem.GetNextString ( recipient );
       
  1812 
       
  1813 	TUid protocolUid = TUid::Uid ( KProtocolUid );
       
  1814 
       
  1815 	//Bind context to desired presence service
       
  1816 	TXIMPRequestId req = presecenCtx->BindToL ( protocolUid,
       
  1817 	                     username,
       
  1818 	                     password,
       
  1819 	                     serviceId );
       
  1820 	TOssAdapMtLogger::Log ( _L ( "Cossadapmt::ximpClient->NewPresenceContextLC() called\n" ) );
       
  1821 	eventObserver->WaitOpToCompleteL ( req );
       
  1822 	MXIMPObjectFactory& objFactory = presecenCtx->ObjectFactory();
       
  1823 	MXIMPIdentity* newGroupId = objFactory.NewIdentityLC();
       
  1824 	MPresentityGroups& groups = presenceFeatures->PresentityGroups() ;
       
  1825 
       
  1826 	TOssAdapMtLogger::Log ( _L ( "presentity groups object created" ) );
       
  1827 	_LIT ( KDummyListId, "" );
       
  1828 	HBufC16* iListId;
       
  1829 	iListId = KDummyListId().AllocL();
       
  1830 	iListId->Des().Fold();
       
  1831 	newGroupId->SetIdentityL ( *iListId );
       
  1832 	delete iListId;
       
  1833 	iListId = NULL;
       
  1834 	req = groups.SubscribePresentityGroupContentL ( *newGroupId );
       
  1835 
       
  1836 	TOssAdapMtLogger::Log ( _L ( "Cossadapmt::groups.SubscribePresentityGroupListL() called" ) );
       
  1837 
       
  1838 	eventObserver->WaitOpToCompleteL ( req );
       
  1839     CleanupStack::PopAndDestroy(2); //newGroupId,presenceFeatures
       
  1840 
       
  1841 	CUserAfter::AfterL ( 1000000 );
       
  1842 	//Bind context to desired presence service
       
  1843 	MImFeatures* imFeatures = NULL;
       
  1844 	imFeatures = MImFeatures::NewL ( presecenCtx );
       
  1845 	CleanupDeletePushL ( imFeatures );
       
  1846 	TOssAdapMtLogger::Log ( _L ( "Cossadapmt::imFeatures created\n" ) );
       
  1847 	MImConversation& imconversation = imFeatures->ImConversation();
       
  1848 	TOssAdapMtLogger::Log ( _L ( "Cossadapmt::imconversation created\n" ) );
       
  1849 	MImConversationInfo *aImMessage = NULL;
       
  1850 	aImMessage = imFeatures->ImObjectFactory().NewImConversationInfoLC();
       
  1851 	MXIMPIdentity* identity = objFactory.NewIdentityLC();
       
  1852 	identity->SetIdentityL ( KMsgId );
       
  1853 	aImMessage->SetMessageIdL ( identity );
       
  1854 	aImMessage->SetTextMessageL ( message );
       
  1855 	CDesCArrayFlat* aRecipients = new ( ELeave ) CDesCArrayFlat ( 2 );
       
  1856 	CleanupStack::PushL ( aRecipients );  
       
  1857 	aRecipients->AppendL ( recipient ); //userid's
       
  1858 	aImMessage->SetRecipientL ( aRecipients );
       
  1859 	TOssAdapMtLogger::Log ( _L ( "Cossadapmt::before sendmessage called\n" ) );
       
  1860 
       
  1861 	for ( TInt i = 0;i < 10;i++ )
       
  1862 		{
       
  1863 		req = imconversation.SendMessageL ( *aImMessage );
       
  1864 		eventObserver->WaitOpToCompleteL ( req );
       
  1865 
       
  1866 		}
       
  1867 	CleanupStack::Pop ( 3 );//identity,aRecipients,aImMessage
       
  1868 
       
  1869 	TOssAdapMtLogger::Log ( _L ( "Cossadapmt::message sent\n " ) );
       
  1870     //Unbind the context and wait completion
       
  1871     req = presecenCtx->UnbindL();
       
  1872     eventObserver->WaitOpToCompleteL( req );
       
  1873 	CleanupStack::PopAndDestroy(4); //imFeatures,presecenCtx,eventObserver,ximpClient,
       
  1874 	TOssAdapMtLogger::Log ( _L ( "Cossadapmt::SendTenMessageL() end" ) );
       
  1875 
       
  1876 	return KErrNone;
       
  1877 
       
  1878 	}
       
  1879 
       
  1880 // -----------------------------------------------------------------------------
       
  1881 // Cossadapmt::SendTwentyMessageL
       
  1882 // SendMessage test method function.
       
  1883 // (other items were commented in a header).
       
  1884 // -----------------------------------------------------------------------------
       
  1885 //
       
  1886 TInt Cossadapmt::SendTwentyMessageL ( CStifItemParser& aItem )
       
  1887 	{
       
  1888 
       
  1889 	//Initialize XIMP client
       
  1890 	TOssAdapMtLogger::Log ( _L ( "Cossadapmt::SendTwentyMessageL() start" ) );
       
  1891 	MXIMPClient* ximpClient = MXIMPClient::NewClientL();
       
  1892 	CleanupDeletePushL ( ximpClient );
       
  1893 	TOssAdapMtLogger::Log ( _L ( "Cossadapmt::MXIMPClient::NewClientL() start" ) );
       
  1894 	//Create new sink to receive presence context events
       
  1895 	CUSContextObserver* eventObserver = CUSContextObserver::NewLC();
       
  1896 	//Create new presence context
       
  1897 	MXIMPContext* presecenCtx = ximpClient->NewPresenceContextLC();
       
  1898 	//Bind context to desired presence service
       
  1899 	presecenCtx->RegisterObserverL ( *eventObserver );
       
  1900 	MPresenceFeatures* presenceFeatures = NULL;
       
  1901 	presenceFeatures = MPresenceFeatures::NewL ( presecenCtx );
       
  1902 	CleanupDeletePushL ( presenceFeatures );
       
  1903 
       
  1904     //read data from cfg file
       
  1905     TPtrC               username;
       
  1906     TPtrC               password;
       
  1907 	TInt                serviceId;
       
  1908     TPtrC               message;
       
  1909     TPtrC               recipient;
       
  1910 
       
  1911 	aItem.GetNextString ( username );
       
  1912 	aItem.GetNextString ( password );
       
  1913 	aItem.GetNextInt ( serviceId );
       
  1914 	aItem.GetNextString ( message );
       
  1915 	aItem.GetNextString ( recipient );
       
  1916 
       
  1917 	TUid protocolUid = TUid::Uid ( KProtocolUid );
       
  1918 
       
  1919 	//Bind context to desired presence service
       
  1920 	TXIMPRequestId req = presecenCtx->BindToL ( protocolUid,
       
  1921 	                     username,
       
  1922 	                     password,
       
  1923 	                     serviceId );
       
  1924 	TOssAdapMtLogger::Log ( _L ( "Cossadapmt::ximpClient->NewPresenceContextLC() called\n" ) );
       
  1925 	eventObserver->WaitOpToCompleteL ( req );
       
  1926 	MXIMPObjectFactory& objFactory = presecenCtx->ObjectFactory();
       
  1927 	MXIMPIdentity* newGroupId = objFactory.NewIdentityLC();
       
  1928 	MPresentityGroups& groups = presenceFeatures->PresentityGroups() ;
       
  1929 
       
  1930 	TOssAdapMtLogger::Log ( _L ( "presentity groups object created" ) );
       
  1931 	_LIT ( KDummyListId, "" );
       
  1932 	HBufC16* iListId;
       
  1933 	iListId = KDummyListId().AllocL();
       
  1934 	iListId->Des().Fold();
       
  1935 	newGroupId->SetIdentityL ( *iListId );
       
  1936 	delete iListId;
       
  1937 	iListId = NULL;
       
  1938 	req = groups.SubscribePresentityGroupContentL ( *newGroupId );
       
  1939 
       
  1940 	TOssAdapMtLogger::Log ( _L ( "Cossadapmt::groups.SubscribePresentityGroupListL() called" ) );
       
  1941 
       
  1942 	eventObserver->WaitOpToCompleteL ( req );
       
  1943    CleanupStack::PopAndDestroy(2); //newGroupId,presenceFeatures
       
  1944 
       
  1945 	CUserAfter::AfterL ( 1000000 );
       
  1946 	//Bind context to desired presence service
       
  1947 	MImFeatures* imFeatures = NULL;
       
  1948 	imFeatures = MImFeatures::NewL ( presecenCtx );
       
  1949 	CleanupDeletePushL ( imFeatures );
       
  1950 	TOssAdapMtLogger::Log ( _L ( "Cossadapmt::imFeatures created\n" ) );
       
  1951 	MImConversation& imconversation = imFeatures->ImConversation();
       
  1952 	TOssAdapMtLogger::Log ( _L ( "Cossadapmt::imconversation created\n" ) );
       
  1953 	MImConversationInfo *aImMessage = NULL;
       
  1954 	aImMessage = imFeatures->ImObjectFactory().NewImConversationInfoLC();
       
  1955 	MXIMPIdentity* identity = objFactory.NewIdentityLC();
       
  1956 	identity->SetIdentityL ( KMsgId );
       
  1957 	aImMessage->SetMessageIdL ( identity );
       
  1958 	aImMessage->SetTextMessageL ( message );
       
  1959 	CDesCArrayFlat* aRecipients = new ( ELeave ) CDesCArrayFlat ( 2 );
       
  1960 	CleanupStack::PushL ( aRecipients );  //userid's
       
  1961 	aRecipients->AppendL ( recipient );
       
  1962 	aImMessage->SetRecipientL ( aRecipients );
       
  1963 	TOssAdapMtLogger::Log ( _L ( "Cossadapmt::before sendmessage called\n" ) );
       
  1964 
       
  1965 	for ( TInt i = 0;i < 20;i++ )
       
  1966 		{
       
  1967 		req = imconversation.SendMessageL ( *aImMessage );
       
  1968 		eventObserver->WaitOpToCompleteL ( req );
       
  1969 
       
  1970 		}
       
  1971 	CleanupStack::Pop ( 3 );//identity,aRecipients,aImMessage
       
  1972 
       
  1973 	TOssAdapMtLogger::Log ( _L ( "Cossadapmt::message sent\n " ) );
       
  1974     //Unbind the context and wait completion
       
  1975     req = presecenCtx->UnbindL();
       
  1976     eventObserver->WaitOpToCompleteL( req );
       
  1977 	CleanupStack::PopAndDestroy(4); //imFeatures,presecenCtx,eventObserver,ximpClient,
       
  1978 	TOssAdapMtLogger::Log ( _L ( "Cossadapmt::SendTwentyMessageL() end" ) );
       
  1979 
       
  1980 	return KErrNone;
       
  1981 
       
  1982 	}
       
  1983 
       
  1984 // -----------------------------------------------------------------------------
       
  1985 // Cossadapmt::SendMessage_MultipleContactsL
       
  1986 // SendMessage test method function.
       
  1987 // (other items were commented in a header).
       
  1988 // -----------------------------------------------------------------------------
       
  1989 //
       
  1990 TInt Cossadapmt::SendMessage_MultipleContactsL ( CStifItemParser& aItem )
       
  1991 	{
       
  1992 
       
  1993 	//Initialize XIMP client
       
  1994 	TOssAdapMtLogger::Log ( _L ( "Cossadapmt::SendMessage_MultipleContactsL() start" ) );
       
  1995 	MXIMPClient* ximpClient = MXIMPClient::NewClientL();
       
  1996 	CleanupDeletePushL ( ximpClient );
       
  1997 	TOssAdapMtLogger::Log ( _L ( "Cossadapmt::MXIMPClient::NewClientL() start" ) );
       
  1998 	//Create new sink to receive presence context events
       
  1999 	CUSContextObserver* eventObserver = CUSContextObserver::NewLC();
       
  2000 	//Create new presence context
       
  2001 	MXIMPContext* presecenCtx = ximpClient->NewPresenceContextLC();
       
  2002 	//Bind context to desired presence service
       
  2003 	presecenCtx->RegisterObserverL ( *eventObserver );
       
  2004 	MPresenceFeatures* presenceFeatures = NULL;
       
  2005 	presenceFeatures = MPresenceFeatures::NewL ( presecenCtx );
       
  2006 	CleanupDeletePushL ( presenceFeatures );
       
  2007 
       
  2008     //read data from cfg file
       
  2009 	TPtrC               username;
       
  2010     TPtrC               password;
       
  2011 	TInt                serviceId;
       
  2012     TPtrC               message;
       
  2013     TPtrC               recipient;
       
  2014     TPtrC               recipient1;
       
  2015     TPtrC               recipient2;
       
  2016     TPtrC               recipient3;
       
  2017 
       
  2018 	aItem.GetNextString ( username );
       
  2019 	aItem.GetNextString ( password );
       
  2020 	aItem.GetNextInt ( serviceId );
       
  2021 	aItem.GetNextString ( message );
       
  2022 	aItem.GetNextString ( recipient );
       
  2023 	aItem.GetNextString ( recipient1 );
       
  2024 	aItem.GetNextString ( recipient2 );
       
  2025 	aItem.GetNextString ( recipient3 );
       
  2026 
       
  2027 	TUid protocolUid = TUid::Uid ( KProtocolUid );
       
  2028 
       
  2029 	//Bind context to desired presence service
       
  2030 	TXIMPRequestId req = presecenCtx->BindToL ( protocolUid,
       
  2031 	                     username,
       
  2032 	                     password,
       
  2033 	                     serviceId );
       
  2034 	TOssAdapMtLogger::Log ( _L ( "Cossadapmt::ximpClient->NewPresenceContextLC() called\n" ) );
       
  2035 	eventObserver->WaitOpToCompleteL ( req );
       
  2036 	MXIMPObjectFactory& objFactory = presecenCtx->ObjectFactory();
       
  2037 	MXIMPIdentity* newGroupId = objFactory.NewIdentityLC();
       
  2038 	MPresentityGroups& groups = presenceFeatures->PresentityGroups() ;
       
  2039 
       
  2040 	TOssAdapMtLogger::Log ( _L ( "presentity groups object created" ) );
       
  2041 	_LIT ( KDummyListId, "" );
       
  2042 	HBufC16* iListId;
       
  2043 	iListId = KDummyListId().AllocL();
       
  2044 	iListId->Des().Fold();
       
  2045 	newGroupId->SetIdentityL ( *iListId );
       
  2046 	delete iListId;
       
  2047 	iListId = NULL;
       
  2048 	req = groups.SubscribePresentityGroupContentL ( *newGroupId );
       
  2049 
       
  2050 	TOssAdapMtLogger::Log ( _L ( "Cossadapmt::groups.SubscribePresentityGroupListL() called" ) );
       
  2051 
       
  2052 	eventObserver->WaitOpToCompleteL ( req );
       
  2053     CleanupStack::PopAndDestroy(2); //newGroupId,presenceFeatures
       
  2054 
       
  2055 	CUserAfter::AfterL ( 1000000 );
       
  2056 	//Bind context to desired presence service
       
  2057 	MImFeatures* imFeatures = NULL;
       
  2058 	imFeatures = MImFeatures::NewL ( presecenCtx );
       
  2059 	CleanupDeletePushL ( imFeatures );
       
  2060 	TOssAdapMtLogger::Log ( _L ( "Cossadapmt::imFeatures created\n" ) );
       
  2061 	MImConversation& imconversation = imFeatures->ImConversation();
       
  2062 	TOssAdapMtLogger::Log ( _L ( "Cossadapmt::imconversation created\n" ) );
       
  2063 	MImConversationInfo *aImMessage = NULL;
       
  2064 	aImMessage = imFeatures->ImObjectFactory().NewImConversationInfoLC();
       
  2065 	MXIMPIdentity* identity = objFactory.NewIdentityLC();
       
  2066 	identity->SetIdentityL ( KMsgId );
       
  2067 	aImMessage->SetMessageIdL ( identity );
       
  2068 	aImMessage->SetTextMessageL ( message );
       
  2069 	CDesCArrayFlat* aRecipients = new ( ELeave ) CDesCArrayFlat ( 2 );
       
  2070 	CleanupStack::PushL ( aRecipients ); 
       
  2071 	aRecipients->AppendL ( recipient );  //userid's
       
  2072 	aRecipients->AppendL ( recipient1 );
       
  2073 	aRecipients->AppendL ( recipient2 );
       
  2074 	aRecipients->AppendL ( recipient3 );
       
  2075 
       
  2076 	aImMessage->SetRecipientL ( aRecipients );
       
  2077 	TOssAdapMtLogger::Log ( _L ( "Cossadapmt::before sendmessage called\n" ) );
       
  2078 
       
  2079 	req = imconversation.SendMessageL ( *aImMessage );
       
  2080 	eventObserver->WaitOpToCompleteL ( req );
       
  2081 	CleanupStack::Pop ( 3 );//identity,aRecipients,aImMessage
       
  2082 	TOssAdapMtLogger::Log ( _L ( "Cossadapmt::message sent\n " ) );
       
  2083 	CUserAfter::AfterL ( 1000000 );
       
  2084 
       
  2085 	//Unbind the context and wait completion
       
  2086     req = presecenCtx->UnbindL();
       
  2087     eventObserver->WaitOpToCompleteL( req );
       
  2088 	CleanupStack::PopAndDestroy(4); //imFeatures,presecenCtx,eventObserver,ximpClient,
       
  2089 	TOssAdapMtLogger::Log ( _L ( "Cossadapmt::SendMessage_MultipleContactsL() end" ) );
       
  2090 
       
  2091 	return KErrNone;
       
  2092 
       
  2093 	}
       
  2094 
       
  2095 // -----------------------------------------------------------------------------
       
  2096 // Cossadapmt::ReceiveMessageL
       
  2097 // SendMessage test method function.
       
  2098 // (other items were commented in a header).
       
  2099 // -----------------------------------------------------------------------------
       
  2100 //
       
  2101 TInt Cossadapmt::ReceiveMessageL ( CStifItemParser& aItem )
       
  2102 	{
       
  2103 
       
  2104 	//Initialize XIMP client
       
  2105 	TOssAdapMtLogger::Log ( _L ( "Cossadapmt::ReceiveMessageL() start" ) );
       
  2106 	MXIMPClient* ximpClient = MXIMPClient::NewClientL();
       
  2107 	CleanupDeletePushL ( ximpClient );
       
  2108 	TOssAdapMtLogger::Log ( _L ( "Cossadapmt::MXIMPClient::NewClientL() start" ) );
       
  2109 	//Create new sink to receive presence context events
       
  2110 	CUSContextObserver* eventObserver = CUSContextObserver::NewLC();
       
  2111 	//Create new presence context
       
  2112 	MXIMPContext* presecenCtx = ximpClient->NewPresenceContextLC();
       
  2113 	//Bind context to desired presence service
       
  2114 	presecenCtx->RegisterObserverL ( *eventObserver );
       
  2115 	MPresenceFeatures* presenceFeatures = NULL;
       
  2116 	presenceFeatures = MPresenceFeatures::NewL ( presecenCtx );
       
  2117 	CleanupDeletePushL ( presenceFeatures );
       
  2118 
       
  2119     //read data from cfg file
       
  2120     TPtrC               username;
       
  2121     TPtrC               password;
       
  2122 	TInt                serviceId;
       
  2123     TPtrC               message;
       
  2124 
       
  2125 	aItem.GetNextString ( username );
       
  2126 	aItem.GetNextString ( password );
       
  2127 	aItem.GetNextInt ( serviceId );
       
  2128 	aItem.GetNextString ( message );
       
  2129 
       
  2130 	TUid protocolUid = TUid::Uid ( KProtocolUid );
       
  2131 
       
  2132 	//Bind context to desired presence service
       
  2133 	TXIMPRequestId req = presecenCtx->BindToL ( protocolUid,
       
  2134 	                     username,
       
  2135 	                     password,
       
  2136 	                     serviceId );
       
  2137 	TOssAdapMtLogger::Log ( _L ( "Cossadapmt::ximpClient->NewPresenceContextLC() called\n" ) );
       
  2138 	eventObserver->WaitOpToCompleteL ( req );
       
  2139 	MXIMPObjectFactory& objFactory = presecenCtx->ObjectFactory();
       
  2140 	MXIMPIdentity* newGroupId = objFactory.NewIdentityLC();
       
  2141 	MPresentityGroups& groups = presenceFeatures->PresentityGroups() ;
       
  2142 
       
  2143 	TOssAdapMtLogger::Log ( _L ( "presentity groups object created" ) );
       
  2144 	_LIT ( KDummyListId, "" );
       
  2145 	HBufC16* iListId;
       
  2146 	iListId = KDummyListId().AllocL();
       
  2147 	iListId->Des().Fold();
       
  2148 	newGroupId->SetIdentityL ( *iListId );
       
  2149 	delete iListId;
       
  2150 	iListId = NULL;
       
  2151 	req = groups.SubscribePresentityGroupContentL ( *newGroupId );
       
  2152 
       
  2153 	TOssAdapMtLogger::Log ( _L ( "Cossadapmt::groups.SubscribePresentityGroupListL() called" ) );
       
  2154 
       
  2155 	eventObserver->WaitOpToCompleteL ( req );
       
  2156    CleanupStack::PopAndDestroy(2); //newGroupId,presenceFeatures
       
  2157 
       
  2158 	CUserAfter::AfterL ( 1000000 );
       
  2159 	//Bind context to desired presence service
       
  2160 	MImFeatures* imFeatures = NULL;
       
  2161 	imFeatures = MImFeatures::NewL ( presecenCtx );
       
  2162 	CleanupDeletePushL ( imFeatures );
       
  2163 	TOssAdapMtLogger::Log ( _L ( "Cossadapmt::imFeatures created\n" ) );
       
  2164 	MImConversation& imconversation = imFeatures->ImConversation();
       
  2165 	TOssAdapMtLogger::Log ( _L ( "Cossadapmt::imconversation created\n" ) );
       
  2166 	MImConversationInfo *aImMessage = NULL;
       
  2167 	aImMessage = imFeatures->ImObjectFactory().NewImConversationInfoLC();
       
  2168 	MXIMPIdentity* identity = objFactory.NewIdentityLC();
       
  2169 	identity->SetIdentityL ( KMsgId );
       
  2170 	aImMessage->SetMessageIdL ( identity );
       
  2171 	aImMessage->SetTextMessageL ( message );
       
  2172 	CDesCArrayFlat* aRecipients = new ( ELeave ) CDesCArrayFlat ( 1 );
       
  2173 	CleanupStack::PushL ( aRecipients );  
       
  2174 	aRecipients->AppendL ( username );  //userid of own
       
  2175 	aImMessage->SetRecipientL ( aRecipients );
       
  2176 	TOssAdapMtLogger::Log ( _L ( "Cossadapmt::before sendmessage called\n" ) );
       
  2177     //send message is to own
       
  2178 	req = imconversation.SendMessageL ( *aImMessage );
       
  2179 	eventObserver->WaitOpToCompleteL ( req );
       
  2180 	CleanupStack::Pop ( 3 );//identity,aRecipients,aImMessage
       
  2181 	//send message to other guy
       
  2182 	TOssAdapMtLogger::Log ( _L ( "Cossadapmt::message sent\n " ) );
       
  2183 	//Unbind the context and wait completion
       
  2184     req = presecenCtx->UnbindL();
       
  2185     eventObserver->WaitOpToCompleteL( req );
       
  2186 	CleanupStack::PopAndDestroy(4); //imFeatures,presecenCtx,eventObserver,ximpClient,
       
  2187 	TOssAdapMtLogger::Log ( _L ( "Cossadapmt::ReceiveMessageL() start" ) );
       
  2188 
       
  2189 	return KErrNone;
       
  2190 
       
  2191 	}
       
  2192 // -----------------------------------------------------------------------------
       
  2193 // Cossadapmt::ReceiveEmptyMessageL
       
  2194 // SendMessage test method function.
       
  2195 // (other items were commented in a header).
       
  2196 // -----------------------------------------------------------------------------
       
  2197 //
       
  2198 TInt Cossadapmt::ReceiveEmptyMessageL ( CStifItemParser& aItem )
       
  2199 	{
       
  2200 
       
  2201 	//Initialize XIMP client
       
  2202 	TOssAdapMtLogger::Log ( _L ( "Cossadapmt::ReceiveEmptyMessageL() start" ) );
       
  2203 	MXIMPClient* ximpClient = MXIMPClient::NewClientL();
       
  2204 	CleanupDeletePushL ( ximpClient );
       
  2205 	TOssAdapMtLogger::Log ( _L ( "Cossadapmt::MXIMPClient::NewClientL() start" ) );
       
  2206 	//Create new sink to receive presence context events
       
  2207 	CUSContextObserver* eventObserver = CUSContextObserver::NewLC();
       
  2208 	//Create new presence context
       
  2209 	MXIMPContext* presecenCtx = ximpClient->NewPresenceContextLC();
       
  2210 	//Bind context to desired presence service
       
  2211 	presecenCtx->RegisterObserverL ( *eventObserver );
       
  2212 	MPresenceFeatures* presenceFeatures = NULL;
       
  2213 	presenceFeatures = MPresenceFeatures::NewL ( presecenCtx );
       
  2214 	CleanupDeletePushL ( presenceFeatures );
       
  2215 
       
  2216     //read data from cfg file
       
  2217     TPtrC               username;
       
  2218     TPtrC               password;
       
  2219 	TInt                serviceId;
       
  2220 
       
  2221 	aItem.GetNextString ( username );
       
  2222 	aItem.GetNextString ( password );
       
  2223 	aItem.GetNextInt ( serviceId );
       
  2224 
       
  2225 	TUid protocolUid = TUid::Uid ( KProtocolUid );
       
  2226 
       
  2227 	//Bind context to desired presence service
       
  2228 	TXIMPRequestId req = presecenCtx->BindToL ( protocolUid,
       
  2229 	                     username,
       
  2230 	                     password,
       
  2231 	                     serviceId );
       
  2232 	TOssAdapMtLogger::Log ( _L ( "Cossadapmt::ximpClient->NewPresenceContextLC() called\n" ) );
       
  2233 	eventObserver->WaitOpToCompleteL ( req );
       
  2234 	MXIMPObjectFactory& objFactory = presecenCtx->ObjectFactory();
       
  2235 	MXIMPIdentity* newGroupId = objFactory.NewIdentityLC();
       
  2236 	MPresentityGroups& groups = presenceFeatures->PresentityGroups() ;
       
  2237 
       
  2238 	TOssAdapMtLogger::Log ( _L ( "presentity groups object created" ) );
       
  2239 	_LIT ( KDummyListId, "" );
       
  2240 	_LIT ( KEmptyMessage, "" );
       
  2241 	HBufC16* iListId;
       
  2242 	iListId = KDummyListId().AllocL();
       
  2243 	iListId->Des().Fold();
       
  2244 	newGroupId->SetIdentityL ( *iListId );
       
  2245 	delete iListId;
       
  2246 	iListId = NULL;
       
  2247 	req = groups.SubscribePresentityGroupContentL ( *newGroupId );
       
  2248 
       
  2249 	TOssAdapMtLogger::Log ( _L ( "Cossadapmt::groups.SubscribePresentityGroupListL() called" ) );
       
  2250 
       
  2251 	eventObserver->WaitOpToCompleteL ( req );
       
  2252    CleanupStack::PopAndDestroy(2); //newGroupId,presenceFeatures
       
  2253 
       
  2254 	CUserAfter::AfterL ( 1000000 );
       
  2255 	//Bind context to desired presence service
       
  2256 	MImFeatures* imFeatures = NULL;
       
  2257 	imFeatures = MImFeatures::NewL ( presecenCtx );
       
  2258 	CleanupDeletePushL ( imFeatures );
       
  2259 	TOssAdapMtLogger::Log ( _L ( "Cossadapmt::imFeatures created\n" ) );
       
  2260 	MImConversation& imconversation = imFeatures->ImConversation();
       
  2261 	TOssAdapMtLogger::Log ( _L ( "Cossadapmt::imconversation created\n" ) );
       
  2262 	MImConversationInfo *aImMessage = NULL;
       
  2263 	aImMessage = imFeatures->ImObjectFactory().NewImConversationInfoLC();
       
  2264 	MXIMPIdentity* identity = objFactory.NewIdentityLC();
       
  2265 	identity->SetIdentityL ( KMsgId );
       
  2266 	aImMessage->SetMessageIdL ( identity );
       
  2267 	aImMessage->SetTextMessageL ( KEmptyMessage );
       
  2268 	CDesCArrayFlat* aRecipients = new ( ELeave ) CDesCArrayFlat ( 1 );
       
  2269 	CleanupStack::PushL ( aRecipients );  
       
  2270 	aRecipients->AppendL ( username );  //userid of own
       
  2271 	aImMessage->SetRecipientL ( aRecipients );
       
  2272 	TOssAdapMtLogger::Log ( _L ( "Cossadapmt::before sendmessage called\n" ) );
       
  2273     //send message is to own
       
  2274 	req = imconversation.SendMessageL ( *aImMessage );
       
  2275 	eventObserver->WaitOpToCompleteL ( req );
       
  2276 	CleanupStack::Pop ( 3 );//identity,aRecipients,aImMessage
       
  2277 	//send message to other guy
       
  2278 	TOssAdapMtLogger::Log ( _L ( "Cossadapmt::message sent\n " ) );
       
  2279 	//Unbind the context and wait completion
       
  2280     req = presecenCtx->UnbindL();
       
  2281     eventObserver->WaitOpToCompleteL( req );
       
  2282 	CleanupStack::PopAndDestroy(4); //imFeatures,presecenCtx,eventObserver,ximpClient,
       
  2283 	TOssAdapMtLogger::Log ( _L ( "Cossadapmt::ReceiveEmptyMessageL() start" ) );
       
  2284 
       
  2285 	return KErrNone;
       
  2286 
       
  2287 	}
       
  2288 
       
  2289 // -----------------------------------------------------------------------------
       
  2290 // Cossadapmt::ReceiveTenMessageL
       
  2291 // SendMessage test method function.
       
  2292 // (other items were commented in a header).
       
  2293 // -----------------------------------------------------------------------------
       
  2294 //
       
  2295 TInt Cossadapmt::ReceiveTenMessageL ( CStifItemParser& aItem )
       
  2296 	{
       
  2297 
       
  2298 	//Initialize XIMP client
       
  2299 	TOssAdapMtLogger::Log ( _L ( "Cossadapmt::ReceiveTenMessageL() start" ) );
       
  2300 	MXIMPClient* ximpClient = MXIMPClient::NewClientL();
       
  2301 	CleanupDeletePushL ( ximpClient );
       
  2302 	TOssAdapMtLogger::Log ( _L ( "Cossadapmt::MXIMPClient::NewClientL() start" ) );
       
  2303 	//Create new sink to receive presence context events
       
  2304 	CUSContextObserver* eventObserver = CUSContextObserver::NewLC();
       
  2305 	//Create new presence context
       
  2306 	MXIMPContext* presecenCtx = ximpClient->NewPresenceContextLC();
       
  2307 	//Bind context to desired presence service
       
  2308 	presecenCtx->RegisterObserverL ( *eventObserver );
       
  2309 	MPresenceFeatures* presenceFeatures = NULL;
       
  2310 	presenceFeatures = MPresenceFeatures::NewL ( presecenCtx );
       
  2311 	CleanupDeletePushL ( presenceFeatures );
       
  2312 
       
  2313     //read data from cfg file
       
  2314     TPtrC               username;
       
  2315     TPtrC               password;
       
  2316 	TInt                serviceId;
       
  2317     TPtrC               message;
       
  2318 
       
  2319 	aItem.GetNextString ( username );
       
  2320 	aItem.GetNextString ( password );
       
  2321 	aItem.GetNextInt ( serviceId );
       
  2322 	aItem.GetNextString ( message );
       
  2323 
       
  2324 	TUid protocolUid = TUid::Uid ( KProtocolUid );
       
  2325 
       
  2326 	//Bind context to desired presence service
       
  2327 	TXIMPRequestId req = presecenCtx->BindToL ( protocolUid,
       
  2328 	                     username,
       
  2329 	                     password,
       
  2330 	                     serviceId );
       
  2331 	TOssAdapMtLogger::Log ( _L ( "Cossadapmt::ximpClient->NewPresenceContextLC() called\n" ) );
       
  2332 	eventObserver->WaitOpToCompleteL ( req );
       
  2333 	MXIMPObjectFactory& objFactory = presecenCtx->ObjectFactory();
       
  2334 	MXIMPIdentity* newGroupId = objFactory.NewIdentityLC();
       
  2335 	MPresentityGroups& groups = presenceFeatures->PresentityGroups() ;
       
  2336 
       
  2337 	TOssAdapMtLogger::Log ( _L ( "presentity groups object created" ) );
       
  2338 	_LIT ( KDummyListId, "" );
       
  2339 	HBufC16* iListId;
       
  2340 	iListId = KDummyListId().AllocL();
       
  2341 	iListId->Des().Fold();
       
  2342 	newGroupId->SetIdentityL ( *iListId );
       
  2343 	delete iListId;
       
  2344 	iListId = NULL;
       
  2345 	req = groups.SubscribePresentityGroupContentL ( *newGroupId );
       
  2346 
       
  2347 	TOssAdapMtLogger::Log ( _L ( "Cossadapmt::groups.SubscribePresentityGroupListL() called" ) );
       
  2348 
       
  2349 	eventObserver->WaitOpToCompleteL ( req );
       
  2350     CleanupStack::PopAndDestroy(2); //newGroupId,presenceFeatures
       
  2351 
       
  2352 	CUserAfter::AfterL ( 1000000 );
       
  2353 	//Bind context to desired presence service
       
  2354 	MImFeatures* imFeatures = NULL;
       
  2355 	imFeatures = MImFeatures::NewL ( presecenCtx );
       
  2356 	CleanupDeletePushL ( imFeatures );
       
  2357 	TOssAdapMtLogger::Log ( _L ( "Cossadapmt::imFeatures created\n" ) );
       
  2358 	MImConversation& imconversation = imFeatures->ImConversation();
       
  2359 	TOssAdapMtLogger::Log ( _L ( "Cossadapmt::imconversation created\n" ) );
       
  2360 	MImConversationInfo *aImMessage = NULL;
       
  2361 	aImMessage = imFeatures->ImObjectFactory().NewImConversationInfoLC();
       
  2362 	MXIMPIdentity* identity = objFactory.NewIdentityLC();
       
  2363 	identity->SetIdentityL ( KMsgId );
       
  2364 	aImMessage->SetMessageIdL ( identity );
       
  2365 	aImMessage->SetTextMessageL ( message );
       
  2366 	CDesCArrayFlat* aRecipients = new ( ELeave ) CDesCArrayFlat ( 2 );
       
  2367 	CleanupStack::PushL ( aRecipients );  
       
  2368 	aRecipients->AppendL ( username );  //userid of own
       
  2369 	aImMessage->SetRecipientL ( aRecipients );
       
  2370 	TOssAdapMtLogger::Log ( _L ( "Cossadapmt::before sendmessage called\n" ) );
       
  2371 
       
  2372 	for ( TInt i = 0;i < 10;i++ )
       
  2373 		{
       
  2374 		req = imconversation.SendMessageL ( *aImMessage );
       
  2375 		eventObserver->WaitOpToCompleteL ( req );
       
  2376 
       
  2377 		}
       
  2378 	CleanupStack::Pop ( 3 );//identity,aRecipients,aImMessage
       
  2379 
       
  2380 	TOssAdapMtLogger::Log ( _L ( "Cossadapmt::message sent\n " ) );
       
  2381     //Unbind the context and wait completion
       
  2382     req = presecenCtx->UnbindL();
       
  2383     eventObserver->WaitOpToCompleteL( req );
       
  2384 	CleanupStack::PopAndDestroy(4); //imFeatures,presecenCtx,eventObserver,ximpClient,
       
  2385 	TOssAdapMtLogger::Log ( _L ( "Cossadapmt::ReceiveTenMessageL() end" ) );
       
  2386 
       
  2387 	return KErrNone;
       
  2388 
       
  2389 	}
       
  2390 
       
  2391 // -----------------------------------------------------------------------------
       
  2392 // Cossadapmt::ReceiveTwentyMessageL
       
  2393 // SendMessage test method function.
       
  2394 // (other items were commented in a header).
       
  2395 // -----------------------------------------------------------------------------
       
  2396 //
       
  2397 TInt Cossadapmt::ReceiveTwentyMessageL ( CStifItemParser& aItem )
       
  2398 	{
       
  2399 
       
  2400 	//Initialize XIMP client
       
  2401 	TOssAdapMtLogger::Log ( _L ( "Cossadapmt::ReceiveTwentyMessageL() start" ) );
       
  2402 	MXIMPClient* ximpClient = MXIMPClient::NewClientL();
       
  2403 	CleanupDeletePushL ( ximpClient );
       
  2404 	TOssAdapMtLogger::Log ( _L ( "Cossadapmt::MXIMPClient::NewClientL() start" ) );
       
  2405 	//Create new sink to receive presence context events
       
  2406 	CUSContextObserver* eventObserver = CUSContextObserver::NewLC();
       
  2407 	//Create new presence context
       
  2408 	MXIMPContext* presecenCtx = ximpClient->NewPresenceContextLC();
       
  2409 	//Bind context to desired presence service
       
  2410 	presecenCtx->RegisterObserverL ( *eventObserver );
       
  2411 	MPresenceFeatures* presenceFeatures = NULL;
       
  2412 	presenceFeatures = MPresenceFeatures::NewL ( presecenCtx );
       
  2413 	CleanupDeletePushL ( presenceFeatures );
       
  2414 
       
  2415     //read data from cfg file
       
  2416     TPtrC               username;
       
  2417     TPtrC               password;
       
  2418 	TInt                serviceId;
       
  2419     TPtrC               message;
       
  2420 
       
  2421 	aItem.GetNextString ( username );
       
  2422 	aItem.GetNextString ( password );
       
  2423 	aItem.GetNextInt ( serviceId );
       
  2424 	aItem.GetNextString ( message );
       
  2425 
       
  2426 	TUid protocolUid = TUid::Uid ( KProtocolUid );
       
  2427 
       
  2428 	//Bind context to desired presence service
       
  2429 	TXIMPRequestId req = presecenCtx->BindToL ( protocolUid,
       
  2430 	                     username,
       
  2431 	                     password,
       
  2432 	                     serviceId );
       
  2433 	TOssAdapMtLogger::Log ( _L ( "Cossadapmt::ximpClient->NewPresenceContextLC() called\n" ) );
       
  2434 	eventObserver->WaitOpToCompleteL ( req );
       
  2435 	MXIMPObjectFactory& objFactory = presecenCtx->ObjectFactory();
       
  2436 	MXIMPIdentity* newGroupId = objFactory.NewIdentityLC();
       
  2437 	MPresentityGroups& groups = presenceFeatures->PresentityGroups() ;
       
  2438 
       
  2439 	TOssAdapMtLogger::Log ( _L ( "presentity groups object created" ) );
       
  2440 	_LIT ( KDummyListId, "" );
       
  2441 	HBufC16* iListId;
       
  2442 	iListId = KDummyListId().AllocL();
       
  2443 	iListId->Des().Fold();
       
  2444 	newGroupId->SetIdentityL ( *iListId );
       
  2445 	delete iListId;
       
  2446 	iListId = NULL;
       
  2447 	req = groups.SubscribePresentityGroupContentL ( *newGroupId );
       
  2448 
       
  2449 	TOssAdapMtLogger::Log ( _L ( "Cossadapmt::groups.SubscribePresentityGroupListL() called" ) );
       
  2450 
       
  2451 	eventObserver->WaitOpToCompleteL ( req );
       
  2452    CleanupStack::PopAndDestroy(2); //newGroupId,presenceFeatures
       
  2453 
       
  2454 	CUserAfter::AfterL ( 1000000 );
       
  2455 	//Bind context to desired presence service
       
  2456 	MImFeatures* imFeatures = NULL;
       
  2457 	imFeatures = MImFeatures::NewL ( presecenCtx );
       
  2458 	CleanupDeletePushL ( imFeatures );
       
  2459 	TOssAdapMtLogger::Log ( _L ( "Cossadapmt::imFeatures created\n" ) );
       
  2460 	MImConversation& imconversation = imFeatures->ImConversation();
       
  2461 	TOssAdapMtLogger::Log ( _L ( "Cossadapmt::imconversation created\n" ) );
       
  2462 	MImConversationInfo *aImMessage = NULL;
       
  2463 	aImMessage = imFeatures->ImObjectFactory().NewImConversationInfoLC();
       
  2464 	MXIMPIdentity* identity = objFactory.NewIdentityLC();
       
  2465 	identity->SetIdentityL ( KMsgId );
       
  2466 	aImMessage->SetMessageIdL ( identity );
       
  2467 	aImMessage->SetTextMessageL ( message );
       
  2468 	CDesCArrayFlat* aRecipients = new ( ELeave ) CDesCArrayFlat ( 2 );
       
  2469 	CleanupStack::PushL ( aRecipients );  
       
  2470 	aRecipients->AppendL ( username ); //userid's of own
       
  2471 	aImMessage->SetRecipientL ( aRecipients );
       
  2472 	TOssAdapMtLogger::Log ( _L ( "Cossadapmt::before sendmessage called\n" ) );
       
  2473 
       
  2474 	for ( TInt i = 0;i < 20;i++ )
       
  2475 		{
       
  2476 		req = imconversation.SendMessageL ( *aImMessage );
       
  2477 		eventObserver->WaitOpToCompleteL ( req );
       
  2478 		}
       
  2479 	CleanupStack::Pop ( 3 );//identity,aRecipients,aImMessage
       
  2480 
       
  2481 	TOssAdapMtLogger::Log ( _L ( "Cossadapmt::message sent\n " ) );
       
  2482     //Unbind the context and wait completion
       
  2483     req = presecenCtx->UnbindL();
       
  2484     eventObserver->WaitOpToCompleteL( req );
       
  2485 	CleanupStack::PopAndDestroy(4); //imFeatures,presecenCtx,eventObserver,ximpClient,
       
  2486 	TOssAdapMtLogger::Log ( _L ( "Cossadapmt::ReceiveTwentyMessageL() end" ) );
       
  2487 
       
  2488 	return KErrNone;
       
  2489 
       
  2490 	}
       
  2491 
       
  2492 
       
  2493 // -----------------------------------------------------------------------------
       
  2494 // Cossadapmt::PublishOwnPresenceL
       
  2495 // Login test method function.
       
  2496 // (other items were commented in a header).
       
  2497 // -----------------------------------------------------------------------------
       
  2498 //
       
  2499 TInt Cossadapmt::PublishOwnPresenceL ( CStifItemParser& aItem )
       
  2500 	{
       
  2501 
       
  2502 
       
  2503 
       
  2504 	//Initialize XIMP client
       
  2505 	TOssAdapMtLogger::Log ( _L ( "Cossadapmt::PublishOwnPresenceL() start" ) );
       
  2506 
       
  2507 	MXIMPClient* ximpClient = MXIMPClient::NewClientL();
       
  2508 	CleanupDeletePushL ( ximpClient );
       
  2509 	TOssAdapMtLogger::Log ( _L ( "Cossadapmt::MXIMPClient::NewClientL() start" ) );
       
  2510 
       
  2511 	//Create new sink to receive presence context events
       
  2512 	CUSContextObserver* eventObserver = CUSContextObserver::NewLC();
       
  2513 
       
  2514 	//Create new presence context
       
  2515 	MXIMPContext* presecenCtx = ximpClient->NewPresenceContextLC();
       
  2516 	TOssAdapMtLogger::Log ( _L ( "Cossadapmt::ximpClient->NewPresenceContextLC() called" ) );
       
  2517 	presecenCtx->RegisterObserverL ( *eventObserver );
       
  2518 
       
  2519 	MPresenceFeatures* presenceFeatures = NULL;
       
  2520     presenceFeatures = MPresenceFeatures::NewL(presecenCtx); 
       
  2521     CleanupDeletePushL( presenceFeatures );
       
  2522 
       
  2523 
       
  2524     //read data from cfg file
       
  2525     TPtrC               username;
       
  2526     TPtrC               password;
       
  2527 	TInt                serviceId;
       
  2528     TInt               availability;
       
  2529     TPtrC               statustext;
       
  2530 
       
  2531 	aItem.GetNextString ( username );
       
  2532 	aItem.GetNextString ( password );
       
  2533 	aItem.GetNextInt ( serviceId );
       
  2534 	aItem.GetNextInt ( availability );
       
  2535 	aItem.GetNextString ( statustext );
       
  2536 
       
  2537 	TUid protocolUid = TUid::Uid ( KProtocolUid );
       
  2538 
       
  2539 	//Bind context to desired presence service
       
  2540 	TXIMPRequestId req = presecenCtx->BindToL ( protocolUid,
       
  2541 	                     username,
       
  2542 	                     password,
       
  2543 	                     serviceId );
       
  2544 	TOssAdapMtLogger::Log ( _L ( "Cossadapmt::presecenCtx->BindToL() called" ) );
       
  2545 	//Wait with CActiveSchedulerWait the binding to complete
       
  2546 	//If binding fails, it is handled with leave
       
  2547 	eventObserver->WaitOpToCompleteL ( req );
       
  2548     // Take handles to object factory and publish interface
       
  2549     MXIMPObjectFactory& objFactory = presecenCtx->ObjectFactory();
       
  2550     MPresencePublishing& publisher = presenceFeatures->PresencePublishing();
       
  2551     //Fill presence doc with presence components and attributes
       
  2552     MPresenceInfo* myPresence = presenceFeatures->PresenceObjectFactory().NewPresenceInfoLC();//1
       
  2553     MServicePresenceInfo* myServicePresence = presenceFeatures->PresenceObjectFactory().NewServicePresenceInfoLC();//2
       
  2554     myServicePresence->SetServiceTypeL( NPresenceInfo::NServiceType::KInstantMessaging );
       
  2555     //MPresenceInfoFieldCollection& attributeFields = myServicePresence->Fields();
       
  2556 
       
  2557     MPersonPresenceInfo *PersonPresence = presenceFeatures->PresenceObjectFactory().NewPersonPresenceInfoLC();
       
  2558     MPresenceInfoFieldCollection& attributeFields = PersonPresence->Fields();
       
  2559     
       
  2560     MPresenceInfoField* infoField = presenceFeatures->PresenceObjectFactory().NewInfoFieldLC();//3
       
  2561 
       
  2562     // "availability" attribute
       
  2563     MPresenceInfoFieldValueEnum* availabilityField = presenceFeatures->PresenceObjectFactory().NewEnumInfoFieldLC();//4
       
  2564     availabilityField->SetValueL( availability ); 
       
  2565     infoField->SetFieldTypeL( NPresenceInfo::NFieldType::KAvailability ); 
       
  2566     infoField->SetFieldValue( availabilityField );
       
  2567     CleanupStack::Pop(); // availabilityField
       
  2568 
       
  2569     attributeFields.AddOrReplaceFieldL(infoField );
       
  2570     //TInt count = serviceFields.FieldCount();
       
  2571     CleanupStack::Pop(); // infoField
       
  2572     
       
  2573     //status text
       
  2574     infoField = presenceFeatures->PresenceObjectFactory().NewInfoFieldLC();//7
       
  2575     MPresenceInfoFieldValueText* statustextField = presenceFeatures->PresenceObjectFactory().NewTextInfoFieldLC();//8
       
  2576     statustextField->SetTextValueL( statustext ); // some status text
       
  2577     infoField->SetFieldTypeL( KStatusTextfield );
       
  2578     infoField->SetFieldValue( statustextField );
       
  2579     CleanupStack::Pop(); // statustextField
       
  2580     attributeFields.AddOrReplaceFieldL( infoField );
       
  2581     CleanupStack::Pop(); // infoField
       
  2582     
       
  2583       
       
  2584      //online status
       
  2585     
       
  2586     infoField = presenceFeatures->PresenceObjectFactory().NewInfoFieldLC();//7
       
  2587     MPresenceInfoFieldValueText* onlineField = presenceFeatures->PresenceObjectFactory().NewTextInfoFieldLC();//8
       
  2588     onlineField->SetTextValueL( _L("T" ) ); // some status text
       
  2589     infoField->SetFieldTypeL( KOnlineStatusfield );
       
  2590     infoField->SetFieldValue( onlineField );
       
  2591     CleanupStack::Pop(); // devmodelField
       
  2592     attributeFields.AddOrReplaceFieldL( infoField );
       
  2593     CleanupStack::Pop(); // infoField
       
  2594      
       
  2595         
       
  2596     myPresence->AddServicePresenceL( myServicePresence );
       
  2597     myPresence->SetPersonPresenceL(PersonPresence);
       
  2598     TInt count = attributeFields.FieldCount();
       
  2599     CleanupStack::Pop(2); // myServicePresence,PersonPresence
       
  2600 
       
  2601     	
       
  2602     //publish the presence
       
  2603     req = publisher.PublishOwnPresenceL( *myPresence );
       
  2604 
       
  2605     // wait completion
       
  2606     eventObserver->WaitOpToCompleteL( req );
       
  2607     CleanupStack::PopAndDestroy(1); // myPresence
       
  2608         
       
  2609     CUserAfter::AfterL ( 1000000 );
       
  2610     req = presecenCtx->UnbindL();
       
  2611     eventObserver->WaitOpToCompleteL( req );
       
  2612 	TOssAdapMtLogger::Log ( _L ( "Cossadapmt::WaitOpToCompleteL() end" ) );
       
  2613 
       
  2614 	CleanupStack::PopAndDestroy ( 4 ); //presenceFeatures,presecenCtx,eventObserver,ximpClient
       
  2615 	TOssAdapMtLogger::Log ( _L ( "Cossadapmt::PublishOwnPresenceL() End" ) );
       
  2616 	return KErrNone;
       
  2617 
       
  2618 	}
       
  2619 // -----------------------------------------------------------------------------
       
  2620 // Cossadapmt::PublishOwnPresenceEmptyTextL
       
  2621 // Login test method function.
       
  2622 // (other items were commented in a header).
       
  2623 // -----------------------------------------------------------------------------
       
  2624 //
       
  2625 TInt Cossadapmt::PublishOwnPresenceEmptyTextL ( CStifItemParser& aItem )
       
  2626 	{
       
  2627 
       
  2628 
       
  2629 
       
  2630 	//Initialize XIMP client
       
  2631 	TOssAdapMtLogger::Log ( _L ( "Cossadapmt::PublishOwnPresenceEmptyTextL() start" ) );
       
  2632 
       
  2633 	MXIMPClient* ximpClient = MXIMPClient::NewClientL();
       
  2634 	CleanupDeletePushL ( ximpClient );
       
  2635 	TOssAdapMtLogger::Log ( _L ( "Cossadapmt::MXIMPClient::NewClientL() start" ) );
       
  2636 
       
  2637 	//Create new sink to receive presence context events
       
  2638 	CUSContextObserver* eventObserver = CUSContextObserver::NewLC();
       
  2639 
       
  2640 	//Create new presence context
       
  2641 	MXIMPContext* presecenCtx = ximpClient->NewPresenceContextLC();
       
  2642 	TOssAdapMtLogger::Log ( _L ( "Cossadapmt::ximpClient->NewPresenceContextLC() called" ) );
       
  2643 	presecenCtx->RegisterObserverL ( *eventObserver );
       
  2644 
       
  2645 	MPresenceFeatures* presenceFeatures = NULL;
       
  2646     presenceFeatures = MPresenceFeatures::NewL(presecenCtx); 
       
  2647     CleanupDeletePushL( presenceFeatures );
       
  2648 
       
  2649 
       
  2650     //read data from cfg file
       
  2651     TPtrC               username;
       
  2652     TPtrC               password;
       
  2653 	TInt                serviceId;
       
  2654     TInt               availability;
       
  2655 
       
  2656 	aItem.GetNextString ( username );
       
  2657 	aItem.GetNextString ( password );
       
  2658 	aItem.GetNextInt ( serviceId );
       
  2659 	aItem.GetNextInt ( availability );
       
  2660 	_LIT ( KBlankStatusText, "" );
       
  2661 
       
  2662 	TUid protocolUid = TUid::Uid ( KProtocolUid );
       
  2663 
       
  2664 	//Bind context to desired presence service
       
  2665 	TXIMPRequestId req = presecenCtx->BindToL ( protocolUid,
       
  2666 	                     username,
       
  2667 	                     password,
       
  2668 	                     serviceId );
       
  2669 	TOssAdapMtLogger::Log ( _L ( "Cossadapmt::presecenCtx->BindToL() called" ) );
       
  2670 	//Wait with CActiveSchedulerWait the binding to complete
       
  2671 	//If binding fails, it is handled with leave
       
  2672 	eventObserver->WaitOpToCompleteL ( req );
       
  2673     // Take handles to object factory and publish interface
       
  2674     MXIMPObjectFactory& objFactory = presecenCtx->ObjectFactory();
       
  2675     MPresencePublishing& publisher = presenceFeatures->PresencePublishing();
       
  2676     //Fill presence doc with presence components and attributes
       
  2677     MPresenceInfo* myPresence = presenceFeatures->PresenceObjectFactory().NewPresenceInfoLC();//1
       
  2678     MServicePresenceInfo* myServicePresence = presenceFeatures->PresenceObjectFactory().NewServicePresenceInfoLC();//2
       
  2679     myServicePresence->SetServiceTypeL( NPresenceInfo::NServiceType::KInstantMessaging );
       
  2680     //MPresenceInfoFieldCollection& attributeFields = myServicePresence->Fields();
       
  2681 
       
  2682     MPersonPresenceInfo *PersonPresence = presenceFeatures->PresenceObjectFactory().NewPersonPresenceInfoLC();
       
  2683     MPresenceInfoFieldCollection& attributeFields = PersonPresence->Fields();
       
  2684     
       
  2685     MPresenceInfoField* infoField = presenceFeatures->PresenceObjectFactory().NewInfoFieldLC();//3
       
  2686 
       
  2687     // "availability" attribute
       
  2688     MPresenceInfoFieldValueEnum* availabilityField = presenceFeatures->PresenceObjectFactory().NewEnumInfoFieldLC();//4
       
  2689     availabilityField->SetValueL( availability ); 
       
  2690     infoField->SetFieldTypeL( NPresenceInfo::NFieldType::KAvailability ); 
       
  2691     infoField->SetFieldValue( availabilityField );
       
  2692     CleanupStack::Pop(); // availabilityField
       
  2693 
       
  2694     attributeFields.AddOrReplaceFieldL(infoField );
       
  2695     //TInt count = serviceFields.FieldCount();
       
  2696     CleanupStack::Pop(); // infoField
       
  2697     
       
  2698     //status text
       
  2699     infoField = presenceFeatures->PresenceObjectFactory().NewInfoFieldLC();//7
       
  2700     MPresenceInfoFieldValueText* statustextField = presenceFeatures->PresenceObjectFactory().NewTextInfoFieldLC();//8
       
  2701     statustextField->SetTextValueL( KBlankStatusText ); // some status text
       
  2702     infoField->SetFieldTypeL( KStatusTextfield );
       
  2703     infoField->SetFieldValue( statustextField );
       
  2704     CleanupStack::Pop(); // statustextField
       
  2705     attributeFields.AddOrReplaceFieldL( infoField );
       
  2706     CleanupStack::Pop(); // infoField
       
  2707     
       
  2708       
       
  2709      //online status
       
  2710     
       
  2711     infoField = presenceFeatures->PresenceObjectFactory().NewInfoFieldLC();//7
       
  2712     MPresenceInfoFieldValueText* onlineField = presenceFeatures->PresenceObjectFactory().NewTextInfoFieldLC();//8
       
  2713     onlineField->SetTextValueL( _L("T" ) ); // some status text
       
  2714     infoField->SetFieldTypeL( KOnlineStatusfield );
       
  2715     infoField->SetFieldValue( onlineField );
       
  2716     CleanupStack::Pop(); // devmodelField
       
  2717     attributeFields.AddOrReplaceFieldL( infoField );
       
  2718     CleanupStack::Pop(); // infoField
       
  2719      
       
  2720         
       
  2721     myPresence->AddServicePresenceL( myServicePresence );
       
  2722     myPresence->SetPersonPresenceL(PersonPresence);
       
  2723     TInt count = attributeFields.FieldCount();
       
  2724     CleanupStack::Pop(2); // myServicePresence,PersonPresence
       
  2725 
       
  2726     	
       
  2727     //publish the presence
       
  2728     req = publisher.PublishOwnPresenceL( *myPresence );
       
  2729 
       
  2730     // wait completion
       
  2731     eventObserver->WaitOpToCompleteL( req );
       
  2732     CleanupStack::PopAndDestroy(1); // myPresence
       
  2733         
       
  2734     CUserAfter::AfterL ( 1000000 );
       
  2735     req = presecenCtx->UnbindL();
       
  2736     eventObserver->WaitOpToCompleteL( req );
       
  2737 	TOssAdapMtLogger::Log ( _L ( "Cossadapmt::WaitOpToCompleteL() end" ) );
       
  2738 
       
  2739 	CleanupStack::PopAndDestroy ( 4 ); //presenceFeatures,presecenCtx,eventObserver,ximpClient
       
  2740 	TOssAdapMtLogger::Log ( _L ( "Cossadapmt::PublishOwnPresenceEmptyTextL() End" ) );
       
  2741 	return KErrNone;
       
  2742 
       
  2743 	}
       
  2744 TInt Cossadapmt::AcceptnotificationRequestL ( CStifItemParser& aItem )
       
  2745 	{
       
  2746 	
       
  2747 	TOssAdapMtLogger::Log ( _L ( "Cossadapmt::AcceptAddnotificationRequestL() start" ) );
       
  2748 
       
  2749 	MXIMPClient* ximpClient = MXIMPClient::NewClientL();
       
  2750 	CleanupDeletePushL ( ximpClient );
       
  2751 	TOssAdapMtLogger::Log ( _L ( "Cossadapmt::MXIMPClient::NewClientL() start" ) );
       
  2752 
       
  2753 	//Create new sink to receive presence context events
       
  2754 	CUSContextObserver* eventObserver = CUSContextObserver::NewLC();
       
  2755 
       
  2756 	//Create new presence context
       
  2757 	MXIMPContext* presecenCtx = ximpClient->NewPresenceContextLC();
       
  2758 	TOssAdapMtLogger::Log ( _L ( "Cossadapmt::ximpClient->NewPresenceContextLC() called" ) );
       
  2759 	presecenCtx->RegisterObserverL ( *eventObserver );
       
  2760 	MPresenceFeatures* presenceFeatures = NULL;
       
  2761 	presenceFeatures = MPresenceFeatures::NewL ( presecenCtx );
       
  2762 	CleanupDeletePushL ( presenceFeatures );
       
  2763 	TOssAdapMtLogger::Log ( _L ( "Loading presence plugin Done" ) );
       
  2764 	MXIMPObjectFactory& objFactory = presecenCtx->ObjectFactory();
       
  2765 	MXIMPIdentity* newGroupId = objFactory.NewIdentityLC();
       
  2766 	MPresentityGroups& groups = presenceFeatures->PresentityGroups() ;
       
  2767     MPresenceAuthorization& authorization = presenceFeatures->PresenceAuthorization();
       
  2768     MPresenceInfoFilter* infoFilt = presenceFeatures->PresenceObjectFactory().NewPresenceInfoFilterLC();
       
  2769    
       
  2770     infoFilt->AcceptPersonFilterL( NPresenceInfo::NFieldType::KAcceptAll );
       
  2771 
       
  2772 	TOssAdapMtLogger::Log ( _L ( "presentity groups object created" ) );
       
  2773 	_LIT ( KDummyListId, "list" );
       
  2774 	HBufC16* iListId;
       
  2775 	iListId = KDummyListId().AllocL();
       
  2776 	iListId->Des().Fold();
       
  2777 	newGroupId->SetIdentityL ( *iListId );
       
  2778 	delete iListId;
       
  2779 	iListId = NULL;
       
  2780 
       
  2781     //read data from cfg file
       
  2782     TPtrC               username;
       
  2783     TPtrC               password;
       
  2784 	TInt                serviceId;
       
  2785     
       
  2786 	aItem.GetNextString ( username );
       
  2787 	aItem.GetNextString ( password );
       
  2788 	aItem.GetNextInt ( serviceId );
       
  2789 
       
  2790 	TUid protocolUid = TUid::Uid ( KProtocolUid );
       
  2791 
       
  2792 	//Bind context to desired presence service
       
  2793 	TXIMPRequestId req = presecenCtx->BindToL ( protocolUid,
       
  2794 	                     username,
       
  2795 	                     password,
       
  2796 	                     serviceId );
       
  2797 	TOssAdapMtLogger::Log ( _L ( "Cossadapmt::presecenCtx->BindToL() called" ) );
       
  2798 	//Wait with CActiveSchedulerWait the binding to complete
       
  2799 	//If binding fails, it is handled with leave
       
  2800 	eventObserver->WaitOpToCompleteL ( req );
       
  2801     req = authorization.SubscribePresenceGrantRequestListL();
       
  2802     
       
  2803     // wait completion
       
  2804     
       
  2805     eventObserver->WaitOpToCompleteL( req );
       
  2806 
       
  2807     CUserAfter::AfterL( 1000000 );
       
  2808 	
       
  2809 	req = groups.SubscribePresentityGroupContentL ( *newGroupId );
       
  2810 
       
  2811 	TOssAdapMtLogger::Log ( _L ( "Cossadapmt::groups.SubscribePresentityGroupListL() called" ) );
       
  2812 
       
  2813 	eventObserver->WaitOpToCompleteL ( req );
       
  2814 
       
  2815 	CUserAfter::AfterL ( 5000000 );
       
  2816 
       
  2817     MXIMPIdentity* testContactId = objFactory.NewIdentityLC();
       
  2818     testContactId->SetIdentityL( KContact1 );
       
  2819     req = authorization.GrantPresenceForPresentityL(*testContactId ,*infoFilt );
       
  2820       
       
  2821     // wait completion
       
  2822     eventObserver->WaitOpToCompleteL( req );
       
  2823     
       
  2824 
       
  2825 	 CleanupStack::PopAndDestroy();//testContactId
       
  2826 	//Unbind the context and wait completion
       
  2827 	req = presecenCtx->UnbindL();
       
  2828 	TOssAdapMtLogger::Log ( _L ( "Cossadapmt::presecenCtx->UnbindL() called" ) );
       
  2829 
       
  2830 	eventObserver->WaitOpToCompleteL ( req );
       
  2831 	TOssAdapMtLogger::Log ( _L ( "Cossadapmt::WaitOpToCompleteL() end" ) );
       
  2832 
       
  2833 	CleanupStack::PopAndDestroy ( 6 );//newGroupId,presenceFeatures,presecenCtx,eventObserver,ximpClient,infoFilt
       
  2834 	TOssAdapMtLogger::Log ( _L ( "Cossadapmt::AcceptAddnotificationRequestL() end" ) );
       
  2835 
       
  2836 	return KErrNone;
       
  2837 	}
       
  2838 
       
  2839 
       
  2840 // -----------------------------------------------------------------------------
       
  2841 // Cossadapmt::RejectAddnotificationRequestL
       
  2842 // AddConatctL contacts test method function.
       
  2843 // (other items were commented in a header).
       
  2844 // -----------------------------------------------------------------------------
       
  2845 //
       
  2846 TInt Cossadapmt::RejectAddnotificationRequestL ( CStifItemParser& aItem )
       
  2847 	{
       
  2848 
       
  2849 	//Initialize XIMP client
       
  2850 	TOssAdapMtLogger::Log ( _L ( "Cossadapmt::RejectAddnotificationRequestL() start" ) );
       
  2851 
       
  2852 	MXIMPClient* ximpClient = MXIMPClient::NewClientL();
       
  2853 	CleanupDeletePushL ( ximpClient );
       
  2854 	TOssAdapMtLogger::Log ( _L ( "Cossadapmt::MXIMPClient::NewClientL() start" ) );
       
  2855 
       
  2856 	//Create new sink to receive presence context events
       
  2857 	CUSContextObserver* eventObserver = CUSContextObserver::NewLC();
       
  2858 
       
  2859 	//Create new presence context
       
  2860 	MXIMPContext* presecenCtx = ximpClient->NewPresenceContextLC();
       
  2861 	TOssAdapMtLogger::Log ( _L ( "Cossadapmt::ximpClient->NewPresenceContextLC() called" ) );
       
  2862 	presecenCtx->RegisterObserverL ( *eventObserver );
       
  2863 	MPresenceFeatures* presenceFeatures = NULL;
       
  2864 	presenceFeatures = MPresenceFeatures::NewL ( presecenCtx );
       
  2865 	CleanupDeletePushL ( presenceFeatures );
       
  2866 	TOssAdapMtLogger::Log ( _L ( "Loading presence plugin Done" ) );
       
  2867 	MXIMPObjectFactory& objFactory = presecenCtx->ObjectFactory();
       
  2868 	MXIMPIdentity* newGroupId = objFactory.NewIdentityLC();
       
  2869 	MPresentityGroups& groups = presenceFeatures->PresentityGroups() ;
       
  2870     MPresenceAuthorization& authorization = presenceFeatures->PresenceAuthorization();
       
  2871     MPresenceInfoFilter* infoFilt = presenceFeatures->PresenceObjectFactory().NewPresenceInfoFilterLC();
       
  2872      
       
  2873      infoFilt->AcceptPersonFilterL( NPresenceInfo::NFieldType::KAcceptAll );
       
  2874 
       
  2875 	TOssAdapMtLogger::Log ( _L ( "presentity groups object created" ) );
       
  2876 	_LIT ( KDummyListId, "list" );
       
  2877 	HBufC16* iListId;
       
  2878 	iListId = KDummyListId().AllocL();
       
  2879 	iListId->Des().Fold();
       
  2880 	newGroupId->SetIdentityL ( *iListId );
       
  2881 	delete iListId;
       
  2882 	iListId = NULL;
       
  2883 
       
  2884     //read data from cfg file
       
  2885     TPtrC               username;
       
  2886     TPtrC               password;
       
  2887 	TInt                serviceId;
       
  2888     
       
  2889 	aItem.GetNextString ( username );
       
  2890 	aItem.GetNextString ( password );
       
  2891 	aItem.GetNextInt ( serviceId );
       
  2892 
       
  2893 	TUid protocolUid = TUid::Uid ( KProtocolUid );
       
  2894 
       
  2895 	//Bind context to desired presence service
       
  2896 	TXIMPRequestId req = presecenCtx->BindToL ( protocolUid,
       
  2897 	                     username,
       
  2898 	                     password,
       
  2899 	                     serviceId );
       
  2900 	TOssAdapMtLogger::Log ( _L ( "Cossadapmt::presecenCtx->BindToL() called" ) );
       
  2901 	//Wait with CActiveSchedulerWait the binding to complete
       
  2902 	//If binding fails, it is handled with leave
       
  2903 	eventObserver->WaitOpToCompleteL ( req );
       
  2904     req = authorization.SubscribePresenceGrantRequestListL();
       
  2905     
       
  2906     // wait completion
       
  2907     
       
  2908     eventObserver->WaitOpToCompleteL( req );
       
  2909 
       
  2910     CUserAfter::AfterL( 1000000 );
       
  2911 	
       
  2912 	req = groups.SubscribePresentityGroupContentL ( *newGroupId );
       
  2913 
       
  2914 	TOssAdapMtLogger::Log ( _L ( "Cossadapmt::groups.SubscribePresentityGroupListL() called" ) );
       
  2915 
       
  2916 	eventObserver->WaitOpToCompleteL ( req );
       
  2917 	CUserAfter::AfterL ( 5000000 );
       
  2918 
       
  2919     MXIMPIdentity* testContactId = objFactory.NewIdentityLC();
       
  2920     testContactId->SetIdentityL( KContact1 );
       
  2921     req = authorization.WithdrawPresenceGrantFromPresentityL(*testContactId);
       
  2922       
       
  2923     // wait completion
       
  2924     eventObserver->WaitOpToCompleteL( req );
       
  2925     
       
  2926     CUserAfter::AfterL( 1000000 );
       
  2927 
       
  2928 	 CleanupStack::PopAndDestroy();//testContactId
       
  2929 	//Unbind the context and wait completion
       
  2930 	req = presecenCtx->UnbindL();
       
  2931 	TOssAdapMtLogger::Log ( _L ( "Cossadapmt::presecenCtx->UnbindL() called" ) );
       
  2932 
       
  2933 	eventObserver->WaitOpToCompleteL ( req );
       
  2934 	TOssAdapMtLogger::Log ( _L ( "Cossadapmt::WaitOpToCompleteL() end" ) );
       
  2935 
       
  2936 	CleanupStack::PopAndDestroy ( 6 );//infoFilt,newGroupId,presenceFeatures,presecenCtx,eventObserver,ximpClient
       
  2937 	TOssAdapMtLogger::Log ( _L ( "Cossadapmt::RejectAddnotificationRequestL() end" ) );
       
  2938 
       
  2939 	return KErrNone;
       
  2940 
       
  2941 	}
       
  2942 // -----------------------------------------------------------------------------
       
  2943 // Cossadapmt::ImOperationsCoverageL
       
  2944 // ImOperationsCoverageL test method function.
       
  2945 // (other items were commented in a header).
       
  2946 // -----------------------------------------------------------------------------
       
  2947 //
       
  2948 TInt Cossadapmt::ImOperationsCoverageL ( CStifItemParser& aItem )
       
  2949 	{
       
  2950 
       
  2951 	//Initialize XIMP client
       
  2952 	TOssAdapMtLogger::Log ( _L ( "Cossadapmt::ImOperationsCoverageL() start" ) );
       
  2953 	MXIMPClient* ximpClient = MXIMPClient::NewClientL();
       
  2954 	CleanupDeletePushL ( ximpClient );
       
  2955 	TOssAdapMtLogger::Log ( _L ( "Cossadapmt::MXIMPClient::NewClientL() start" ) );
       
  2956 	//Create new sink to receive presence context events
       
  2957 	CUSContextObserver* eventObserver = CUSContextObserver::NewLC();
       
  2958 	//Create new presence context
       
  2959 	MXIMPContext* presecenCtx = ximpClient->NewPresenceContextLC();
       
  2960 	//Bind context to desired presence service
       
  2961 	presecenCtx->RegisterObserverL ( *eventObserver );
       
  2962 	MPresenceFeatures* presenceFeatures = NULL;
       
  2963 	presenceFeatures = MPresenceFeatures::NewL ( presecenCtx );
       
  2964 	CleanupDeletePushL ( presenceFeatures );
       
  2965 
       
  2966     //read data from cfg file
       
  2967     TPtrC               username;
       
  2968     TPtrC               password;
       
  2969 	TInt                serviceId;
       
  2970     TPtrC               message;
       
  2971     TPtrC               contact;
       
  2972 	aItem.GetNextString ( username );
       
  2973 	aItem.GetNextString ( password );
       
  2974 	aItem.GetNextInt ( serviceId );
       
  2975 	aItem.GetNextString ( message );
       
  2976 	aItem.GetNextString ( contact );
       
  2977 	TUid protocolUid = TUid::Uid ( KProtocolUid );
       
  2978 
       
  2979 	//Bind context to desired presence service
       
  2980 	TXIMPRequestId req = presecenCtx->BindToL ( protocolUid,
       
  2981 	                     username,
       
  2982 	                     password,
       
  2983 	                     serviceId );
       
  2984 	TOssAdapMtLogger::Log ( _L ( "Cossadapmt::ximpClient->NewPresenceContextLC() called\n" ) );
       
  2985 	eventObserver->WaitOpToCompleteL ( req );
       
  2986 	MXIMPObjectFactory& objFactory = presecenCtx->ObjectFactory();
       
  2987 	MXIMPIdentity* newGroupId = objFactory.NewIdentityLC();
       
  2988 	MPresentityGroups& groups = presenceFeatures->PresentityGroups() ;
       
  2989 
       
  2990 	TOssAdapMtLogger::Log ( _L ( "presentity groups object created" ) );
       
  2991 	_LIT ( KDummyListId, "" );
       
  2992 	HBufC16* iListId;
       
  2993 	iListId = KDummyListId().AllocL();
       
  2994 	iListId->Des().Fold();
       
  2995 	newGroupId->SetIdentityL ( *iListId );
       
  2996 	delete iListId;
       
  2997 	iListId = NULL;
       
  2998 	req = groups.SubscribePresentityGroupContentL ( *newGroupId );
       
  2999 
       
  3000 	TOssAdapMtLogger::Log ( _L ( "Cossadapmt::groups.SubscribePresentityGroupListL() called" ) );
       
  3001 
       
  3002 	eventObserver->WaitOpToCompleteL ( req );
       
  3003    CleanupStack::PopAndDestroy(2); //newGroupId,presenceFeatures
       
  3004 
       
  3005 	CUserAfter::AfterL ( 1000000 );
       
  3006 	//Bind context to desired presence service
       
  3007 	MImFeatures* imFeatures = NULL;
       
  3008 	imFeatures = MImFeatures::NewL ( presecenCtx );
       
  3009 	CleanupDeletePushL ( imFeatures );
       
  3010 	TOssAdapMtLogger::Log ( _L ( "Cossadapmt::imFeatures created\n" ) );
       
  3011 	MImConversation& imconversation = imFeatures->ImConversation();
       
  3012 	TOssAdapMtLogger::Log ( _L ( "Cossadapmt::imconversation created\n" ) );
       
  3013 	MImConversationInfo *aImMessage = NULL;
       
  3014 	aImMessage = imFeatures->ImObjectFactory().NewImConversationInfoLC();
       
  3015 	MXIMPIdentity* identity = objFactory.NewIdentityLC();
       
  3016 	identity->SetIdentityL ( KMsgId );
       
  3017 	aImMessage->SetMessageIdL ( identity );
       
  3018 	aImMessage->SetTextMessageL ( message );
       
  3019 	CDesCArrayFlat* aRecipients = new ( ELeave ) CDesCArrayFlat ( 1 );
       
  3020 	CleanupStack::PushL ( aRecipients );  
       
  3021 	aRecipients->AppendL ( username );  //userid of own
       
  3022 	aImMessage->SetRecipientL ( aRecipients );
       
  3023 	TOssAdapMtLogger::Log ( _L ( "Cossadapmt::before sendmessage called\n" ) );
       
  3024     //send message is to own
       
  3025 	req = imconversation.SendMessageL ( *aImMessage );
       
  3026 	eventObserver->WaitOpToCompleteL ( req );
       
  3027 	CleanupStack::Pop ( 3 );//identity,aRecipients,aImMessage
       
  3028 	//send message to other guy
       
  3029 	TOssAdapMtLogger::Log ( _L ( "Cossadapmt::message sent\n " ) );
       
  3030 	//Unbind the context and wait completion
       
  3031     req = presecenCtx->UnbindL();
       
  3032     eventObserver->WaitOpToCompleteL( req );
       
  3033 	CleanupStack::PopAndDestroy(4); //imFeatures,presecenCtx,eventObserver,ximpClient,
       
  3034 	TOssAdapMtLogger::Log ( _L ( "Cossadapmt::ImOperationsCoverageL() start" ) );
       
  3035 
       
  3036 	return KErrNone;
       
  3037 
       
  3038 	}		
       
  3039 // -----------------------------------------------------------------------------
       
  3040 // Cossadapmt::SetAvtarL
       
  3041 // Login test method function.
       
  3042 // (other items were commented in a header).
       
  3043 // -----------------------------------------------------------------------------
       
  3044 //
       
  3045 TInt Cossadapmt::SetAvtarL ( CStifItemParser& aItem )
       
  3046     {
       
  3047 
       
  3048 
       
  3049 
       
  3050     //Initialize XIMP client
       
  3051     TOssAdapMtLogger::Log ( _L ( "Cossadapmt::SetAvtarL() start" ) );
       
  3052 
       
  3053     MXIMPClient* ximpClient = MXIMPClient::NewClientL();
       
  3054     CleanupDeletePushL ( ximpClient );
       
  3055     TOssAdapMtLogger::Log ( _L ( "Cossadapmt::MXIMPClient::NewClientL() start" ) );
       
  3056 
       
  3057     //Create new sink to receive presence context events
       
  3058     CUSContextObserver* eventObserver = CUSContextObserver::NewLC();
       
  3059 
       
  3060     //Create new presence context
       
  3061     MXIMPContext* presecenCtx = ximpClient->NewPresenceContextLC();
       
  3062     TOssAdapMtLogger::Log ( _L ( "Cossadapmt::ximpClient->NewPresenceContextLC() called" ) );
       
  3063     presecenCtx->RegisterObserverL ( *eventObserver );
       
  3064 
       
  3065     MPresenceFeatures* presenceFeatures = NULL;
       
  3066     presenceFeatures = MPresenceFeatures::NewL(presecenCtx); 
       
  3067     CleanupDeletePushL( presenceFeatures );
       
  3068 
       
  3069 
       
  3070     //read data from cfg file
       
  3071     TPtrC               username;
       
  3072     TPtrC               password;
       
  3073     TInt                serviceId;
       
  3074     TPtrC               filename;
       
  3075     aItem.GetNextString ( username );
       
  3076     aItem.GetNextString ( password );
       
  3077     aItem.GetNextInt ( serviceId );
       
  3078     aItem.GetNextString ( filename );
       
  3079     TUid protocolUid = TUid::Uid ( KProtocolUid );
       
  3080     
       
  3081     //Bind context to desired presence service
       
  3082     TXIMPRequestId req = presecenCtx->BindToL ( protocolUid,
       
  3083                          username,
       
  3084                          password,
       
  3085                          serviceId );
       
  3086     TOssAdapMtLogger::Log ( _L ( "Cossadapmt::presecenCtx->BindToL() called" ) );
       
  3087     //Wait with CActiveSchedulerWait the binding to complete
       
  3088     //If binding fails, it is handled with leave
       
  3089     eventObserver->WaitOpToCompleteL ( req );
       
  3090     // Take handles to object factory and publish interface
       
  3091     // Take handles to object factory and publish interface
       
  3092     presenceFeatures = MPresenceFeatures::NewL(presecenCtx); 
       
  3093     MXIMPObjectFactory& objFactory = presecenCtx->ObjectFactory();
       
  3094    
       
  3095     MXIMPIdentity* newGroupId = objFactory.NewIdentityLC();
       
  3096     MXIMPIdentity* newmemberId = objFactory.NewIdentityLC();
       
  3097 
       
  3098     CleanupDeletePushL( presenceFeatures );
       
  3099 
       
  3100     MPresencePublishing& publisher = presenceFeatures->PresencePublishing();
       
  3101   
       
  3102     //Fill presence doc with presence components and attributes
       
  3103     MPresenceInfo* myPresence = presenceFeatures->PresenceObjectFactory().NewPresenceInfoLC();//1
       
  3104     MPersonPresenceInfo *PersonPresence = presenceFeatures->PresenceObjectFactory().NewPersonPresenceInfoLC();
       
  3105     MPresenceInfoFieldCollection& attributeFields = PersonPresence->Fields();
       
  3106   
       
  3107     MPresenceInfoField* infoField = presenceFeatures->PresenceObjectFactory().NewInfoFieldLC();//3
       
  3108 
       
  3109    //based on the state conver it to  ximpfw status.
       
  3110  
       
  3111 
       
  3112     // "availability" attribute
       
  3113     MPresenceInfoFieldValueBinary* avatarField = presenceFeatures->PresenceObjectFactory().NewBinaryInfoFieldLC();//4
       
  3114     //avatarField->SetBinaryValueL(*(aImageLoader->GetContentData()));
       
  3115     _LIT8(KMimeType,"image/gif");
       
  3116     TBufC8<20> mimetype(KMimeType);
       
  3117 
       
  3118     avatarField->SetMimeTypeL(mimetype.Des());
       
  3119    RFile file;
       
  3120    RFs iFs;
       
  3121    User::LeaveIfError( iFs.Connect() );
       
  3122    User::LeaveIfError( file.Open( iFs, _L("c:\\index.gif"), EFileRead ) );
       
  3123    CleanupClosePushL( file );
       
  3124         
       
  3125     // Get file size
       
  3126     TInt fileSize = 0;
       
  3127     User::LeaveIfError( file.Size( fileSize ) );
       
  3128     
       
  3129     // Check file size, if bigger than max transaction content -> leave
       
  3130   /*  if ( fileSize >
       
  3131         iImpsFactory.CreateImClientL()->MaxTransactionContentLengthL() )
       
  3132         {
       
  3133         User::Leave( KErrOverflow );
       
  3134         }*/
       
  3135         
       
  3136     // Get file content
       
  3137     HBufC8* Content = HBufC8::NewL( fileSize );
       
  3138     TPtr8 ptr( Content->Des() );
       
  3139     User::LeaveIfError( file.Read( ptr, fileSize ) );
       
  3140     
       
  3141     avatarField->SetBinaryValueL(*Content);
       
  3142     infoField->SetFieldTypeL( NPresenceInfo::NFieldType::KAvatar ); 
       
  3143     infoField->SetFieldValue( avatarField );
       
  3144     CleanupStack::Pop(); // availabilityField
       
  3145 
       
  3146     attributeFields.AddOrReplaceFieldL(infoField );
       
  3147  
       
  3148     CleanupStack::Pop(); // infoField
       
  3149                   
       
  3150     myPresence->SetPersonPresenceL(PersonPresence);
       
  3151     CleanupStack::Pop(1); // PersonPresence
       
  3152 
       
  3153     req = publisher.PublishOwnPresenceL( *myPresence );
       
  3154 
       
  3155     // wait completion
       
  3156     eventObserver->WaitOpToCompleteL( req );
       
  3157     CleanupStack::PopAndDestroy(1); // myPresence
       
  3158         
       
  3159     req = presecenCtx->UnbindL();
       
  3160     eventObserver->WaitOpToCompleteL( req );
       
  3161     TOssAdapMtLogger::Log ( _L ( "Cossadapmt::WaitOpToCompleteL() end" ) );
       
  3162 
       
  3163     CleanupStack::PopAndDestroy ( 4 ); //presenceFeatures,presecenCtx,eventObserver,ximpClient
       
  3164     TOssAdapMtLogger::Log ( _L ( "Cossadapmt::SetAvtarL() End" ) );
       
  3165     return KErrNone;
       
  3166 
       
  3167     }
       
  3168 //  [End of File] - Do not remove