/**
Auxilary function should be called only when we need to generate hash values from the screen and returns its hex format.
@param aHexString the output MD5 hash hex string obtained from iBitmapDevice
*/
EXPORT_C void CTHashReferenceImages::GenerateHashAndReturnInHexFormatL(TDes &aHexString)
	{
	TInt bufLen = CFbsBitmap::ScanLineLength(iBitmapDevice->SizeInPixels().iWidth, iBitmapDevice->DisplayMode());
	RBuf8 buff;
	buff.CreateL(bufLen);
	CleanupClosePushL(buff);	
	CMD5 *md = CMD5::NewL();
	CleanupStack::PushL(md);
	for (TPoint pos(0, 0); pos.iY < iBitmapDevice->SizeInPixels().iHeight; pos.iY++)
		{
		iBitmapDevice->GetScanLine(buff,pos,iBitmapDevice->SizeInPixels().iWidth,iBitmapDevice->DisplayMode());
		md->Update(buff);
		}

	TBuf8<KLengthOfHashValue> hashString;
	//md will be reset after calling CMD5::Final() as Final will call Reset.
	hashString.Copy(md->Final());
	aHexString.Zero();

	for(TInt icount=0; icount < hashString.Length(); icount++)
		{
		aHexString.AppendNumFixedWidth(hashString[icount], EHex, 4);
		}
	CleanupStack::PopAndDestroy(2, &buff);
	}
// ---------------------------------------------------------------------------
// CPresenceXDM::GetUniqueRuleId()
// ---------------------------------------------------------------------------
//    
void CPresenceXDM::GetUniqueRuleId(TDes& aRuleId)
    {
	OPENG_DP(D_OPENG_LIT( " CPresenceXDM::GetUniqueRuleId" ));
    aRuleId.Copy(KPresRuleIDPrefix);
    TInt myNumber;

    // make sure that newly created rule id doesnt exist in the document
    while (IsRuleExist(aRuleId))
        {
        aRuleId.Delete(KPresRuleIDPrefixLength, KPresRuleIDNumLength);
        myNumber = Math::Random() - KPresRuleIdCalc;
        aRuleId.AppendNumFixedWidth(myNumber,EDecimal,KPresRuleIDNumLength);
        }
    OPENG_DP(D_OPENG_LIT( "     aRuleId = %S" ), &aRuleId);
    }