Hi hotcheese,
sorry for my late, but i have been busy with my job more i was sick, it's not a good period...
So, i tried my program and now it does not terminate after it does its job, however i post my code...hope that can help someone of the community.
Code:
....
....
....
....
CSmsEngine* CSmsEngine::NewL()
{
CSmsEngine* self = new (ELeave) CSmsEngine();
CleanupStack::PushL( self );
self->ConstructL();
CleanupStack::Pop( self );
return self;
}
void CSmsEngine::ConstructL() {
iSession = CMsvSession::OpenSyncL( *this );
iClientMtmReg = CClientMtmRegistry::NewL(*iSession);
// Get the SMS Mtm client from the registry
iSmsMtm = static_cast<CSmsClientMtm*>(
iClientMtmReg->NewMtmL( KUidMsgTypeSMS ) );
container = new(ELeave) RArray<TMsvId>();
}
CSmsEngine::~CSmsEngine() {
delete iSmsMtm;
delete iClientMtmReg;
delete iSession;
}
void CSmsEngine::HandleSessionEventL( TMsvSessionEvent aEvent, TAny* aArg1,
TAny* aArg2, TAny* /*aArg3*/ ) {
CConsoleBase* console;
console=Console::NewL(_L("Event!"),TSize (KConsFullScreen,KConsFullScreen)); // Create a consol
CleanupStack::PushL(console);
console->Printf(_L("Handle event\n"));
CMsvEntrySelection* entries ( NULL );
TMsvId* folderId ( NULL );
TMsvEntry entry;
switch (aEvent) {
case EMsvEntriesCreated:
// One or more entries have been created
folderId = static_cast<TMsvId*>( aArg2 );
// We are interested only in the Inbox messages
if ( *folderId != KMsvGlobalInBoxIndexEntryId ) {
break;
}
entries = static_cast<CMsvEntrySelection*>( aArg1 );
console->Printf(_L("Message in inbox\n"));
//Process each created entry, one at a time.
for(TInt i = 0; i < entries->Count(); i++) {
TMsvId folder;
User::LeaveIfError( iSession->GetEntry( entries->At( i ), folder, entry ) );
// We are interested only in the sms messages
if ( entry.iMtm != KUidMsgTypeSMS ) {
break;
}
if (container->Find(entry.Id())!=KErrNotFound) {
// We just created this message ourselves
break;
}
console->Printf(_L("clone it\n"));
CloneMessageL( entry );
console->Printf(_L("done!\n"));
// Delete the original message
iSmsMtm->SwitchCurrentEntryL( entry.Parent() );
iSmsMtm->Entry().DeleteL( entry.Id() );
}
break;
default:
// Ignore all the other messages
break;
}
console->Getch(); // get and ignore character
CleanupStack::PopAndDestroy(); //console, ws, ls, timer
}
void CSmsEngine::CloneMessageL( TMsvEntry& aEntry ) {
iSmsMtm->SwitchCurrentEntryL( aEntry.Id() );
CMsvEntry& cEntry( iSmsMtm->Entry() );
TMsvEntry tEntry = cEntry.Entry();
HBufC* details = HBufC::NewLC( tEntry.iDetails.Length() );
*details = tEntry.iDetails;
HBufC* description = HBufC::NewLC( tEntry.iDescription.Length() );
*description = tEntry.iDescription;
// Store the original message text
CParaFormatLayer* pf = CParaFormatLayer::NewL();
CleanupStack::PushL( pf );
CCharFormatLayer* cf = CCharFormatLayer::NewL();
CleanupStack::PushL( cf );
CRichText* richText = CRichText::NewL( pf, cf,
CEditableText::EFlatStorage );
CleanupStack::PopAndDestroy( cf );
CleanupStack::PopAndDestroy( pf );
CleanupStack::PushL( richText );
CMsvStore* store = cEntry.ReadStoreL();
CleanupStack::PushL( store );
store->RestoreBodyTextL( *richText );
CleanupStack::PopAndDestroy( store );
if (richText->DocumentLength() <= 120) {
// Demonstrate how the message can be modified.
// Append some text to the original content
richText->InsertL( richText->DocumentLength(), _L( "...Changed.." ) );
}
// Create new message
iSmsMtm->SwitchCurrentEntryL( aEntry.Parent() );
iSmsMtm->CreateMessageL( KUidMsgTypeSMS.iUid );
// Set the index entry details to be equal to the original message details
// In the real world application, you might need to copy more details
TMsvEntry entry = iSmsMtm->Entry().Entry();
iLastChangedMessageId = entry.Id();
container->Append(iLastChangedMessageId);
entry.SetInPreparation( tEntry.InPreparation() );
entry.SetVisible( tEntry.Visible() );
entry.iDate = tEntry.iDate;
// In real app, you might have to regenerate description if the old
// description doesn't match the changed text
entry.iDescription.Set( *description );
entry.iDetails.Set( *details );
entry.SetUnread( tEntry.Unread() );
iSmsMtm->Entry().ChangeL( entry );
iSmsMtm->SaveMessageL();
// Now save the original message text
CMsvStore* messageStore = iSmsMtm->Entry().EditStoreL();
CleanupStack::PushL( messageStore );
// To make programmatically created message display "From", not "To"
// in the Messaging application, it is needed to store the ESmsDeliver PDU
// into the message header
CSmsHeader* header = CSmsHeader::NewL( CSmsPDU::ESmsDeliver, *richText );
CleanupStack::PushL( header );
header->StoreL( *messageStore );
CleanupStack::PopAndDestroy( header );
messageStore->StoreBodyTextL( *richText );
messageStore->CommitL();
CleanupStack::PopAndDestroy( messageStore );
CleanupStack::PopAndDestroy( richText );
CleanupStack::PopAndDestroy( description );
CleanupStack::PopAndDestroy( details );
}
As you can see, there is no CActiveScheduler::Stop() into my code, after receiving an sms, cloneMessageL(entry) is called, and a text String is attached to incoming sms.
Let me know if something is wrong.
Thanks in advance,
regards
edcruise.
PS.