Read-only archive of the All About Symbian forum (2001–2013) · About this archive

problem in Active objects...

0 replies · 1,976 views · Started 20 May 2005

Hi,
I have developed a programme which uses Active object class.
I have made a child class of CActive class.
Problem is that i am instantiating this child class in a JNI method. now i have to make that JNI method to wait untill that request from active object to be replied in RunL() method because I want to return that value from that JNI method. but JNI method returns immidiately after calling CActive`s child class request method in my case Start() and I am unable to get that value back to java code. I have also tried with User::WaitForRequest() and User::WaitForAnyRequest but syatems halts in this case.I want calling method to wait untill request is completed and return value is sent. please tell me the solution and whether Callback method should be used here ad if yes could somebody tell me from where can i get examples of callback method.

Here is the CPP code if it help some.

extern " C"
{
#include " Test.h" // generated by javah

}
class CSActive : public CActive
{
public:
static CSActive* NewL();
CSActive();
~CSActive();
// Request
void Start();
TMobileIMSI ShowText();

private:
// from CActive
void RunL();
void DoCancel();
// Utility
private:
// Member variables
// Pointers elsewhere
CMobileInfo* mi;
TMobileIMSI imsi;
int state;
};

jstring IMsiL(JNIEnv* aJNI)
{
CActiveScheduler* csch=new(ELeave) CActiveScheduler();
CActiveScheduler::Install(csch );

CSActive* iCSActive = CSActive::NewL();
iCSActive-> Start();
// User::WaitForRequest(iCSActive-> iStatus); // wait for request to complete
TBuf< 50> buf;
buf.Append(_L(" IMSI: " ));
buf.Append(iCSActive-> ShowText());

return aJNI-> NewString(buf.Ptr(),6);
}
JNIEXPORT jstring JNICALL Java_Test_IMsi(JNIEnv* aJNI, jclass /*cls*/)
{
jstring str = NULL;
TRAPD(err, str = IMsiL(aJNI));
if(!err) return str;
else return NULL;
}
CSActive* CSActive::NewL()
{
CSActive* self=new(ELeave) CSActive;
return self;
}
CSActive::CSActive() : CActive(0)
{
mi = CMobileInfo::NewL();
CActiveScheduler::Add(this);
}

CSActive::~CSActive()
{
Canc el();
delete mi;
}

void CSActive::Start()
{
_LIT(KMobinfoPanic, " Mobinfo panic" );
__ASSERT_ALWAYS(!IsActive(), User::Panic(KMobinfoPanic, 1));

RNotifier notifier;
int err = notifier.Connect();
notifier.InfoPrint(_L(" in start " ));

state = 1;
mi-> GetIMSI(imsi, iStatus);
notifier.InfoPrint(_L(" After Request " ));

SetActive();
notifier.InfoPrint(_L(" After Set Active " ));
notifier.Close();
}
void CSActive::RunL()
{
RNotifier notifier;
int err = notifier.Connect();
notifier.InfoPrint(_L(" in RunL " ));
notifier.Close();

if(state == 1)
{
ShowText();
}
}
void CSActive:😃oCancel()
{
}

TMobileIMSI CSActive::ShowText()
{

RNotifier notifier;
int err = notifier.Connect();
TBuf< 50> buf1;
buf1.Append(_L(" IMSI: " ));
buf1.Append(imsi);
notifier.InfoPrint(buf 1);
notifier.Close();

return imsi;
}

furthermore if somebody send me code examples of using Active object.

Thanx
Toseef