×

Discussion Board

Results 1 to 9 of 9
  1. #1
    Registered User
    Join Date
    Jan 2006
    Posts
    19

    Exe stops after one time

    Hi at all,
    I have an exe program that modify incoming sms. It intercepts incoming sms, elaborate it, and deliver it.
    To do this, i registered to MSMSEngineObserver, in such a way that every SMS event can be caught.
    But, it seems that, every time a sms event happens, my program terminate and i must re-run it to work correctly.
    More precisely, I have 2 class. First is entry point, that call the second, the SMS engine.
    From the entry point:
    Code:
        CActiveScheduler* scheduler = new(ELeave) CActiveScheduler;
        CleanupStack::PushL(scheduler);
        CActiveScheduler::Install(scheduler);
    
        CSmsEngine* aoMain = CSmsEngine::NewL();
        CActiveScheduler::Start();
    
        CleanupStack::PopAndDestroy(aoMain);
        CleanupStack::PopAndDestroy(scheduler);
    i call my engine. After an SMS event happens, CSmsEngine::HandleSessionEventL engine method is called, then SMS is processed. After method is executed, program terminate. I tried to add a while(true) { ... } that wraps entry point, but many program instance are created.
    Maybe i must use notify Event method or anything else about Active Objects ??

    Any help is appreciate.
    regards,
    edcruise

  2. #2
    Nokia Developer Champion
    Join Date
    Jul 2004
    Posts
    2,015

    Re: Exe stops after one time

    I don't wish to sound rude, but if you've attempted to use a while(true) loop to keep an executable running then you have a long way to go in understanding real-time programming.

    If this code terminates after receiving an SMS then presumably you've got a call to CActiveScheduler::Stop() somewhere.
    Last edited by hotcheese; 2007-09-11 at 22:28.

  3. #3
    Registered User
    Join Date
    Jan 2006
    Posts
    19

    Re: Exe stops after one time

    Hi hotcheese,
    don't worry, i'm a newbie...i know that it takes a lot before i really can understand real-time programming..but i'm studing
    Well, i understand while(true) {...} is wrong, I don't know where to add CActiveScheduler::Stop(). If add it at the end of entry point could be right ??
    Code:
        CActiveScheduler* scheduler = new(ELeave) CActiveScheduler;
        CleanupStack::PushL(scheduler);
        CActiveScheduler::Install(scheduler);
    
        CSmsEngine* aoMain = CSmsEngine::NewL();
        CActiveScheduler::Start();
        CActiveScheduler::Stop();
    
        CleanupStack::PopAndDestroy(aoMain);
        CleanupStack::PopAndDestroy(scheduler);
    What do you mean with 'somewhere' ?
    It doesn't sound me right, anywhere i'll try it.

    Thanks for help.
    regards,
    edcruise.

  4. #4
    Nokia Developer Champion
    Join Date
    Jul 2004
    Posts
    2,015

    Re: Exe stops after one time

    What I meant was that you probably already have a call to CActiveScheduler::Stop() in your code but it was being called after receiving one SMS and not when you want your program to finish. If you already have no call to Stop() then your code should hang, if its not hanging then there's something majorly wrong with it.

    Lets see your CSMSEngine code.

    Look at item number 8 to try to understand how the active scheduler works:
    http://www.newlc.com/topic-13580
    Last edited by hotcheese; 2007-09-13 at 17:55.

  5. #5
    Registered User
    Join Date
    Jan 2006
    Posts
    19

    Re: Exe stops after one time

    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.

  6. #6
    Nokia Developer Moderator
    Join Date
    Feb 2006
    Location
    Oslo, Norway
    Posts
    28,698

    Re: Exe stops after one time

    I have not checked the code in depth, but here are 2 observations:
    #1: when EMsvEntriesCreated happens, the SMS is not ready (it has only the TMsvEntry, no body, etc.). Check any example, they check if creation happens with an SMS in the Inbox, and store its TMsvId, then when EMsvEntriesChanged happens, they re-check (in order to make sure that the new message is under change), and access the body, etc.
    #2: CloneMessageL creates a new message, which results invoking your HandleSessionEventL once more with EMsvEntriesCreated. If #1 would not happen, you would end up in creating endless copies of the incoming message

    The relation is simple:
    CBaseMtm::CreateMessageL/CMsvEntry::Create results in EMsvEntriesCreated. Since you pass a simple TMsvEntry object to these methods, you cannot expect anything else to be available
    CBaseMtm::ChangeL results in EMsvEntriesChanged. At this time, the message is usually ready, thus it has Body, attachments, etc.

  7. #7
    Registered User
    Join Date
    Jan 2006
    Posts
    19

    Re: Exe stops after one time

    Hi wizard_hu_,
    thanks for your answer, i understood what you said and then, after searching around the forum, wiki and other site, i developed this code:
    Code:
    void CSmsEngine::HandleSessionEventL( TMsvSessionEvent aEvent, TAny* aArg1, 
                                          TAny* aArg2, TAny* /*aArg3*/ ) {
        CConsoleBase* console;
        console=Console::NewL(_L("Event"),TSize (KConsFullScreen,KConsFullScreen)); // Create a console
        CleanupStack::PushL(console);
        console->Printf(_L("Handle event\n"));
    
        CMsvEntrySelection* entries ( NULL );
        TMsvId* folderId ( NULL );
        TMsvEntry entry;
        
        static TInt iNewMessageId = 0;
    
        switch (aEvent) {
    	// A new entry has been created in the message server
    	case EMsvEntriesCreated: {
    	    folderId = static_cast<TMsvId*>( aArg2 );
                if(*folderId == KMsvGlobalInBoxIndexEntryId) {
    		CMsvEntrySelection* entries = static_cast<CMsvEntrySelection *>(aArg1);
    		iNewMessageId = entries->At(0);
    		console->Printf(_L("Message in inbox\n"));
    	    }
    	    break;
    	}
    
    	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);
    		
    		TInt index = entries->Find(iNewMessageId);
    		
    		if(KErrNotFound == index) {
    			console->Printf(_L("No entry found!\n"));
    	                break;
    		}
    		TMsvId folder;
    		User::LeaveIfError( iSession->GetEntry( entries->At( index ), folder, entry ) );
    		        
    		console->Printf(_L("clone it\n"));
    	        CloneMessageL( entry );
    	        console->Printf(_L("done!\n"));
    		iNewMessageId = 0 ;
    		}
            break;
         }
    }    
    	console->Getch(); // get and ignore character
    	CleanupStack::PopAndDestroy(); //console, ws, ls, timer
    }
    I attached only main function that intercepts sms and does the job. Now i get sms intercepting EMSENTRIESCREATED event, get the id of my sms and after in the EMSENTRIESCHANGED event i append my '..Changed.." string.
    But what if i receve more than one sms at time ??
    I have static TInt iNewMessageId then i have only on instance of such variable and then i can't handle more than one sms receive.
    Maybe should I need an array to store all sms id or exist a event queue handle by the system?
    More at time, my app does not work correctly.
    Do you observe anything else of strange ?
    I hope my question is not a stupid question, and hope that can be helpful for somebody.
    Thanks in advance.
    regards,
    edcruise.

  8. #8
    Nokia Developer Champion
    Join Date
    Jul 2004
    Posts
    2,015

    Re: Exe stops after one time

    >>So, i tried my program and now it does not terminate after it does its job

    So what did you change to make it continue to run and not terminate?

    If it now no longer terminates then what is your question?

  9. #9
    Registered User
    Join Date
    Jan 2006
    Posts
    19

    Re: Exe stops after one time

    Hi hotcheese,
    after analyzed my code, i change something and now it works, or rather does not terminate incorrectly. I attached my code in previous post in such a way that you can look at it. After read your link to newlc site, to real-time programming in symbian, i changed something in my code, and now works correctly.
    But wizard_hu observed some thing that is wrong in my code, i hope that now, after changed it, be right.

    If you look at my code, you find something that is wrong ? NOw it does not works correctly, some sms is not intercepted....

    Thanks in advance.
    regards,
    edcruise.

Similar Threads

  1. exe that detects a new SMS recieved???
    By harish13_ks in forum Symbian
    Replies: 2
    Last Post: 2007-07-28, 20:38
  2. difference between exe and application frame
    By manjunaths in forum Symbian User Interface
    Replies: 2
    Last Post: 2006-12-05, 07:07
  3. difference between exe and application frame work
    By manjunaths in forum Symbian
    Replies: 4
    Last Post: 2006-12-05, 07:01
  4. Replies: 0
    Last Post: 2004-01-14, 15:22
  5. How to get correct time.
    By dzaga in forum Mobile Java General
    Replies: 2
    Last Post: 2003-08-06, 22:03

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
×