Example #1
0
void
Logger::openLogFile(wstring file)
{
	if(!isFileOpen())
	{
		wchar_t* szFullPath = new wchar_t[4096];
		wchar_t* pFileName;
		GetFullPathName(
			file.c_str(),
			4096,
			szFullPath,
			&pFileName
		);
		logFullPath = szFullPath;
		logFileName = pFileName;
		std::transform(logFullPath.begin(),logFullPath.end(),logFullPath.begin(), towlower);
		hLog = CreateFile(
					szFullPath,
					GENERIC_WRITE,
					FILE_SHARE_READ,
					NULL,
					CREATE_ALWAYS,
					FILE_ATTRIBUTE_NORMAL,
					NULL
					);
		if(hLog != INVALID_HANDLE_VALUE)
		{
			DebugPrint(L"Logger-openLogFile: Log file successfully opened - %ls\n", szFullPath);
			fileOpen = true;
		} else {
			printf("Logger: ERROR %08x - Could not open log file %ls\n", GetLastError(), szFullPath);
		}
		delete [] szFullPath;
	}
}
Example #2
0
void
AnalysisDataVectorPlotModule::pointsAdded(const AnalysisDataPointSetRef &points)
{
    if (points.firstColumn() % DIM != 0 || points.columnCount() % DIM != 0)
    {
        GMX_THROW(APIError("Partial data points"));
    }
    if (!isFileOpen())
    {
        return;
    }
    for (int i = 0; i < points.columnCount(); i += 3)
    {
        for (int d = 0; d < DIM; ++d)
        {
            if (bWrite_[i])
            {
                writeValue(points.values()[i + d]);
            }
        }
        if (bWrite_[DIM])
        {
            const rvec        y = { points.y(i), points.y(i + 1), points.y(i + 2) };
            AnalysisDataValue value(norm(y));
            writeValue(value);
        }
    }
}
void CardReader::unparseKeyLine(const char *key, char *value) {
  if (!cardOK || !isFileOpen()) return;
  file.writeError = false;
  file.write(key);
  if (file.writeError) {
    ECHO_LM(ER, MSG_SD_ERR_WRITE_TO_FILE);
    return;
  }
  
  file.writeError = false;
  file.write("=");
  if (file.writeError) {
    ECHO_LM(ER, MSG_SD_ERR_WRITE_TO_FILE);
    return;
  }
  
  file.writeError = false;
  file.write(value);
  if (file.writeError) {
    ECHO_LM(ER, MSG_SD_ERR_WRITE_TO_FILE);
    return;
  }

  file.writeError = false;
  file.write("\n");
  if (file.writeError) {
    ECHO_LM(ER, MSG_SD_ERR_WRITE_TO_FILE);
    return;
  }
}
Example #4
0
void RecordingFile::startRecording(msr::airlib::VehicleSimApiBase* vehicle_sim_api)
{
    try {
        std::string log_folderpath = common_utils::FileSystem::getLogFolderPath(true);
        image_path_ = common_utils::FileSystem::ensureFolder(log_folderpath, "images");
        std::string log_filepath = common_utils::FileSystem::getLogFileNamePath(log_folderpath, record_filename, "", ".txt", false);
        if (log_filepath != "")
            createFile(log_filepath, vehicle_sim_api->getRecordFileLine(true));
        else {
            UAirBlueprintLib::LogMessageString("Cannot start recording because path for log file is not available", "", LogDebugLevel::Failure);
            return;
        }

        if (isFileOpen()) {
            is_recording_ = true;

            UAirBlueprintLib::LogMessage(TEXT("Recording: "), TEXT("Started"), LogDebugLevel::Success);
        }
        else
            UAirBlueprintLib::LogMessageString("Error creating log file", log_filepath.c_str(), LogDebugLevel::Failure);
    }
    catch(...) {
        UAirBlueprintLib::LogMessageString("Error in startRecording", "", LogDebugLevel::Failure);
    }
}
Example #5
0
void RecordingFile::closeFile()
{
    if (isFileOpen())
        delete log_file_handle_;

    log_file_handle_ = nullptr;
}
void CardReader::parseKeyLine(char *key, char *value, int &len_k, int &len_v) {
  if (!cardOK || !isFileOpen()) {
    key[0] = value[0] = '\0';
    len_k = len_v = 0;
    return;
  }
  int ln_buf = 0;
  char ln_char;
  bool ln_space = false, ln_ignore = false, key_found = false;
  while(!eof()) {		//READ KEY
    ln_char = (char)get();
    if(ln_char == '\n') {
      ln_buf = 0;
      ln_ignore = false;  //We've reached a new line try to find a key again
      continue;
    }
    if(ln_ignore) continue;
    if(ln_char == ' ') {
      ln_space = true;
      continue;
    }
    if(ln_char == '=') {
      key[ln_buf] = '\0';
      len_k = ln_buf;
      key_found = true;
      break; //key finded and buffered
    }
    if(ln_char == ';' || ln_buf+1 >= len_k || ln_space && ln_buf > 0) { //comments on key is not allowd. Also key len can't be longer than len_k or contain spaces. Stop buffering and try the next line
      ln_ignore = true;
      continue;
    }
    ln_space = false;
    key[ln_buf] = ln_char;
    ln_buf++;
  }
  if(!key_found) { //definitly there isn't no more key that can be readed in the file
    key[0] = value[0] = '\0';
    len_k = len_v = 0;
    return;
  }
  ln_buf = 0;
  ln_ignore = false;
  while(!eof()) {		//READ VALUE
    ln_char = (char)get();
	  if(ln_char == '\n') {
      value[ln_buf] = '\0';
      len_v = ln_buf;
      break;	//new line reached, we can stop
    }
    if(ln_ignore|| ln_char == ' ' && ln_buf == 0) continue; //ignore also initial spaces of the value
    if(ln_char == ';' || ln_buf+1 >= len_v) { //comments reached or value len longer than len_v. Stop buffering and go to the next line.
      ln_ignore = true;
      continue;
    }
    value[ln_buf] = ln_char;
    ln_buf++;
  }
}
Example #7
0
void
Logger::closeLogFile()
{
	if(isFileOpen())
	{
		CloseHandle(hLog);
		fileOpen = false;
	}
}
Example #8
0
void
AbstractPlotModule::frameFinished(const AnalysisDataFrameHeader & /*header*/)
{
    if (!isFileOpen())
    {
        return;
    }
    std::fprintf(impl_->fp_, "\n");
}
  int ResultsViewerData::addFile(const QString& alias, const QString& filename)
  {
    if (!QFileInfo(filename).exists()) return RVD_FILEDOESNOTEXIST;
    if (isFileOpen(filename)) return RVD_FILEALREADYOPENED;
    openstudio::path p = toPath(filename);

    return addFile(alias, openstudio::SqlFile(p));

  }
Example #10
0
/*
 * Main method.
 * This method is responsible for opening the input and output files and
 * closing them at the end (or if an error occured).
 */
int main(int argc, char *argv[])
{
    if(isValidArgumentsNum(argc,"Usage: Perceptron <input file> <output file>\n"))
    {
        //making sure files opened properly, and closing only opened files.
        FILE* input_file = fopen(argv[1],"r");
        if(isFileOpen(input_file,argv[1]))
        {
            FILE* output_file = fopen(argv[2],"w");
            if(isFileOpen(output_file,argv[2]))
            {
                perceptron(input_file,output_file);
                fclose(output_file);
            }
            fclose(input_file);
        }
    }
    return 0;
}
  int ResultsViewerData::addFile(const QString& alias, openstudio::SqlFile sqlFile)
  {
    if (!sqlFile.connectionOpen()) return RVD_UNSUPPORTEDFILEFORMAT;
    if (isFileOpen(sqlFile)) return RVD_FILEALREADYOPENED;

    m_sqlFileMap[sqlFile] = alias;

    if (!sqlFile.supportedVersion()) return RVD_UNSUPPORTEDVERSION;

    return RVD_SUCCESS;
  }
Example #12
0
void
AnalysisDataPlotModule::pointsAdded(const AnalysisDataPointSetRef &points)
{
    if (!isFileOpen())
    {
        return;
    }
    for (int i = 0; i < points.columnCount(); ++i)
    {
        writeValue(points.values()[i]);
    }
}
Example #13
0
void
AbstractPlotModule::frameStarted(const AnalysisDataFrameHeader &frame)
{
    if (!isFileOpen())
    {
        return;
    }
    if (!impl_->bOmitX_)
    {
        std::fprintf(impl_->fp_, impl_->xformat_, frame.x() * impl_->xscale_);
    }
}
Example #14
0
void
AbstractPlotModule::writeValue(const AnalysisDataValue &value) const
{
    GMX_ASSERT(isFileOpen(), "File not opened, but write attempted");
    const real y = value.isSet() ? value.value() : 0.0;
    std::fprintf(impl_->fp_, impl_->yformat_, y);
    if (impl_->bErrorsAsSeparateColumn_)
    {
        const real dy = value.isSet() ? value.error() : 0.0;
        std::fprintf(impl_->fp_, impl_->yformat_, dy);
    }
}
 void ResultsViewerData::removeFile(const QString& filename)
 {
   if (isFileOpen(filename))
   {
     for(auto iter=m_sqlFileMap.begin(); iter!=m_sqlFileMap.end(); ++iter) 
     {
       if ( toPath(filename.toUpper()) == toPath(toQString((*iter).first.energyPlusSqliteFile()).toUpper()) ) 
       {
         m_sqlFileMap.erase(iter);
         break;
       }
     }
   }
 }
Example #16
0
 void ResultsViewerData::removeFile(const QString& filename)
 {
   if (isFileOpen(filename))
   {
     std::map<openstudio::SqlFile, QString>::iterator iter;
     for(iter=m_sqlFileMap.begin(); iter!=m_sqlFileMap.end(); ++iter) 
     {
       if ( filename.toUpper() == toQString((*iter).first.energyPlusSqliteFile()).toUpper() ) 
       {
         m_sqlFileMap.erase(iter);
         break;
       }
     }
   }
 }
Example #17
0
void RecordingFile::stopRecording(bool ignore_if_stopped)
{
    is_recording_ = false;
    if (! isFileOpen()) {
        if (ignore_if_stopped)
            return;

        UAirBlueprintLib::LogMessage(TEXT("Recording Error"), TEXT("File was not open"), LogDebugLevel::Failure);
    }
    else
        closeFile();

    UAirBlueprintLib::LogMessage(TEXT("Recording: "), TEXT("Stopped"), LogDebugLevel::Success);
    UAirBlueprintLib::LogMessage(TEXT("Data saved to: "), FString(image_path_.c_str()), LogDebugLevel::Success);
}
Example #18
0
int DataFileManager::closeFile() {
    if (!isFileOpen()) {
        merror(M_FILE_MESSAGE_DOMAIN, "Attempt to close a data file when there isn't one open");
    } else {
        mprintf(M_FILE_MESSAGE_DOMAIN, "Closing data file...");
        
        running = false;
        eventHandlerThread.join();
        eventBufferReader.reset();
        mwk2Writer.reset();
        
        mprintf(M_FILE_MESSAGE_DOMAIN, "Closed data file: %s", filename.c_str());
        global_outgoing_event_buffer->putEvent(SystemEventFactory::dataFileClosedResponse(filename.c_str(),
                                                                                          M_COMMAND_SUCCESS));
    }
    return 0;
}
Example #19
0
void
Logger::writeSystemEventToLog(wstring* type, wstring* time, 
							  wstring* process, wstring* action, 
							  wstring* object)
{
	if(isFileOpen())
	{
		wstring message = L"\"";
		message += *time;
		message += L"\",\"";
		message += *type;
		message += L"\",\"";
		message += *action;
		message += L"\",\"";
		message += *process;
		message += L"\",\"";
		message += *object;
		message += L"\"\r\n";
		writeToLog(&message);
	}
}
Example #20
0
void 
Logger::writeToLog(wstring* message)
{
	if(isFileOpen())
	{
		size_t charsConverted;
		char* szMessage = convertToMultiByteString(message, &charsConverted);
		if(szMessage != NULL)
		{
			DWORD bytesWritten;
			WriteFile(
				hLog,
				szMessage,
				static_cast<unsigned long>(charsConverted), // Ignore null charater
				&bytesWritten,
				NULL
				);

			free(szMessage);
		}
	}
}
Example #21
0
int DataFileManager::openFile(std::string _filename, DatumFileOptions opt) {
    if (isFileOpen()) {
        mwarning(M_FILE_MESSAGE_DOMAIN, "Data file already open at \"%s\"", filename.c_str());
        return -1;
    }
    
    // first we need to format the file name with the correct path and
    // extension
    filename = appendDataFileExtension(prependDataFilePath(_filename).string());
    const auto filepath = boost::filesystem::path(filename);
    
    if (boost::filesystem::exists(filepath)) {
        if (opt == M_NO_OVERWRITE) {
            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;
        }
        try {
            boost::filesystem::remove(filepath);
        } catch (const std::exception &e) {
            merror(M_FILE_MESSAGE_DOMAIN, "Can't remove existing file \"%s\": %s", filename.c_str(), e.what());
            global_outgoing_event_buffer->putEvent(SystemEventFactory::dataFileOpenedResponse(filename.c_str(),
                                                                                              M_COMMAND_FAILURE));
            return -1;
        }
    }
    
    // Ensure that the destination directory exists
    try {
        boost::filesystem::create_directories(filepath.parent_path());
    } catch (const std::exception &e) {
        merror(M_FILE_MESSAGE_DOMAIN, "Could not create data file destination directory: %s", e.what());
        global_outgoing_event_buffer->putEvent(SystemEventFactory::dataFileOpenedResponse(filename.c_str(),
                                                                                          M_COMMAND_FAILURE));
        return -1;
    }
    
    // Create the file
    try {
        mwk2Writer.reset(new MWK2Writer(filename));
    } catch (const SimpleException &e) {
        merror(M_FILE_MESSAGE_DOMAIN, "Could not create file \"%s\": %s", filename.c_str(), e.what());
        global_outgoing_event_buffer->putEvent(SystemEventFactory::dataFileOpenedResponse(filename.c_str(),
                                                                                          M_COMMAND_FAILURE));
        return -1;
    }
    
    // Generate list of excluded event codes
    excludedEventCodes.clear();
    for (auto &var : global_variable_registry->getGlobalVariables()) {
        if (var->getProperties()->getExcludeFromDataFile()) {
            excludedEventCodes.insert(var->getCodecCode());
        }
    }
    
    // Create the event buffer reader
    eventBufferReader.reset(new EventBufferReader(global_outgoing_event_buffer));
    
    // Start the event handler thread
    running = true;
    eventHandlerThread = std::thread([this]() { handleEvents(); });
    
    // Announce component codec, variable codec, experiment state, and all current
    // variable values
    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();
    
    mprintf(M_FILE_MESSAGE_DOMAIN, "Opened 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;
}