imservices/ossprotocoladaptation/tsrc/ossadapmt/src/uscontextobserver.cpp
branchRCL_3
changeset 20 7797b2f86d2b
parent 18 b6f2a363adf7
child 25 cfe5eb8bb9ca
equal deleted inserted replaced
18:b6f2a363adf7 20:7797b2f86d2b
     1 /*
       
     2 * Copyright (c) 2007-2008 Nokia Corporation and/or its subsidiary(-ies).
       
     3 * All rights reserved.
       
     4 * This component and the accompanying materials are made available
       
     5 * under the terms of "Eclipse Public License v1.0"
       
     6 * which accompanies this distribution, and is available
       
     7 * at the URL "http://www.eclipse.org/legal/epl-v10.html".
       
     8 *
       
     9 * Initial Contributors:
       
    10 * Nokia Corporation - initial contribution.
       
    11 *
       
    12 * Contributors:
       
    13 *
       
    14 * Description: uscontextobserver.cpp
       
    15 *
       
    16 */
       
    17 
       
    18 #include "uscontextobserver.h"
       
    19 
       
    20 #include <ximpidentity.h>
       
    21 #include <presenceinfofieldvaluetext.h>
       
    22 #include <presenceinfofieldvalueenum.h>
       
    23 #include <ximpstatus.h>
       
    24 #include <ximpcontextstateevent.h>
       
    25 #include <ximprequestcompleteevent.h>
       
    26 #include <presentitypresenceevent.h>
       
    27 #include <presentitygrouplistevent.h>
       
    28 #include <presentitygroupinfo.h>
       
    29 #include <presentitygroupcontentevent.h>
       
    30 #include <presentitygroupmemberinfo.h>
       
    31 #include <presencegrantrequestlistevent.h>
       
    32 #include <presenceblocklistevent.h>
       
    33 #include <presentitypresenceevent.h>
       
    34 #include <presencewatcherlistevent.h>
       
    35 #include "ossadapmt.h"
       
    36 #include <ximpdatasubscriptionstate.h>
       
    37 #include <presencewatcherinfo.h>
       
    38 #include "ximpcontextstate.h"
       
    39 #include <presenceinfo.h>
       
    40 #include <servicepresenceinfo.h>
       
    41 #include <devicepresenceinfo.h>
       
    42 #include <presencegrantrequestinfo.h>
       
    43 #include <presenceblockinfo.h>
       
    44 #include <presenceinfofieldcollection.h>
       
    45 #include <personpresenceinfo.h>
       
    46 #include <presenceinfofield.h>
       
    47 
       
    48 #include "imconversationevent.h"
       
    49 #include <searchevent.h>
       
    50 
       
    51 #include "imconversationinfo.h"
       
    52 #include <searchinfo.h>
       
    53 #include <searchkeysevent.h>
       
    54 #include <searchkeyinfo.h>
       
    55 
       
    56 #include <e32math.h>
       
    57 #include <f32file.h>
       
    58 #include <utf.h>
       
    59 // ============================ MEMBER FUNCTIONS ===============================
       
    60 
       
    61 // CONSTRUCTION
       
    62 CUSContextObserver* CUSContextObserver::NewLC()
       
    63 	{
       
    64 	CUSContextObserver* self = new ( ELeave ) CUSContextObserver();
       
    65 	CleanupStack::PushL ( self );
       
    66 	return self;
       
    67 	}
       
    68 
       
    69 
       
    70 CUSContextObserver::~CUSContextObserver()
       
    71 	{
       
    72 	}
       
    73 
       
    74 
       
    75 CUSContextObserver::CUSContextObserver()
       
    76 	{
       
    77 	}
       
    78 
       
    79 
       
    80 
       
    81 // ===========================================================================
       
    82 // PUBLIC FUNCTIONS
       
    83 // ===========================================================================
       
    84 //
       
    85 void CUSContextObserver::WaitOpToCompleteL ( const TXIMPRequestId& aOpToWait )
       
    86 	{
       
    87 	iReqToWait = aOpToWait;
       
    88 
       
    89 	iWait.Start();
       
    90 
       
    91 	}
       
    92 
       
    93 /*void CUSContextObserver::WaitCompleteL()
       
    94  {
       
    95  iWait.AsyncStop();
       
    96  }*/
       
    97 
       
    98 // ===========================================================================
       
    99 // FROM MXIMPContextObserver
       
   100 // ===========================================================================
       
   101 //
       
   102 void CUSContextObserver::HandlePresenceContextEvent (
       
   103     const MXIMPContext& /*aContext*/,
       
   104     const MXIMPBase& aEvent )
       
   105 	{
       
   106 
       
   107 	TOssAdapMtLogger::Log ( _L ( "HandlePresenceContextEvent called" ) );
       
   108 
       
   109 	TInt32 eventId = aEvent.GetInterfaceId();
       
   110 
       
   111 	switch ( aEvent.GetInterfaceId() )
       
   112 		{
       
   113 			_LIT ( KDir, "EVENT_LOG" );  // here we hv to write a folder name in wch we want to create log file
       
   114 			_LIT ( KFile, "event.txt" );          //here we hv to write a file name in wch we want to log default path is  " c:/Logs/"
       
   115 
       
   116 		case MXIMPRequestCompleteEvent::KInterfaceId:
       
   117 				{
       
   118 				TOssAdapMtLogger::Log ( _L ( "CUSContextObserver::MXIMPRequestCompleteEvent() start" ) );
       
   119 
       
   120 				const MXIMPRequestCompleteEvent* complEvent =
       
   121 				    TXIMPGetInterface< const MXIMPRequestCompleteEvent >::From ( aEvent,
       
   122 				            MXIMPBase::EPanicIfUnknown );
       
   123 
       
   124 				RFileLogger::WriteFormat ( KDir, KFile, EFileLoggingModeAppend, _L ( "*************BEGIN******************" ) );
       
   125 				_LIT ( KMsg, "Recvd RequestCompleteEvent " );         // here we hv to write message or text wch we want to write in log file
       
   126 				RFileLogger::WriteFormat ( KDir, KFile, EFileLoggingModeAppend, KMsg );
       
   127 
       
   128 				if ( iWait.IsStarted() && ( complEvent->RequestId() == iReqToWait ) )
       
   129 					{
       
   130 					iReqResult = complEvent->CompletionResult().ResultCode();
       
   131 					RFileLogger::WriteFormat ( KDir, KFile, EFileLoggingModeAppend, _L ( "Error code for the request is %d " ), iReqResult );
       
   132 					iWait.AsyncStop();
       
   133 					}
       
   134 
       
   135 				TOssAdapMtLogger::Log ( _L ( "CUSContextObserver::MXIMPRequestCompleteEvent() end" ) );
       
   136 
       
   137 				break;
       
   138 				}
       
   139 
       
   140 		case MXIMPContextStateEvent::KInterfaceId:
       
   141 				{
       
   142 				const MXIMPContextStateEvent* ctxtStateEvent =
       
   143 				    TXIMPGetInterface< const MXIMPContextStateEvent >::From ( aEvent,
       
   144 				            MXIMPBase::EPanicIfUnknown );
       
   145 				RFileLogger::WriteFormat ( KDir, KFile, EFileLoggingModeAppend, _L ( "*************BEGIN******************" ) );
       
   146 				_LIT ( KMsg, "Recvd PresenceContextStateEvent " );         // here we hv to write message or text wch we want to write in log file
       
   147 				RFileLogger::WriteFormat ( KDir, KFile, EFileLoggingModeAppend, KMsg );
       
   148 				const MXIMPStatus* fwStatus = ctxtStateEvent->StateChangeReason();
       
   149 				const MXIMPContextState& cState = ctxtStateEvent->ContextState();
       
   150 				MXIMPContextState::TState state = cState.ContextState();
       
   151 				break;
       
   152 				}
       
   153 
       
   154 		case MPresentityGroupListEvent::KInterfaceId:
       
   155 				{
       
   156 				const MPresentityGroupListEvent* groupListEvent =
       
   157 				    TXIMPGetInterface< const MPresentityGroupListEvent >::From ( aEvent,
       
   158 				            MXIMPBase::EPanicIfUnknown );
       
   159 
       
   160 				TBuf<100> sdstate;
       
   161 				TBuf<100> ssstate;
       
   162 				_LIT ( Kna, "   Susbcription state is unavailable" );
       
   163 				_LIT ( Kava, "   Susbcription state is available" );
       
   164 				_LIT ( KDef, "   Susbcription state is ERROR" );
       
   165 
       
   166 				const  MXIMPDataSubscriptionState&  dstate = groupListEvent->DataSubscriptionState();
       
   167 
       
   168 				switch ( dstate.SubscriptionState() )
       
   169 					{
       
   170 
       
   171 					case 0:
       
   172 						ssstate.Copy ( Kna );
       
   173 						break;
       
   174 
       
   175 					case 1:
       
   176 						ssstate.Copy ( Kava );
       
   177 						break;
       
   178 
       
   179 					default:
       
   180 						ssstate.Copy ( KDef );
       
   181 						break;
       
   182 					}
       
   183 
       
   184 				_LIT ( Kdna, "   Data state is unavailable" );
       
   185 
       
   186 				_LIT ( Kdava, "   Data state is available" );
       
   187 				_LIT ( KdDef, "   Data state is ERROR" );
       
   188 
       
   189 
       
   190 				switch ( dstate.SubscriptionState() )
       
   191 					{
       
   192 
       
   193 					case 0:
       
   194 						sdstate.Copy ( Kdna );
       
   195 						break;
       
   196 
       
   197 					case 1:
       
   198 						sdstate.Copy ( Kdava );
       
   199 						break;
       
   200 
       
   201 					default:
       
   202 						sdstate.Copy ( KdDef );
       
   203 						break;
       
   204 					}
       
   205 
       
   206 				RFileLogger::WriteFormat ( KDir, KFile, EFileLoggingModeAppend, _L ( "*************BEGIN******************" ) );
       
   207 
       
   208 				RFileLogger::WriteFormat ( KDir, KFile, EFileLoggingModeAppend, _L ( "Recvd PresentityGroupListEvent New:%d, Updt:%d, Disappeared:%d, Current:%d, SubscrState:%d, DataState:%d" ), groupListEvent->NewGroupsCount(), groupListEvent->UpdatedGroupsCount(), groupListEvent->DisappearedGroupsCount(), groupListEvent->CurrentGroupsCount(), dstate.SubscriptionState(), dstate.DataState() );//KMsg);
       
   209 				RFileLogger::Write ( KDir, KFile, EFileLoggingModeAppend, sdstate );
       
   210 				RFileLogger::Write ( KDir, KFile, EFileLoggingModeAppend, ssstate );
       
   211 				break;
       
   212 				}
       
   213 
       
   214 
       
   215 		case MPresentityGroupContentEvent::KInterfaceId:
       
   216 				{
       
   217 				const MPresentityGroupContentEvent* groupContentEvent =
       
   218 				    TXIMPGetInterface< const MPresentityGroupContentEvent >::From ( aEvent,
       
   219 				            MXIMPBase::EPanicIfUnknown );
       
   220 				TBuf<100> sdstate;
       
   221 				TBuf<100> ssstate;
       
   222 				_LIT ( Kna, "   Susbcription state is unavailable" );
       
   223 				_LIT ( Kava, "   Susbcription state is available" );
       
   224 				_LIT ( KDef, "   Susbcription state is ERROR" );
       
   225 
       
   226 				const MXIMPDataSubscriptionState&  dstate = groupContentEvent->DataSubscriptionState();
       
   227 
       
   228 				switch ( dstate.SubscriptionState() )
       
   229 					{
       
   230 
       
   231 					case 0:
       
   232 						ssstate.Copy ( Kna );
       
   233 						break;
       
   234 
       
   235 					case 1:
       
   236 						ssstate.Copy ( Kava );
       
   237 						break;
       
   238 
       
   239 					default:
       
   240 						ssstate.Copy ( KDef );
       
   241 						break;
       
   242 					}
       
   243 
       
   244 				_LIT ( Kdna, "   Data state is unavailable" );
       
   245 
       
   246 				_LIT ( Kdava, "   Data state is available" );
       
   247 				_LIT ( KdDef, "   Data state is ERROR" );
       
   248 
       
   249 
       
   250 				switch ( dstate.SubscriptionState() )
       
   251 					{
       
   252 
       
   253 					case 0:
       
   254 						sdstate.Copy ( Kdna );
       
   255 						break;
       
   256 
       
   257 					case 1:
       
   258 						sdstate.Copy ( Kdava );
       
   259 						break;
       
   260 
       
   261 					default:
       
   262 						sdstate.Copy ( KdDef );
       
   263 						break;
       
   264 					}
       
   265 
       
   266 
       
   267 				RFileLogger::WriteFormat ( KDir, KFile, EFileLoggingModeAppend, _L ( "*************BEGIN******************" ) );
       
   268 
       
   269 				RFileLogger::WriteFormat ( KDir, KFile, EFileLoggingModeAppend, _L ( "Recvd PresentityGroupContentEvent New:%d, Updt:%d, Disappeared:%d, Current:%d, SubscrState:%d, DataState:%d" ), groupContentEvent->NewMembersCount(), groupContentEvent->UpdatedMembersCount(), groupContentEvent->DisappearedMembersCount(), groupContentEvent->CurrentMembersCount(), dstate.SubscriptionState(), dstate.DataState() );
       
   270 				RFileLogger::Write ( KDir, KFile, EFileLoggingModeAppend, sdstate );
       
   271 				RFileLogger::Write ( KDir, KFile, EFileLoggingModeAppend, ssstate );
       
   272 				RFileLogger::Write ( KDir, KFile, EFileLoggingModeAppend, groupContentEvent->GroupId().Identity() );
       
   273 				// print the list contents
       
   274 
       
   275 				for ( TInt i = 0; i < groupContentEvent->CurrentMembersCount(); i++ )
       
   276 					{
       
   277 					const MPresentityGroupMemberInfo& gi = groupContentEvent->CurrentMember ( i );
       
   278 
       
   279 					RFileLogger::WriteFormat ( KDir, KFile, EFileLoggingModeAppend, _L ( "Id and displayname for cur group member %d X" ), i );
       
   280 					RFileLogger::Write ( KDir, KFile, EFileLoggingModeAppend, gi.GroupMemberId().Identity() );
       
   281 					RFileLogger::Write ( KDir, KFile, EFileLoggingModeAppend, gi.GroupMemberDisplayName() );
       
   282 //     EUNIT_ASSERT_EQUALS_DESC( gi.GroupMemberId().Identity(), iContactid[i], "contact id's does'nt match");
       
   283 //     EUNIT_ASSERT_EQUALS_DESC( gi.GroupMemberDisplayName(), iNickname[i], "contact nickname  does'nt match");
       
   284 
       
   285 					}
       
   286 
       
   287 				// print the list contents
       
   288 				for ( TInt i = 0; i < groupContentEvent->NewMembersCount(); i++ )
       
   289 					{
       
   290 					const MPresentityGroupMemberInfo& gi = groupContentEvent->NewMember ( i );
       
   291 
       
   292 
       
   293 					RFileLogger::WriteFormat ( KDir, KFile, EFileLoggingModeAppend, _L ( "Id and displayname for new group member %d X" ), i );
       
   294 					RFileLogger::Write ( KDir, KFile, EFileLoggingModeAppend, gi.GroupMemberId().Identity() );
       
   295 					RFileLogger::Write ( KDir, KFile, EFileLoggingModeAppend, gi.GroupMemberDisplayName() );
       
   296 //     EUNIT_ASSERT_EQUALS_DESC( gi.GroupMemberId().Identity(), iContactid[i], "contact id's does'nt match");
       
   297 //     EUNIT_ASSERT_EQUALS_DESC( gi.GroupMemberDisplayName(), iNickname[i], "contact nickname  does'nt match");
       
   298 					}
       
   299 
       
   300 
       
   301 				RFileLogger::WriteFormat ( KDir, KFile, EFileLoggingModeAppend, _L ( "*************END*******************" ) );
       
   302 
       
   303 				break;
       
   304 				}
       
   305 
       
   306 		case MPresenceGrantRequestListEvent::KInterfaceId:
       
   307 				{
       
   308 				const MPresenceGrantRequestListEvent* grantreqEvent =
       
   309 				    TXIMPGetInterface< const MPresenceGrantRequestListEvent >::From ( aEvent,
       
   310 				            MXIMPBase::EPanicIfUnknown );
       
   311 				TBuf<100> sdstate;
       
   312 				TBuf<100> ssstate;
       
   313 				_LIT ( Kna, "   Susbcription state is unavailable" );
       
   314 				_LIT ( Kava, "   Susbcription state is available" );
       
   315 				_LIT ( KDef, "   Susbcription state is ERROR" );
       
   316 
       
   317 				const  MXIMPDataSubscriptionState&  dstate = grantreqEvent->DataSubscriptionState();
       
   318 
       
   319 				switch ( dstate.SubscriptionState() )
       
   320 					{
       
   321 
       
   322 					case 0:
       
   323 						ssstate.Copy ( Kna );
       
   324 						break;
       
   325 
       
   326 					case 1:
       
   327 						ssstate.Copy ( Kava );
       
   328 						break;
       
   329 
       
   330 					default:
       
   331 						ssstate.Copy ( KDef );
       
   332 						break;
       
   333 					}
       
   334 
       
   335 				_LIT ( Kdna, "   Data state is unavailable" );
       
   336 
       
   337 				_LIT ( Kdava, "   Data state is available" );
       
   338 				_LIT ( KdDef, "   Data state is ERROR" );
       
   339 
       
   340 
       
   341 				switch ( dstate.SubscriptionState() )
       
   342 					{
       
   343 
       
   344 					case 0:
       
   345 						sdstate.Copy ( Kdna );
       
   346 						break;
       
   347 
       
   348 					case 1:
       
   349 						sdstate.Copy ( Kdava );
       
   350 						break;
       
   351 
       
   352 					default:
       
   353 						sdstate.Copy ( KdDef );
       
   354 						break;
       
   355 					}
       
   356 
       
   357 				RFileLogger::WriteFormat ( KDir, KFile, EFileLoggingModeAppend, _L ( "*************BEGIN******************" ) );
       
   358 
       
   359 				RFileLogger::WriteFormat ( KDir, KFile, EFileLoggingModeAppend, _L ( "Recvd Presentity Grant event" ) );
       
   360 				RFileLogger::Write ( KDir, KFile, EFileLoggingModeAppend, sdstate );
       
   361 				RFileLogger::Write ( KDir, KFile, EFileLoggingModeAppend, ssstate );
       
   362 
       
   363 				TInt index = grantreqEvent->NewRequestsCount();
       
   364 
       
   365 				for ( TInt i = 0; i < index; i++ )
       
   366 					{
       
   367 					const MPresenceGrantRequestInfo& grantinfo = grantreqEvent->NewRequest ( i );
       
   368 
       
   369 					RFileLogger::Write ( KDir, KFile, EFileLoggingModeAppend, grantinfo.RequestorId().Identity() );
       
   370 					const TDesC16 dispname = grantinfo.RequestorDisplayName();
       
   371 					RFileLogger::Write ( KDir, KFile, EFileLoggingModeAppend, dispname );
       
   372 					}
       
   373 
       
   374 				index = grantreqEvent->CurrentRequestsCount();
       
   375 
       
   376 				for ( TInt i = 0; i < index; i++ )
       
   377 					{
       
   378 					const MPresenceGrantRequestInfo& grantinfo = grantreqEvent->CurrentRequest ( i );
       
   379 
       
   380 					RFileLogger::Write ( KDir, KFile, EFileLoggingModeAppend, grantinfo.RequestorId().Identity() );
       
   381 					const TDesC16 dispname = grantinfo.RequestorDisplayName();
       
   382 					RFileLogger::Write ( KDir, KFile, EFileLoggingModeAppend, dispname );
       
   383 					}
       
   384 
       
   385 				break;
       
   386 				}
       
   387 
       
   388 		case MPresenceBlockListEvent::KInterfaceId:
       
   389 				{
       
   390 				const MPresenceBlockListEvent* blockListEvent =
       
   391 				    TXIMPGetInterface< const MPresenceBlockListEvent >::From ( aEvent,
       
   392 				            MXIMPBase::EPanicIfUnknown );
       
   393 				TBuf<100> sdstate;
       
   394 				TBuf<100> ssstate;
       
   395 				_LIT ( Kna, "   Susbcription state is unavailable" );
       
   396 				_LIT ( Kava, "   Susbcription state is available" );
       
   397 				_LIT ( KDef, "   Susbcription state is ERROR" );
       
   398 
       
   399 				const  MXIMPDataSubscriptionState&  dstate = blockListEvent->DataSubscriptionState();
       
   400 
       
   401 				switch ( dstate.SubscriptionState() )
       
   402 					{
       
   403 
       
   404 					case 0:
       
   405 						ssstate.Copy ( Kna );
       
   406 						break;
       
   407 
       
   408 					case 1:
       
   409 						ssstate.Copy ( Kava );
       
   410 						break;
       
   411 
       
   412 					default:
       
   413 						ssstate.Copy ( KDef );
       
   414 						break;
       
   415 					}
       
   416 
       
   417 				_LIT ( Kdna, "   Data state is unavailable" );
       
   418 
       
   419 				_LIT ( Kdava, "   Data state is available" );
       
   420 				_LIT ( KdDef, "   Data state is ERROR" );
       
   421 
       
   422 
       
   423 				switch ( dstate.SubscriptionState() )
       
   424 					{
       
   425 
       
   426 					case 0:
       
   427 						sdstate.Copy ( Kdna );
       
   428 						break;
       
   429 
       
   430 					case 1:
       
   431 						sdstate.Copy ( Kdava );
       
   432 						break;
       
   433 
       
   434 					default:
       
   435 						sdstate.Copy ( KdDef );
       
   436 						break;
       
   437 					}
       
   438 
       
   439 				RFileLogger::WriteFormat ( KDir, KFile, EFileLoggingModeAppend, _L ( "*************BEGIN******************" ) );
       
   440 
       
   441 				RFileLogger::WriteFormat ( KDir, KFile, EFileLoggingModeAppend, _L ( "Recvd Presentity Grant event" ) );
       
   442 				RFileLogger::Write ( KDir, KFile, EFileLoggingModeAppend, sdstate );
       
   443 				RFileLogger::Write ( KDir, KFile, EFileLoggingModeAppend, ssstate );
       
   444 
       
   445 				TInt index = blockListEvent->NewBlocksCount();
       
   446 
       
   447 				for ( TInt i = 0; i < index; i++ )
       
   448 					{
       
   449 					const MPresenceBlockInfo& blockinfo = blockListEvent->NewBlock ( i );
       
   450 
       
   451 					RFileLogger::Write ( KDir, KFile, EFileLoggingModeAppend, blockinfo.BlockedEntityId().Identity() );
       
   452 					const TDesC16& dispname = blockinfo.BlockedEntityDisplayName();
       
   453 					RFileLogger::Write ( KDir, KFile, EFileLoggingModeAppend, dispname );
       
   454 					}
       
   455 
       
   456 				index = blockListEvent->CurrentBlocksCount();
       
   457 
       
   458 				for ( TInt i = 0; i < index; i++ )
       
   459 					{
       
   460 					const MPresenceBlockInfo& blockinfo = blockListEvent->CurrentBlock ( i );
       
   461 
       
   462 					RFileLogger::Write ( KDir, KFile, EFileLoggingModeAppend, blockinfo.BlockedEntityId().Identity() );
       
   463 					const TDesC16& dispname = blockinfo.BlockedEntityDisplayName();
       
   464 					RFileLogger::Write ( KDir, KFile, EFileLoggingModeAppend, dispname );
       
   465 					}
       
   466 
       
   467 				break;
       
   468 				}
       
   469 
       
   470 		case MPresentityPresenceEvent::KInterfaceId:
       
   471 				{
       
   472 				const MPresentityPresenceEvent* PresentityPresenceEvent =
       
   473 				    TXIMPGetInterface< const MPresentityPresenceEvent >::From ( aEvent,
       
   474 				            MXIMPBase::EPanicIfUnknown );
       
   475 				TBuf<100> sdstate;
       
   476 				TBuf<100> ssstate;
       
   477 				_LIT ( Kna, "   Susbcription state is unavailable" );
       
   478 				_LIT ( Kava, "   Susbcription state is available" );
       
   479 				_LIT ( KDef, "   Susbcription state is ERROR" );
       
   480 
       
   481 				const  MXIMPDataSubscriptionState&  dstate = PresentityPresenceEvent->DataSubscriptionState();
       
   482 
       
   483 				switch ( dstate.SubscriptionState() )
       
   484 					{
       
   485 
       
   486 					case 0:
       
   487 						ssstate.Copy ( Kna );
       
   488 						break;
       
   489 
       
   490 					case 1:
       
   491 						ssstate.Copy ( Kava );
       
   492 						break;
       
   493 
       
   494 					default:
       
   495 						ssstate.Copy ( KDef );
       
   496 						break;
       
   497 					}
       
   498 
       
   499 				_LIT ( Kdna, "   Data state is unavailable" );
       
   500 
       
   501 				_LIT ( Kdava, "   Data state is available" );
       
   502 				_LIT ( KdDef, "   Data state is ERROR" );
       
   503 
       
   504 
       
   505 				switch ( dstate.SubscriptionState() )
       
   506 					{
       
   507 
       
   508 					case 0:
       
   509 						sdstate.Copy ( Kdna );
       
   510 						break;
       
   511 
       
   512 					case 1:
       
   513 						sdstate.Copy ( Kdava );
       
   514 						break;
       
   515 
       
   516 					default:
       
   517 						sdstate.Copy ( KdDef );
       
   518 						break;
       
   519 					}
       
   520 
       
   521 				RFileLogger::WriteFormat ( KDir, KFile, EFileLoggingModeAppend, _L ( "*************BEGIN******************" ) );
       
   522 
       
   523 				RFileLogger::WriteFormat ( KDir, KFile, EFileLoggingModeAppend, _L ( "Recvd Presentity PresenceEvent" ) );
       
   524 				RFileLogger::Write ( KDir, KFile, EFileLoggingModeAppend, sdstate );
       
   525 				RFileLogger::Write ( KDir, KFile, EFileLoggingModeAppend, ssstate );
       
   526 
       
   527 				RFileLogger::Write ( KDir, KFile, EFileLoggingModeAppend, PresentityPresenceEvent->PresentityId().Identity() );
       
   528 
       
   529 				const MPresenceInfo& pi = PresentityPresenceEvent->SubscribedPresence();
       
   530 				const MPersonPresenceInfo* ppi =  pi.PersonPresence();
       
   531 				const MPresenceInfoFieldCollection& presinf = ppi->Fields();
       
   532 				TInt index = presinf.FieldCount();
       
   533 				// const MXIMPBase base;
       
   534 
       
   535 				for ( TInt i = 0; i < index; i++ )
       
   536 					{
       
   537 					const MPresenceInfoField& infofield = presinf.FieldAt ( i );
       
   538 					RFileLogger::Write ( KDir, KFile, EFileLoggingModeAppend, infofield.FieldType() );
       
   539 					const MPresenceInfoFieldValueText* PresentityPresencestatus =
       
   540 					    TXIMPGetInterface< const MPresenceInfoFieldValueText >::From ( infofield.FieldValue(),
       
   541 					            MXIMPBase::EPanicIfUnknown );
       
   542 					RFileLogger::Write ( KDir, KFile, EFileLoggingModeAppend, PresentityPresencestatus->TextValue() );
       
   543 					//          EUNIT_ASSERT_EQUALS_DESC(PresentityPresencestatus->TextValue(), iPersonpresattributes[i], "statustext does'nt match");
       
   544 					}
       
   545 
       
   546 				index = pi.ServicePresenceCount();
       
   547 
       
   548 				for ( TInt i = 0; i < index; i++ )
       
   549 					{
       
   550 					const MServicePresenceInfo& servicePresinfo = pi.ServicePresenceAt ( i );
       
   551 					RFileLogger::Write ( KDir, KFile, EFileLoggingModeAppend, servicePresinfo.ServiceType() );
       
   552 //            EUNIT_ASSERT_EQUALS_DESC(servicePresinfo.ServiceType(), servctype, "service does'nt match");
       
   553 					const MPresenceInfoFieldCollection& fields = servicePresinfo.Fields();
       
   554 
       
   555 					for ( TInt j = 0; j < fields.FieldCount(); j++ )
       
   556 						{
       
   557 						const MPresenceInfoField& infofield = fields.FieldAt ( j );
       
   558 						RFileLogger::Write ( KDir, KFile, EFileLoggingModeAppend, infofield.FieldType() );
       
   559 						const MPresenceInfoFieldValueText* Presenceavailability =
       
   560 						    TXIMPGetInterface< const MPresenceInfoFieldValueText >::From ( infofield.FieldValue(),
       
   561 						            MXIMPBase::EPanicIfUnknown );
       
   562 
       
   563 //               EUNIT_ASSERT_EQUALS_DESC(Presenceavailability->TextValue(), _L("OPEN") , "Comm capability  does'nt match");
       
   564 						RFileLogger::WriteFormat ( KDir, KFile, EFileLoggingModeAppend, Presenceavailability->TextValue() );
       
   565 						}
       
   566 					}
       
   567 
       
   568 				index = pi.DevicePresenceCount();
       
   569 
       
   570 				for ( TInt i = 0; i < index; i++ )
       
   571 					{
       
   572 					const MDevicePresenceInfo& DevicePresinfo = pi.DevicePresenceAt ( i );
       
   573 					const TPtrC8 devicename = DevicePresinfo.DeviceName();
       
   574 					RFileLogger::Write ( KDir, KFile, EFileLoggingModeAppend, DevicePresinfo.DeviceName() );
       
   575 					const MPresenceInfoFieldCollection& fields = DevicePresinfo.Fields();
       
   576 					TInt fieldcount = fields.FieldCount();
       
   577 
       
   578 					for ( TInt j = 0; j < fieldcount; j++ )
       
   579 						{
       
   580 						const MPresenceInfoField& infofield = fields.FieldAt ( j );
       
   581 						const TDesC8* fieldtype = & ( infofield.FieldType() );
       
   582 						RFileLogger::Write ( KDir, KFile, EFileLoggingModeAppend, *fieldtype );
       
   583 						const MXIMPBase& base = infofield.FieldValue();
       
   584 						const MPresenceInfoFieldValueText* Presentityvalue =
       
   585 						    TXIMPGetInterface< const MPresenceInfoFieldValueText >::From ( infofield.FieldValue(),
       
   586 						            MXIMPBase::EPanicIfUnknown );
       
   587 
       
   588 						RFileLogger::Write ( KDir, KFile, EFileLoggingModeAppend, Presentityvalue->TextValue() );
       
   589 //               EUNIT_ASSERT_EQUALS_DESC(Presentityvalue->TextValue(), clienttype, "Clienttype does'nt match");
       
   590 						}
       
   591 
       
   592 
       
   593 					}
       
   594 
       
   595 				_LIT ( KMsg, " presentity presence event  is getting " );         // here we hv to write message or text wch we want to write in log file
       
   596 
       
   597 				RFileLogger::WriteFormat ( KDir, KFile, EFileLoggingModeAppend, KMsg );
       
   598 				break;
       
   599 				}
       
   600 
       
   601 		case MPresenceWatcherListEvent::KInterfaceId:
       
   602 				{
       
   603 				const MPresenceWatcherListEvent* watcherListEvent =
       
   604 				    TXIMPGetInterface< const MPresenceWatcherListEvent >::From ( aEvent,
       
   605 				            MXIMPBase::EPanicIfUnknown );
       
   606 				TBuf<100> sdstate;
       
   607 				TBuf<100> ssstate;
       
   608 			
       
   609 				const  MXIMPDataSubscriptionState&  dstate = watcherListEvent->DataSubscriptionState();
       
   610 
       
   611 				RFileLogger::WriteFormat ( KDir, KFile, EFileLoggingModeAppend, _L ( "Recvd watcher event" ) );
       
   612 				// print the list contents
       
   613 
       
   614 				for ( TInt i = 0; i < watcherListEvent->CurrentWatchersCount(); i++ )
       
   615 					{
       
   616 					const MPresenceWatcherInfo& gi = watcherListEvent->CurrentWatcher ( i );
       
   617 
       
   618 					gid[i].Copy ( gi.WatcherId().Identity() );
       
   619 					RFileLogger::WriteFormat ( KDir, KFile, EFileLoggingModeAppend, _L ( "Id and displayname for cur watcher group %d X" ), i );
       
   620 					RFileLogger::Write ( KDir, KFile, EFileLoggingModeAppend, gi.WatcherId().Identity() );
       
   621 //             EUNIT_ASSERT_EQUALS_DESC(gi.WatcherId().Identity(), KContact1, "watcher does'nt match");
       
   622 					RFileLogger::Write ( KDir, KFile, EFileLoggingModeAppend, gi.WatcherDisplayName() );
       
   623 					//  EUNIT_ASSERT_EQUALS_DESC(gi.WatcherDisplayName(), KNickname1, "Devicename does'nt match");
       
   624 					}
       
   625 
       
   626 				gidcount = watcherListEvent->CurrentWatchersCount();
       
   627 
       
   628 				// print the list contents
       
   629 
       
   630 				for ( TInt i = 0; i < watcherListEvent->NewWatchersCount(); i++ )
       
   631 					{
       
   632 					const MPresenceWatcherInfo& gi = watcherListEvent->NewWatcher ( i );
       
   633 					gid[i].Copy ( gi.WatcherId().Identity() );
       
   634 					RFileLogger::WriteFormat ( KDir, KFile, EFileLoggingModeAppend, _L ( "Id and displayname for new group %d X" ), i );
       
   635 					RFileLogger::Write ( KDir, KFile, EFileLoggingModeAppend, gi.WatcherId().Identity() );
       
   636 //             EUNIT_ASSERT_EQUALS_DESC(gi.WatcherId().Identity(), KContact1, "watcher does'nt match");
       
   637 					RFileLogger::Write ( KDir, KFile, EFileLoggingModeAppend, gi.WatcherDisplayName() );
       
   638 					// EUNIT_ASSERT_EQUALS_DESC(gi.WatcherDisplayName(), KNickname1, "Devicename does'nt match");
       
   639 					}
       
   640 
       
   641 				RFileLogger::WriteFormat ( KDir, KFile, EFileLoggingModeAppend, _L ( "*************END*******************" ) );
       
   642 
       
   643 				gidcount = watcherListEvent->NewWatchersCount();
       
   644 
       
   645 				break;
       
   646 				}
       
   647 
       
   648 		case MImConversationEvent::KInterfaceId:
       
   649 				{
       
   650 				RFileLogger::WriteFormat ( KDir, KFile, EFileLoggingModeAppend, _L ( "Recvd conversation event" ) );
       
   651 
       
   652 				const MImConversationEvent* convEvent =
       
   653 				    TXIMPGetInterface< const MImConversationEvent >::From
       
   654 				    ( aEvent, MXIMPBase::EPanicIfUnknown );
       
   655 				TInt count = convEvent->NewTextMessageCount();
       
   656 				const MImConversationInfo& convInfo = convEvent->NewTextMessage ( 0 );
       
   657 				const MXIMPIdentity& identity = convInfo.MessageId();
       
   658 				const TDesC16& msg = convInfo.TextMessage();
       
   659 				RFileLogger::WriteFormat ( KDir, KFile, EFileLoggingModeAppend, _L ( "message is" ) );
       
   660 				RFileLogger::Write ( KDir, KFile, EFileLoggingModeAppend, convInfo.TextMessage() );
       
   661 				RFileLogger::Write ( KDir, KFile, EFileLoggingModeAppend, convInfo.MessageId().Identity() );
       
   662 
       
   663 				/*  const MDesCArray& array= convInfo.RecipientL();
       
   664 				  TPtrC sender=array.MdcaPoint(0);*/
       
   665 				break;
       
   666 				}
       
   667 		case MSearchEvent::KInterfaceId:
       
   668 				{
       
   669 				RFileLogger::WriteFormat ( KDir, KFile, EFileLoggingModeAppend, _L ( "search event"));
       
   670 				const MSearchEvent* srchEvent = 
       
   671 				TXIMPGetInterface< const MSearchEvent >::From
       
   672 										(aEvent, MXIMPBase::EPanicIfUnknown);	
       
   673 				TInt count=	srchEvent->SearchResultCount();
       
   674 				RFileLogger::WriteFormat ( KDir, KFile, EFileLoggingModeAppend,_L("result count  :%d "),count);
       
   675 				RFileLogger::Write ( KDir, KFile, EFileLoggingModeAppend, srchEvent->SearchId().Identity() );
       
   676 				
       
   677 				TInt64 radn;
       
   678 				TInt random = Math::Rand( radn );
       
   679 				
       
   680 				for(TInt i=0;i<count;++i)
       
   681 					{
       
   682 					const MSearchInfo& info=srchEvent->SearchResult(i);
       
   683 					RFileLogger::WriteFormat ( KDir, KFile, EFileLoggingModeAppend,_L("Result No:%d "),i);
       
   684 					RFileLogger::Write ( KDir, KFile, EFileLoggingModeAppend, info.GetFieldInfo(EFirstName) );
       
   685 					RFileLogger::Write ( KDir, KFile, EFileLoggingModeAppend, info.GetFieldInfo(ELastName) );
       
   686 					RFileLogger::Write ( KDir, KFile, EFileLoggingModeAppend, info.GetFieldInfo(EEmailAddress) );
       
   687 					//take a random contact
       
   688 					if ( i == random % count ) 
       
   689 						{
       
   690 						
       
   691 						RFs fs;
       
   692 						RFile file;
       
   693 						TBuf8<100> buf;
       
   694 						User::LeaveIfError( fs.Connect() );
       
   695 						User::LeaveIfError( file.Replace( fs, 
       
   696 									KAddContactFileName, EFileWrite ) );
       
   697 									
       
   698 						CnvUtfConverter::ConvertFromUnicodeToUtf8( buf, 
       
   699 											info.GetFieldInfo(EEmailAddress) ); 
       
   700 						file.Write( buf );
       
   701 						file.Close();
       
   702 						fs.Close();
       
   703 							
       
   704 						}
       
   705 					}
       
   706 				RFileLogger::WriteFormat ( KDir, KFile, EFileLoggingModeAppend, _L ( "search event processed"));	
       
   707 				break;	
       
   708 				}
       
   709 				
       
   710 		case MSearchKeysEvent::KInterfaceId:
       
   711             {
       
   712             const MSearchKeysEvent* srchEvent = 
       
   713                         TXIMPGetInterface< const MSearchKeysEvent >::From
       
   714                                                 (aEvent, MXIMPBase::EPanicIfUnknown);
       
   715             TInt count= srchEvent->InfoCount();
       
   716             
       
   717             for(TInt a=0; a < count; a++)
       
   718                 {
       
   719                 const MSearchKeyInfo& keyInfo=srchEvent->SearchKeyInfo( a);
       
   720                 switch(keyInfo.Type())
       
   721                     {
       
   722                     case EKey:
       
   723                         {
       
   724                         TInt key= keyInfo.Key();
       
   725                         }
       
   726                         break;
       
   727                        
       
   728                     case ELabel:
       
   729                         {
       
   730                         TPtrC label = keyInfo.Label();
       
   731                         break;
       
   732                         }
       
   733                 	}
       
   734                  }
       
   735             
       
   736             break;
       
   737             }
       
   738 		
       
   739 		default:
       
   740 				{
       
   741 				break;
       
   742 				}
       
   743 		}
       
   744 	}
       
   745 
       
   746 
       
   747 // end of file
       
   748 
       
   749 
       
   750 
       
   751 
       
   752 
       
   753