×

Discussion Board

Results 1 to 7 of 7
  1. #1
    Regular Contributor
    Join Date
    Sep 2008
    Posts
    290

    implementation problem

    Hi,

    i want to get events from a timer and from a change (writing) to a file.

    So my implementaion of my active objects...

    Code:
    #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()
    	{
    	iFServSession.NotifyChange( ENotifyWrite, iStatus, *iPath );
    	CActiveScheduler::Add(this); // Add to scheduler
    	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 (iState == EUninitialized)
    		{
    		// Do something the first time RunL() is called
    		iState = EInitialized;
    		}
    	else if (iState != EError)
    		{
    		// Do something
    		}
    	iStateObserver.FileMonitorStateL( iState );
    	//Start watching!
    	Cancel();
    	iFServSession.NotifyChange( ENotifyWrite, iStatus, *iPath );
    	SetActive(); // Tell scheduler a request is active
    	}
    
    TInt CFileMonitorAO::RunError(TInt aError)
    	{
    	return aError;
    	}
    
    void CFileMonitorAO::StartL(TTimeIntervalMicroSeconds32 aDelay)
    	{
    
    	}

    and

    Code:
    #include "TimerMonitorAO.h"
    #include "Engine.h"
    
    CTimerMonitorAO::CTimerMonitorAO( MTimerMonitorStateObserver& aStateObserver ) :
    	CActive(EPriorityStandard),  // Standard priority
    	iStateObserver( aStateObserver )
    	{
    	// No implementation required
    	}
    
    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	
    	}
    
    void CTimerMonitorAO::DoCancel()
    	{
    	iTimer.Cancel();
    	}
    
    void CTimerMonitorAO::StartL(TTimeIntervalMicroSeconds32 aDelay)
    	{
    	Cancel(); // Cancel any request, just to be sure
    	iState = EUninitialized;
    	iTimeInterval = aDelay;
    	iTimer.After(iStatus, aDelay); // Set for later
    	SetActive(); // Tell scheduler a request is active
    	}
    
    void CTimerMonitorAO::RunL()
    	{
    	User::LeaveIfError( iStatus.Int() );
    	
    	if ( ! IsActive() )
    		{
    		iTimer.After(iStatus, iTimeInterval );
    		SetActive();
    		}
    	}
    
    TInt CTimerMonitorAO::RunError(TInt aError)
    	{
    	return aError;
    	}
    my header files...


    Code:
    #ifndef FILEMONITORAO_H
    #define FILEMONITORAO_H
    
    #include <e32base.h>	// For CActive, link against: euser.lib
    #include <e32std.h>		// For RTimer, link against: euser.lib
    #include <f32file.h> 
    #include <bautils.h>
    
    
    class MFileMonitorStateObserver
    	{
    public:
    	virtual void FileMonitorStateL( TInt aState ) = 0;
    	};
    
    
    class CFileMonitorAO : public CActive
    	{
    public:
    	// Cancel and destroy
    	~CFileMonitorAO();
    
    	// Two-phased constructor.
    	static CFileMonitorAO* NewL( MFileMonitorStateObserver& aStateObserver, 
    								 RFs& aFServSession,
    								 const HBufC* aPath );
    
    	// Two-phased constructor.
    	static CFileMonitorAO* NewLC( MFileMonitorStateObserver& aStateObserver, 
    								  RFs& aFServSession,
    								  const HBufC* aPath );
    
    public:
    	
    	// Function for making the initial request
    	void StartL(TTimeIntervalMicroSeconds32 aDelay);
    	MFileMonitorStateObserver& iStateObserver;
    	
    private:
    	// C++ constructor
    	CFileMonitorAO( MFileMonitorStateObserver& aStateObserver,
    					RFs& aFServSession,
    					const HBufC* aPath );
    
    	// Second-phase constructor
    	void ConstructL();
    
    private:
    	// From CActive
    	// Handle completion
    	void RunL();
    
    	// How to cancel me
    	void DoCancel();
    
    	// Override to handle leaves from RunL(). Default implementation causes
    	// the active scheduler to panic.
    	TInt RunError(TInt aError);
    
    private:
    	enum TFileMonitorAOState
    		{
    		EUninitialized, // Uninitialized
    		EInitialized, // Initalized
    		EError
    		// Error condition
    		};
    
    private:
    	TInt iState; // State of the active object
    	RFs& iFServSession; 
    	const HBufC* iPath;
    	};
    
    #endif // FILEMONITORAO_H
    and

    Code:
    #ifndef TIMERMONITOR_H
    #define TIMERMONITOR_H
    
    #include <e32base.h>	// For CActive, link against: euser.lib
    #include <e32std.h>		// For RTimer, link against: euser.lib
    
    
    class MTimerMonitorStateObserver
    	{
    public:
    	virtual void TimertMonitorStateL( TInt aState ) = 0;
    	};
    
    
    class CTimerMonitorAO : public CActive
    	{
    public:
    	// Cancel and destroy
    	~CTimerMonitorAO();
    
    	// Two-phased constructor.
    	static CTimerMonitorAO* NewL( MTimerMonitorStateObserver& iStateObserver );
    
    	// Two-phased constructor.
    	static CTimerMonitorAO* NewLC( MTimerMonitorStateObserver& iStateObserver );
    
    public:
    	// New functions
    	// Function for making the initial request
    	void StartL(TTimeIntervalMicroSeconds32 aDelay);
    	
    	//void SetLogger(RFileLogger& Logger );
    	MTimerMonitorStateObserver& iStateObserver;
    
    private:
    	// C++ constructor
    	CTimerMonitorAO( MTimerMonitorStateObserver& aStateObserver );
    
    	// Second-phase constructor
    	void ConstructL();
    
    private:
    	
    	void RunL();
    
    	void DoCancel();
    
    	TInt RunError(TInt aError);
    	
    	TTimeIntervalMicroSeconds32 iTimeInterval;
    	
    private:
    	enum TTimerMonitorState
    		{
    		EUninitialized, // Uninitialized
    		EInitialized, // Initalized
    		EError,
    		// Error condition
    		EConnecting,
    		EConnected
    		};
    
    private:
    	TInt iState; // State of the active object
    	RTimer iTimer; // Provides async timing service		
    	};
    
    #endif // TIMERMONITOR_H

    and then i defined an engine which controls my active objects


    Code:
    #include "TimerMonitorAO.h"
    #include "Engine.h"
    
    CTimerMonitorAO::CTimerMonitorAO( MTimerMonitorStateObserver& aStateObserver ) :
    	CActive(EPriorityStandard),  // Standard priority
    	iStateObserver( aStateObserver )
    	{
    	// No implementation required
    	}
    
    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	
    	}
    
    void CTimerMonitorAO::DoCancel()
    	{
    	iTimer.Cancel();
    	}
    
    void CTimerMonitorAO::StartL(TTimeIntervalMicroSeconds32 aDelay)
    	{
    	Cancel(); // Cancel any request, just to be sure
    	iState = EUninitialized;
    	iTimeInterval = aDelay;
    	iTimer.After(iStatus, aDelay); // Set for later
    	SetActive(); // Tell scheduler a request is active
    	}
    
    void CTimerMonitorAO::RunL()
    	{
    	User::LeaveIfError( iStatus.Int() );
    	
    	if ( ! IsActive() )
    		{
    		iTimer.After(iStatus, iTimeInterval );
    		SetActive();
    		}
    	}
    
    TInt CTimerMonitorAO::RunError(TInt aError)
    	{
    	return aError;
    	}

    and

    Code:
    #include "Engine.h"
    
    CEngine::CEngine()
    	{
    	// No implementation required
    	}
    
    CEngine::~CEngine()
    	{
    	iDb.Close();
    	iFServSession.Close();
    	iDbSession.Close();
    	}
    
    CEngine* CEngine::NewLC()
    	{
    	CEngine* self = new (ELeave) CEngine( *this );
    	CleanupStack::PushL(self);
    	self->ConstructL();
    	return self;
    	}
    
    CEngine* CEngine::NewL()
    	{
    	CEngine* self = CEngine::NewLC();
    	CleanupStack::Pop(); // self;
    	return self;
    	}
    
    void CEngine::ConstructL()
    	{
    	iFServSession.Connect();
    	iDbSession.Connect();
    	
    	iTimerMonitor = CTimerMonitorAO::NewLC( );
    	
    	
    	}
    
    
    void CEngine::FileMonitorStateL( TInt aState )
    	{
    	
    	}
    
    
    void CEngine::TimerMonitorStateL( TInt aState )
    	{
    	
    	}

    but my engine fails while compiling. I don't know how to declare the constructor.

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

    Re: implementation problem

    and call it at...

    Code:
    LOCAL_C void MainL()
    	{
    	//Logger.Connect();
    	//Logger.CreateLog(_L("MyLogs"),_L("DeMonLog.txt"),EFileLoggingModeOverwrite);
    	//Logger.Write( _L("DeMon Start") );
    	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);
    	
    	}
    Greetz
    Franky

  3. #3
    Nokia Developer Moderator
    Join Date
    Sep 2004
    Location
    Tampere, Finland
    Posts
    11,355

    Re: implementation problem

    We could of course pretend to be compilers and verify your code. But wouldn't it be easier for you to let us know what the reported error are, so that we focus on the right areas?
    -- Lucian

    If you are not yet a DVLUP member it is time to correct that mistake :) Click here to join: http://www.dvlup.com/lucian/Invite

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

    Re: implementation problem

    Hi,

    he problem is the line

    Code:
    CEngine* self = new (ELeave) CEngine( *this );
    the error is:
    Creation Time Description Resource Path Location Type
    1246828171744 illegal use of 'this' Engine.cpp DeMon/src line 27 C/C++ Problem


    Well i know that the call of CEngine or the declaration is wrong, but i don't know how to fix this.


    Greetz
    Franky

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

    Re: implementation problem

    "I don't know how to declare the constructor."

    What have you tried so far?
    Last edited by The Cynic; 2009-07-05 at 22:52.

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

    Thumbs up Re: implementation problem

    Hi,


    thanks for your replies!
    Yes i was confused about the compiler error. No i don't have a problem to create A and B and put it together. But it was my fault! So always read compiler error carefully get a cold drink these hot days and then...

    Code:
    class MTimerMonitorStateObserver
    	{
    public:
          virtual void TimertMonitorStateL( TInt aState ) = 0;
    	};
    check your deklaration. Erase the "t"

    put these stuff to Engine.cpp

    Code:
    ...
    CEngine::CEngine()
    	{
    	iTimerMonitor = NULL;
    	iFileMonitor = NULL;
    	iPath = 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;
    		}
    	}
    
    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()
    	{
    	iFServSession.Connect();
    	iDbSession.Connect();
    	//This is the file to be watched...
    	_LIT( KPath, "C:\\Data\\Config\\Worker.txt" );
    	iTimerMonitor = CTimerMonitorAO::NewL( *this );
    	iFileMonitor = CFileMonitorAO::NewL( *this, iFServSession , KPath().AllocL() );
    	}
    ...
    and it should work.



    Greetz
    Franky

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

    Re: implementation problem

    A couple of FYI's for you

    - there's no need to set something to NULL in the constructor of a CBase derived class, it's done automatically for you.
    - its pointless setting things to NULL in a class's destructor

    P.S.
    I must admit I was too lazy to look at your code to see if there is a problem, but I would recommend you have a look at

    iFileMonitor = CFileMonitorAO::NewL( *this, iFServSession , KPath().AllocL() );

    to see if KPath().AllocL() is a potential problem - the fact that a temporary HBufC is being allocated.

    But why are you doing that anyway, seems very strange.

Similar Threads

  1. Problem with CAknDoubleStyleListBox with a CAknSearchField
    By jjig in forum Symbian User Interface
    Replies: 2
    Last Post: 2009-09-17, 00:58
  2. Problem with eglSwapBuffers and heap corruption
    By greatape in forum Symbian Media (Closed)
    Replies: 2
    Last Post: 2007-05-24, 03:35
  3. netcards - Problem with opening adapter
    By kernj in forum Symbian Tools & SDKs
    Replies: 5
    Last Post: 2007-01-10, 08:56
  4. problem with the obex implementation of the 6230
    By vvvvv2k in forum Bluetooth Technology
    Replies: 5
    Last Post: 2005-04-21, 12:32
  5. Problem: S60 SDK for CW in PC with .NET
    By anttij in forum Carbide.c++ IDE and plug-ins (Closed)
    Replies: 1
    Last Post: 2005-02-28, 11:36

Posting Permissions

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