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

📄 cmmssreceivehandler.cpp

📁 Symbian 手机发送彩信程序 mmssend
💻 CPP
字号:
/*  Copyright (c) 2004, Nokia. All rights reserved */

// INCLUDE FILES
#include <mmsconst.h>
#include <smut.h>
#include <miutset.h>

#include <msvids.h>
#include <mtclreg.h>
#include <mtclbase.h>
#include <txtrich.h>

#include "CMsvHandler.h"
#include "CMmssReceiveHandler.h"
#include "MMsvObserver.h"

// ================= MEMBER FUNCTIONS =======================
//
// ----------------------------------------------------------------------------
// CMmssReceiveHandler::NewL()
// Standard construction sequence.
// ----------------------------------------------------------------------------
//
CMmssReceiveHandler* CMmssReceiveHandler::NewL( MMsvObserver& aObserver )
    {
    CMmssReceiveHandler* self = CMmssReceiveHandler::NewLC( aObserver );
    CleanupStack::Pop();
    return self;
    }
// ----------------------------------------------------------------------------
// CMmssReceiveHandler::NewLC()
// Standard construction sequence.
// ----------------------------------------------------------------------------
//
CMmssReceiveHandler* CMmssReceiveHandler::NewLC( MMsvObserver& aObserver )
    {
    CMmssReceiveHandler* self = new ( ELeave ) CMmssReceiveHandler( aObserver );
    CleanupStack::PushL( self );
    self->ConstructL();
    return self;
    }

// ----------------------------------------------------------------------------
// CMmssReceiveHandler::CMmssReceiveHandler()
// Constructror
// ----------------------------------------------------------------------------
//
CMmssReceiveHandler::CMmssReceiveHandler( MMsvObserver& aObserver )
    : CMsvHandler( aObserver ), iPhase( EIdle )
    {
    // No implementation required
    }

// ----------------------------------------------------------------------------
// CMmssReceiveHandler::~CMmssReceiveHandler()
// Destructor
// ----------------------------------------------------------------------------
//
CMmssReceiveHandler::~CMmssReceiveHandler()
    {
    // No implementation required
    }

// ----------------------------------------------------------------------------
// CMmssReceiveHandler::ConstructL()
// Call CMsvHandler to construct the objects
// ----------------------------------------------------------------------------
//
void CMmssReceiveHandler::ConstructL()
    {
    CMsvHandler::ConstructL();
    }

// ----------------------------------------------------------------------------
// CMmssReceiveHandler::RunL()
// This method is derived from CActive class
// ----------------------------------------------------------------------------
//
void CMmssReceiveHandler::RunL()
    {
    // Mtm's should always return KErrNone and clients should rely on
    // other means to check on operation progress
    User::LeaveIfError( iStatus.Int() );

    // Determine the current operations progress
    // Note : This class is only appropriate to Locally acting operations
    //        such as Create, Move, Delete.
    // The class McliUtils is located at msvapi.h
    // We could use instead of this McliUtils class for example:
    // CMsvOperation::ProgressL and CMsvOperation::FinalProgress methods.
    TUid mtmUid( iOperation->Mtm() );
    if ( mtmUid == KUidMsvLocalServiceMtm )
        {
        TMsvLocalOperationProgress progress;
        progress = McliUtils::GetLocalProgressL( *iOperation );
        User::LeaveIfError( progress.iError );
        }

    delete iOperation;
    iOperation = NULL;

    switch ( iPhase )
        {
        // ESentForward, ESentReply and EWaitingForDeleted
        // are just examples to reuse received message.
        // We could sent forward the message, sent reply message
        // (games, "out of office") or just delete the message.
        // In example application preferred method would be
        // just delete the message and notfiy about it.
        case ESentForward:
            iPhase = ESentForward;
            break;
        case ESentReply:
            iPhase = EWaitingForDeleted;
            break;
        case EWaitingForDeleted:
            iObserver.HandleStatusChange( MMsvObserver::EDeleted );
            iPhase = EIdle;
            break;
        case EIdle:         // Shouldn't get triggered in this state
        default:
            break;
        }
    }

// ----------------------------------------------------------------------------
// CMmssReceiveHandler::MessageReceivedL()
// Handle received messages
// ----------------------------------------------------------------------------
//
void CMmssReceiveHandler::MessageReceivedL( TMsvId aEntryId )
    {
    // Load this entry to our mtm
    SetMtmEntryL( aEntryId );
    iMtm->LoadMessageL();

    TMsvEntry msvEntry( iMtm->Entry().Entry() );

    // If MMS message, notify about it
    // Note: This informs about all received MMS messages
    if ( msvEntry.iMtm == KUidMsgTypeMultimedia )
        {
        // In this section, we could change the message folder or delete
        // the received message. In this example application, we do not
        // either of those.
        iPhase = EWaitingForDeleted;

        // Notify about the received MMS message
        iObserver.HandleReceivedMessageL();
        }
    }

// ----------------------------------------------------------------------------
// CMmssReceiveHandler::HandleSessionEventL()
// Framework calls this method to trigger the events
// ----------------------------------------------------------------------------
//
void CMmssReceiveHandler::HandleSessionEventL(TMsvSessionEvent aEvent,
											 TAny* aArg1, TAny* aArg2,
                                             TAny* /*aArg3*/)
    {
    switch ( aEvent )
        {
        // flowthrough, not used in this example application
        case EMsvEntriesCreated:
        case EMsvEntriesDeleted:
            break;
#ifdef __WINS__
        // This case is used only for testing purposes (WINS only)
        // A entry has been moved (e.g from Sent-folder to Inbox-folder)
        // This could be used in phone's application, but we aren't interested
        // in only moving the messages between the folders. We need to actually
        // send and receive the message, so that's why the EMsvEntriesChanged
        // is used for receiving the messages in the real environment.
        // Flowthrough (EMsvEntriesMoved is identical to EMsvEntriesChanged)
        case EMsvEntriesMoved:
#endif
        // A new entry has been created in the message server
        case EMsvEntriesChanged:
            {
            // We are interested in messages that are created in Inbox
            // entry id from the session event
            TMsvId* entryId = static_cast<TMsvId*>( aArg2 );

            // new entry has been created in Inbox folder
            if (*entryId == KMsvGlobalInBoxIndexEntryId)
                {
                // We take the created entries into a selection
                CMsvEntrySelection* entries = 
                                    static_cast<CMsvEntrySelection*>( aArg1 );

                //Process each created entry, one at a time.
                for(TInt i( 0 ); i < entries->Count(); i++)
                    {
                    // this checks the entry and handles it if
                    // it is targeted to MMS application.
                    MessageReceivedL( entries->At( i ) );
                    }
                }
            break;
            }

        // This event tells us that the session has been opened
        case EMsvServerReady:
            // Construct the mtm registry
            CompleteConstructL();
			iObserver.HandleServerStatusChange( MMsvObserver::EServerOpen );
            break;
        case EMsvCloseSession:
            // Handle close session
            // Note: If program gets in this part, then it will call to shutdown
            // the Message Server, which affects to all clients. The Message
            // Server will stop acting with clients. This part should be
            // avoided in all cases ( ref. CloseMessageServer() ).
            // iSession->CloseMessageServer();
			iObserver.HandleServerStatusChange( MMsvObserver::EServerClose );
            iObserver.ExitFromProgram();
            break;
        case EMsvServerTerminated:
            // Handle server terminated
            // Note: If program gets in this part, then it will call to shutdown
            // the Message Server, which affects to all clients. The Message
            // Server will stop acting with clients. This part should be
            // avoided in all cases ( ref. CloseMessageServer() ).
            // iSession->CloseMessageServer();
			iObserver.HandleServerStatusChange( MMsvObserver::EServerTerminate );
            iObserver.ExitFromProgram();
            break;
        case EMsvGeneralError:
        case EMsvServerFailedToStart:
            // A major problem has occurred
            iObserver.HandleErrorL( MMsvObserver::EFatalServerError );
            iObserver.ExitFromProgram();
            break;
        default:
            // All other events are ignored
            break;
        }
    }
// End of File

⌨️ 快捷键说明

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