⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 debugentries.cpp

📁 series60 应用程序开发的源代码 series60 应用程序开发的源代码
💻 CPP
字号:
/**
* 
* @brief Definition of CDebugEntries
*
* Copyright (c) EMCC Software Ltd 2003
* @version 1.0
*/
#if defined(_DEBUG)
// INCLUDES

//  Class include
#include "debugentries.h"

// System includes
#include <barsread.h>                // TResourceReader
#include <eikenv.h>                    // CEikonEnv
#include <logcli.h>                    // CLogClient
#include <logview.h>                // CLogView
#include <callsummary.rsg>            // R_EVENT_LIST
#include <CPbkContactEngine.h>        // CPbkContactEngine 
#include <TPbkContactItemField.h>    // TPbkContactItemField 
#include <CPbkContactItem.h>        // CPbkContactItem
 
/**
* Symbian OS 2 phase constructor.
* Constructs the CAddEntries using the NewLC method, popping
* the constructed object from the CleanupStack before returning it.
* 
* @param aLogClient the interface class to the log engine
* @param aObserverRequestStatus TRequestStatus which will be completed when all
* the entries have been added to the log engine.
* @return The newly constructed CAddEntries
*/
CAddEntries* CAddEntries::NewL(CLogClient& aLogClient, TRequestStatus& aObserverRequestStatus)
{
    CAddEntries* self = CAddEntries::NewLC(aLogClient, aObserverRequestStatus);
    CleanupStack::Pop(self);
    return self;
}

/**
* Symbian OS 2 phase constructor.
* Constructs the CAddEntries using the constructor and ConstructL 
* method, leaving the constructed object on the CleanupStack before returning it.
* 
* @param aLogClient the interface class to the log engine
* @param aObserverRequestStatus TRequestStatus which will be completed when all
* the entries have been added to the log engine.
* @return The newly constructed CAddEntries
*/
CAddEntries* CAddEntries::NewLC(CLogClient& aLogClient, TRequestStatus& aObserverRequestStatus)
{
    CAddEntries* self = new (ELeave) CAddEntries(aLogClient, aObserverRequestStatus);
    CleanupStack::PushL(self);
    self->ConstructL();
    return self;
}

/**
* C++ Constructor
* @param aLogClient the interface class to the log engine
* @param aObserverRequestStatus TRequestStatus which will be completed when all
* the entries have been added to the log engine.
*/
CAddEntries::CAddEntries(CLogClient& aLogClient, TRequestStatus& aObserverRequestStatus)
    :CActive(CActive::EPriorityStandard), iLogClient(aLogClient), iObserverRequestStatus(aObserverRequestStatus)
{
}

/**
* Destructor
*/
CAddEntries::~CAddEntries()
{
    Cancel();
    iEventArray.ResetAndDestroy();
}

/**
* Symbian OS 2nd phase constructor. Reads in events
* from resource file and makes an asynchronous request to add the
* first event to the log engine.
*/ 
void CAddEntries::ConstructL()
{
    // Set the observers request status to pending
    iObserverRequestStatus = KRequestPending;

    // read dummy events from resource file
    ReadLogEventsL();
    iEntryAdded = 0;

    // Issue a request to add the first event to the log
    iLogClient.AddEvent(*(iEventArray[iEntryAdded]), iStatus);
    CActiveScheduler::Add(this);
    SetActive();
}

/**
* Called from CActive::Cancel(), allowing this object 
* to provide specific cleanup activity.
*
*/
void CAddEntries::DoCancel()
{
}

/**
* Called when the an asynchronous request completes, i.e. when an
* event has been successfully added
*/
void CAddEntries::RunL()
{
    if (iStatus != KErrNone)
    {
        // indicate that there has been an error adding the entries
        TRequestStatus* p = &iObserverRequestStatus;
        User::RequestComplete(p, iStatus.Int());
    }

    iEntryAdded++;

    if (iEntryAdded < iNumberOfEntries)
    {    
        // Issue a request to add the next event to the log 
        iLogClient.AddEvent(*(iEventArray[iEntryAdded]), iStatus);
        SetActive();
    }
    else
    {
        // indicate that the entries have all been added.
        TRequestStatus* p = &iObserverRequestStatus;
        User::RequestComplete(p, KErrNone);
    }
}

/**
* Called if RunL leaves
* 
* @param the error that RunL leaves with. 
* @return error code
*/
TInt CAddEntries::RunError(TInt /*aError*/)
{
    return KErrNone;    // Ignore errors.
}

/** 
* Read events to be added to the log from the resource file
*/
void CAddEntries::ReadLogEventsL()
{
    TResourceReader reader;
    // An unnamed buffer is created for use by reader and is placed onto the Cleanup Stack.
    CEikonEnv::Static()->CreateResourceReaderLC(reader, R_EVENT_LIST);
    
    iNumberOfEntries = reader.ReadUint8();
    for (TInt i = 0; i < iNumberOfEntries; i++)
    {
        // logEvent does not need to be added to the cleanup stack
        // since the code called is leave-safe
        CLogEvent* logEvent = CLogEvent::NewL();
        logEvent->SetEventType(KLogCallEventTypeUid);
        logEvent->SetDurationType(KLogDurationValid);
        TInt direction = reader.ReadInt32();

        TBuf<64> directionStr;
        iLogClient.GetString(directionStr, direction);
        logEvent->SetDirection(directionStr);

        TLogDuration duration;
        duration = reader.ReadUint32();
        logEvent->SetDuration(duration);

        TPtrC number = reader.ReadTPtrC();
        logEvent->SetNumber(number);
        TInt contactId = reader.ReadInt32();

        if (contactId != KNullContactId)
        {
            // If we are setting a contact for our dummy entry we
            // should make sure that there is a contact to be associated with.

            // Returns the global Phonebook engine instance
            CPbkContactEngine* pbkContactEngine = CPbkContactEngine::Static();
            // create a new contact
            CPbkContactItem* contactItem = pbkContactEngine->CreateEmptyContactL();  
            CleanupStack::PushL(contactItem);

            // Find the phonenumber field of the contact, and add the telephone number to the contact
            TPbkContactItemField* phoneNumber = contactItem->FindField(EPbkFieldIdPhoneNumberGeneral);
            phoneNumber->TextStorage()->SetTextL(number);

            // Add the new contact to the phonebook.
            contactId = pbkContactEngine->AddNewContactL(*contactItem);
            CleanupStack::PopAndDestroy(contactItem);
        }

        logEvent->SetContact(contactId);
        
        TTime time;
        time.HomeTime();
        logEvent->SetTime(time);

        // Ownership of logEvent is passed to iEventArray.
        iEventArray.Append(logEvent);
    }

    CleanupStack::PopAndDestroy(); // Popping the buffer created for use by reader
}

#endif // (_DEBUG)

// end of file

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -