?? mmssendastransport.cpp
字號:
// Copyright (c) 2004 - 2007, Symbian Software Ltd. All rights reserved.
#include "mmssendastransport.h"
// -------- (de)allocation --------
CMmsSendAsTransport* CMmsSendAsTransport::NewL(TAny* aTransportCreateInfo)
/**
This factory function is defined so the class can be instantiated
via ECOM, which means it can only take a single TAny* argument.
@param aTransportCreateInfo Pointer to an instance of
TTransportCreateInfo, which contains the
data required to allocate the transport.
@return Transport that sends messages to a remote
device via MMS. This is owned by the caller.
*/
{
const TTransportInterfaceCreateInfo& tci =
*reinterpret_cast<TTransportInterfaceCreateInfo*>(aTransportCreateInfo);
return New2L(tci.iObserver, *tci.iAddress, tci.iInitListen);
}
CMmsSendAsTransport* CMmsSendAsTransport::New2L(MTransportObserver& aObserver, const TDesC& aAddress, TBool aInitListen)
/**
Factory function allocates a new instance of CMmsSendAsTransport,
which can then be used to communicate with a remote device.
@param aObserver Observer to notify about transport events.
This is managed by the CTransport superclass.
@param aAddress Remote device's address. This should be a
string containing a telephone number.
@param aInitListen If true, this object should start by listening
for an incoming payload. Otherwise, it should
wait for its owner to send a payload to the remote
device.
@return Transport that sends messages to a remote
device via MMS. This is owned by the caller.
*/
{
CMmsSendAsTransport* self = new(ELeave) CMmsSendAsTransport(aObserver);
CleanupStack::PushL(self);
self->ConstructL(aAddress, aInitListen);
CleanupStack::Pop(self);
return self;
}
CMmsSendAsTransport::CMmsSendAsTransport(MTransportObserver& aObserver)
/**
This constructor is defined to initialize the base class with
the supplied observer.
@param aObserver Observer to notify about transport events.
This is managed by the CTransport superclass.
*/
: CMessageTransport(aObserver),
iState(EStWaitingToBuild)
{
// empty.
}
void CMmsSendAsTransport::ConstructL(const TDesC& aAddress, TBool aInitListen)
/**
Second-phase constructor initializes the base class and
connects to the sendas server.
@param aAddress Remote device's address. This should be a
string containing a telephone number.
@param aInitListen If true, this object should start by listening
for an incoming payload. Otherwise, it should
wait for its owner to send a payload to the remote
device.
*/
{
CMessageTransport::ConstructL(aAddress, aInitListen);
TInt r = iFs.Connect();
if (r == KErrNone)
r = iSendAs.Connect();
User::LeaveIfError(r);
}
CMmsSendAsTransport::~CMmsSendAsTransport()
/**
Cancel any outstanding operations and free resources
used by this transport.
*/
{
Cancel();
iSendAsMessage.Close();
iSendAs.Close();
iFs.Close();
}
// -------- implement CMessageTransport --------
void CMmsSendAsTransport::BuildAndSendMessageL(const TDesC& aPayloadText)
/**
Implement CMessageTransport by constructing a multimedia message
where the the contents of payload are included as a text attachment.
@param aPayloadText Text to send to remote device. This is
retrieved with ExtractPlainTextLC on the
remote device.
*/
{
__MT_ASSERT(iState == EStWaitingToBuild, EMsBsBadState);
iSendAsMessage.CreateL(iSendAs, KUidMsgTypeMultimedia);
iSendAsMessage.AddRecipientL(*iRemoteAddress, RSendAsMessage::ESendAsRecipientTo);
iSendAsMessage.SetSubjectL(KMmsSubjectLine);
// add the payload as a text attachment
RFile textFile;
iSendAsMessage.CreateAttachmentL(KPayloadAttachmentName, textFile, /*aMimeType*/ KMmsTextPlain);
CleanupClosePushL(textFile);
HBufC8* framedPayload = MmsUtils::BuildFramedPayloadLC(aPayloadText);
TInt r = textFile.Write(*framedPayload);
if (r == KErrNone)
r = textFile.Flush();
User::LeaveIfError(r);
CleanupStack::PopAndDestroy(2, &textFile); // framedPayload
// add image as an attachment
TFileName fnImage;
MmsUtils::FileNameFromPrivateDirL(iFs, fnImage, KImageAttachmentName);
// RunL is invoked when the attachment has been added
iState = EStAddingImage;
iSendAsMessage.AddAttachment(fnImage, KImageAttachmentMimeType8, iStatus);
}
TBool CMmsSendAsTransport::ShouldUseReceivedMtmUid(TUid aMtmUid) const
/**
Implement CMessageTransport by checking whether the supplied
MTM UID is for multimedia messages.
@param aMtmUid UID associated with incoming message.
@return Whether the supplied MTM UID is for a
multimedia messages.
*/
{
return aMtmUid == KUidMsgTypeMultimedia;
}
HBufC* CMmsSendAsTransport::ExtractPlainTextLC(CMsvStore& aStore) const
/**
Implement CMessageTransport by extracting the payload body text
from an attachment in the supplied store.
@param aStore Store which contains message's attachments.
@return Payload text. This pointer is placed on the
cleanup stack and owned by the caller.
*/
{
return MmsUtils::ExtractPlainTextLC(aStore);
}
// -------- override CTransport, CMessageTransport --------
void CMmsSendAsTransport::RunL()
/**
Implement CActive and override CTransport.
If added the image attachment, send the message. If sent
the message then queue a pending read.
*/
{
switch (iState)
{
case EStAddingImage:
User::LeaveIfError(iStatus.Int());
// added image attachment so send the message
iState = EStSending;
iSendAsMessage.SendMessage(iStatus);
SetActive();
break;
case EStSending:
// if finished sending then run CTransport::RunL to notify owner
// that message has been sent
iState = EStWaitingToBuild;
iSendAsMessage.Close();
// fall through
case EStWaitingToBuild:
// read has completed, which is handled in CMessageTransport
CMessageTransport::RunL();
break;
}
}
void CMmsSendAsTransport::DoCancel()
/**
Implement CActive and override CMessageTransport by calling
building or sending the message. If not building or sending a
message then cancel any pending read.
*/
{
switch (iState)
{
case EStAddingImage:
case EStSending:
iSendAsMessage.Cancel();
break;
case EStWaitingToBuild:
// cancel pending read
CMessageTransport::DoCancel();
break;
}
}
?? 快捷鍵說明
復(fù)制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -