RContactDatabase and RThread problems
Hello, everybody.
I have problems with RThread.
I use next line to call function in separate thread:
[CODE]
TInt res = iHashingPHThread.Create(KPBHashingThread, PhoneBookChanged, KDefaultStackSize, NULL, (TAny*) this);
if (res == KErrNone)
{
iHashingPHThread.Resume();
}[/CODE]
This is my function:
[CODE]TInt CCommonStorage::PhoneBookChanged(TAny* pObj)
{
LOGF(_L("+ CCommonStorage::PhoneBookChanged()"));
CTrapCleanup* cleanupStack = CTrapCleanup::New();
const CContactIdArray *itemArray = storage->GetDataBase()->SortedItemsL(); // just return array with contacts
storage->GetABChecksum(itemArray);
delete cleanupStack;
cleanupStack = NULL;
return 0;
}
TBool CCommonStorage::GetABChecksum(const CContactIdArray *itemArray)
{
for (int i = 0; i < count; ++i)
{
TContactItemId itemID = (*itemArray)[i];
CContactItem *item = NULL;
item = pDatabase->ReadMinimalContactL(itemID); // exception cbase66
// do smth
}
return ret;
}
[/CODE]
Actually I cannot perform any operations with stack. Where is my mistake and what should I do to fix it?
Thank you.
Re: RContactDatabase and RThread problems
For the panic itself, the explanation is that instantiating CTrapCleanup does not start [I]using[/I] it. You need a TRAP/D for that.[CODE]TInt CCommonStorage::PhoneBookChanged(TAny* pObj)
{
LOGF(_L("+ CCommonStorage::PhoneBookChanged()"));
CTrapCleanup* cleanupStack = CTrapCleanup::New();
[COLOR="#FF0000"]TRAPD([/COLOR]err,
const CContactIdArray *itemArray = storage->GetDataBase()->SortedItemsL(); // just return array with contacts
storage->GetABChecksum(itemArray);
[COLOR="#FF0000"]);[/COLOR]
delete cleanupStack;
cleanupStack = NULL;
return 0;
}[/CODE]could be a minimal fix for this panic.
However note that it is absolutely not sure that a single contact database object could be shared between threads. My guess would be exactly that it can not be shared, and in this case you will need creating an other instance in the secondary thread.
Re: RContactDatabase and RThread problems
It helped. But now, when I' trying create new db I get CBase44 panic.
[CODE]TBool CCommonStorage::GetABChecksum(const CContactIdArray *itemArray)
{
CContactDatabase *DB = CContactDatabase::OpenL(); // panic
for (int i = 0; i < count; ++i)
{
TContactItemId itemID = (*itemArray)[i];
CContactItem *item = NULL;
item = DB->ReadMinimalContactL(itemID);
// do smth
}
return ret;
}[/CODE]
Re: RContactDatabase and RThread problems
Can you check the panic again, and write it exactly as it is shown ?
Re: RContactDatabase and RThread problems
Consider reading the documentation of that message, E32USER-CBase 44. Similarly to the Cleanup Stack, that other thing is also has to be created manually for a secondary thread. After creation, use Install, one of its static methods.