Beispiel #1
0
PRFloat64 getVariance(VarianceState* inVariance)
/*
**  Determine the variance based on the given state.
*/
{
    PRFloat64 retval = 0.0;

    if(NULL != inVariance && 1 < inVariance->mCount)
    {
        PRFloat64 count;
        PRFloat64 squaredSum;
        PRFloat64 avg;
        PRFloat64 squaredAvg;
        PRInt64 isquaredSum;

        /*
        **  Avoids a compiler error (not impl) under MSVC.
        */
        isquaredSum = inVariance->mSquaredSum;

        count = (PRFloat64)inVariance->mCount;
        LL_L2F(squaredSum, isquaredSum);

        avg = getAverage(inVariance);
        squaredAvg = avg * avg;

        retval = (squaredSum - (count * squaredAvg)) / (count - 1.0);
    }

    return retval;
}
Beispiel #2
0
PRFloat64 getAverage(VarianceState* inVariance)
/*
**  Determine the mean/average based on the given state.
*/
{
    PRFloat64 retval = 0.0;

    if(NULL != inVariance && 0 < inVariance->mCount)
    {
        PRFloat64 count;
        PRFloat64 sum;
        PRInt64 isum;

        /*
        **  Avoids a compiler error (not impl) under MSVC.
        */
        isum = inVariance->mSum;

        count = (PRFloat64)inVariance->mCount;
        LL_L2F(sum, isum);

        retval = sum / count;
    }

    return retval;
}
// this is a utility function
void nsAbPalmHotSync::ConvertAssignPalmIDAttrib(PRUint32 id, nsIAbMDBCard * card)  
{ 
    PRInt64 l;
    LL_UI2L(l, id);
    PRFloat64 f;
    LL_L2F(f, l);
    char buf[128];
    PR_cnvtf(buf, 128, 0, f);
    card->SetAbDatabase(mABDB);
    card->SetStringAttribute(CARD_ATTRIB_PALMID,NS_ConvertASCIItoUTF16(buf).get());
}
Beispiel #4
0
//
// Native method FileGetSize
//
JSBool PR_CALLBACK
InstallFileOpFileGetSize(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval)
{
  nsInstall *nativeThis =
    GetNativeThis(cx, obj, argv);
  if (!nativeThis)
    return JS_FALSE;

  PRInt64     nativeRet;
  JSObject *jsObj;
  nsInstallFolder *folder;

  *rval = INT_TO_JSVAL(nsInstall::UNEXPECTED_ERROR);

  //  public int FileGetSize (String NativeFolderPath);

  if (argc == 0 || argv[0] == JSVAL_NULL || !JSVAL_IS_OBJECT(argv[0])) //argv[0] MUST be a jsval
  {
    *rval = INT_TO_JSVAL(nsInstall::INVALID_ARGUMENTS);
    return JS_TRUE;
  }

  jsObj = JSVAL_TO_OBJECT(argv[0]);

  if (!JS_InstanceOf(cx, jsObj, &FileSpecObjectClass, nsnull))
  {
    *rval = INT_TO_JSVAL(nsInstall::INVALID_ARGUMENTS);
    return JS_TRUE;
  }

  folder = (nsInstallFolder*)JS_GetPrivate(cx, jsObj);

  if(!folder || NS_OK != nativeThis->FileOpFileGetSize(*folder, &nativeRet))
  {
    return JS_TRUE;
  }
   
  PRFloat64 f; /* jsdouble's *are* PRFloat64's */
  
  LL_L2F( f, nativeRet ); /* make float which is same type for js and nspr (native double) */
  JS_NewDoubleValue( cx, f, rval );
  
  return JS_TRUE;
}
nsresult nsAbPalmHotSync::UpdateMozABWithPalmRecords()
{
    if(!mInitialized || !mABDB || !mDBOpen)
        return NS_ERROR_NOT_INITIALIZED;

    nsresult rv = NS_OK;

    for(PRInt32 i=mPalmRecords.Count()-1; i >=0;  i--) 
    {
        nsABCOMCardStruct * palmRec = (nsABCOMCardStruct *)mPalmRecords.ElementAt(i);
        nsAbIPCCard ipcCard(palmRec, PR_FALSE);

        char recordIDBuf[128]; 
        PRInt64 l;
        LL_UI2L(l, palmRec->dwRecordId);
        PRFloat64 f;
        LL_L2F(f, l);
        PR_cnvtf(recordIDBuf, 128, 0, f);

        // if the card already exists
        nsCOMPtr<nsIAbCard> existingCard;
        rv = mABDB->GetCardFromAttribute(nsnull, CARD_ATTRIB_PALMID,
					 nsDependentCString(recordIDBuf),
					 PR_FALSE, getter_AddRefs(existingCard));
        if (!existingCard)
        {
          rv = mABDB->GetCardFromAttribute(nsnull, CARD_ATTRIB_DISPLAY,
					   nsDependentCString((const char *) palmRec->displayName),
					   PR_FALSE, getter_AddRefs(existingCard));
          // if card with this display name exists, just continue; But, we should make sure
          // it's associated with the palm card going forward, so set the palmid.
          if (NS_SUCCEEDED(rv) && existingCard)
          {
            nsCOMPtr<nsIAbMDBCard> dbCard = do_QueryInterface(existingCard);

            dbCard->SetStringAttribute(CARD_ATTRIB_PALMID, NS_ConvertASCIItoUTF16(recordIDBuf).get());
            continue;
          }

        }
        if(NS_SUCCEEDED(rv) && existingCard) 
        {
            // Archived is the same as deleted in palm.
            if(palmRec->dwStatus & ATTR_DELETED || palmRec->dwStatus & ATTR_ARCHIVED) 
            {
                mABDB->DeleteCard(existingCard, PR_FALSE, nsnull);
                continue;
            }
            if(palmRec->dwStatus & ATTR_NEW)
                continue;
            if(palmRec->dwStatus & ATTR_MODIFIED) 
            {
                PRBool isEqual=PR_FALSE;
                ipcCard.Equals(existingCard, &isEqual);
                if(isEqual)
                    continue;
                else 
                {
                    existingCard->Copy(&ipcCard);
                    rv = mABDB->EditCard(existingCard, PR_FALSE, nsnull);
                    continue;
                }
            }
        }

        nsCOMPtr<nsIAbMDBCard> dbCard;
        dbCard = do_CreateInstance(NS_ABMDBCARD_CONTRACTID, &rv);
        if(NS_FAILED(rv))
            continue;

        nsCOMPtr<nsIAbCard> newCard;
        newCard = do_QueryInterface(dbCard, &rv);
        if(NS_FAILED(rv)) 
            continue;

        rv = newCard->Copy(&ipcCard);
        if(NS_FAILED(rv)) 
            continue;

        // if the card does not exist
        if((ipcCard.GetStatus() == ATTR_NEW)
            ||(ipcCard.GetStatus() == ATTR_MODIFIED)
            || (ipcCard.GetStatus() == ATTR_NONE)) 
        {
            PRUint32 modTimeInSec;
            PRTime2Seconds(PR_Now(), &modTimeInSec);
            ipcCard.SetLastModifiedDate(modTimeInSec);
            rv = mABDB->CreateNewCardAndAddToDB(newCard, PR_FALSE, nsnull);
            if(NS_SUCCEEDED(rv)) 
            {
                // now set the attribute for the PalmRecID in the card in the DB
                dbCard->SetAbDatabase(mABDB);
                dbCard->SetStringAttribute(CARD_ATTRIB_PALMID, NS_ConvertASCIItoUTF16(recordIDBuf).get());
                newCard = do_QueryInterface(dbCard, &rv);
                if(NS_SUCCEEDED(rv))
                    rv = mABDB->EditCard(newCard, PR_FALSE, nsnull);
            }
        }
    }

    return rv;
}