void CLocaSenderImpl::ConstructL()
{
	CALLSTACKITEM_N(_CL("CLocaSenderImpl"), _CL("ConstructL"));

	Mlogger::ConstructL(AppContextAccess());

	iDb=CDb::NewL(AppContext(), _L("LOCALOGIC"), EFileWrite);

	iLocaLogic=CLocaLogic::NewL(AppContext(), iDb->Db());
	iBlueJack=CBlueJack::NewL(AppContext(), *this);
	iTimeOut=CTimeOut::NewL(*this);

	SubscribeL(KBluetoothTuple);
	SubscribeL(KRemoteBluetoothTuple);

	Settings().GetSettingL(SETTING_LOCA_BLUEJACK_MESSAGE_TIMEOUT, iMessageTimeOut);
	Settings().NotifyOnChange(SETTING_LOCA_BLUEJACK_MESSAGE_TIMEOUT, this);
	Settings().GetSettingL(SETTING_PUBLISH_AUTHOR, iNodeName);
	Settings().NotifyOnChange(SETTING_PUBLISH_AUTHOR, this);

	iRandomSeed=GetTime().Int64();
	iEnabled=EFalse;
	Settings().GetSettingL(SETTING_ENABLE_LOCA_BLUEJACK, iEnabled);
	Settings().NotifyOnChange(SETTING_ENABLE_LOCA_BLUEJACK, this);

#if defined(__WINS__) && defined(CONTEXTLOCA)
	//LoadScriptL(iLocaLogic, _L("_general.py"));
	//LoadScriptL(iLocaLogic, _L("024_hangout.py"));
#endif
}
void CSmsStatusReplierImpl::ConstructL()
{
	Mlogger::ConstructL(AppContextAccess());
	iSms->AddHandler(this);
	iBuf=HBufC::NewL(512);
	iNames=new (ELeave) CDesC16ArraySeg(128);
	iValues=new (ELeave) CDesC16ArraySeg(128);
	SubscribeL(KBatteryTuple);
	SubscribeL(KStatusTuple);

	TBuf<20>	imei;
#ifndef __WINS__
	GetImeiL(imei);
#else
	// Return a fake IMEI when working on emulator
	_LIT(KEmulatorImsi, "244050000000000");
	imei.Copy(KEmulatorImsi);
#endif
	SetStatus(_L("imei"), imei);
}
// Single client, subscribed to the group, then subscribe list
void T_PresenceGroupListManagement::T_HandlePresentityGroupList_Subscribed_L()
    {
    EUNIT_PRINT( _L("Handle presentity group list, subscribed to the group.") );

    // log in
    BindL();
    SubscribeGroupL( KPresentUri1 );
    SubscribeL();

    // ------------------------------------------------------
    // some startup stuff
    CXIMPTestContextWrapper* wrapper = iWrapperMgr->GetWrapperL( 0 );
    MXIMPContext* context = wrapper->GetContext();

    CXIMPTestListener* listener2 = CXIMPTestListener::NewL( context );
    CleanupStack::PushL( listener2 );
    // ------------------------------------------------------

    // Tell the protocol it should act normally
    wrapper->GetMessenger()->SetNoError();

    // ------------------------------------------------------
    // 1. Create faked server message about group list
    SendSrvMsgL( KPresentUri1,
            KPresentDispName1,
            CXIMPTestFileSrvMsg::ETestSrvMsgPresentityGroupCreate );

    // ------------------------------------------------------
    // expect empty MPresentityGroupList event.

    CPresentityGroupListEventImp* event = XIMPTestEventFactory::CreateGroupListEventLCX(
            KPresentUri1, KPresentDispName1,
            XIMPTestEventFactory::ETestPGLCreated,
            KPresentUri1, KPresentDispName1,
            MXIMPDataSubscriptionState::ESubscriptionActive,
            MXIMPDataSubscriptionState::EDataAvailable
            );

    listener2->ExpectL( event );
    CleanupStack::Pop( event ); // 4 more items in cleanupstack

    EUNIT_ASSERT_DESC( KErrNone == listener2->WaitAndAssertL(), "HandlePresentityGroupListL failed" );
    CleanupStack::PopAndDestroy( 4 ); // lists
    // ------------------------------------------------------

    CleanupStack::PopAndDestroy( listener2 );

    // clean it up
    UnsubscribeL();
    UnsubscribeGroupL( KPresentUri1 );
    UnbindL();
    }
void CLocaRemoteEvents::ConstructL()
{
	Mlogger::ConstructL(AppContextAccess());
	SubscribeL(KRemoteLocaLogicTuple);
}
// ---------------------------------------------------------------------------
// ---------------------------------------------------------------------------
void T_PresenceWatcherListManagement::T_HandlePresenceWatcherList_L()
    {
    EUNIT_PRINT( _L("Handle presence watcher list.") );

    BindL();
    SubscribeL();

    // ------------------------------------------------------
    // some startup stuff
    CXIMPTestContextWrapper* wrapper = iWrapperMgr->GetWrapperL( 0 );
    MXIMPContext* context = wrapper->GetContext();

    CXIMPTestListener* listener2 = CXIMPTestListener::NewL( context );
    CleanupStack::PushL( listener2 );
    // ------------------------------------------------------

    // Tell the protocol it should act normally
    wrapper->GetMessenger()->SetNoError();

    // ------------------------------------------------------
    // 1. Create faked server message about watcher list (empty)
    SendSrvMsgL( CXIMPTestFileSrvMsg::ETestSrvMsgPresenceWatcherList );

    // ------------------------------------------------------
    // expect empty MPresencewatcherList event.

    RPrWatLstInfoImpArray* currentList(NULL);
    CPresenceWatcherListEventImp* event = CreateWatcherListEventLCX(
            KNullDesC, KNullDesC,
        MXIMPDataSubscriptionState::ESubscriptionActive,
        MXIMPDataSubscriptionState::EDataAvailable,
        ETestPWlCurrent, currentList);

    listener2->ExpectL( event );
    CleanupStack::Pop( event ); // 3 more items in cleanupstack

    //Waqas: Fixed task Ticket#22
    EUNIT_ASSERT_DESC( KErrNone == listener2->WaitAndAssertL(), "HandlePresenceWatcherListL failed" );
    CleanupStack::PopAndDestroy( 3 ); // lists
    // ------------------------------------------------------


    // ------------------------------------------------------
    // 2. Create faked server message about watcher list (new)
    listener2->Reset();

    _LIT16( KWatcherUri1,      "http://carpe.diem.com" );
    _LIT16( KWatcherDispName1, "DispnameA, LoremI" );

    SendSrvMsgL( KWatcherUri1,
                 KWatcherDispName1,
                 CXIMPTestFileSrvMsg::ETestSrvMsgPresenceWatcherList );

    // ------------------------------------------------------
    // MPresencewatcherList event.

    currentList = NULL; // previous one was destroyed
    //Now create the actual event
    event = CreateWatcherListEventLCX(  // previous event was destroyed
            KWatcherUri1, KWatcherDispName1,
        MXIMPDataSubscriptionState::ESubscriptionActive,
        MXIMPDataSubscriptionState::EDataAvailable,
        ETestPWlNew, currentList);
    

    listener2->ExpectL( event );
    CleanupStack::Pop( event ); // 3 more items in cleanupstack

    EUNIT_ASSERT_DESC( KErrNone == listener2->WaitAndAssertL(), "HandlePresenceWatcherListL failed" );
    CleanupStack::PopAndDestroy( 3 ); // lists


    // ------------------------------------------------------
    // 3. Create faked server message about watcher list (disappeared)
    listener2->Reset();

    SendSrvMsgL( CXIMPTestFileSrvMsg::ETestSrvMsgPresenceWatcherList );
    // ------------------------------------------------------
    // MPresencewatcherList event.

    CXIMPIdentityImp* idForEvent = CXIMPIdentityImp::NewLC( KWatcherUri1 );
    // we need to create current list to give to the event
    currentList = new ( ELeave ) RPrWatLstInfoImpArray; // previous is destroyed
    CleanupDeletePushL( currentList );
            // create the group info
    CPresenceWatcherInfoImp* watcherInfoForEvent = 
                            CPresenceWatcherInfoImp::NewLC( (MPresenceWatcherInfo::TWatcherType)0, *idForEvent, KWatcherDispName1);
    currentList->AppendL( watcherInfoForEvent );
    CleanupStack::Pop( watcherInfoForEvent );
    CleanupStack::Pop( currentList );
    CleanupStack::PopAndDestroy( idForEvent );    


    //Now create the actual event
    event = CreateWatcherListEventLCX(
            KWatcherUri1, KWatcherDispName1,
        MXIMPDataSubscriptionState::ESubscriptionActive,
        MXIMPDataSubscriptionState::EDataAvailable,
        ETestPWlDisappeared, currentList);

    listener2->ExpectL( event );
    CleanupStack::Pop( event ); // 3 more items in cleanupstack

    //Waqas: Fixed task Ticket#22
    EUNIT_ASSERT_DESC( KErrNone == listener2->WaitAndAssertL(), "HandlePresenceWatcherListL failed" );

    CleanupStack::PopAndDestroy( 3 ); // lists


    // clean it up
    UnsubscribeL();
    
    /* TODO later on better time.
    // ------------------------------------------------------
    // 4. Create faked server message about watcher list (no subscribers to list)
    //    Make sure no event is 
    listener2->Reset();
    
    event = CreateWatcherListEventLCX(
            KNullDesC, KNullDesC,
            ETestPWlEmpty );

    //EUNIT_ASSERT_DESC( KErrNone == listener2->WaitAndAssertL(), "HandlePresenceWatcherListL failed" );

    */
    CleanupStack::PopAndDestroy( listener2 );
    
    UnbindL();
    }
void T_PresenceGroupListManagement::T_HandlePresentityGroupUpdate_L()
    {
    EUNIT_PRINT( _L("Handle presentity group displayname update.") );

    // log in and subscribe a group list
    BindL();
    SubscribeL();

    // ------------------------------------------------------
    // some startup stuff

    CXIMPTestContextWrapper* wrapper = iWrapperMgr->GetWrapperL( 0 );
    MXIMPContext* context = wrapper->GetContext();

    CXIMPTestListener* listener2 = CXIMPTestListener::NewL( context );
    CleanupStack::PushL( listener2 );
    // ------------------------------------------------------

    // Tell the protocol it should act normally
    wrapper->GetMessenger()->SetNoError();

    // ------------------------------------------------------
    // 1. Create faked notification about create
    SendSrvMsgL( KPresentUri1, KPresentDispName1,
            CXIMPTestFileSrvMsg::ETestSrvMsgPresentityGroupCreate );

    // ------------------------------------------------------
    // expect MPresentityGroupList event.

    CPresentityGroupListEventImp* event = XIMPTestEventFactory::CreateGroupListEventLCX(
            KPresentUri1, KPresentDispName1,
            XIMPTestEventFactory::ETestPGLCreated,
            KPresentUri1, KPresentDispName1,
            MXIMPDataSubscriptionState::ESubscriptionActive,
            MXIMPDataSubscriptionState::EDataAvailable
            );

    listener2->ExpectL( event );
    CleanupStack::Pop( event ); // 4 more items in cleanupstack

    EUNIT_ASSERT_DESC( KErrNone == listener2->WaitAndAssertL(), "HandlePresentityGroupListL failed (Creation)" );
    CleanupStack::PopAndDestroy( 4 ); // lists

    // ------------------------------------------------------
    // 4. Change displayname of group and send faked notification about
    // update

    SendSrvMsgL( KPresentUri1, KPresentDispName2,
            CXIMPTestFileSrvMsg::ETestSrvMsgPresentityGroupUpdate );

    // ------------------------------------------------------
    // expect MPresentityGroupList event.

    event = XIMPTestEventFactory::CreateGroupListEventLCX(
            KPresentUri1, KPresentDispName2,
            XIMPTestEventFactory::ETestPGLUpdated,
            KPresentUri1, KPresentDispName2,
            MXIMPDataSubscriptionState::ESubscriptionActive,
            MXIMPDataSubscriptionState::EDataAvailable
            );

    listener2->ExpectL( event );
    CleanupStack::Pop( event ); // 4 more items in cleanupstack

    EUNIT_ASSERT_DESC( KErrNone == listener2->WaitAndAssertL(), "HandlePresentityGroupListL failed (Update)" );
    CleanupStack::PopAndDestroy( 4 ); // lists
    // ------------------------------------------------------

    CleanupStack::PopAndDestroy( listener2 );

    // unsubscribe group list and log out
    UnsubscribeL();
    UnbindL();
    }