Exemplo n.º 1
0
void FileSettings::constrainCacheToMaxSize(int size)
{
	const QString dataPath = dataFilePath();
	QDir dataDir(dataPath);

	// get size of cache
	QFileInfoList dataFileInfoList = dataDir.entryInfoList(QDir::Files | QDir::NoDotDot, QDir::Time);
	int cacheSize = QFileInfo(dataPath).size();
	for (int i = 0; i < dataFileInfoList.size(); ++i)
		cacheSize += dataFileInfoList.at(i).size();

	while (cacheSize > size) // remove oldest file settings from cache
	{
		if (dataFileInfoList.isEmpty())
			break;
		const QString fileName = dataFileInfoList.last().fileName();
		int fileSize = dataFileInfoList.takeLast().size();
		if (dataDir.remove(fileName))
			cacheSize -= fileSize;
	}
}
Exemplo n.º 2
0
/****************************************************************************
Desc: Returns the requested file handle
****************************************************************************/
RCODE F_MultiFileHdl::getFileHdl(
	FLMUINT				uiFileNum,
	FLMBOOL				bGetForWrite,
	IF_FileHdl **		ppFileHdl)
{
	RCODE					rc	= NE_FLM_OK;
	IF_FileSystem *	pFileSystem = f_getFileSysPtr();
	FLMUINT				uiSlot;
	IF_FileHdl *		pTmpHdl;
	char					szPath[ F_PATH_MAX_SIZE];

	f_assert( m_bOpen);

	*ppFileHdl = NULL;

	uiSlot = uiFileNum % F_MULTI_FHDL_LIST_SIZE;
	pTmpHdl = m_pFileHdlList[ uiSlot].pFileHdl;

	if( pTmpHdl && m_pFileHdlList[ uiSlot].uiFileNum != uiFileNum)
	{
		if( RC_BAD( rc = pTmpHdl->flush()))
		{
			goto Exit;
		}

		pTmpHdl->closeFile();
		pTmpHdl->Release();
		pTmpHdl = NULL;

		f_memset( &m_pFileHdlList[ uiSlot], 0, sizeof( FH_INFO));
	}

	if( !pTmpHdl)
	{
		dataFilePath( uiFileNum, szPath);
		if( RC_BAD( rc = pFileSystem->openFile( szPath, 
			FLM_IO_RDWR, &pTmpHdl)))
		{
			if( rc == NE_FLM_IO_PATH_NOT_FOUND && bGetForWrite)
			{
				if( RC_BAD( rc = pFileSystem->createFile( szPath,
 					FLM_IO_RDWR, &pTmpHdl)))
				{
					goto Exit;
				}
			}
			else
			{
				goto Exit;
			}
		}

		m_pFileHdlList[ uiSlot].pFileHdl = pTmpHdl;
		m_pFileHdlList[ uiSlot].uiFileNum = uiFileNum;
		f_assert( !m_pFileHdlList[ uiSlot].bDirty);
	}

	*ppFileHdl = m_pFileHdlList[ uiSlot].pFileHdl;
	if( bGetForWrite)
	{
		m_pFileHdlList[ uiSlot].bDirty = TRUE;
	}

Exit:

	return( rc);
}
Exemplo n.º 3
0
int DataFileManager::openFile(std::string _filename, DatumFileOptions opt) {
    // first we need to format the file name with the correct path and
    // extension
	std::string _ext_(appendDataFileExtension(
											  prependDataFilePath(_filename.c_str()).string()));    
    filename = _ext_;
    
    // form the scarab uri
    std::string prefix = "ldobinary:file://";
    std::string uri = prefix + filename;
	
	if(opt == M_NO_OVERWRITE) {
		FILE *fd = fopen(filename.c_str(), "r");
		if(fd != 0) {
			// badness....don't overwrite my file!
			fclose(fd);
			
			merror(M_FILE_MESSAGE_DOMAIN,
				   "Can't overwrite existing file: %s", filename.c_str());
			
            global_outgoing_event_buffer->putEvent(SystemEventFactory::dataFileOpenedResponse(filename.c_str(), 
																				M_COMMAND_FAILURE));
			return -1;
		}
	}			
	
    // Ensure that the data file directory exists
    boost::filesystem::create_directories(dataFilePath());
    
    if(scarab_create_file(filename.c_str()) != 0){
		merror(M_FILE_MESSAGE_DOMAIN,
			   "Could not create file: %s", filename.c_str());
		return -1;
	}
    
    // Generate list of excluded event codes
    std::unordered_set<int> excludedEventCodes;
    for (auto &var : global_variable_registry->getGlobalVariables()) {
        if (var->getProperties()->getExcludeFromDataFile()) {
            excludedEventCodes.insert(var->getCodecCode());
        }
    }
    
    scarab_connection = shared_ptr<ScarabWriteConnection>(new ScarabWriteConnection(global_outgoing_event_buffer,
                                                                                    uri,
                                                                                    excludedEventCodes));
    scarab_connection->connect();
	
    if(scarab_connection->isConnected()) {
        scarab_connection->startThread(M_DATAFILE_SERVICE_INTERVAL_US);
        file_open = true;
		
        // write out the event-code to name/description mapping
        // this is an essential part of the self-describing nature of the
        // MWorks/Scarab format
		global_outgoing_event_buffer->putEvent(SystemEventFactory::componentCodecPackage());
		global_outgoing_event_buffer->putEvent(SystemEventFactory::codecPackage());
		global_outgoing_event_buffer->putEvent(SystemEventFactory::currentExperimentState());
		global_variable_registry->announceAll();
    } else {
        merror(M_FILE_MESSAGE_DOMAIN,
			   "Failed to open file: %s", uri.c_str());
        global_outgoing_event_buffer->putEvent(SystemEventFactory::dataFileOpenedResponse(filename.c_str(), 
																			M_COMMAND_FAILURE));
        return -1;
    }
    
	mprintf(M_FILE_MESSAGE_DOMAIN, "Opening data file: %s", filename.c_str());
	
    // everything went ok so issue the success event
    global_outgoing_event_buffer->putEvent(SystemEventFactory::dataFileOpenedResponse(filename.c_str(), 
																		M_COMMAND_SUCCESS)); 
    return 0;
}
Exemplo n.º 4
0
QString FileSettings::fileSettingsPath(const QString &fileName)
{
	QString filePath = fileName;
	return dataFilePath() + QLatin1Char('/') + (filePath.replace(QLatin1String("/"), QLatin1String("_")) + QLatin1String(".ini"));
}