×

Discussion Board

Page 1 of 2 12 LastLast
Results 1 to 15 of 16
  1. #1
    Regular Contributor
    Join Date
    Sep 2008
    Posts
    290

    Active object is not active

    Hi,

    my problem is that i create two active objects but no one is active...

    my application cpp file...

    Code:
    //Include Files  
    //User includes
    #include "DeMon.h"
    
    LOCAL_C void MainL()
    	{
    	CEngine* Engine = CEngine::NewLC();
    	CActiveScheduler::Start();
    	CleanupStack::PopAndDestroy( Engine );
    	}
    
    LOCAL_C void DoStartL()
    	{
    	CActiveScheduler* scheduler = new (ELeave) CActiveScheduler();
    	CleanupStack::PushL(scheduler);
    	CActiveScheduler::Install(scheduler);
    	MainL();
    	CleanupStack::PopAndDestroy(scheduler);
    	}
    
    GLDEF_C TInt E32Main()
    	{
    	__UHEAP_MARK;
    	CTrapCleanup* cleanup = CTrapCleanup::New();
    	if ( !( cleanup ) )
    		{
    		/*
    		 * cannot go on. Need to panic the app. 
    		 * We cannot live without cleanup stack :)
    		 */ 
    		 return KErrNoMemory;
    		}
    	TRAPD( err, DoStartL() );
    	if ( err )
    		{
    		User::Panic( _L("Task background process\n failed with error code: %i"), err );
    		}
    	delete cleanup;
    	__UHEAP_MARKEND;
    	return KErrNone;
    	}

    and my engine...

    Code:
    #include "Engine.h"
    
    
    _LIT( KPath, "C:\\Data\\Sync.txt" );
    
    CEngine::CEngine()
    	{
    	iTimerMonitor = NULL;
    	iFileMonitor = NULL;
    	iPath = NULL;
    	iServerName = NULL;
    	iDbSessionConn = EFalse;
    	iFileServerConn = EFalse;
    	iDatabaseOpen = EFalse;
    	iHasTCPConn = EFalse;
    	}
    
    CEngine::~CEngine()
    	{
    	iDb.Close();
    	iFServSession.Close();
    	iDbSession.Close();
    	if( iTimerMonitor != NULL )
    		{
    		delete iTimerMonitor;
    		iTimerMonitor = NULL;
    		}
    	if( iFileMonitor != NULL )
    		{
    		delete iFileMonitor;
    		iFileMonitor = NULL;
    		}
    	if (iPath != NULL )
    		{
    		delete iPath;
    		iPath = NULL;
    		}
    	if (iServerName != NULL )
    		{
    		delete iServerName;
    		iServerName = NULL;
    		}
    	if (iUserName != NULL )
    		{
    		delete iUserName;
    		iUserName = NULL;
    		}
    	if (iPassword != NULL )
    		{
    		delete iPassword;
    		iPassword = NULL;
    		}
    	Logger.CloseLog();
    	Logger.Close();
    	}
    
    CEngine* CEngine::NewLC()
    	{
    	CEngine* self = new (ELeave) CEngine();
    	CleanupStack::PushL(self);
    	self->ConstructL();
    	return self;
    	}
    
    CEngine* CEngine::NewL()
    	{
    	CEngine* self = CEngine::NewLC();
    	CleanupStack::Pop(); // self;
    	return self;
    	}
    
    void CEngine::ConstructL()
    	{
    	
    	Logger.Connect();
    	Logger.CreateLog(_L("MyLogs"),_L("DeMonLog.txt"),EFileLoggingModeOverwrite);
    	
    	
    	TInt Err = iFServSession.Connect();
    	if (Err == KErrNone )
    		{
    		iFileServerConn = ETrue;
    		}
    	Err = iDbSession.Connect();
    	if ( Err == KErrNone )
    		{
    		iDbSessionConn = ETrue;
    		}
    	_LIT(KStandardDatabase, "C:\\Data\\MyDbs.db" );
    	if(BaflUtils::FileExists( iFServSession, KStandardDatabase ) )
    		{
    		Err = iDb.Open(iDbSession, KStandardDatabase); 		
    		if ( Err == KErrNone )
    			{
    			iDatabaseOpen = ETrue;
    			}
    		}
    	//Just run only when database is open!!!!!!!!
    	
    	
    	
    	if ( iDatabaseOpen && iDbSessionConn && iFileServerConn)
    		{
    		QueryOverPeriodeOfTime();
    		GetConnectionDataFromDbL();
    		Logger.Write( _L("just reaching iTimerMonitor!") );
    		iTimerMonitor = CTimerMonitorAO::NewL( *this );
    		Logger.Write( _L("now start iTimerMonitor!") );
    		iTimerMonitor->StartL( iPeriode );
    		Logger.Write( _L("iTimerMonitor ...started!") );
    		//This is the file to be watched...
    		iFileMonitor = CFileMonitorAO::NewL( *this, iFServSession , KPath().AllocL() );
    		Logger.Write( _L("iFileMonitor ...Start") );
    		}
    	}
    
    
    void CEngine::QueryOverPeriodeOfTime()
    	{
    	Logger.Write( _L("CEngine::QueryOverPeriodeOfTime  ...Start") );
    	TBool TableIsClosed( EFalse );
    	if( iDatabaseOpen )
    	   {	   
    		_LIT( KSelectQuery, "SELECT demandPeriode_Id, itemText FROM DemandPeriode WHERE demandPeriode_Id = 1");
    		RDbView table;
    		TInt Err = table.Prepare( iDb, TDbQuery( KSelectQuery ) );
    		if( Err == KErrNone )
    			{
    			CleanupClosePushL( table );	
    			Err = iDb.Begin();
    			if( Err == KErrNone )
    			   {
    			   table.EvaluateAll();
    			   table.FirstL();
    			   if ( table.AtRow() )
    				   {
    				   table.GetL();
    				   HBufC* colVal = table.ColDes( 2 ).AllocLC();
    				   table.Close();
    				   TableIsClosed = ETrue;
    				   _LIT( KNoPeriode, "none" );
    				   _LIT( K60SecPeriode,"60 Secs" );
    				   _LIT( K30MinPeriode,"30 Minutes" );
    				   _LIT( K60MinPeriode,"1 Hour" );
    				   if ( colVal->Des().Right( KNoPeriode().Length() ).Find( KNoPeriode ) == 0 )
    					   {
    				   	   iPeriode = TTimeIntervalMicroSeconds32( 0 );			   							
    				   	   }
    				   	else if ( colVal->Des().Right( K60SecPeriode().Length() ).Find( K60SecPeriode ) == 0 ) 
    				   		{
    				   		iPeriode = TTimeIntervalMicroSeconds32( 60 * 1000000 ); //60 * one second == 60 seconds			   									
    				   		}
    				   	else if ( colVal->Des().Right( K30MinPeriode().Length() ).Find( K30MinPeriode ) == 0 ) 
    				   		{
    				   		iPeriode = TTimeIntervalMicroSeconds32( 1800 * 1000000 );
    				   		}
    				   	else if ( colVal->Des().Right( K60MinPeriode().Length() ).Find( K60MinPeriode ) == 0 ) 						 				
    				   		{
    				   	    iPeriode = TTimeIntervalMicroSeconds32( 3600 * 1000000 );
    				   	    }	
    				   	CleanupStack::PopAndDestroy( colVal );						 
    				   	}//table.AtRow()	
    			   iDb.Commit();
    			   //iDb.Compact();
    			   }
    			if ( !TableIsClosed )
    				{
    				table.Close();
    				}
    			CleanupStack::PopAndDestroy( 1 ); //table
    			}
    	   }
    	Logger.Write( _L("CEngine::QueryOverPeriodeOfTime  ...End") );
    	}
    
    //Handles events raised by FileMonitorAO
    void CEngine::FileMonitorStateL( TInt aState )
    	{
    	Logger.Write( _L("CEngine::FileMonitorStateL  ...Start") );
    	switch( aState )
    		{
    		case 1962:
    			{
    			//Dateimonitor beenden
    			delete iTimerMonitor;
    			iTimerMonitor = NULL;
    			QueryOverPeriodeOfTime();
    			//Dateimonitor neu starten!!!!
    			iTimerMonitor = CTimerMonitorAO::NewL( *this );
    			iTimerMonitor->StartL( iPeriode );
    			//Ip, Port Username,...
    			GetConnectionDataFromDbL();
    			}
    			break;
    		}
    	Logger.Write( _L("CEngine::FileMonitorStateL  ...End") );
    	}
    
    //Handles events raised by TimerMonitorAO
    void CEngine::TimerMonitorStateL( TInt aState )
    	{
    	Logger.Write( _L("CEngine::TimerMonitorStateL  ...Start") );
    	switch( aState )
    		{
    		case 1:
    			break;
    		}
    	ConnectL();
    	//Do something with the socket!
    	Close();
    	Logger.Write( _L("CEngine::TimerMonitorStateL  ...End") );
    	}
    
    
    void CEngine::GetConnectionDataFromDbL()
    	{
    	Logger.Write( _L("CEngine::GetConnectionDataFromDbL  ...Start") );
    	TBool TableIsClosed( EFalse );
    	if( iDatabaseOpen )
    		{	   
    		_LIT( KSelectOptionQuery, "SELECT option_Id, servername, port FROM Option WHERE option_Id = 1");
    		RDbView tableOpt;
    		TInt Err = tableOpt.Prepare( iDb, TDbQuery( KSelectOptionQuery ) );
    		if( Err == KErrNone )
    			{
    			CleanupClosePushL( tableOpt );	
    			Err = iDb.Begin();
    			if( Err == KErrNone )
    			   {
    			   tableOpt.EvaluateAll();
    			   tableOpt.FirstL();
    			   if ( tableOpt.AtRow() )
    				   {
    				   tableOpt.GetL();
    				   iServerName = tableOpt.ColDes( 2 ).Alloc();
    				   iPort = tableOpt.ColInt( 3 );
    				   tableOpt.Close();
    				   TableIsClosed = ETrue;
    				   }
    			   iDb.Commit();
    			   //iDb.Compact();
    			   }
    			if ( !TableIsClosed )
    				{
    				tableOpt.Close();
    				}
    			CleanupStack::PopAndDestroy( 1 );//tableOpt
    			}
    		
    		
    		
    		
    		TableIsClosed = EFalse;
    		_LIT( KSelectUserQuery, "SELECT user_Id, username, password FROM User WHERE user_Id = 1");
    		RDbView tableUsr;
    		Err = tableUsr.Prepare( iDb, TDbQuery( KSelectUserQuery ) );
    		if( Err == KErrNone )
    			{
    			CleanupClosePushL( tableUsr );	
    			Err = iDb.Begin();
    			if( Err == KErrNone )
    				{
    				tableUsr.EvaluateAll();
    				tableUsr.FirstL();
    				if ( tableUsr.AtRow() )
    					{
    					tableUsr.GetL();
    					iUserName = tableUsr.ColDes( 2 ).Alloc();
    					iPassword = tableUsr.ColDes8( 3 ).Alloc();
    					tableUsr.Close();
    					TableIsClosed = ETrue;
    					}
    				iDb.Commit();
    				//iDb.Compact();
    				}
    			if ( !TableIsClosed )
    				{
    				tableUsr.Close();
    				}
    			CleanupStack::PopAndDestroy( 1 ); //tableUsr
    			}			
    		
    		
    		TableIsClosed = EFalse;
    		_LIT( KSelectIAPQuery, "SELECT accesspoints_Id, Iap_Id, itemText FROM AccessPoints WHERE accesspoints_Id = 1");
    		RDbView tableIAP;
    		Err = tableIAP.Prepare( iDb, TDbQuery( KSelectIAPQuery ) );
    		if( Err == KErrNone )
    			{
    			CleanupClosePushL( tableIAP );	
    			Err = iDb.Begin();
    			if( Err == KErrNone )
    				{
    				tableIAP.EvaluateAll();
    				tableIAP.FirstL();
    				if ( tableIAP.AtRow() )
    					{
    					tableIAP.GetL();					
    					iIap_Id = tableIAP.ColUint32( 2 );
    					tableIAP.Close();
    					TableIsClosed = ETrue;
    					}
    				iDb.Commit();
    				//iDb.Compact();
    				}
    			if ( !TableIsClosed )
    				{
    				tableIAP.Close();
    				}
    			CleanupStack::PopAndDestroy( 1 ); //tableUsr
    			}							
    		}
    	Logger.Write( _L("CEngine::GetConnectionDataFromDbL  ...End") );
    	}
    
    void CEngine::ConnectL()
    	{
    	Logger.Write( _L("CEngine::ConnectL  ...Start") );
    	TRequestStatus Status;
    	
    	TInt Err = iSocketServer.Connect();
    	if (Err == KErrNone )
    		{
    		// Set the connection preferences
    		iConnection.Open( iSocketServer );
    		TCommDbConnPref prefs;
    		prefs.SetIapId( iIap_Id );
    		prefs.SetDialogPreference(ECommDbDialogPrefDoNotPrompt);
    		prefs.SetDirection(ECommDbConnectionDirectionOutgoing);
    		iConnection.Start( prefs );
    		
    		Err = iSocket.Open( iSocketServer, 
    						  	KAfInet, 
    							KSockStream,
    							KProtocolInetTcp,
    							iConnection );
    		if ( Err == KErrNone )
    		    {
    		    iAddress.SetPort( iPort );
    		    iAddress.Input( *iServerName );
    		    iSocket.Connect( iAddress, Status );
    		    User::WaitForRequest(  Status );
    		    iHasTCPConn = ETrue;
    		    iConnection.Stop();
    		    }
    		}
    	Logger.Write( _L("CEngine::ConnectL  ...End") );
    	
    	}
    
    void CEngine::Close()
    	{
    	Logger.Write( _L("CEngine::Close()  ...Start") );
    	iSocket.Close();
    	iSocketServer.Close();
    	Logger.Write( _L("CEngine::Close()  ...End") );
    	}

  2. #2
    Regular Contributor
    Join Date
    Sep 2008
    Posts
    290

    Re: Active object is not active

    and my TimerAO

    Code:
    #include "TimerMonitorAO.h"
    #include "Engine.h"
    
    CTimerMonitorAO::CTimerMonitorAO( MTimerMonitorStateObserver& aStateObserver ) :
    	CActive(EPriorityStandard),  // Standard priority
    	iStateObserver( aStateObserver )
    	{
    	// No implementation required
    	iLogger.Connect();
    	iLogger.CreateLog(_L("MyLogs"),_L("TimerAO.txt"),EFileLoggingModeOverwrite);
    	}
    
    CTimerMonitorAO* CTimerMonitorAO::NewLC( MTimerMonitorStateObserver& aStateObserver )
    	{
    	CTimerMonitorAO* self = new (ELeave) CTimerMonitorAO( aStateObserver );
    	CleanupStack::PushL(self);
    	self->ConstructL();
    	return self;
    	}
    
    CTimerMonitorAO* CTimerMonitorAO::NewL( MTimerMonitorStateObserver& aStateObserver )
    	{
    	CTimerMonitorAO* self = CTimerMonitorAO::NewLC( aStateObserver );
    	CleanupStack::Pop(); // self;
    	return self;
    	}
    
    void CTimerMonitorAO::ConstructL()
    	{
    	User::LeaveIfError(iTimer.CreateLocal()); // Initialize timer
    	CActiveScheduler::Add(this); // Add to scheduler
    	}
    
    CTimerMonitorAO::~CTimerMonitorAO()
    	{
    	Cancel(); // Cancel any request, if outstanding
    	iTimer.Close(); // Destroy the RTimer object	
    	iLogger.CloseLog();
    	iLogger.Close();
    	}
    
    void CTimerMonitorAO::DoCancel()
    	{
    	iTimer.Cancel();
    	}
    
    void CTimerMonitorAO::StartL(TTimeIntervalMicroSeconds32 aDelay)
    	{
    	iLogger.Write( _L("CTimerMonitorAO::StartL ...started!") );
    	Cancel(); // Cancel any request, just to be sure
    	iLogger.Write( _L("CTimerMonitorAO::StartL ...cancel!") );
    	iState = EUninitialized;
    	iTimeInterval = TTimeIntervalMicroSeconds32 (aDelay );
    	iTimer.After(iStatus, aDelay); // Set for later
    	iLogger.Write( _L("CTimerMonitorAO::StartL ...After!") );
    	SetActive(); // Tell scheduler a request is active
    	iLogger.Write( _L("CTimerMonitorAO::StartL ...SetActive end!") );
    	}
    
    void CTimerMonitorAO::RunL()
    	{
    	if (iState == EUninitialized)
    		{
    		// Do something the first time RunL() is called
    		iState = EInitialized;
    		}
    	else if (iState != EError)
    		{
    		// Do something
    		}
    	iLogger.Write( _L("CTimerMonitorAO::RunL ...started!") );
    	iStateObserver.TimerMonitorStateL( iStatus.Int() );
    	iTimer.After(iStatus, iTimeInterval );
    	SetActive();
    	}
    
    TInt CTimerMonitorAO::RunError(TInt aError)
    	{
    	return aError;
    	}

    and my FileMonitorAO
    Code:
    /*
     ============================================================================
     Name		 : FileMonitorAO.cpp
     Author	     : Frank Sohn
     Version	 : 1.0
     Copyright   : copyright 2008-2009 Gobas Gruppe
     Description : CFileMonitorAO implementation
     ============================================================================
     */
    
    #include "FileMonitorAO.h"
    
    CFileMonitorAO::CFileMonitorAO( MFileMonitorStateObserver& aStateObserver,
    								RFs& aFServSession,
    								const HBufC* aPath) :
    	CActive(EPriorityStandard), // Standard priority
    	iStateObserver( aStateObserver ),
    	iFServSession( aFServSession ),
    	iPath( aPath ) 
    	{
    	//No implementation required
    	}
    
    CFileMonitorAO* CFileMonitorAO::NewLC( MFileMonitorStateObserver& aStateObserver,
    									   RFs& aFServSession,
    									   const HBufC* aPath)
    	{
    	CFileMonitorAO* self = new (ELeave) CFileMonitorAO( aStateObserver,
    														aFServSession,
    														aPath );
    	CleanupStack::PushL(self);
    	self->ConstructL();
    	return self;
    	}
    
    CFileMonitorAO* CFileMonitorAO::NewL( MFileMonitorStateObserver& aStateObserver,
    									  RFs& aFServSession,	
    									  const HBufC* aPath)
    	{
    	CFileMonitorAO* self = CFileMonitorAO::NewLC( aStateObserver,
    												  aFServSession,
    												  aPath);
    	CleanupStack::Pop(); // self;
    	return self;
    	}
    
    void CFileMonitorAO::ConstructL()
    	{
    	CActiveScheduler::Add(this); // Add to scheduler
    	iFServSession.NotifyChange( ENotifyWrite, iStatus, *iPath );
    	SetActive();
    	}
    
    CFileMonitorAO::~CFileMonitorAO()
    	{
    	Cancel(); // Cancel any request, if outstanding
    	iFServSession.Close(); //Destroy ther RFs object
    	// Delete instance variables if any
    	delete iPath;
    	iPath = NULL;
    	}
    
    void CFileMonitorAO::DoCancel()
    	{
    	iFServSession.NotifyChangeCancel();
    	}
    
    void CFileMonitorAO::RunL()
    	{
    	if ( iStatus == KErrNone ) 
    		{
    		iStateObserver.FileMonitorStateL( 1962 );
    		//Start watching!
    		Cancel();
    		iFServSession.NotifyChange( ENotifyWrite, iStatus, *iPath );
    		SetActive(); // Tell scheduler a request is active
    		}
    	}
    
    TInt CFileMonitorAO::RunError(TInt aError)
    	{
    	return aError;
    	}
    My TimerAO.txt contains fhe following lines:

    CTimermonitorAO ...started!

    CTimerMonitorAO ...cancel!


    Why is the AO not started?


    Greetz
    Franky

  3. #3
    Super Contributor
    Join Date
    Jun 2006
    Location
    India
    Posts
    3,037

    Re: Active object is not active

    Hi,

    I think the statement is not correct

    iTimeInterval = TTimeIntervalMicroSeconds32 (aDelay );
    above shold be like:
    TTimeIntervalMicroSeconds32 iTimeInterval (aDelay );
    or
    iTimeInterval = aDelay ;

    Keep your question length short snd empasize on the error part only.
    Use [URL="http://qt.nokia.com/products/qt-quick/"]Qt-Quick[/URL] to make your application UI more attractive.

    [URL="http://store.ovi.com/content/271896"]http://store.ovi.com/content/271896[/URL] | [URL="http://store.ovi.com/content/276199"]http://store.ovi.com/content/276199[/URL] |[URL="http://store.ovi.com/content/276202"] http://store.ovi.com/content/276202[/URL] | [URL="http://store.ovi.com/content/280827"]http://store.ovi.com/content/280827[/URL]

  4. #4
    Registered User
    Join Date
    Feb 2007
    Location
    Tampere
    Posts
    370

    Re: Active object is not active

    Hi,

    Just looked into your code, the code looks good.

    One query,
    iPeriode
    in Engine.cpp, I didnt find where it was initialized.
    Also would suggest testing one active object at a time, before you start using both of them, that way it would be easy to use.
    Regards

    - MVP
    "Dare To Dream" - A.P.J.Kalam

  5. #5
    Registered User
    Join Date
    Apr 2005
    Location
    Barcelona
    Posts
    1,678

    Re: Active object is not active

    You'd do better relying on the cleanup stack for error handling. This will make your code easier to read (instead of having all those if and booleans)

    As per the AO issue, check and log the iPeriode value you're passing.

  6. #6
    Registered User
    Join Date
    Apr 2005
    Location
    Barcelona
    Posts
    1,678

    Re: Active object is not active

    Quote Originally Posted by mrudulpen View Post
    Hi,

    Just looked into your code, the code looks good.

    One query, in Engine.cpp, I didnt find where it was initialized.
    Also would suggest testing one active object at a time, before you start using both of them, that way it would be easy to use.
    It's in QueryOverPeriodeOfTime().. assuming many conditions held true ;-)

  7. #7
    Registered User
    Join Date
    Feb 2007
    Location
    Tampere
    Posts
    370

    Re: Active object is not active

    Hi,



    Yeah got lost in the lines of code

    Frank,
    Better check what value you are passing as suggested by David.
    Regards

    - MVP
    "Dare To Dream" - A.P.J.Kalam

  8. #8
    Regular Contributor
    Join Date
    Sep 2008
    Posts
    290

    Re: Active object is not active

    Hi,

    ok now my methods look like this

    Code:
    void CEngine::QueryTCPConnectionDataL()
    	{
    	Logger.Write( _L("CEngine::QueryTCPConnectionDataL  ...Start") );
    	_LIT( KSelectOptionQuery, "SELECT option_Id, servername, port FROM Option WHERE option_Id = 1");
    	RDbView table;
    	User::LeaveIfError( table.Prepare( iDb, TDbQuery( KSelectOptionQuery ) ) );
    	CleanupClosePushL( table );	
    	User::LeaveIfError( iDb.Begin() );	
    	User::LeaveIfError( table.EvaluateAll() );
    	table.FirstL();
    	if ( table.AtRow() )
    		{
    		table.GetL();
    		iServerName = table.ColDes( 2 ).Alloc();
    		iPort = table.ColInt( 3 );				  
    		}
    	User::LeaveIfError( iDb.Commit() );		
    	CleanupStack::PopAndDestroy( 1 );//table
    	Logger.Write( _L("CEngine::QueryTCPConnectionDataL  ...End") );
    	}


    If i run the code in the emulator it works. But on my mobile the code reachaes not the line after (bold) ....


    Code:
    Cancel(); // Cancel any request, just to be sure
    iLogger.Write( _L("CTimerMonitorAO::StartL ...cancel!") );
    iState = EUninitialized;
    iTimeInterval = aDelay;
    iLogger.WriteFormat( _L("Interval =%d"),  aDelay.Int() );
    iTimer.After(iStatus, aDelay); // Set for later
    iLogger.Write( _L("CTimerMonitorAO::StartL ...After!") );

    well now i that...

    Code:
    ...
    const TTimeIntervalMicroSeconds32 KActivityInterval60s = 60 * 1000 * 1000; // 60s
    const TTimeIntervalMicroSeconds32 KActivityInterval30Min = 1800 * 1000 * 1000; // 30Min
    const TTimeIntervalMicroSeconds32 KActivityInterval60Min = 3600 * 1000 * 1000; // 60Min
    
    ...
    
    bold not reached...
    void CEngine::QueryOverPeriodeOfTimeL()
    	{
    	Logger.Write( _L("CEngine::QueryOverPeriodeOfTime  ...Start") );
    	_LIT( KSelectQuery, "SELECT demandPeriode_Id, itemText FROM DemandPeriode WHERE demandPeriode_Id = 1");
    	RDbView table;
    	User::LeaveIfError( table.Prepare( iDb, TDbQuery( KSelectQuery ) ) );	
    	CleanupClosePushL( table );	
    	User::LeaveIfError( iDb.Begin() );
    	User::LeaveIfError( table.EvaluateAll() );
    	table.FirstL();
    	if ( table.AtRow() )
    		{
    		table.GetL();
    		HBufC* colVal = table.ColDes( 2 ).AllocLC();		  
    		_LIT( KNoPeriode, "none" );
    		_LIT( K60SecPeriode,"60 Seconds" );
    		_LIT( K30MinPeriode,"30 Minutes" );
    		_LIT( K60MinPeriode,"1 Hour" );
    		if ( colVal->Des().Right( KNoPeriode().Length() ).Find( KNoPeriode ) == 0 )
    			{
    			//iPeriode = TTimeIntervalMicroSeconds32( 0 );		
    			//iTimerMonitor->StartL( TTimeIntervalMicroSeconds32( 0 ) );
    			}
    		else if ( colVal->Des().Right( K60SecPeriode().Length() ).Find( K60SecPeriode ) == 0 ) 
    			{
    			//iPeriode = TTimeIntervalMicroSeconds32( 60 * 1000000 ); //60 * one second == 60 seconds
    			iTimerMonitor->StartL( KActivityInterval60s );
    			}
    		else if ( colVal->Des().Right( K30MinPeriode().Length() ).Find( K30MinPeriode ) == 0 ) 
    			{
    			//iPeriode = TTimeIntervalMicroSeconds32( 1800 * 1000000 );
    			iTimerMonitor->StartL( KActivityInterval30Min );
    			}
    		else if ( colVal->Des().Right( K60MinPeriode().Length() ).Find( K60MinPeriode ) == 0 ) 						 				
    			{
    			//iPeriode = TTimeIntervalMicroSeconds32( 3600 * 1000000 );
    			iTimerMonitor->StartL( KActivityInterval60Min );
    			}	
    		CleanupStack::PopAndDestroy( colVal );						 
    		}//table.AtRow()	
    	User::LeaveIfError( iDb.Commit() );		
    	CleanupStack::PopAndDestroy( 1 ); //table
    			
    	Logger.Write( _L("CEngine::QueryOverPeriodeOfTime  ...End") );
    	}
    Well i think that iTimer.After does not work!

    Greetz
    Franky

  9. #9
    Registered User
    Join Date
    Feb 2007
    Location
    Tampere
    Posts
    370

    Re: Active object is not active

    Hi,

    What is the time interval that is being passed? Probably enabling prints in the StartL to print time interval too, would help trace error. Also if your engine code is still the same, your iTimerMonitor is initialized after, QueryOverPeriodeOfTimeL(), this is potentially a problem.
    Regards

    - MVP
    "Dare To Dream" - A.P.J.Kalam

  10. #10
    Regular Contributor
    Join Date
    Sep 2008
    Posts
    290

    Re: Active object is not active

    Hi,


    this is my log entry:


    Code:
    void CTimerMonitorAO::StartL(TTimeIntervalMicroSeconds32 aDelay)
    ...
    iLogger.WriteFormat( _L("Interval =%d"),  aDelay.Int() );
    ...

    the output at my log file is:
    "Interval=-694967296"



    my new engine.cpp...


    Code:
    #include "Engine.h"
    
    
    _LIT( KPath, "C:\\Data\\Sync.txt" );          
    const TTimeIntervalMicroSeconds32 KActivityInterval60s = 60 * 1000 * 1000; // 60s
    const TTimeIntervalMicroSeconds32 KActivityInterval30Min = 1800 * 1000 * 1000; // 30Min
    const TTimeIntervalMicroSeconds32 KActivityInterval60Min = 3600 * 1000 * 1000; // 60Min
    
    CEngine::CEngine()
    	{
    	iTimerMonitor = NULL;
    	iFileMonitor = NULL;
    	iPath = NULL;
    	iServerName = NULL;
    	}
    
    CEngine::~CEngine()
    	{
    	iDb.Close();
    	iFServSession.Close();
    	iDbSession.Close();
    	if( iTimerMonitor != NULL )
    		{
    		delete iTimerMonitor;
    		iTimerMonitor = NULL;
    		}
    	if( iFileMonitor != NULL )
    		{
    		delete iFileMonitor;
    		iFileMonitor = NULL;
    		}
    	if (iPath != NULL )
    		{
    		delete iPath;
    		iPath = NULL;
    		}
    	if (iServerName != NULL )
    		{
    		delete iServerName;
    		iServerName = NULL;
    		}
    	if (iUserName != NULL )
    		{
    		delete iUserName;
    		iUserName = NULL;
    		}
    	if (iPassword != NULL )
    		{
    		delete iPassword;
    		iPassword = NULL;
    		}
    	Logger.CloseLog();
    	Logger.Close();
    	}
    
    CEngine* CEngine::NewLC()
    	{
    	CEngine* self = new (ELeave) CEngine();
    	CleanupStack::PushL(self);
    	self->ConstructL();
    	return self;
    	}
    
    CEngine* CEngine::NewL()
    	{
    	CEngine* self = CEngine::NewLC();
    	CleanupStack::Pop(); // self;
    	return self;
    	}
    
    void CEngine::ConstructL()
    	{
    	
    	Logger.Connect();
    	Logger.CreateLog(_L("MyLogs"),_L("DeMonLog.txt"),EFileLoggingModeOverwrite);
    	
    	User::LeaveIfError( iFServSession.Connect() );
    	User::LeaveIfError( iDbSession.Connect() );
    	
    	_LIT(KStandardGobasDatabase, "C:\\Data\\MyDbs.db" );
    	if(BaflUtils::FileExists( iFServSession, KStandardGobasDatabase ) )
    		{
    		User::LeaveIfError( iDb.Open(iDbSession, KStandardGobasDatabase ) ); 		
    		}
    	//Just run only when database is open!!!!!!!!
    	
    	
    	QueryTCPConnectionDataL();
    	QueryUserDataL();
    	QueryAccessPointDataL();
    	
    	Logger.Write( _L("just reaching iTimerMonitor!") );
    	iTimerMonitor = CTimerMonitorAO::NewL( *this );
    	Logger.Write( _L("now set Periode!") );
    	QueryOverPeriodeOfTimeL();
    	//Logger.WriteFormat( _L("(Engine) Periode=%d"), iPeriode.Int() );
    	//iTimerMonitor->StartL( iPeriode );
    	Logger.Write( _L("iTimerMonitor ...started!") );
    	//This is the file to be watched...
    	iFileMonitor = CFileMonitorAO::NewL( *this, iFServSession , KPath().AllocL() );
    	Logger.Write( _L("iFileMonitor ...Start") );		
    	}
    
    
    void CEngine::QueryOverPeriodeOfTimeL()
    	{
    	Logger.Write( _L("CEngine::QueryOverPeriodeOfTime  ...Start") );
    	_LIT( KSelectQuery, "SELECT demandPeriode_Id, itemText FROM DemandPeriode WHERE demandPeriode_Id = 1");
    	RDbView table;
    	User::LeaveIfError( table.Prepare( iDb, TDbQuery( KSelectQuery ) ) );	
    	CleanupClosePushL( table );	
    	User::LeaveIfError( iDb.Begin() );
    	User::LeaveIfError( table.EvaluateAll() );
    	table.FirstL();
    	if ( table.AtRow() )
    		{
    		table.GetL();
    		HBufC* colVal = table.ColDes( 2 ).AllocLC();		  
    		_LIT( KNoPeriode, "none" );
    		_LIT( K60SecPeriode,"60 Seconds" );
    		_LIT( K30MinPeriode,"30 Minutes" );
    		_LIT( K60MinPeriode,"1 Hour" );
    		if ( colVal->Des().Right( KNoPeriode().Length() ).Find( KNoPeriode ) == 0 )
    			{
    			//iPeriode = TTimeIntervalMicroSeconds32( 0 );		
    			//iTimerMonitor->StartL( TTimeIntervalMicroSeconds32( 0 ) );
    			}
    		else if ( colVal->Des().Right( K60SecPeriode().Length() ).Find( K60SecPeriode ) == 0 ) 
    			{
    			//iPeriode = TTimeIntervalMicroSeconds32( 60 * 1000000 ); //60 * one second == 60 seconds
    			iTimerMonitor->StartL( KActivityInterval60s );
    			}
    		else if ( colVal->Des().Right( K30MinPeriode().Length() ).Find( K30MinPeriode ) == 0 ) 
    			{
    			//iPeriode = TTimeIntervalMicroSeconds32( 1800 * 1000000 );
    			iTimerMonitor->StartL( KActivityInterval30Min );
    			}
    		else if ( colVal->Des().Right( K60MinPeriode().Length() ).Find( K60MinPeriode ) == 0 ) 						 				
    			{
    			//iPeriode = TTimeIntervalMicroSeconds32( 3600 * 1000000 );
    			iTimerMonitor->StartL( KActivityInterval60Min );
    			}	
    		CleanupStack::PopAndDestroy( colVal );						 
    		}//table.AtRow()	
    	User::LeaveIfError( iDb.Commit() );		
    	CleanupStack::PopAndDestroy( 1 ); //table
    			
    	Logger.Write( _L("CEngine::QueryOverPeriodeOfTime  ...End") );
    	}
    
    //Handles events raised by FileMonitorAO
    void CEngine::FileMonitorStateL( TInt aState )
    	{
    	Logger.Write( _L("CEngine::FileMonitorStateL  ...Start") );
    	switch( aState )
    		{
    		case 1962:
    			{
    			//Dateimonitor beenden
    			
    
    			}
    			break;
    		}
    	delete iTimerMonitor;
    				iTimerMonitor = NULL;
    				
    				
    				QueryTCPConnectionDataL();
    				QueryUserDataL();
    				QueryAccessPointDataL();
    				
    				//Dateimonitor neu starten!!!!
    				iTimerMonitor = CTimerMonitorAO::NewL( *this );
    				QueryOverPeriodeOfTimeL();
    				//iTimerMonitor->StartL( iPeriode );
    				//Ip, Port Username,...
    	
    	Logger.Write( _L("CEngine::FileMonitorStateL  ...End") );
    	}
    
    //Handles events raised by TimerMonitorAO
    void CEngine::TimerMonitorStateL( TInt aState )
    	{
    	Logger.Write( _L("CEngine::TimerMonitorStateL  ...Start") );
    	switch( aState )
    		{
    		case 1:
    			break;
    		}
    	ConnectL();
    	//Do something with the socket!
    	Close();
    	Logger.Write( _L("CEngine::TimerMonitorStateL  ...End") );
    	}
    
    
    void CEngine::QueryTCPConnectionDataL()
    	{
    	Logger.Write( _L("CEngine::QueryTCPConnectionDataL  ...Start") );
    	_LIT( KSelectOptionQuery, "SELECT option_Id, servername, port FROM Option WHERE option_Id = 1");
    	RDbView table;
    	User::LeaveIfError( table.Prepare( iDb, TDbQuery( KSelectOptionQuery ) ) );
    	CleanupClosePushL( table );	
    	User::LeaveIfError( iDb.Begin() );	
    	User::LeaveIfError( table.EvaluateAll() );
    	table.FirstL();
    	if ( table.AtRow() )
    		{
    		table.GetL();
    		iServerName = table.ColDes( 2 ).Alloc();
    		iPort = table.ColInt( 3 );				  
    		}
    	User::LeaveIfError( iDb.Commit() );		
    	CleanupStack::PopAndDestroy( 1 );//table
    	Logger.Write( _L("CEngine::QueryTCPConnectionDataL  ...End") );
    	}
    		
    		
    void CEngine::QueryUserDataL()
    	{
    	Logger.Write( _L("CEngine::QueryUserDataL  ...Start") );
    	_LIT( KSelectUserQuery, "SELECT user_Id, username, password FROM User WHERE user_Id = 1");
    	RDbView table;
    	User::LeaveIfError( table.Prepare( iDb, TDbQuery( KSelectUserQuery ) ) );	
    	CleanupClosePushL( table );	
    	User::LeaveIfError( iDb.Begin() );	
    	User::LeaveIfError( table.EvaluateAll() );
    	table.FirstL();
    	if ( table.AtRow() )
    		{
    		table.GetL();
    		iUserName = table.ColDes( 2 ).Alloc();
    		iPassword = table.ColDes8( 3 ).Alloc();					
    		}
    	User::LeaveIfError( iDb.Commit() );
    	CleanupStack::PopAndDestroy( 1 ); //table
    	Logger.Write( _L("CEngine::QueryUserDataL  ...End") );
    	}			
    		
    	
    void CEngine::QueryAccessPointDataL()
    	{	
    	Logger.Write( _L("CEngine::QueryAccessPointDataL  ...Start") );
    	_LIT( KSelectIAPQuery, "SELECT accesspoints_Id, Iap_Id, itemText FROM AccessPoints WHERE accesspoints_Id = 1");
    	RDbView table;
    	User::LeaveIfError( table.Prepare( iDb, TDbQuery( KSelectIAPQuery ) ) );
    	CleanupClosePushL( table );	
    	User::LeaveIfError( iDb.Begin() );	
    	User::LeaveIfError( table.EvaluateAll() );	
    	table.FirstL();
    	if ( table.AtRow() )
    		{
    		table.GetL();					
    		iIap_Id = table.ColUint32( 2 );
    		}			
    	User::LeaveIfError( iDb.Commit() );
    	CleanupStack::PopAndDestroy( 1 ); //table
    	Logger.Write( _L("CEngine::QueryAccessPointDataL  ...End") );
    	}
    
    void CEngine::ConnectL()
    	{
    	Logger.Write( _L("CEngine::ConnectL  ...Start") );
    	TRequestStatus Status;
    	
    	User::LeaveIfError( iSocketServer.Connect() );
    	// Set the connection preferences
    	iConnection.Open( iSocketServer );
    	TCommDbConnPref prefs;
    	prefs.SetIapId( iIap_Id );
    	prefs.SetDialogPreference(ECommDbDialogPrefDoNotPrompt);
    	prefs.SetDirection(ECommDbConnectionDirectionOutgoing);
    	iConnection.Start( prefs );
    		
    	User::LeaveIfError( iSocket.Open( iSocketServer, 
    									  KAfInet, 
    									  KSockStream,
    									  KProtocolInetTcp,
    									  iConnection ) );
    		
    	iAddress.SetPort( iPort );
    	iAddress.Input( *iServerName );
    	iSocket.Connect( iAddress, Status );
    	User::WaitForRequest(  Status );	  
    	iConnection.Stop();
    				
    	Logger.Write( _L("CEngine::ConnectL  ...End") );
    	
    	}
    
    void CEngine::Close()
    	{
    	Logger.Write( _L("CEngine::Close()  ...Start") );
    	iSocket.Close();
    	iSocketServer.Close();
    	Logger.Write( _L("CEngine::Close()  ...End") );
    	}

    Greetz
    Franky

  11. #11
    Regular Contributor
    Join Date
    Mar 2009
    Posts
    58

    Re: Active object is not active

    P.S. To make your code smaller - in a destructor there's no need to have a check for for !=NULL before deleting something, and setting something to NULL after deleting it in a destructor is a waste. A literal waste for it will add unnecessary code to your ROM size and add CPU cycles, negligible yes, but when everybody does it thousands of times collectively thats thousands of unnecessary stuff.

  12. #12
    Regular Contributor
    Join Date
    Sep 2008
    Posts
    290

    Re: Active object is not active

    Hi,

    yes! My Engine class runs only while app runs! So my new destructor looks like this...

    Code:
    CEngine::~CEngine()
    	{
    	iDb.Close();
    	iFServSession.Close();
    	iDbSession.Close();
    		
    	delete iTimerMonitor;	
    	delete iFileMonitor;
    	delete iPath;
    	delete iServerName;
    	delete iUserName;
    	delete iPassword;
    	
    	Logger.CloseLog();
    	Logger.Close();
    	}

    Greetz
    Franky

  13. #13
    Regular Contributor
    Join Date
    Sep 2008
    Posts
    290

    Re: Active object is not active

    Hi,

    my problem is at this line...

    this code runs (means that my demon.exe is active....)
    Code:
    if ( QueryTimePeriodeDataL() )
    	{
    	iTimerMonitor = CTimerMonitorAO::NewL( *this );
    	iTimerMonitor->StartL( 60 * 1000 * 1000  );
    	}

    but his wont (means no demon process is active!)


    Code:
    if ( QueryTimePeriodeDataL() )
    	{
    	iTimerMonitor = CTimerMonitorAO::NewL( *this );
    	iTimerMonitor->StartL(  iPeriode );
    	}

    this is my code which sets iPeriode

    Code:
    TBool CEngine::QueryTimePeriodeDataL()
    	{
    	TBool Result;
    	_LIT( KSelectQuery, "SELECT demandPeriode_Id, itemText FROM DemandPeriode WHERE demandPeriode_Id = 1");
    	RDbView table;
    	User::LeaveIfError( table.Prepare( iDb, TDbQuery( KSelectQuery ) ) );	
    	CleanupClosePushL( table );	
    	User::LeaveIfError( iDb.Begin() );
    	User::LeaveIfError( table.EvaluateAll() );
    	table.FirstL();
    	if ( table.AtRow() )
    		{
    		table.GetL();
    		HBufC* colVal = table.ColDes( 2 ).AllocLC();		  
    		_LIT( KNoPeriode, "kein" );
    		_LIT( K60SecPeriode,"60 Sekunden" );
    		_LIT( K30MinPeriode,"30 Minuten" );
    		_LIT( K60MinPeriode,"1 Stunde" );
    		if ( colVal->Des().Right( KNoPeriode().Length() ).Find( KNoPeriode ) == 0 )
    			{
    			iPeriode = TTimeIntervalMicroSeconds32( 0 );
    			Result = EFalse;
    			}
    		else if ( colVal->Des().Right( K60SecPeriode().Length() ).Find( K60SecPeriode ) == 0 ) 
    			{
    			iPeriode = KActivityInterval60s;
    			Result = ETrue;
    			}
    		else if ( colVal->Des().Right( K30MinPeriode().Length() ).Find( K30MinPeriode ) == 0 ) 
    			{
    			iPeriode = KActivityInterval30Min;
    			Result = ETrue;
    			}
    		else if ( colVal->Des().Right( K60MinPeriode().Length() ).Find( K60MinPeriode ) == 0 ) 						 				
    			{
    			iPeriode = KActivityInterval60Min;	
    			Result = ETrue;
    			}	
    		CleanupStack::PopAndDestroy( colVal );						 
    		}//table.AtRow()	
    	User::LeaveIfError( iDb.Commit() );		
    	CleanupStack::PopAndDestroy( 1 ); //table
    	return Result;
    	}
    this is my StartL

    Code:
    void CTimerMonitorAO::StartL(TTimeIntervalMicroSeconds32 aDelay)
    	{
    	Cancel(); // Cancel any request, just to be sure
    	iTimeInterval = aDelay;
    	iState = EUninitialized;
    	iTimer.After(iStatus, aDelay); // Set for later
    	SetActive(); // Tell scheduler a request is active
    	}

    and this is my dekalration of iPeriode at Engine.h

    Code:
    ...
    Private:
    ...
    TTimeIntervalMicroSeconds32 iPeriode; 


    Greetz
    Franky

  14. #14
    Registered User
    Join Date
    Feb 2007
    Location
    Tampere
    Posts
    370

    Re: Active object is not active

    Hi Frank,

    So what is the curent problem now with the application? I am bit confused as to what your problem is now
    Regards

    - MVP
    "Dare To Dream" - A.P.J.Kalam

  15. #15
    Regular Contributor
    Join Date
    Sep 2008
    Posts
    290

    Re: Active object is not active

    Hi,



    i have a main application which starts my background app. My background app reads a database file and uses the content to (re)configure timer periode ...
    To do so my main application ( a GUI-App ) changes data in the database, write text into a file (C:\\data\\sync.txt). If this file is changed the file notifier will make the background app read again database content (a new timer periode)! When i make this
    Code:
    iTimerMonitor->StartL( 60 * 1000 * 1000  );
    my background app runs, but if i make this
    Code:
    iTimerMonitor->StartL(  iPeriode );
    it quits.

    So my attempt for later activity of my background app (therefore a console app without console stuff) it should stop the timer a start it again

    Code:
    void CEngine::FileMonitorStateL( TInt aState )
    	{
    	delete iTimerMonitor;
    	if ( QueryTimePeriodeDataL() )
    		{
    		iTimerMonitor = CTimerMonitorAO::NewL( *this );
    		iTimerMonitor->StartL( iPeriode );
    		}
    	}

    But the question is why does the background app show activity when i use "60 * 1000 * 1000" and stops if i use "IPeriode"

    Greetz
    Franky

Similar Threads

  1. Wrong implementation of active object
    By petr_kovar in forum Symbian
    Replies: 20
    Last Post: 2008-12-04, 00:28
  2. active object has an active object?
    By nir_e123 in forum Symbian
    Replies: 4
    Last Post: 2008-02-19, 20:14
  3. Active Object in EXE
    By Larry101 in forum Symbian
    Replies: 21
    Last Post: 2007-01-25, 07:57
  4. Active Object and CAknNumberQueryDialog
    By _angel in forum Symbian
    Replies: 4
    Last Post: 2004-03-31, 07:04
  5. synchronously Active Object to asynchronously Avtive Object
    By nextage in forum Symbian Networking & Messaging (Closed)
    Replies: 1
    Last Post: 2003-07-10, 08:08

Posting Permissions

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