|
|
User login
Feeds |
Active Objects not executing (for IMEI number)
|
|||||
| Fri, 2004-12-10 00:12 | |
|
Hi all, I'm trying to use the third-party CTelephony library (a part of the Beta Series 80 SDK). Using code off of a Nokia website, I am getting the IMEI number of a phone. The request is asynchronous. Here is the code:
Code: TRequestStatus iStatus; CTelephony::TPhoneIdV1 iPhoneId; CTelephony* telephony = NULL; TRAPD(err2, telephony = CTelephony::NewL()); if (telephony) { if (pSerialNumber) { CTelephony::TPhoneIdV1Pckg phoneInfo(iPhoneId); telephony->GetPhoneId(iStatus, phoneInfo); // User::WaitForRequest(iStatus) will hang the device, so wait manually // int safety = 0; while(safety < 5000) { safety++; if (iStatus.Int() != KRequestPending) safety = 6000; // the following causes a KernExec 3 // CActiveScheduler::RunIfReady(err, CActive::EPriorityIdle); // doesn't work CCoeEnv::Flush(); } TPtrC theIMEI(iPhoneId.iSerialNumber); } } I should be able to use User::WaitForRequest(iStatus), but that simply hangs forever. I tried flushing the system with CCoeEnv::Flush(), still no avail. How can I get this to work? And I have no idea how RunIfReady could cause a Kern Exec 3, anybody out there ever experience this? One thing that may be of interest, this code is located in a DLL. At some point, when the control flow returns to the calling APP (I think right after a dialog is displayed), I get a E32USER-CBase 46 (stray signal). Sounds like the active object is finally executed, albeit too late. Has anyone run into a problem like this before? I've been working on it all day and I'm flustered beyond belief! |
|
Forum posts: 64
If yes, are you defining a local iStatus instead of using the iStatus Object defined in the CActive baseclass?
Forum posts: 149
No, the only active object is in the telephony class, that I presume is activated with the GetPhoneId call. The method you see above is not in an active object at all.
Forum posts: 42
I had the same problem with MobInfo.
(symbiandev.net: feedback.api / [MobInfo] CMobileInfo::GetIMSI(TMobileIMSI& aImsi, TRequestStatus& aStatus))
That api hangs too, if calling User::Wait...()
The only way is to "be" a ActiveObject.
You have to inherit from CActive and support a RunL() and all the other stuff.
A synchronous wait seems not be possible with MobInfo.
Don't know way, maybe a bug.
Perhaps it's the same feature in CTelephony
--
Tobias
www.HBufC.com
Tobias.Stoeger
Forum posts: 364
Is this code part of an app, exe, dll etc.?
If GetPhoneID() is using active objects and you don't have an active scheduler installed then it'll hang.
You're calling CActiveScuduler::RunIFReady() yet you say you're not using an active object, so what RunL are you trying to execute?
P.S.
What has flushing the window server buffer got to do with anything?
Forum posts: 149
Forum posts: 68
TPlpVariantMachineId imei;
PlpVariant::GetMachineIdL(imei);
Forum posts: 364
Yes if its an app there should be an active scheduler installed for you as part of the framework stuff.
You won't be able to force it.
I'm sorry I don't know why its not completing if you call User::WaitForRequest(), though doing it this way will cause your app to appear to hang anyway so you might want to consider using an active object anyway.
Forum posts: 16
//=============================================
// Filename: Phoneutils.h
//=============================================
#include <etel3rdparty.h>
/* Declare the client class */
class CIMEI : public CActive
{
public:
CIMEI();
// Construction
void ConstructL();
// Destruction
~CIMEI();
static CIMEI* NewL();
// Issue request: retrieve IMEI
void GetIMEI(TRequestStatus &aStatus);
// Cancel request
void DoCancel();
// Service completed request
void RunL();
private:
CTelephony* iTelephony; // telephony object we own
CTelephony::TPhoneIdV1 iV1;
CTelephony::TPhoneIdV1Pckg* iPkg;
TRequestStatus *iIMEIStatus;
public:
TBuf<50> retrievedIMEI;
};
/* Define the client class */
CIMEI::CIMEI() : CActive(EPriorityStandard) {}
CIMEI* CIMEI::NewL()
{
CIMEI* self =new(ELeave) CIMEI();
CleanupStack::PushL(self);
self->ConstructL();
CleanupStack::Pop(self);
return self;
}
void CIMEI::ConstructL()
{
iPkg = new (ELeave) CTelephony::TPhoneIdV1Pckg(iV1);
iTelephony = CTelephony::NewL();
CActiveScheduler::Add(this);
}
CIMEI::~CIMEI()
{
Cancel(); // if any request outstanding, calls DoCancel() to cleanup
delete iTelephony;
delete iPkg;
}
void CIMEI::GetIMEI(TRequestStatus& aStatus)
{
aStatus=KRequestPending;
iIMEIStatus = &aStatus;
iTelephony->GetPhoneId( iStatus, *iPkg );
SetActive();
CActiveScheduler::Start();
}
void CIMEI::RunL()
{
if ( (iStatus == KErrNone) )
{
retrievedIMEI = (*iPkg)().iSerialNumber; // Read IMEI from package buffer
}
CActiveScheduler::Stop();
//Signal complete and pass back result of CActive object
User::RequestComplete(iIMEIStatus,iStatus.Int());
}
void CIMEI::DoCancel()
{
Cancel();
}
//=============================================
// Filename: testapp.cpp
//=============================================
#include "Phoneutils.h"
void CTestApp::test()
{
CIMEI* imei = CIMEI::NewL();
CleanupStack::PushL(imei);
TRequestStatus status;
imei->GetIMEI(status);
// wait for request to complete
User::WaitForRequest(status);
// Check if IMEI retrieved correctly
if (status==KErrNone)
{
TBuf<50> imeistr(imei->retrievedIMEI);
CEikonEnv::Static()->InfoWinL(_L("IMEI:"),imeistr);
}
else
CEikonEnv::Static()->InfoWinL(_L("IMEI:"),_L("Error retrieving IMEI"));
CleanupStack::PopAndDestroy();
}
Forum posts: 4
I don't know why User::WaitForRequest(iStatus); isn't working, but I think I see a few problems with doing the RunIfReady.
The active scheduler is a means of cooperative multitasking, which means you need to give the active scheduler some time to run. By calling RunIfReady repeatedly, your request will never complete because the control never returns to the active scheduler for processing requests. You can use User::WaitForAnyRequest() (which might have the same problems as User::WaitForRequest(iStatus)
Anyway, I think that's how this works. I've been using a WaitForAnyRequest/RunIfReady loop in a totally different application and I haven't found any problems with doing this.
Good luck, I hope you find a solution.
TnyLtSprGy
Forum posts: 47
Hi,
where or at what point of my application can I use this?
It is e.g working perfectly in AppUI::HandleCommandL(), but never returns when called in AppUI::ConstructL()
Regards
lkz633