Esempio n. 1
0
blast_reader_t*
blast_reader_open(string_t source) {
    void* addr;
    int64_t size;
    blast_reader_t* reader;
    int fd;

    fd = _open(source.str, O_RDONLY);
    if (fd == 0)
        return 0;

    size = _lseek(fd, 0, SEEK_END);
    if (size <= 0) {
        _close(fd);
        return 0;
    }
    _lseek(fd, 0, SEEK_SET);

    addr = memory_allocate(HASH_BLAST, (size_t)size, 0, MEMORY_PERSISTENT);
    _read(fd, addr, (int)size);
    _close(fd);
    /*addr = mmap( 0, size, PROT_READ, MAP_FILE | MAP_PRIVATE, fd, 0 );
    if( addr == MAP_FAILED )
    {
        int err = system_error();
        log_warnf( HASH_BLAST, WARNING_SYSTEM_CALL_FAIL, "Unable to mmap file '%s' (%d) size %d: %s (%d)", source, fd, size, system_error_message( err ), err );
        close( fd );
        return 0;
    }

    log_infof( HASH_BLAST, "Mapped '%s' size %lld to memory region 0x%" PRIfixPTR, source, size, addr );*/

    reader = memory_allocate(HASH_BLAST, sizeof(blast_reader_t), 0,
                             MEMORY_PERSISTENT | MEMORY_ZERO_INITIALIZED);

    string_const_t filename = path_file_name(STRING_ARGS(source));
    reader->name = string_clone(STRING_ARGS(filename));
    reader->data = addr;
    //reader->id = fd;
    reader->size = (uint64_t)size;
    reader->cache = blast_reader_cache;
    reader->uncache = blast_reader_uncache;
    reader->map = blast_reader_map;
    reader->unmap = blast_reader_unmap;

    return reader;
}
Esempio n. 2
0
char* path_subdirectory_name( const char* path, const char* root )
{
	char* subpath;
	char* testpath;
	char* testroot;
	char* pathofpath;
	unsigned int pathprotocol, rootprotocol;
	char* cpath = string_clone( path );
	char* croot = string_clone( root );

	cpath = path_clean( cpath, path_is_absolute( cpath ) );
	croot = path_clean( croot, path_is_absolute( croot ) );

	pathofpath = path_directory_name( cpath );

	testpath = pathofpath;
	pathprotocol = string_find_string( testpath, "://", 0 );
	if( pathprotocol != STRING_NPOS )
		testpath += pathprotocol + 2; // add two to treat as absolute path

	testroot = croot;
	rootprotocol = string_find_string( testroot, "://", 0 );
	if( rootprotocol != STRING_NPOS )
		testroot += rootprotocol + 2;

	if( ( rootprotocol != STRING_NPOS ) && ( ( pathprotocol == STRING_NPOS ) || ( pathprotocol != rootprotocol ) || !string_equal_substr( cpath, croot, rootprotocol ) ) )
		subpath = string_allocate( 0 );
	else if( !string_equal_substr( testpath, testroot, string_length( testroot ) ) )
		subpath = string_allocate( 0 );
	else
	{
		char* filename = path_file_name( cpath );

		subpath = string_substr( testpath, string_length( testroot ), STRING_NPOS );
		subpath = path_clean( path_append( subpath, filename ), false );

		string_deallocate( filename );
	}
	string_deallocate( pathofpath );
	string_deallocate( cpath );
	string_deallocate( croot );

	return subpath;
}
Esempio n. 3
0
Socket* set_up_connection__gui( Robot_location& robot_location_a, 
                                Robot_location& robot_location_b,
                                Targets_manager* target_configurations_manager_ptr)
{
  int host_port_g = 1103;
  int conenctions = 1;

  std::cout <<"in main thread : " <<boost::this_thread::get_id()<<std::endl;
  std::cout <<"before connecting to gui "<<std::endl<<std::endl;

  Socket_server server_g(host_port_g, conenctions);
  //here gui should be executed
  Socket* socket_g=server_g.accept();
  std::cout <<"connected to gui"<<std::endl;

  std::stringstream initial_command;
  initial_command << configuration.get_workspace_file_name()<<" ";  //workspace filename
  initial_command << configuration.get_robot_file_name_a()<<" ";    //robot filename
  initial_command << configuration.get_all_target_configurations_file_name()<<" "; //query filename
  socket_g->send_line(initial_command.str().c_str());

  //now send intial placements of each robot
  double x_a = CGAL::to_double(robot_location_a.get().get_location().x());
  double y_a = CGAL::to_double(robot_location_a.get().get_location().y());
  double t_a = robot_location_a.get().get_rotation().to_angle();

  double x_b = CGAL::to_double(robot_location_b.get().get_location().x());
  double y_b = CGAL::to_double(robot_location_b.get().get_location().y());
  double t_b = robot_location_b.get().get_rotation().to_angle();
  
  std::string path_file_name("initial_location.txt");
  ofstream path_os(path_file_name.c_str());
  path_os << 2 <<std::endl;
  //initial location
  path_os << x_a <<" " << y_a <<" " << t_a <<" "
          << x_b <<" " << y_b <<" " << t_b <<std::endl;
  //no movement
  path_os << 0 <<" " << 0 <<" " << 0 <<" "
          << 0 <<" " << 0 <<" " << 0 <<" " << 0 <<" " << std::endl;
  
  //get motion status and write to file
  std::string status_file_name("initial_status.txt");
  ofstream status_os(status_file_name.c_str());

  //get status 
  Int_vec configuration_status;  
  target_configurations_manager_ptr->get_configuration_status(configuration_status);
  
  //write status to file
  status_os <<"2" <<std::endl;  //one entry
  status_os <<0<<std::endl;     //before motion
  for (unsigned int i(0); i < configuration_status.size(); ++i)
    status_os <<configuration_status[i]<<" ";
  status_os <<1<<std::endl;     //after motion
  for (unsigned int i(0); i < configuration_status.size(); ++i)
    status_os <<configuration_status[i]<<" ";
  status_os <<std::endl;

  std::stringstream path_update;
	path_update << path_file_name << " "; //path to draw filename
	path_update << status_file_name << " "; //state to draw filename
	socket_g->send_line(path_update.str().c_str());

  return socket_g;
}