Beispiel #1
0
/**
 * @brief Clean up load status information
 *
 * @param self [in/out] Load status information
 * @return void
 */
static WriterResult
DirectWriterClose(DirectWriter *self, bool onError)
{
	WriterResult	ret = { 0 };

	Assert(self != NULL);

	/* Flush unflushed block buffer and close the heap file. */
	if (!onError)
		flush_pages(self);

	close_data_file(self);
	UnlinkLSF(self);

	if (!onError)
	{
		SpoolerClose(&self->spooler);
		ret.num_dup_new = self->spooler.dup_new;
		ret.num_dup_old = self->spooler.dup_old;

		if (self->base.rel)
			heap_close(self->base.rel, AccessExclusiveLock);

		if (self->blocks)
			pfree(self->blocks);

		pfree(self);
	}

	return ret;
}
Beispiel #2
0
static int save_points(int end_track) {

   int error = 0;
   int i;

   roadmap_log(ROADMAP_INFO, "Saving points, end_track:%d", end_track);
   if (track_file == NULL) return -1;

   for (i=0; i<points_count; i++) {
      RoadMapGpsPosition *pos = &TrackPoints[i].gps_point;
      if (fwrite(&pos->longitude, sizeof(pos->longitude), 1, track_file) != 1) {
         error = 1;
      }
      if (fwrite(&pos->latitude, sizeof(pos->latitude), 1, track_file) != 1) {
         error = 1;
      }
      if (fwrite(&TrackPoints[i].time, sizeof(TrackPoints[i].time), 1,
            track_file) != 1) {
         error = 1;
      }

      fflush(track_file);

      if (error) {
         roadmap_log(ROADMAP_ERROR, "Error writing GPS data.");
         roadmap_messagebox("Error", "Error writing GPS data.");
         close_data_file();
         return -1;
      }
   }

   if (end_track) {
      int null[3] = {0, 0, 0};
      if (fwrite(null, sizeof(null), 1, track_file) != 1) {
         roadmap_messagebox("Error", "Error writing GPS data.");
         close_data_file();
         return -1;
      }
   }

   points_count = 0;

   return 0;
}
Beispiel #3
0
void open_data_file() {
  if (_g_data_fd > 0)
    close_data_file();

  _g_data_fd = open(_g_data_filename.c_str(), O_WRONLY | O_CREAT, S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH);

  if (_g_data_fd < 0) {
    fprintf(_g_error, "ERROR: failed to create file \"%s\"\n", _g_data_filename.c_str());
    exit(6);
  }
  else {
    fprintf(_g_info, "Data will be written out to `%s'\n", _g_data_filename.c_str());
  }
}
Beispiel #4
0
static void track_rec_upload (void) {
   char *file_name;

   if (RecordGpsData) {
      track_end ();
      RecordGpsData = 0;
      close_data_file();
   }

   file_name = roadmap_path_join(roadmap_config_get(&RoadMapConfigMapPath),
                                 "track_data.bin");                      

   NOPH_try(exception_handler, NULL) {
      editor_upload_file (file_name, 1);
   } NOPH_catch();
Beispiel #5
0
uint8_t test_builddata(uint8_t ev, uint16_t lparam, void* rparam)
{

    printf("test_builddata()\n");
    uint8_t meta[] = {DATA_COL_STEP, DATA_COL_DIST, DATA_COL_HR};
    uint32_t data[] = {1234, 5678, 9012};

    create_data_file(12, 11, 28);
    write_data_line(0x00, 1, 1, meta, data, 3);
    write_data_line(0x00, 1, 2, meta, data, 3);
    write_data_line(0x01, 1, 3, meta, data, 3);
    write_data_line(0x02, 1, 4, meta, data, 3);
    write_data_line(0x03, 1, 5, meta, data, 3);
    close_data_file();

    return 0;
}
Eyelink::~Eyelink(){
    
    boost::mutex::scoped_lock lock(EyelinkDriverLock);
    
	if (Eyelink_Initialized) {
        
		if (!stopped) {
			mwarning(M_IODEVICE_MESSAGE_DOMAIN,"Eyelink is still running !");
            //eyelink stop recording
			if(eyelink_is_connected()) { stop_recording(); }
		}
        
		if (schedule_node) {
			schedule_node->cancel();
			schedule_node.reset();
		}
		
		if(eyelink_is_connected()) {
			
			// Places EyeLink tracker in off-line (idle) mode
			set_offline_mode();
			// close any open data files
			
			if ( close_data_file() == 0 ) {
                mprintf(M_IODEVICE_MESSAGE_DOMAIN,"Eyelink closed data file %s.",data_file_name);
            }
			
			if (eyelink_close(1)) // disconnect from tracker
			{
				merror(M_IODEVICE_MESSAGE_DOMAIN, "Could not close Eyelink connection");
			}
            
			//close_eyelink_system();
			
            mprintf(M_IODEVICE_MESSAGE_DOMAIN, "Eyelink %d System Version %s disconnected.",tracker_version,version_info);
            
		}
		else {
			mwarning(M_IODEVICE_MESSAGE_DOMAIN,"Error, Eyelink Shutdown failed");
		}
		
		Eyelink_Initialized = false;
        
    }
}
Beispiel #7
0
static void
check_file (const char* file_name)
{
  FILE *fp;

  int tmp;
  int base;
  int inex_re;
  int inex_im;
  mpc_t expected, got;
  mpc_rnd_t rnd = MPC_RNDNN;
  int inex = 0, expected_inex;
  size_t expected_size, size;
  known_signs_t ks = {1, 1};

  fp = open_data_file (file_name);

  mpc_init2 (expected, 53);
  mpc_init2 (got, 53);

  /* read data file */
  line_number = 1;
  nextchar = getc (fp);
  skip_whitespace_comments (fp);

  while (nextchar != EOF)
    {
      /* 1. read a line of data: expected result, base, rounding mode */
      read_ternary (fp, &inex_re);
      read_ternary (fp, &inex_im);
      read_mpc (fp, expected, &ks);
      if (inex_re == TERNARY_ERROR || inex_im == TERNARY_ERROR)
         expected_inex = -1;
      else
         expected_inex = MPC_INEX (inex_re, inex_im);
      read_int (fp, &tmp, "size");
      expected_size = (size_t)tmp;
      read_int (fp, &base, "base");
      read_mpc_rounding_mode (fp, &rnd);

      /* 2. read string at the same precision as the expected result */
      while (nextchar != '"')
        nextchar = getc (fp);
      mpfr_set_prec (MPC_RE (got), MPC_PREC_RE (expected));
      mpfr_set_prec (MPC_IM (got), MPC_PREC_IM (expected));
      inex = mpc_inp_str (got, fp, &size, base, rnd);

      /* 3. compare this result with the expected one */
      if (inex != expected_inex || !same_mpc_value (got, expected, ks)
          || size != expected_size)
        {
          printf ("mpc_inp_str failed (line %lu) with rounding mode %s\n",
                  line_number, rnd_mode[rnd]);
          if (inex != expected_inex)
            printf("     got inexact value: %d\nexpected inexact value: %d\n",
                   inex, expected_inex);
          if (size !=  expected_size)
            printf ("     got size: %lu\nexpected size: %lu\n     ",
                    (unsigned long int) size, (unsigned long int) expected_size);
          printf ("    ");
          OUT (got);
          OUT (expected);

          exit (1);
        }

      while ((nextchar = getc (fp)) != '"');
      nextchar = getc (fp);

      skip_whitespace_comments (fp);
    }

  mpc_clear (expected);
  mpc_clear (got);
  close_data_file (fp);
}
Beispiel #8
0
void close_data_file_to_prepare_for_next_spill() {
  close_data_file();
}
Beispiel #9
0
/**
 * @brief Write block buffer contents.	Number of block buffer to be
 * written is specified by num argument.
 *
 * Flow:
 * <ol>
 *	 <li>If no more space is available in the data file, switch to a new one.</li>
 *	 <li>Compute block number which can be written to the current file.</li>
 *	 <li>Save the last block number in the load status file.</li>
 *	 <li>Write to the current file.</li>
 *	 <li>If there are other data, write them too.</li>
 * </ol>
 *
 * @param loader [in] Direct Writer.
 * @return File descriptor for the current data file.
 */
static void
flush_pages(DirectWriter *loader)
{
	int			i;
	int			num;
	LoadStatus *ls = &loader->ls;

	num = loader->curblk;
	if (!PageIsEmpty(GetCurrentPage(loader)))
		num += 1;

	if (num <= 0)
		return;		/* no work */

	/*
	 * Add WAL entry (only the first page) to ensure the current xid will
	 * be recorded in xlog. We must flush some xlog records with XLogFlush()
	 * before write any data blocks to follow the WAL protocol.
	 *
	 * If postgres process, such as loader and COPY, is killed by "kill -9",
	 * database will be rewound to the last checkpoint and recovery will
	 * be performed using WAL.
	 *
	 * After the recovery, if there are xid's which have not been recorded
	 * to WAL, such xid's will be reused.
	 *
	 * However, in the loader and COPY, data file is actually updated and
	 * xid must not be reused.
	 *
	 * WAL entry with such xid can be added using XLogInsert().  However,
	 * such entries are not really written to the disk immediately.
	 * WAL entries are flushed to the disk by XLogFlush(), typically
	 * when a transaction is commited.	COPY prevents xid reuse by
	 * this method.
	 */
#if PG_VERSION_NUM >= 90100
	if (ls->ls.create_cnt == 0 && !RELATION_IS_LOCAL(loader->base.rel)
			&& !(loader->base.rel->rd_rel->relpersistence == RELPERSISTENCE_UNLOGGED) )
	{
		XLogRecPtr	recptr;

		recptr = log_newpage(&ls->ls.rnode, MAIN_FORKNUM,
			ls->ls.exist_cnt, loader->blocks);
		XLogFlush(recptr);
	}
#else
	if (ls->ls.create_cnt == 0 && !RELATION_IS_LOCAL(loader->base.rel) )
	{
		XLogRecPtr	recptr;

		recptr = log_newpage(&ls->ls.rnode, MAIN_FORKNUM,
			ls->ls.exist_cnt, loader->blocks);
		XLogFlush(recptr);
	}
#endif
	/*
	 * Write blocks. We might need to write multiple files on boundary of
	 * relation segments.
	 */
	for (i = 0; i < num;)
	{
		char	   *buffer;
		int			total;
		int			written;
		int			flush_num;
		BlockNumber	relblks = LS_TOTAL_CNT(ls);

		/* Switch to the next file if the current file has been filled up. */
		if (relblks % RELSEG_SIZE == 0)
			close_data_file(loader);
		if (loader->datafd == -1)
			loader->datafd = open_data_file(ls->ls.rnode,
											RELATION_IS_LOCAL(loader->base.rel),
											relblks);

		/* Number of blocks to be added to the current file. */
		flush_num = Min(num - i, RELSEG_SIZE - relblks % RELSEG_SIZE);
		Assert(flush_num > 0);

		/* Write the last block number to the load status file. */
		UpdateLSF(loader, flush_num);

#if PG_VERSION_NUM >= 90300
		/* If we need a checksum, add it */
	        if (DataChecksumsEnabled()){
        		int j = 0;
			Page contained_page;
	        	for (  j=0; j<flush_num; j++ ) {
                		contained_page = GetTargetPage(loader,j);
		                ((PageHeader) contained_page)->pd_checksum = 
					pg_checksum_page((char *) contained_page, LS_TOTAL_CNT(ls) - 1 - j);
        		}
		}	
#endif

		/*
		 * Flush flush_num data block to the current file.
		 * Then the current file size becomes RELSEG_SIZE self->blocks.
		 */
		buffer = loader->blocks + BLCKSZ * i;
		total = BLCKSZ * flush_num;
		written = 0;
		while (total > 0)
		{
			int	len = write(loader->datafd, buffer + written, total);
			if (len == -1)
			{
				/* fatal error, do not want to write blocks anymore */
				ereport(ERROR, (errcode_for_file_access(),
								errmsg("could not write to data file: %m")));
			}
			written += len;
			total -= len;
		}

		i += flush_num;
	}

	/*
	 * NOTICE: Be sure reset curblk to 0 and reinitialize recycled page
	 * if you will continue to use blocks.
	 */
}