void CMessageStats::SetStatsL(const TBBBtDeviceInfo& aDevice,
		const TMessageStats& aStats)
{
	CALLSTACKITEM_N(_CL("CDevStats"), _CL("SetStatsL"));


	if (SeekToDevL(aDevice)) {
		iTable.UpdateL();
	} else {
		iTable.InsertL();
		iTable.SetColL(EDevAddr, aDevice.iMAC());
		iCount++;
	}

	iTable.SetColL(EFailureCount, aStats.iFailureCount);
	iTable.SetColL(ESuccessCount, aStats.iSuccessCount);
	iTable.SetColL(EPreviousLocalSuccess, aStats.iPreviousLocalSuccess);
	iTable.SetColL(EPreviousRemoteSuccess, aStats.iPreviousRemoteSuccess);
	iTable.SetColL(EPreviousLocalFailure, aStats.iPreviousLocalFailure);
	iTable.SetColL(EPreviousRemoteFailure, aStats.iPreviousRemoteFailure);
	iTable.SetColL(ELocalFailureCount, aStats.iLocalFailureCount);
	iTable.SetColL(ELastSeen, aStats.iLastSeen);

	PutL();

	if (iCount > MAX_STATS + STATS_HYSTERESIS) {
		SwitchIndexL(EIdxLastSeen);
		iTable.FirstL();
		while (iCount > MAX_STATS - STATS_HYSTERESIS) {
			DeleteL();
			iCount--;
			iTable.NextL();
		}
	} else if ( AppContext().NoSpaceLeft() ) {
		SwitchIndexL(EIdxLastSeen);
		iTable.FirstL();
		for (int i=0; i<STATS_HYSTERESIS && iCount>0; i++) {
			DeleteL();
			iCount--;
			iTable.NextL();
		}
	}

}
void CDevStats::SetStatsL(const TBBBtDeviceInfo& aDevice,
						  const TDesC& aNodeName,
		const TDevStats& aStats)
{
	CALLSTACKITEM_N(_CL("CDevStats"), _CL("SetStatsL"));

	if (SeekToDevL(aDevice, aNodeName)) {
		iTable.UpdateL();
	} else {
		iCount++;
		iTable.InsertL();
		iTable.SetColL(EDevAddr, aDevice.iMAC());
		iTable.SetColL(ENode, iNodes->GetNodeIdL(aNodeName));
	}

	iTable.SetColL(ELastSeen, aStats.iLastSeen);
	iTable.SetColL(EVisitBegin, aStats.iVisitBegin);
	iTable.SetColL(EPreviousVisitBegin, aStats.iPreviousVisitBegin);
	iTable.SetColL(EPreviousVisitEnd, aStats.iPreviousVisitEnd);
	iTable.SetColL(ECountStay, aStats.iCountStay);
	iTable.SetColL(ESumStay, aStats.iSumStay);
	iTable.SetColL(ESquareSumStay, aStats.iSquareSumStay);
	iTable.SetColL(EMaxStay, aStats.iMaxStay);
	iTable.SetColL(EFirstSeen, aStats.iFirstSeen);

	PutL();
	if (iCount > MAX_STATS + STATS_HYSTERESIS) {
		SwitchIndexL(EIdxLastSeen);
		iTable.FirstL();
		while (iCount > MAX_STATS - STATS_HYSTERESIS) {
			DeleteL();
			iCount--;
			iTable.NextL();
		}
	} else if ( AppContext().NoSpaceLeft() ) {
		for (int i=0; i<STATS_HYSTERESIS && iCount>0; i++) {
			DeleteL();
			iCount--;
			iTable.NextL();
		}
	}
}
Exemplo n.º 3
0
/**
Removes the properties from the URIPropertiesTbl. The function removes the URI from the 
URITbl table if it is not having a dependency. See the table structure

@param aUriId URI Id value 
@param aPropId Property Id value
*/
void CUriListInterface::RemoveUriL ( TInt aUriId, TInt aPropId )
	{
	iDbAccessor->BeginTransactionL ();
	// This is not to delete the object rather to do a rollback operation incase of a failure
	CleanupStack::PushL ( TCleanupItem ( CUriListInterface::RollbackTrans, iDbAccessor ) );
	
	// Delete from properties table
	DeleteL ( KUriPropsTblName(), URILIST::EPropId, aPropId );

	// The URI also need to be removed if it is not marked for another service type.
	// Check for dependency. 
	if ( CheckDependencyL( aUriId ) )
		{
		// No dependency. The URI also need to be removed			
		DeleteL ( KUriTblName(), URILIST::EId, aUriId );
		}	
	
	// Delete the same from view
	DeleteL ( KViewName(), URILIST::EPropId, aPropId );
	iDbAccessor->CommitTransactionL ();
	CleanupStack::Pop (); // iDbAccessor
	}
EXPORT_C void CGenericIntMap::AddDataL(uint32 Key, void* data, bool overwrite)
{
	if (overwrite) {
		DeleteL(Key);
	}
	TBtreePos pos;
	Entry e;
	e.key=Key; e.data=data;
	TBool no_dup=iTree->InsertL(pos, e);
	if (no_dup) iCount++;
	if (! no_dup && iDeletor) {
		(*iDeletor)(data);
	}
}
	void SetAsAcceptedL(const TDesC8& aMac, TInt aMessageCode) {
		if (iCount>MAX_STATS || NoSpaceLeft()) {
			SwitchIndexL(1);
			iTable.FirstL();
			TInt deleted=0;
			while(deleted<STATS_HYSTERESIS) {
				DeleteL();
				iCount--;
				deleted++;
				iTable.NextL();
			}
		}
		iTable.InsertL();
		iTable.SetColL(EMac, aMac);
		iTable.SetColL(EMessageCode, aMessageCode);
		iTable.SetColL(ELastSeen, GetTime());
		PutL();
	}
Exemplo n.º 6
0
int main (int argc, char** argv)
{
    int a, pop, sum, k;
    int l, o, c;
    int fd, val;

    MyRecord temprec, r;
    char ch;
    char phoneno[20];
    char town[20];
    char min[20], max[20];
    char word[20];
    l = 0;
    o = 0;
    c = 0;
    char loadFile[20], opFile[20], configFile[20];

    /* Diabasma orismatwn */

    opterr = 0;

    while ((a = getopt (argc, argv, "l:o:c:")) != -1)
        switch (a)
        {
           case 'l':
             strcpy(loadFile, optarg);
             l = 1;
             break;
           case 'o':
             strcpy(opFile, optarg);
             o = 1;
             break;
           case 'c':
             strcpy(configFile, optarg);
             c = 1;
             break;
           case '?':
             if (optopt == 'p' || optopt == 'i' || optopt == 'd')
               fprintf (stderr, "Option -%c requires an argument.\n", optopt);
             else if (isprint (optopt))
               fprintf (stderr, "Unknown option `-%c'.\n", optopt);
             else
               fprintf (stderr,
                        "Unknown option character `\\x%x'.\n",
                        optopt);
             return 1;
           default:
             abort ();
        }

   InitializeI(&start_town);

   /* Xrhsh orismatwn */
    if(c == 1)
    {
        FILE* con;
        con = fopen(configFile,"r");
        if (con == NULL)
        {
            printf("Cannot open configuration file\n");
        }
        else
            while(!feof(con))
            {
                if(fscanf(con, "%s %d", word, &val) == 2)
                    if(strcmp(word, "Hash_Table_Size") == 0)
                    {
                        hashtsize = val;
                        hashtable = malloc(hashtsize*(sizeof(pnode)));
                    }
            }
    }
    if(l == 1)
    {
        Load_file(loadFile);
        l = 0;
    }
     if(o == 1)                     // An uparxei operation file tote to stdin anakateuthunetai sto arxeio ayto k diabazontai oi entoles kanonika mexri na teleiwsei
    {
        if(hashtsize == 0)
        {
            hashtsize = primes(DEFAULT_HASH_SIZE);
            hashtable = malloc(hashtsize*(sizeof(pnode)));
        }
        if( access(opFile, F_OK ) != -1 )
        {
            fd = dup(fileno(stdin));
            freopen(opFile, "r", stdin);
        }
        else
            printf("Cannot open operation file\n");

    }
    memset(max, '0', 20);
    memset(min, '0', 20);
    if(hashtsize == 0)
        {
            hashtsize = primes(DEFAULT_HASH_SIZE);
            hashtable = malloc(hashtsize*(sizeof(pnode)));
        }
    if(o == 0)
        printf("Give input\n");

    /* Epanalipsh gia thn eisagwgh entolwn. Diavasma prwtou xarakthra kai elegxos periptwsewn */
    while(1)
    {


        ch = getchar();
        if(ch == 'i')
        {
            ReadValue(&temprec);
            if(SearchL(temprec.phone, hashtable, hashtsize, &r) == 0)
                InsertL(temprec, hashtable, hashtsize, start_town);
            else
                printf("Number %s already exists. Cannot add the same number twice.\n", temprec.phone);
            //temp_town = start_town;
		}
		else if(ch == 'q')
		{
            scanf("%10s", phoneno);
            if(SearchL(phoneno, hashtable, hashtsize, &r) == 1)
                WriteValue(r);
            else
                printf("Number %s not found.\n", phoneno);
            memset(phoneno, '\0', 20);
		}
		else if(ch == 'd')
		{
            scanf("%10s", phoneno);
            DeleteL(phoneno, hashtable, hashtsize, start_town);
            memset(phoneno, '\0', 20);
		}
		else if(ch == 'l')
        {
            scanf("%s", loadFile);
            Load_file(loadFile);
        }
		else if(ch == 'e')
		{
            FreeIndex(start_town);
            free(start_town);
            free(hashtable);
            return 0;
		}
		else if(ch == 'p')
		{
            scanf("%s", town);
            pop = PopulationI(start_town, town);
            if(pop > 0)
                printf("%s: %d\n", town, pop);
            else
                printf("Town %s not found.\n", town);
            memset(town, '\0', 20);
		}
		else if(ch == 's')
		{
            scanf("%s", town);
            sum = SummaryI(start_town, town);
            if(sum > 0)
                printf("%s: %d\n", town, sum);
            else
                printf("Town %s not found.\n", town);
            memset(town, '\0', 20);
		}
		else if(ch == 't')
		{
            scanf("%d", &k);
            Top(start_town, k);
		}
		else if(ch == 'f')
		{
            ch = getchar();
            if(ch == 't')
            {
                ch = getchar();
                if(ch == ' ')
                {
                    scanf("%s %d", town, &k);
                    TopKSpenders(start_town, town, k);
                }
                else if(ch == 's')
                    TopTownSpenders(start_town);
            }
		}
		else if(ch == 'm')
		{
            ch = getchar();
            if(ch == 'a')
            {
                ch = getchar();
                if(ch == 'x')
                {
                    //if(max[0] == '0')
                        Max(start_town);
                }
            }
            else if(ch == 'i')
            {
                ch = getchar();
                if(ch == 'n')
                {
                   // if(min[0] == '0')
                        Min(start_town);
                }
            }
		}
		//scanf("%20s", junk);
		if(o == 1 && ch == EOF)     // An yparxei operation file san orisma kai exei teleiwsei h anagnwsh epanafora tou stdin.
        {
            fflush(stdin);
            dup2(fd, fileno(stdin));
            close(fd);
            clearerr(stdin);
            o = 0;
            printf("Operation file finished succesfully.\n");
        }
        fflush(stdin);
    }

    return 0;

    }
/**
Updates communication addresses in the database.

If there are the same number of items to be updated as are already in the database, the
existing records are overwritten using the update statement. However, if there is a
different number of addresses to be updated, records in the database (if there are any)
are deleted (using DeleteL() ) and the new data is inserted (using CreateInDbL() ).

@param aItem A contact item whose communication addresses are to be updated in the contacts database.
*/
void CPplCommAddrTable::UpdateL(const CContactItem& aItem)
	{
	// Check that the contact item is a card, own card or ICC entry.
	const TUid type(aItem.Type() );
	if (type != KUidContactCard && type != KUidContactOwnCard && type != KUidContactICCEntry && type != KUidContactGroup)
		{
		return;
		}

	const TContactItemId KItemId(aItem.Id() );

	// create lists for comm_addrs and go through contact item to populate them with any new ones we find
	RArray<TMatch> newPhones;
	RArray<TPtrC>  newEmails;
	RArray<TPtrC>  newSips;
	CleanupClosePushL(newPhones);
	CleanupClosePushL(newEmails);
	CleanupClosePushL(newSips);
	
	CPplCommAddrTable::TCommAddrExtraInfoType extraInfoType = ENonMobileNumber;

	for (TInt fieldNum = aItem.CardFields().Count() - 1; fieldNum >= 0; --fieldNum)
		{
		CContactItemField& currField = aItem.CardFields()[fieldNum];
		const CContentType& contType = currField.ContentType();
		TBool isPhone(contType.ContainsFieldType(KUidContactFieldPhoneNumber) ||
					  contType.ContainsFieldType(KUidContactFieldFax)		  ||
					  contType.ContainsFieldType(KUidContactFieldSms)		  );
		TBool isEmail(contType.ContainsFieldType(KUidContactFieldEMail) );
		TBool isSip(contType.ContainsFieldType(KUidContactFieldSIPID) );

		// check it's a field we want and that it's not empty
		// store a new address if we haven't already seen it -- no point storing the same one twice.
		if ((isPhone || isEmail || isSip) && currField.StorageType() == KStorageTypeText
				&& currField.TextStorage()->IsFull() )
			{
			// get phone numbers
			if (isPhone)
				{
				TMatch phoneNumber;
				phoneNumber = CreatePaddedPhoneDigitsL(currField.TextStorage()->Text(), KLowerSevenDigits,
													   KMaxPhoneMatchLength - KLowerSevenDigits);
				if (newPhones.Find(phoneNumber, TIdentityRelation<TMatch>(&TMatch::Equals) ) == KErrNotFound)
					{
					newPhones.AppendL(phoneNumber);
					}
				if(contType.ContainsFieldType(KUidContactFieldVCardMapCELL))
                    {
                    extraInfoType = EMobileNumber;
                    }
				}
			// get email addresses
			else if (isEmail && newEmails.Find(currField.TextStorage()->Text() ) == KErrNotFound)
				{
				newEmails.AppendL(currField.TextStorage()->Text() );
				}
			// get SIP addresses
			else if (newSips.Find(currField.TextStorage()->Text() ) == KErrNotFound)
				{
				newSips.AppendL(currField.TextStorage()->Text() );
				}
			}
		}

	// if there are no comm addresses in the contact item, delete any from the database
	if (!(newPhones.Count() + newEmails.Count() + newSips.Count() ) )
		{
		TBool lowDiskErr(EFalse);
		DeleteL(aItem, lowDiskErr);
		CleanupStack::PopAndDestroy(3, &newPhones); // and newSips, newEmails
		if (lowDiskErr)
			{
			User::Leave(KErrDiskFull);
			}
		return;
		}

	// create from the database a list of comm_addr_ids that can be recycled as their
	// comm_addrs are in the database but not in the new version of the contact item
	RArray<TInt> freeCommAddrIds;
	CleanupClosePushL(freeCommAddrIds);

	// weed out addresses from the list that are already in the db but haven't changed
	// and populate the freeCommAddrIds list
	RemoveNonUpdatedAddrsL(newPhones, newEmails, newSips, freeCommAddrIds, KItemId, extraInfoType);

	// do the actual updating on an address-by-address basis

	DoUpdateCommAddrsL(newPhones, newEmails, newSips, freeCommAddrIds, KItemId,extraInfoType);

	CleanupStack::PopAndDestroy(4, &newPhones); // and freeCommAddrIds, newSips, newEmails
	}