示例#1
0
int main(int arg, char** argv)
{
  /* Test SectionReader
   * -------------------
   * To run this code : 
   *   cd storage/ndb/src/kernel/vm
   *   make testSectionReader
   *   ./testSectionReader
   *
   * Will print "OK" in success case and return 0
   */

  g_sectionSegmentPool.setSize(1024);
  
  printf("g_sectionSegmentPool size is %u\n",
         g_sectionSegmentPool.getSize());

  const Uint32 Iterations= 2000;
  const Uint32 Sections= 5;
  Uint32 sizes[ Sections ];
  Uint32 iVals[ Sections ];

  for (Uint32 t=0; t < Iterations; t++)
  {
    for (Uint32 i=0; i<Sections; i++)
    {
      Uint32 available= g_sectionSegmentPool.getNoOfFree();
      sizes[i] = available ? 
        myRandom48(SectionSegment::DataLength * 
                   available)
        : 0;

      //if (0 == (sizes[i] % 60))
      //  printf("Iteration %u, section %u, allocating %u words\n",
      //         t, i, sizes[i]);
      if (t % 100 == 0)
        if (i==0)
          printf("\nIteration %u", t);
      
      if (sizes[i] > 0)
      {
        iVals[i]= createSection(&g_sectionSegmentPool, sizes[i]);

        VERIFY(testSR(iVals[i], &g_sectionSegmentPool, sizes[i]) == 0);
      }
      else
        iVals[i]= RNIL;
    }

    
    for (Uint32 i=0; i < Sections; i++)
    {
      if (sizes[i] > 0)
        freeSection(&g_sectionSegmentPool, iVals[i]);
    }
  }
  
  printf("\nOK\n");
  return 0;
}
	//---------------------------------------------------------------------
	bool PagedWorld::load(StreamSerialiser& ser)
	{
		if (!ser.readChunkBegin(CHUNK_ID, CHUNK_VERSION, "PagedWorld"))
			return false;

		// Name
		ser.read(&mName);
		// Sections
		while(ser.peekNextChunkID() == CHUNK_SECTIONDECLARATION_ID)
		{
			ser.readChunkBegin();
			String sectionType, sectionName;
			ser.read(&sectionType);
			ser.read(&sectionName);
			ser.readChunkEnd(CHUNK_SECTIONDECLARATION_ID);
			// Scene manager will be loaded
			PagedWorldSection* sec = createSection(0, sectionType, sectionName);
			bool sectionsOk = sec->load(ser);
			if (!sectionsOk)
				destroySection(sec);
		}

		ser.readChunkEnd(CHUNK_ID);

		return true;

	}
	//---------------------------------------------------------------------
	PagedWorldSection* PagedWorld::createSection(PageStrategy* strategy, SceneManager* sceneMgr, 
		const String& sectionName)
	{
		PagedWorldSection* ret = createSection(sceneMgr, "General", sectionName);
		ret->setStrategy(strategy);

		return ret;
	}
	//---------------------------------------------------------------------
	PagedWorldSection* PagedWorld::createSection(const String& strategyName, SceneManager* sceneMgr,
		const String& sectionName)
	{
		// get the strategy
		PageStrategy* strategy = mManager->getStrategy(strategyName);

		return createSection(strategy, sceneMgr, sectionName);
		
	}
示例#5
0
int
main(int argc, char *argv[])
{
	PetscInitialize(&argc, &argv, NULL, NULL);

	PetscInt polyDegree = 4;
	DM meshSkeleton = createMesh(PETSC_COMM_WORLD, "../test_files/small.ex2");
	meshSkeleton = createSection(meshSkeleton, polyDegree);
	PetscFinalize();
	return 0;
}
示例#6
0
bool KLUPD::IniFile::createSection(const NoCaseString &sectionName, const NoCaseString &comment, const std::vector<Key> &keys)
{
    if(!createSection(sectionName, comment))
        return false;

    Section *section = getSection(sectionName);
    if(!section)
        return false;

    section->m_name = sectionName;
    for(std::vector<Key>::const_iterator keyIter = keys.begin(); keyIter != keys.end(); ++keyIter)
    {
        if(!keyIter->m_key.empty())
            section->m_keys.push_back(Key(keyIter->m_key, keyIter->m_value, keyIter->m_comment));
    }

    m_dirty = true;
    return true;
}
示例#7
0
bool KLUPD::IniFile::setValue(const NoCaseString &keyName, const NoCaseString &value, const NoCaseString &sectionName, const NoCaseString &comment)
{
    if(keyName.empty())
        return false;

    Section *section = getSection(sectionName);
    if(!section)
    {
        if(!(m_flags & AUTOCREATE_SECTIONS) || !createSection(sectionName, L""))
            return false;

        section = getSection(sectionName);
    }

    // sanity check
    if(!section)
        return false;

    // if the key does not exist in that section, and the value passed is not NoCaseString(L"") then add the new key
    Key *pKey = getKey(keyName, sectionName);
    if(!pKey && (m_flags & AUTOCREATE_KEYS))
    {
        m_dirty = true;
        section->m_keys.push_back(Key(keyName, value, comment));
        return true;
    }

    if(pKey)
    {
        pKey->m_value = value;
        pKey->m_comment = comment;
        m_dirty = true;
        return true;
    }

    return false;
}
示例#8
0
bool KLUPD::IniFile::load()
{
    if(!LocalFile(m_fileName, pLog).exists())
    {
        TRACE_MESSAGE2("File does not exist '%S'", m_fileName.toWideChar());
        return false;
    }

    // do not create a new file here.  If it doesn't exist, just return false and report the failure.
    FileStream file(pLog);
    if(!file.open(m_fileName, std::ios::in))
    {
        TRACE_MESSAGE2("Failed to load ini configuration file, because failed to open file '%S'",
            m_fileName.toWideChar());
        return false;
    }

    const bool autoKey = (m_flags & AUTOCREATE_KEYS) == AUTOCREATE_KEYS;
    const bool autoSec = (m_flags & AUTOCREATE_SECTIONS) == AUTOCREATE_SECTIONS;

    NoCaseString comment;
    Section *section = getSection(L"");

    // needs to be set to restore the original values later
    m_flags |= AUTOCREATE_KEYS | AUTOCREATE_SECTIONS;

    bool doneWithFile = false;
    while(!doneWithFile)
    {
        NoCaseString line;
        file.getLine(line);
        line.trim();

        doneWithFile = file.done();

        if(line.find_first_of(s_commentIndicators.toWideChar()) == 0)
        {
            comment += L"\n";
            comment += line;
        }
        // new section
        else if(line.find_first_of("[") == 0)
        {
            line.erase(0, 1);
            const size_t lastOffset = line.find_last_of("]");
            if(lastOffset != NoCaseStringImplementation::npos)
            {
                line.erase(lastOffset, 1);

                createSection(line, comment);
                section = getSection(line);
                comment = NoCaseString();
            }
        }
        // we have a key, add this key/value pair
        else if(!line.empty())
        {
            NoCaseString keyName = getNextWord(line);
            NoCaseString value = line;

            if(!keyName.empty())
            {
                setValue(keyName, value, section ? section->m_name : NoCaseString(), comment);
                comment = NoCaseString(L"");
            }
        }
    }

    // restore the original flag values.
    if(!autoKey)
        m_flags &= ~AUTOCREATE_KEYS;
    if(!autoSec)
        m_flags &= ~AUTOCREATE_SECTIONS;
    return true;
}
示例#9
0
Section::Section(const Texture& t, Rect<float>* r)
{
    createSection(t, r);
}
示例#10
0
unsigned int ExecutionChartSectionCreator::addTrace(SoftwareTraceEvent *event)
{
    QChar c;
    switch(event->id) {
    case 0x1:
        createSection(event->timestamp, event->timestamp, -1, "Exited");
        break;
    case 0x10:
        m_inException = true;
        switch (event->value) {
        case 0x1:
            createSection(event->timestamp, event->timestamp, -1, "System start");
            break;
        case 0x2:
            createSection(event->timestamp, event->timestamp, -1, "Bus fault");
            break;
        case 0x3:
            createSection(event->timestamp, event->timestamp, -1, "Data page fault");
            break;
        case 0x4:
            createSection(event->timestamp, event->timestamp, -1, "Insn page fault");
            break;
        case 0x5:
            createSection(event->timestamp, event->timestamp, -1, "Timer exception");
            break;
        case 0x6:
            createSection(event->timestamp, event->timestamp, -1, "Alignment exception");
            break;
        case 0x7:
            createSection(event->timestamp, event->timestamp, -1, "Illegal instruction");
            break;
        case 0x8:
            createSection(event->timestamp, event->timestamp, -1, "Interrupt");
            break;
        case 0x9:
            createSection(event->timestamp, event->timestamp, -1, "Data TLB miss");
            break;
        case 0xa:
            createSection(event->timestamp, event->timestamp, -1, "Instruction TLB miss");
            break;
        case 0xb:
            createSection(event->timestamp, event->timestamp, -1, "Range exception");
            break;
        case 0xc:
            createSection(event->timestamp, event->timestamp, -1, "Syscall");
            break;
        }
        break;
    case 0x20:
        m_currentSectionDefinition = event->value;
        break;
    case 0x21:
        c = event->value & 0xff;
        if (m_sectionNames.find(m_currentSectionDefinition) == m_sectionNames.end()) {
            m_sectionNames[m_currentSectionDefinition] = c;
        } else {
            m_sectionNames[m_currentSectionDefinition] += c;
        }
        break;
    case 0x22:
        m_activeSection = (int) event->value;

        if (!m_handleExceptions || !m_inException) {
            if (m_sectionNames.find(m_activeSection) != m_sectionNames.end()) {
                createSection(event->timestamp, event->timestamp, m_activeSection, m_sectionNames[m_activeSection]);
            } else if (m_globalSectionNames.find(m_activeSection) != m_globalSectionNames.end()) {
                createSection(event->timestamp, event->timestamp, m_activeSection, m_globalSectionNames[m_activeSection]);
            }
        }
        break;
    case 0x23:
        // Activate exception handling for the sections
        m_handleExceptions = true;
    case 0x11:
        // Return from exception
        if (m_handleExceptions && m_inException) {
            if (m_sectionNames.find(m_activeSection) != m_sectionNames.end()) {
                createSection(event->timestamp, event->timestamp, m_activeSection, m_sectionNames[m_activeSection]);
            } else if (m_globalSectionNames.find(m_activeSection) != m_globalSectionNames.end()) {
                createSection(event->timestamp, event->timestamp, m_activeSection, m_globalSectionNames[m_activeSection]);
            }
        }
        m_inException = false;
        break;
    case 0x25:
        c = event->value & 0xff;
        if (m_globalSectionNames.find(m_currentSectionDefinition) == m_globalSectionNames.end()) {
            m_globalSectionNames[m_currentSectionDefinition] = c;
        } else {
            m_globalSectionNames[m_currentSectionDefinition] += c;
        }
        break;
    default:
        break;
    }

    return event->timestamp;
}
示例#11
0
BinarySection *BinaryImage::createSection(const QString &name, Interval<Address> extent)
{
    return createSection(name, extent.lower(), extent.upper());
}