Multi threading Issue with CActive

Login to reply to this topic.
Wed, 2006-04-19 12:52
Joined: 2005-10-10
Forum posts: 37
Hi all,

I'm developing an application which uses the MobInfo API.

I'm threading this class using CActive.  The problem is that I get Kern Exec - 3 whenever i try a File Write operation in the RunL() function.

How do i resolve this???

Please help me out on this...

Thanks...

The Cruise is on...


Wed, 2006-04-19 14:54
Joined: 2004-05-24
Forum posts: 982
Re: Multi threading Issue with CActive
Kern Exec 3 stands for unhandled exception occured...so it's not necesary from AO

pirosl

Wed, 2006-04-19 17:06
Joined: 2005-10-10
Forum posts: 37
Re: Multithreading of Etel and MobInfo Issue with CActive
i understand that pirosl...

i guess i forgot to mention that i get Error Reason 42 also... This error number as per SDL is raised for the CActiveScheduler.  It talks of a Stray Signal.

Anyways, I would like to rephrase my question once again...

I'm writing a UIQ application which would do these things:

1.  I want a thread / Active Object running which will monitor the Etel Server for an Incoming / Outgoing call. 
>>>This I'm successful in coding...

2.  Once an Incoming / Outgoing call is attended, i want to start another thread / AO which would link to the MobInfo library and extract network parameters like MCC, MNC, LAC ID etc...

3.  These parameters are to be written into a file say NetworkLog.txt...

I'm trying to on a very broad perspective, trying to implement Celltrack kind of functionality only during the period of Incoming / Outgoing calls...

What I'm able to do is to create 1 UIQ app ui class where this is happening individually on 2 menu selections...

When i try to put them together... I'm facing errors 42, 71 and Kern Exec - 3.

How do you people suggest I do the threading / active object scheduling of this app???

Eventually i want this to be made into a Dll / Exe which will run on boot and keep monitoring continuously...

I'm developing on UIQ 2.1 for Sony Ericsson P900.

I would love to see some suggestions on having this run neatly...

Thanks...

The Cruise is on...

Wed, 2006-04-19 17:30
Joined: 2004-05-24
Forum posts: 982
Re: Multi threading Issue with CActive
Probably one way to achieve your problem is:
have 2 ao....the first one issue a request to monitor the phone. When the request is complete (eg. incoming/outgoing call) the ao's run method is called....from this method your second ao will issue a request....at completion its run method will be invoked.

Have i missed smth?

If you error is EUser42, it is raised by SetActive....and the problem is that you want to set as active an ao which is already active......so check again your code.

pirosl

Wed, 2006-04-19 23:48
Joined: 2005-10-10
Forum posts: 37
Re: Multi threading Issue with CActive
Hi priosl,

I've posted the code file that i had written previous to our talk... This is causing a Kern Exec - 3 Error...  This error too comes only during closing the appilcation...

The Text file is created but Write Fails...

What am I doing Wrong over here???

Code:
/*
* ============================================================================
*  Name     : Phoneobserver.cpp
*  Part of  : Callengine
*  ===========================================================================
*/

//INCLUDES

#include <e32base.h>

#include <e32std.h>

#include <etel.h>

#include "CallEngine.h"

#include "phoneobserver.h"

#include <f32file.h>
#include <s32file.h>


#ifndef __WINS__

_LIT(KLog_try2, "c:\\Log_try2.txt");

#else

        _LIT(KLog_try2, "c:\\Log_try2.txt");
#endif


// ---------------------------------------------------------
// CPhoneObserver::CPhoneObserver()
// C++ default constructor
// ---------------------------------------------------------
CPhoneObserver::CPhoneObserver(): CActive(EPriorityStandard)
{
}

// ---------------------------------------------------------
// CPhoneObserver::~CPhoneObserver()
// C++ destructor
// ---------------------------------------------------------
CPhoneObserver::~CPhoneObserver()
{
Cancel();
}


// ---------------------------------------------------------
// CPhoneObserver::NewL()
// Two phase constructor
// ---------------------------------------------------------
CPhoneObserver* CPhoneObserver::NewL(CCallEngineAppUi* aAppUi, RLine* aLine)
{
    CPhoneObserver* self = NewLC(aAppUi, aLine);
    CleanupStack::Pop(self);
    return self;
}

// ---------------------------------------------------------
// CPhoneObserver::NewLC()
// ---------------------------------------------------------
CPhoneObserver* CPhoneObserver::NewLC(CCallEngineAppUi* aAppUi, RLine* aLine)
{
    CPhoneObserver* self = new (ELeave) CPhoneObserver();
    CleanupStack::PushL(self);
    self->ConstructL(aAppUi, aLine);
    self->Start();
    return self;
}

// ---------------------------------------------------------
// CPhoneObserver::RunL()
// Called by active object framework when line event occurs
// ---------------------------------------------------------
void CPhoneObserver::RunL()
{
if (iStatus.Int() == KErrNone)
{
if (iLineStatus == RCall::EStatusRinging)
{

{
RFs fileSession;
User::LeaveIfError(fileSession.Connect());
CleanupClosePushL(fileSession);

RFile file;

TBuf8<30> KWriteDat1;
KWriteDat1=iStatus.Int();

file.Create(fileSession,KLog_try2,EFileWrite|EFileRead );
CleanupClosePushL(file);

file.Write(KWriteDat1);

CleanupStack::PopAndDestroy();
CleanupStack::PopAndDestroy();
}

}

else if (iLineStatus == RCall::EStatusAnswering)

{
{
RFs fileSession;
User::LeaveIfError(fileSession.Connect());
CleanupClosePushL(fileSession);

RFile file;

TBuf8<30> KWriteDat;
KWriteDat=iStatus.Int();

file.Create(fileSession,KLog_try2,EFileWrite|EFileRead );
CleanupClosePushL(file);

file.Write(KWriteDat);

CleanupStack::PopAndDestroy();
CleanupStack::PopAndDestroy();
}

}

Start();
}


else
{
Cancel();
}
}


// ---------------------------------------------------------
// CPhoneObserver::RunError()
// Called by active object framework when error occurs
// ---------------------------------------------------------

TInt CPhoneObserver::RunError(TInt Error)
{
return Error;
}


// ---------------------------------------------------------
// CPhoneObserver::DoCancel()
// Cancels active objects callback request
// ---------------------------------------------------------

void CPhoneObserver::DoCancel()
{
iLine -> NotifyStatusChangeCancel();
}


// ---------------------------------------------------------
// CPhoneObserver::ConstructL()
//
// ---------------------------------------------------------

void CPhoneObserver::ConstructL(CCallEngineAppUi* aAppUi, RLine* aLine)
{
iAppUi = aAppUi;
iLine = aLine;

    CActiveScheduler::Add(this);
}


// ---------------------------------------------------------
// CPhoneObserver::Start()
// Active object is activated
// ---------------------------------------------------------

void CPhoneObserver::Start()
{
Cancel();
iLine -> NotifyStatusChange(iStatus, iLineStatus);
SetActive();
}

// ---------------------------------------------------------
// CPhoneObserver::Deactivate()
// Active object is canceled outside of this class.
// ---------------------------------------------------------
void CPhoneObserver::Deactivate()
{
DoCancel();
}
   
// End of File

The Cruise is on...

Thu, 2006-04-20 06:37
Joined: 2005-02-12
Forum posts: 98
Re: Multi threading Issue with CActive
Just a Suggestion Try to use following

KWriteDat1.Copy(_L("Status="));
KWriteDat1.AppendNum(iStatus.Int());   
AddDebugMessage(KWriteDat1);   


void YourClass::AddDebugMessage(const TDesC& aMessage)
{
    TBuf8<200>buf8;
    buf8.Copy(aMessage);
    TFileName iFullPath ;
    iFullPath.Append(_L("C:\\debug.txt"));
    RFs iFs;
    RFile myFile;
    User::LeaveIfError(iFs.Connect());
    if(!BaflUtils::FileExists(iFs,iFullPath))
        User::LeaveIfError(myFile.Create(iFs,iFullPath,EFileWrite));
    else
        User::LeaveIfError(myFile.Open(iFs,iFullPath,EFileWrite));

    TInt endpos;
    myFile.Size(endpos);
    myFile.Seek(ESeekStart,endpos);
    myFile.Write(endpos,buf8);
    myFile.Close();
    iFs.Close();
}

Thu, 2006-04-20 10:14
Joined: 2004-05-24
Forum posts: 982
Re: Multi threading Issue with CActive
So ashwinmt...can you please let us know where do you get the error exactly....or when?

pirosl

Thu, 2006-04-20 12:51
Joined: 2005-10-10
Forum posts: 37
Re: Multi threading Issue with CActive
Hi priosl...


I've sorted out all the errors as per the ideas you gave yesterday.

Now i've got only one issue... The network data is not getting written to the file....

This has caught up most of the time today...

Do help me on this....

The Cruise is on...

Thu, 2006-04-20 12:55
Joined: 2004-05-24
Forum posts: 982
Re: Multi threading Issue with CActive
Do you get any error there? Or your app terminates with success but there is nothing in file?

pirosl

Thu, 2006-04-20 15:12
Joined: 2005-10-10
Forum posts: 37
Re: Multi threading Issue with CActive
My App terminates with success but there's nothing in the file... Also, in the menu item, if i click on CallObserve Option twice, it crashes with error number 11.

How do i resolve both the issues

The Cruise is on...

Thu, 2006-04-20 15:29
Joined: 2004-05-24
Forum posts: 982
Re: Multi threading Issue with CActive
Are you sure you're closing and releasing the file after you write in it?

pirosl

Thu, 2006-04-20 16:24
Joined: 2005-10-10
Forum posts: 37
Re: Multi threading Issue with CActive
Yes...

THis is my file writing code...

Code:
void CCallEngineAppUi::Temp_Write()
{
RFs fileSession;
RFile file;

if(!BaflUtils::FileExists(fileSession,KLog_try3))
{
User::LeaveIfError(file.Create(fileSession,KLog_try3,EFileWrite));
CleanupClosePushL(fileSession);
}
else
{
User::LeaveIfError(file.Open(fileSession,KLog_try3,EFileWrite));
CleanupClosePushL(file);
}
file.Write(iAppView->Nw_Buf);

CleanupStack::PopAndDestroy();
CleanupStack::PopAndDestroy();
}

Tell me where i'm wrong.....

The Cruise is on...

Thu, 2006-04-20 16:44
Joined: 2004-05-24
Forum posts: 982
Re: Multi threading Issue with CActive
When closing a file you have written to, you should ensure that data is committed to the file by invoking RFile::Flush

pirosl

Fri, 2006-04-21 06:15
Joined: 2005-02-12
Forum posts: 98
Re: Multi threading Issue with CActive
Check that your buffer is not empty like this
if(buffer.Length()==0)
file.Write(_L8("Empty Buffer"));
Fri, 2006-04-21 07:17
Joined: 2005-10-10
Forum posts: 37
Re: Multi threading Issue with CActive
I checked the buffer.Length()

It does not write anything..... even thougth the buffer has data...

Even if the buffer is actually empty, it's gotta write the _L8("Empty Buffer")...

Thats not happening too...

The file's perfectly created.... I have a file called NwLog.txt in C drive but it has no data on it...

I'm having a vague guess that this is happening cause of some mixup in my active scheduler code...  But i'm not too sure about this as the whole application runs very smoothly and doesnt throw panics or errors at any point of time during it's run...

Can someone tell me what's happening???

The Cruise is on...

Fri, 2006-04-21 09:42
Joined: 2004-09-14
Forum posts: 140
Re: Multi threading Issue with CActive
Please consult the documentation for RFile::Create.

If the file fails to be created then the file handle will not be valid.

I suggest you check the return code from file.Create.

Paul Todd

  • Login to reply to this topic.