Пример #1
0
void Wave::initWithData(const uint8_t* data, size_t size)
{
    if( size < sizeof(RiffHeader) )
    {
        g2cerror( "Wav data too small for riff header.\n" );
        exit(0);
    }
    
    RiffHeader* riff = (RiffHeader*)(data);
    memcpy(riff, data, sizeof(RiffHeader));
    
    checkTag(riff->riffTag, "RIFF");
    
    if( size < sizeof(RiffHeader) + sizeof(WavHeader) )
    {
        g2cerror( "Wav data too small both riff header and wav header."
            "  Cannot read.\n" );
        exit(0);
    }
    
    WavHeader* wav = (WavHeader*)(data + sizeof(RiffHeader));
    
    checkTag(wav->waveTag, "WAVE");
    checkTag(wav->fmtTag, "fmt ");
    checkTag(wav->dataTag, "data");
    
    if( wav->audioFormat!=1 )
    {
        g2cerror( "Wave expected audio format 1 representing"
            " audio PCM format, %d found instead.\n", wav->audioFormat );
    }
        
    if( wav->bitsPerSample%8 != 0 || wav->bitsPerSample<=0 || wav->bitsPerSample > 4096 )
    {
        g2clog( "WARNING: Wave bits-per-sample = %d\n", wav->bitsPerSample );
    }
    
    if( (wav->sampleRate) <= 0 || (wav->sampleRate) > 250000 )
    {
        g2clog( "WARNING: Wave sample-rate = %d\n", wav->sampleRate );
    }
    
    sampleRate = wav->sampleRate;
    numChannels = wav->numChannels;
    bytesPerSample = wav->bitsPerSample / 8;
    numSamples = wav->dataSize / bytesPerSample;
    this->data = (uint8_t*)(wav+1);
    
    if( this->data + wav->dataSize > data + size )
    {
        g2clog( "Size of data encoded in wav exceeds size of data given." );
        exit(0);
    }
}
Пример #2
0
void IntlParametersBlock::processParametersBlock(ProcessString* processString, ClumpletWriter& pb)
{
	for (pb.rewind(); !pb.isEof(); pb.moveNext())
	{
		UCHAR tag = pb.getClumpTag();
		string s;

		switch (checkTag(tag))
		{
		case TAG_SKIP:
			break;

		case TAG_STRING:
			pb.getString(s);
			processString(s);
			pb.deleteClumplet();
			pb.insertString(tag, s);
			break;

		case TAG_COMMAND_LINE:
			pb.getString(s);
			processCommandLine(processString, s);
			pb.deleteClumplet();
			pb.insertString(tag, s);
			break;
		}
	}
}
Пример #3
0
	void GameObjectTagManager::onTagRemoved(Object* obj, unsigned tagIndex)
	{
		xassert(!obj->hasTag(checkTag(tagIndex)));

		// Maybe clear have been invoked
		if (!taggedObjects[tagIndex].empty()) 
			XiAssert::areEqual(taggedObjects[tagIndex].erase(obj), 1u);
	}
Пример #4
0
	void GameObjectTagManager::onTagAdded(Object* obj, unsigned tagIndex)
	{
		xassert(obj->hasTag(checkTag(tagIndex)));

		auto res = taggedObjects[tagIndex].insert(obj);

		xassert(res.second && "The GameObject already has this tag"); // insert success
	}
Пример #5
0
void TreeView::checkTag(const QModelIndex &parent, QAbstractItemModel *model)
{
	for (int i = 0, count = model->rowCount(parent); i < count; ++i) {
		QModelIndex index = model->index(i, 0, parent);
		checkTag(index, model);
		if (!m_closedIndexes.contains(index.data(TagName).toString()))
			setExpanded(index, true);
	}
}
Пример #6
0
void saveStateSet(SaveState* state, const char* tagName, UInt32 value)
{
    checkTag(state, tagName);

    stateExtendBuffer(state, 3);
    state->buffer[state->offset++] = tagFromName(tagName);
    state->buffer[state->offset++] = sizeof(UInt32);
    state->buffer[state->offset++] = value;
}
Пример #7
0
void TagWatcher::tick(void){

  if ( _running ) {
    
    checkTag();
  } 
  
  _timer.update();
}
Пример #8
0
void saveStateSetBuffer(SaveState* state, const char* tagName, void* buffer, UInt32 length)
{
    checkTag(state, tagName);

    stateExtendBuffer(state, 2 + (length + sizeof(UInt32) - 1) / sizeof(UInt32));
    state->buffer[state->offset++] = tagFromName(tagName);
    state->buffer[state->offset++] = length;
    memcpy(state->buffer + state->offset, buffer, length);
    state->offset += (length + sizeof(UInt32) - 1) / sizeof(UInt32);
}
Пример #9
0
void IntlParametersBlock::processParametersBlock(ProcessString* processString, ClumpletWriter& pb)
{
	const char* tagName = NULL;
	try
	{
		for (pb.rewind(); !pb.isEof(); )
		{
			UCHAR tag = pb.getClumpTag();
			string s;

			tagName = NULL;
			switch (checkTag(tag, &tagName))
			{
			case TAG_SKIP:
				pb.moveNext();
				break;

			case TAG_STRING:
				pb.getString(s);
				processString(s);
				pb.deleteClumplet();
				pb.insertString(tag, s);
				break;

			case TAG_COMMAND_LINE:
				pb.getString(s);
				processCommandLine(processString, s);
				pb.deleteClumplet();
				pb.insertString(tag, s);
				break;
			}
		}
	}
	catch (const Firebird::status_exception& st)
	{
		LocalStatus ls;
		CheckStatusWrapper l(&ls);
		st.stuffException(&l);
		if ((l.getState() & IStatus::STATE_ERRORS) && (l.getErrors()[1] == isc_bad_conn_str) && tagName)
		{
			Arg::Gds newErrors(isc_intl_char);
			newErrors << tagName;

			const ISC_STATUS* errors = l.getErrors();
			newErrors << Arg::StatusVector(errors + 2);		// skip isc_bad_conn_str

			l.setErrors(newErrors.value());
			status_exception::raise(&l);
		}

		// other case leave exception as is
		throw;
	}
}
Пример #10
0
void IsoCurveParameters::getDataFromDoc(XMLDoc &doc) {
  XMLNodePtr root = doc.getRoot();
  checkTag(root, _T("IsoCurve"));
  doc.getValueLF(root, _T("expr"         ), m_expr        );
  doc.getValue(  root, _T("cellsize"     ), m_cellSize    );
  getValue(doc,  root, _T("boundingbox"  ), m_boundingBox );
  doc.getValue(  root, _T("machinecode"  ), m_machineCode );
  doc.getValue(  root, _T("includetime"  ), m_includeTime );
  if (m_includeTime) {
    getValue(doc, root, _T("timeinterval"), m_tInterval   );
    doc.getValue( root, _T("framecount"  ), m_frameCount  );
  }
}
void loop(){

  char tagString[13];
  
  getRFIDTagName(tagString);
  
  validRFID = checkTag(tagString); //Check if it is a match

  // turn on green LED if valid RFID
  setTrainLed(validRFID);

  clearTag(tagString); //Clear the char of all value
  resetReader(); //eset the RFID reader
}
Пример #12
0
/*----------------------------------------------------------------*/
int SockInfo::setup(uint64_t tag) {
    fd = socket(AF_INET, SOCK_STREAM, 0);
    if (fd < 0) {
        testPrintE("socket creation failed: %s", strerror(errno));
        return -1;
    }
    if (doCtrlCommand("t %d %" PRIu64, fd, tag) < 0) {
        testPrintE("socket setup: failed to tag");
        close(fd);
        return -1;
    }
    if (!checkTag(tag, getuid())) {
        testPrintE("socket setup: Unexpected results: tag not found");
        close(fd);
        return -1;
    }
    if (doCtrlCommand("u %d", fd) < 0) {
        testPrintE("socket setup: Unexpected results");
        close(fd);
        return -1;
    }
    return 0;
}
Пример #13
0
void ChatView::appendMessage(QString message, RoomMessageTypeFlags messageType, QString sender, UserLevelFlags userLevel, QString UserPrivLevel, bool playerBold)
{
    bool atBottom = verticalScrollBar()->value() >= verticalScrollBar()->maximum();
    bool sameSender = (sender == lastSender) && !lastSender.isEmpty();
    QTextCursor cursor = prepareBlock(sameSender);
    lastSender = sender;
    
    // timestamp
    if (showTimestamps && (!sameSender || sender.toLower() == "servatrice") && !sender.isEmpty()) {
        QTextCharFormat timeFormat;
        timeFormat.setForeground(QColor(SERVER_MESSAGE_COLOR));
        if (sender.isEmpty())
            timeFormat.setFontWeight(QFont::Bold);
        cursor.setCharFormat(timeFormat);
        cursor.insertText(QDateTime::currentDateTime().toString("[hh:mm:ss] "));
    }

    // nickname
    if (sender.toLower() != "servatrice") {
        QTextCharFormat senderFormat;
        if (tabSupervisor && tabSupervisor->getUserInfo() &&
            (sender == QString::fromStdString(tabSupervisor->getUserInfo()->name()))) {
            senderFormat.setForeground(QBrush(getCustomMentionColor()));
            senderFormat.setFontWeight(QFont::Bold);
        } else {
            senderFormat.setForeground(QBrush(OTHER_USER_COLOR));
            if (playerBold)
                senderFormat.setFontWeight(QFont::Bold);
        }
        senderFormat.setAnchor(true);
        senderFormat.setAnchorHref("user://" + QString::number(userLevel) + "_" + sender);
        if (sameSender) {
            cursor.insertText("    ");
        } else {
            if (!sender.isEmpty() && tabSupervisor->getUserListsTab()) {
                const int pixelSize = QFontInfo(cursor.charFormat().font()).pixelSize();
                QMap<QString, UserListTWI *> buddyList = tabSupervisor->getUserListsTab()->getBuddyList()->getUsers();
                cursor.insertImage(UserLevelPixmapGenerator::generatePixmap(pixelSize, userLevel, buddyList.contains(sender), UserPrivLevel).toImage());
                cursor.insertText(" ");
            }
            cursor.setCharFormat(senderFormat);
            if (!sender.isEmpty())
                sender.append(": ");
            cursor.insertText(sender);
        }
    }

    // use different color for server messages 
    defaultFormat = QTextCharFormat();
    if (sender.isEmpty()) {
        switch (messageType) {
            case Event_RoomSay::Welcome:
                defaultFormat.setForeground(Qt::darkGreen);
                defaultFormat.setFontWeight(QFont::Bold);
                break;
            case Event_RoomSay::ChatHistory:
                defaultFormat.setForeground(Qt::gray);
                defaultFormat.setFontWeight(QFont::Light);
                defaultFormat.setFontItalic(true);
                break;
            default:
                defaultFormat.setForeground(Qt::darkGreen);
                defaultFormat.setFontWeight(QFont::Bold);
        }
    } else if (sender.toLower() == "servatrice") {
        defaultFormat.setForeground(Qt::darkGreen);
        defaultFormat.setFontWeight(QFont::Bold);
    }
    cursor.setCharFormat(defaultFormat);

    bool mentionEnabled = settingsCache->getChatMention();
    highlightedWords = settingsCache->getHighlightWords().split(' ', QString::SkipEmptyParts);

    // parse the message
    while (message.size())
    {
        QChar c = message.at(0);    
        switch(c.toLatin1())
        {
            case '[':
                checkTag(cursor, message);
                break;
            case '@':
                if(mentionEnabled) {
                    checkMention(cursor, message, sender, userLevel);
                } else {
                    cursor.insertText(c, defaultFormat);
                    message = message.mid(1);
                }
                break;
            case ' ':
                cursor.insertText(c, defaultFormat);
                message = message.mid(1);
                break;
            default:
                if(c.isLetterOrNumber()) {
                    checkWord(cursor, message);
                } else {
                    cursor.insertText(c, defaultFormat);
                    message = message.mid(1);
                }
                break;
        }
    }

    if (atBottom)
        verticalScrollBar()->setValue(verticalScrollBar()->maximum());
}
Пример #14
0
int asn_sequence::readAll(std::istream& istr){
	if(!checkTag(istr))
		return -1;
	if(!readSize(istr))
		return -1;
	int readOctets = 2;
	int charleft = size;
	if(elements.empty()){
		while (charleft > 0){
			int tmptag = read(istr), x;
			if (tmptag < 0) {
				istr.clear();
				istr.seekg(0);
				writeable = 0;
				return -1;
			}
			istr.unget();
			istr.unget();
			if(tmptag==2){
				asn_int *tmpi = new asn_int;
				x = tmpi->readAll(istr);
				if(x <0) return -1;
				charleft = charleft-x;
				readOctets += x;
				addElement(tmpi);
			}
			else if(tmptag==19){
				asn_string *tmps = new asn_string;
				x = tmps->readAll(istr);
				if(x <0) return -1;
				charleft = charleft-x;
				readOctets += x;
				addElement(tmps);
			}
			else if(tmptag==48){
				asn_sequence *tmpss = new asn_sequence;
				x = tmpss->readAll(istr);
				if(x <0) return -1;
				charleft =charleft-x;
				readOctets += x;
				addElement(tmpss);
			}
			else{
				istr.clear();
				istr.seekg(0);
				writeable = 0;
				return -1;
			}
		}
		writeable = 1;
		return readOctets;
	}
	else{
		for (std::vector<asn_object*>::iterator it = elements.begin() ; it != elements.end(); ++it){
			int x = (*it)->readAll(istr);
			if (x<0){
				istr.clear();
				istr.seekg(0);
				/*
				for(int i = 0; i<readOctets; i++){
					istr.unget();
					istr.unget();
				}*/
				return -1;
			}
			readOctets += x;
		}
		writeable = 1;
		return readOctets;
	}
}
Пример #15
0
int main()
{
    memset (L2cache, 0, sizeof (cacheLine));

    // initialize the counters
    int refCount = 0;
    int readCount = 0;
    int writeCount = 0;
    int hitCount = 0;
    int missCount = 0;
    int hitM = 0;
    int hit = 0;
    int way;

    // initialize the input from the tracefile
    int n;

    // to handle the addr in hex, must be specified with prefix '0x'
    // it will be read as hex as long as the read uses %x instead of %d
    int addr;

    // initialize the LRU bits to the way
    setLRUbitsToWay();

    // open the tracefile, make it available to 'r' read
    // open the output file to make it available to append each iteration's result
    ifp = fopen("testfile.txt", "r");
    ofp = fopen("testout.txt", "a");

    fprintf(ofp,"-----------------------------------------------------------------------------------------------------\n");
    fflush(ofp);

    // set it up to read line by line
    // set n and addr accordingly
    while (fscanf(ifp, "%d %x\n", &n, &addr) != EOF)
    {
        // parse 32-bit hex address
        int tag = addr >> 20;
        int index = (addr >> 6) & 16383;
        // get 1 bit from the fifth position to check later whether 1 or 0
        int byteSelect = (addr >> 5) & ~(~0 << 1);
        refCount++;

        fprintf(ofp,"Reference: %d\n",refCount);
        fflush(ofp);

        switch (n)
        {
        // the L1 cache makes a read request
        // n = 0 read data request from L1 cache
        // n = 2 instruction fetch (treated as a read request from L1 cache)
        case 0:
        case 2:
            readCount++;
            // determine whether this tag exists in the cache and, if so, which way
            way = checkTag(index, tag);
            // if the tag exists
            if (way == 0 || way == 1 || way == 2 || way == 3)
            {
                // this tag exists and it's valid as per its MESI bits
                int MESI = L2cache[index][way].MESIbits;
                if (MESI == M || MESI == E || MESI == S)
                {
                    hitCount++;
                    // update the LRU to set 'way' to least recently used
                    updateLRU(index, way);
                    dataToL1(byteSelect,index,tag,way);
                    // MESI remains unchanged
                    // copy the addr to address in the cacheLine struct for case 9 display
                    L2cache[index][way].address = addr;
                }
                // this tag exists but it's been invalidated and can't be used
                else
                {
                    missCount++;
                    dataFromDRAM(addr,index,way,refCount);
                    dataToL1(byteSelect,index,tag,way);
                    // update LRU
                    updateLRU(index, way);
                    L2cache[index][way].MESIbits = E;
                    L2cache[index][way].address = addr;
                }
            }
            // this tag simply doesn't exist in the cache in any form
            else
            {
                missCount++;
                // use the LRU bit to determine which way to evict
                way = checkLRU(index);
                // update LRU
                updateLRU(index, way);
                dataFromDRAM(addr,index,way,refCount);
                L2cache[index][way].tag = tag;
                dataToL1(byteSelect,index,tag,way);
                L2cache[index][way].MESIbits = E;
                L2cache[index][way].address = addr;
            }
            break;
        // 1 write data request from L1 cache
        case 1:
            writeCount++;
            // determine whether this tag exists in the cache and, if so, which way
            way = checkTag(index, tag);
            // if the tag exists
            if (way == 0 || way == 1 || way == 2 || way == 3)
            {
                // this tag exists so check if it's valid as per its MESI bits
                int MESI = L2cache[index][way].MESIbits;
                if (MESI == M || MESI == E || MESI == S)
                {
                    hitCount++;
                    // update the LRU to set 'way' to least recently used
                    updateLRU(index, way);
                    // set MESI to modified because only we have it now
                    L2cache[index][way].MESIbits = E;
                    // because L2 has everything in L1, we send contents of our L2
                    // from our copy of that index/way to the DRAM
                    dataToDRAM(addr,index,way,refCount);
                    L2cache[index][way].MESIbits = M;
                    L2cache[index][way].address = addr;
                }
                // this tag exists but its MESI bits say invalid, needs to be updated
                // in this case we have to get the data from L1 and expand it to 64 bytes
                else
                {
                    missCount++;
                    // update LRU
                    updateLRU(index, way);
                    // set MESI to Modified
                    L2cache[index][way].MESIbits = E;
                    dataFromL1(index, way, addr, byteSelect);
                    dataToDRAM(addr,index,way,refCount);
                    // MESI = Exclusive after memory write
                    L2cache[index][way].MESIbits = M;
                    L2cache[index][way].address = addr;
                }
            }
            // this tag simply doesn't exist in the cache in any form
            // this covers the very unlikely odd case where L1 has what L2 doesn't
            else
            {
                missCount++;
                // use the LRU bit to determine which way to evict
                way = checkLRU(index);
                L2cache[index][way].MESIbits = E;
                dataFromL1(index, way, addr, byteSelect);
                L2cache[index][way].tag = tag;
                dataToDRAM(addr,index,way,refCount);
                // update LRU
                updateLRU(index, way);
                // MESI = Exclusive after memory write
                L2cache[index][way].MESIbits = M;
                L2cache[index][way].address = addr;
            }

            break;
        // 4 snooped a read request from another processor
        case 4:
            readCount++;
            // determine whether this tag exists in the cache and, if so, which way
            way = checkTag(index, tag);
            // if the tag exists
            if (way == 0 || way == 1 || way == 2 || way == 3)
            {
                // this tag exists so check if it's valid as per its MESI bits
                int MESI = L2cache[index][way].MESIbits;
                // if the tag exists but it's modified
                if (MESI == M)
                {
                    hitCount++;
                    hitM++;
                    // first response is to read out our modified copy to other cache
                    dataToSnooped(addr);
                    // then we write to our L1, just in case, and on to DRAM
                    dataToL1(byteSelect,index,tag,way);
                    dataToDRAM(addr,index,way,refCount);
                    // set MESI to shared after mem write to other processor completed
                    L2cache[index][way].MESIbits = S;
                    L2cache[index][way].address = addr;
                }
                // if the tag exists but it's exclusive
                else if (MESI == E || MESI == S)
                {
                    hitCount++;
                    hit++;
                    dataToSnooped(addr);
                    dataToL1(byteSelect,index,tag,way);
                    // set MESI to shared after mem write to other processor completed
                    L2cache[index][way].MESIbits = S;
                    L2cache[index][way].address = addr;
                }
                // if the tag exists but it's invalid -- we don't have it
                else
                {
                    missCount++;
                }
            }
            break;
        // 3 invalidate command or snooped write request
        case 3:
            way = checkTag(index, tag);
            // if the tag exists
            if (way == 0 || way == 1 || way == 2 || way == 3)
            {
                // this tag exists so check if it's valid as per its MESI bits
                int MESI = L2cache[index][way].MESIbits;
                if (MESI == I)
                {
                    missCount++;
                }
                else if (MESI == M || MESI == E || MESI == S)
                {
                    L2cache[index][way].MESIbits = I;
                    hitCount++;
                    L2cache[index][way].address = addr;
                }
                // if we don't have it, we do nothing
            }
            break;
        // snooped write request from another processor
        case 5:
            writeCount++;
            way = checkTag(index, tag);
            // if the tag exists
            if (way == 0 || way == 1 || way == 2 || way == 3)
            {
                // this tag exists so check if it's valid as per its MESI bits
                int MESI = L2cache[index][way].MESIbits;
                // if the tag exists but it's modified
                if (MESI == M || MESI == E || MESI == S)
                {
                    hitCount++;
                    L2cache[index][way].MESIbits = I;
                    L2cache[index][way].address = addr;
                }
                else
                {
                    missCount++;
                }
                // if we don't have it, we ignore entirely
            }
            else
                missCount++;
            break;
        // 6 snooped read for ownership request
        case 6:
            readCount++;
            way = checkTag(index, tag);
            // if the tag exists
            if (way == 0 || way == 1 || way == 2 || way == 3)
            {
                // this tag exists so check if it's valid as per its MESI bits
                int MESI = L2cache[index][way].MESIbits;
                // if the tag exists but it's modified, we can serve this request
                // before setting our MESI bits to invalid
                if (MESI == M || MESI == E || MESI == S)
                {
                    hitCount++;
                    if (MESI == M)
                    {
                        hitM++;
                    }
                    dataToSnooped(addr);
                    invalidateInL1(addr);
                    L2cache[index][way].MESIbits = I;
                    // LRU update not necessary here because our algorithm checks for
                    // empty (invalid MESI bit) lines first before checking LRU bits
                    L2cache[index][way].address = addr;
                }
                else
                {
                    missCount++;
                }
                // if we don't have it, we do nothing
            }
            break;
        // 8 clear the cache and refresh all states
        case 8:
            // Use the algorithm for n = 3||5 and step through all indices and ways.
            // No MESI, LRU, or counter updates here, and no display.
            way = 0;

            for (index = 0; index < 16384; index++)
            {
                L2cache[index][0].MESIbits = 3;
                L2cache[index][0].LRUbits = 0;
                L2cache[index][1].MESIbits = 3;
                L2cache[index][1].LRUbits = 1;
                L2cache[index][2].MESIbits = 3;
                L2cache[index][2].LRUbits = 2;
                L2cache[index][3].MESIbits = 3;
                L2cache[index][3].LRUbits = 3;
                L2cache[index][way].address = addr;
            }

            break;
        // 9 print everything, destroy nothing
        case 9:
            // Print contents of L2 cache in a pretty, pretty box to an output file

            ofpD = fopen("display.txt", "a");

            fprintf(ofpD,"------------------------------------------------------\n");
            fprintf(ofpD,"At reference number %d, the L2 cache looked like this.\n\n",refCount);
            fflush(ofpD);

            for (index = 0; index < 16384; index++)
            {
                for (way = 0; way < 4; way++)
                {
                    if (L2cache[index][way].MESIbits != I)
                    {
                        fprintf(ofpD,"Index %d way %d tag %d LRUbits %d MESIbits %d\n\n",index,way,tag,L2cache[index][way].LRUbits,L2cache[index][way].MESIbits);
                        fflush(ofpD);
                    }
                }
            }

            break;
            // end switch statement
        }
        // print the counters in a neat form here at the end of each loop for testing

        float hitRatio;
        int total = hitCount + missCount;
        hitRatio = (float) hitCount / total;

        if ( n >= 0 && n < 8)
        {
            fprintf(ofp, "\ntag %d stored in index %d at way %d\n",tag,index,way);
            fflush(ofp);
            fprintf(ofp, "n address    hitCount missCount LRU: way0  way1 way2 way3 MESI  readCount writeCount hitRatio\n");
            fflush(ofp);

            fprintf(ofp, "%-1d 0x%-8x %-8d %-15d %-5d %-4d %-4d %-4d %-4d %-9d %-11d %-4f\n",
                    n, addr, hitCount, missCount, L2cache[index][0].LRUbits, L2cache[index][1].LRUbits, L2cache[index][2].LRUbits, L2cache[index][3].LRUbits, L2cache[index][way].MESIbits, readCount, writeCount, hitRatio);
            fflush(ofp);

        }
        else if (n == 8)
        {
            fprintf(ofp, "the MESI bits of every line in this cache were set to invalid\n");
            fflush(ofp);
        }
        else if (n == 9)
        {
            fprintf(ofp, "all valid lines with contents, LRU bits, and MESI bits in display.txt\n");
            fflush(ofp);
        }
        fprintf(ofp,"--------------------------------------------------------------------------------------------------\n");
        fflush(ofp);

        // end while loop
    }

    float hitRatio = (float) hitCount / refCount;

    printf(" Total References: %d\n Reads: %d\n Writes: %d\n Hits: %d\n Misses %d\n Hit ratio: %f\n",refCount,readCount,writeCount,hitCount,missCount,hitRatio);

    return 0;
// end of main() function
}
Пример #16
0
char * getNextSection(struct _CMCIConnection * con)
{
	char * xmlb    = NULL;
  char * workptr = NULL;
  char * curptr  = NULL;
  int    xmlblen = 0;
  int    tagval  = 0;
  int    retcode = 0; 
  int    toval   = 0;
  
   /*
    * free that old buffer 
    */
  
  if(con->asynRCntl.escanInfo.section != NULL) {
     free(con->asynRCntl.escanInfo.section);
     con->asynRCntl.escanInfo.section = NULL ;
  }
  
  if((retcode = pthread_mutex_lock(&(con->asynRCntl.escanlock))) != 0){
     printf(" getNextSection pthread lock return code %d\n",retcode) ;	
  }
  
  /*
   * If we have no more new data from the server , we 
   * unlock and sleep then check till we see that we have 
   * received new data 
   */
  
  while(con->asynRCntl.escanInfo.prevtotl == con->asynRCntl.escanInfo.recdtotl){
     if((retcode = pthread_mutex_unlock(&(con->asynRCntl.escanlock))) != 0){
        printf(" getNextSection pthread lock return code %d\n",retcode) ;	
     }
     /* *******************************************
      * ******************************************* 
      * timeout toval keeps us from hanging forever
      * *******************************************
      * *******************************************
      */
     usleep(1000) ;
     toval++ ;

     if(toval>5000) 
         longjmp (save_env, 1);
     
     if(con->asynRCntl.escanInfo.prevtotl != con->asynRCntl.escanInfo.recdtotl){
     	  /* 
     	   * we got more data , exit this loop
     	   */
        if((retcode = pthread_mutex_lock(&(con->asynRCntl.escanlock))) != 0){
             printf(" getNextSection pthread lock return code %d\n",retcode) ;	
        }
        break;
     }   
  }

  if((con->asynRCntl.xfer_state == XFER_DATA_RECVD) ||
     (con->asynRCntl.xfer_state == XFER_COMPLETE)	)    {

     workptr = LASTPTR(&(con->asynRCntl.escanInfo)) ;
     curptr  = CURPTR(&(con->asynRCntl.escanInfo));
  
     con->asynRCntl.escanInfo.ssecoff = con->asynRCntl.escanInfo.curoff ;
     
     toval = 0;
     while(workptr > curptr) {   
        if(*workptr == '>'){
        	 tagval = checkTag(workptr , con->asynRCntl.eMethodType) ;
        	 if(tagval == 0){
              con->asynRCntl.escanInfo.curoff = con->asynRCntl.escanInfo.curoff + (workptr - curptr) + 1 ;
              xmlblen = ((workptr - curptr) + 5) ;
           
              xmlb = malloc(xmlblen + 64) ;
              con->asynRCntl.escanInfo.section = xmlb ;

              con->asynRCntl.escanInfo.sectlen = xmlblen + 5 ;
              memset(xmlb , 0x0cc , xmlblen + 5) ;
                                   
              if(xmlb != NULL){
                 memcpy(xmlb , SSECPTR(&con->asynRCntl.escanInfo) , xmlblen) ;
                 strcpy((xmlb+(xmlblen - 4)) , "<EC>") ;
                 con->asynRCntl.escanInfo.getnew = 0 ;
 
              } else {
           	     /* getNextSection xmlb is NULL !!! This is bad */
              }
                           
              con->asynRCntl.escanInfo.prevtotl = con->asynRCntl.escanInfo.recdtotl ;

              if((retcode =  pthread_mutex_unlock(&(con->asynRCntl.escanlock))) != 0){
              	 printf(" getNextSection pthread lock return code %d\n",retcode) ;	
              }
              return(xmlb) ;
          } else {
          	  /* 
          	   * backup before this tag 
          	   */
              workptr = workptr - tagval ;
              if(workptr <= curptr){
                 if (con->asynRCntl.escanInfo.prevtotl != con->asynRCntl.escanInfo.recdtotl){
                 	  pthread_mutex_unlock(&(con->asynRCntl.escanlock));
                 	  usleep(1000) ;
                 	  toval++ ;
                 	  if(toval > 5000)
                 	     longjmp (save_env, 2);
                 	  pthread_mutex_lock(&(con->asynRCntl.escanlock));
                    workptr = LASTPTR(&(con->asynRCntl.escanInfo)) ;
                    curptr  = CURPTR(&(con->asynRCntl.escanInfo));                	
                 }
              }
              continue;
          }
        } else {
           workptr-- ;
           if(workptr <= curptr){
              if (con->asynRCntl.escanInfo.prevtotl != con->asynRCntl.escanInfo.recdtotl){
                 workptr = LASTPTR(&(con->asynRCntl.escanInfo)) ;
                 curptr  = CURPTR(&(con->asynRCntl.escanInfo));
              }
           }
        }
     }
  }
  
  if((retcode =  pthread_mutex_unlock(&(con->asynRCntl.escanlock))) != 0){
     printf(" getNextSection pthread unlock return code %d\n",retcode) ;	
  }
  return(NULL) ;
}