#ifndef GXY_IMEI_H
#define GXY_IMEI_H
#ifdef EKA2
#include <etel3rdparty.h>
typedef TBuf<CTelephony::KPhoneSerialNumberSize> TMBookMachineId;
#else
#include <Plpvariant.h>
typedef TPlpVariantMachineId TMBookMachineId;
#endif
#include <e32base.h>
class MBookIMEI
#ifdef EKA2
: public CActive
#endif
{
public:
static void GetIMEI(TMBookMachineId& aMachineId);
#ifdef EKA2
private:
MBookIMEI();
// Construction
void ConstructL();
// Destruction
~MBookIMEI();
static MBookIMEI* NewL();
// Issue request: retrieve IMEI
void RequestIMEI(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;
TMBookMachineId retrievedIMEI;
#endif
};
#endif
///==================================================================///
//
//====================================================
//
#include "MBookIMEI.h"
void MBookIMEI::GetIMEI(TMBookMachineId& aMachineId)
{
#ifdef SERIES60_3RD
MBookIMEI* imei = MBookIMEI::NewL();
CleanupStack::PushL(imei);
TRequestStatus status;
imei->RequestIMEI(status);
// wait for request to complete
User::WaitForRequest(status);
// Check if IMEI retrieved correctly
if (status==KErrNone)
{
aMachineId = imei->retrievedIMEI;
}else
{
}
CleanupStack::PopAndDestroy();
#else
PlpVariant::GetMachineIdL(aMachineId);
#endif
}
#ifdef SERIES60_3RD
MBookIMEI::MBookIMEI() : CActive(EPriorityStandard) {}
MBookIMEI* MBookIMEI::NewL()
{
MBookIMEI* self =new(ELeave) MBookIMEI();
CleanupStack::PushL(self);
self->ConstructL();
CleanupStack::Pop(self);
return self;
}
void MBookIMEI::ConstructL()
{
iPkg = new (ELeave) CTelephony::TPhoneIdV1Pckg(iV1);
iTelephony = CTelephony::NewL();
CActiveScheduler::Add(this);
}
MBookIMEI::~MBookIMEI()
{
Cancel(); // if any request outstanding, calls DoCancel() to cleanup
delete iTelephony;
delete iPkg;
}
void MBookIMEI::RequestIMEI(TRequestStatus& aStatus)
{
aStatus=KRequestPending;
iIMEIStatus = &aStatus;
iTelephony->GetPhoneId( iStatus, *iPkg );
SetActive();
CActiveScheduler::Start();
}
void MBookIMEI::RunL()
{
if ( (iStatus == KErrNone) )
{
retrievedIMEI.Append(iV1.iSerialNumber); // Read IMEI from package buffer
}
CActiveScheduler::Stop();
//Signal complete and pass back result of CActive object
User::RequestComplete(iIMEIStatus,iStatus.Int());
}
void MBookIMEI::DoCancel()
{
Cancel();
}
#endif