MemoryMappedFile::MemoryMappedFile(const char *filename, size_t offset, size_t length)
    : m_file(NULL), m_mapping(NULL)
{
    FileHandle fd;
    fd.handle = CreateFile(filename, GENERIC_READ | GENERIC_WRITE, FILE_SHARE_READ | FILE_SHARE_WRITE, NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL);

    if (fd.handle == INVALID_HANDLE_VALUE)
    {
        throw IOException(std::string("Failed to open existing file: ") + filename + " " + toString(GetLastError()), SOURCEINFO);
    }

    if (0 == length && 0 == offset)
    {
        LARGE_INTEGER fileSize;
        if (!GetFileSizeEx(fd.handle, &fileSize))
        {
            cleanUp();
            throw IOException(std::string("Failed query size of existing file: ") + filename + " " + toString(GetLastError()), SOURCEINFO);
        }

        length = (size_t)fileSize.QuadPart;
    }

    m_memorySize = length;
    m_memory = doMapping(m_memorySize, fd, offset);

    if (!m_memory)
    {
        cleanUp();
        throw IOException(std::string("Failed to Map Memory: ") + filename + " " + toString(GetLastError()), SOURCEINFO);
    }
}
MemoryMappedFile::MemoryMappedFile(const char *filename, size_t size)
    : m_file(NULL), m_mapping(NULL), m_memory(NULL)
{
    FileHandle fd;
    fd.handle = CreateFile(filename, GENERIC_READ | GENERIC_WRITE, FILE_SHARE_READ | FILE_SHARE_WRITE, NULL, CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL);

    if (fd.handle == INVALID_HANDLE_VALUE)
    {
        throw IOException(std::string("Failed to create file: ") + filename + " " + toString(GetLastError()), SOURCEINFO);
    }

    if (!fill(fd, size, 0))
    {
        cleanUp();
        throw IOException(std::string("Failed to write to file: ") + filename + " " + toString(GetLastError()), SOURCEINFO);
    }

    m_memorySize = size;
    m_memory = doMapping(m_memorySize, fd, 0);

    if (!m_memory)
    {
        cleanUp();
        throw IOException(std::string("Failed to Map Memory: ") + filename + " " + toString(GetLastError()), SOURCEINFO);
    }
}
MemoryMappedFile::MemoryMappedFile(const char *filename, size_t length)
{
    FileHandle fd;
    fd.handle = open(filename, O_RDWR|O_CREAT, 0666);
    if (fd.handle < 0)
    {
        throw IOException(std::string("Failed to create file: ") + filename, SOURCEINFO);
    }

    m_memorySize = length;

    OnScopeExit tidy ([&]()
    {
        close(fd.handle);
    });

    if (!fill(fd, length, 0))
    {
        throw IOException(std::string("Failed to write to file: ") + filename, SOURCEINFO);
    }

    m_memory = doMapping(length, fd, 0);
}
Ejemplo n.º 4
0
//we want the boat to stay within 350-425 range finders for sensors
//Get feedback from fanboat
void mapping::sensorFilter_callback(const fanboat_ll::fanboatLL::ConstPtr& f_ll)
{
	fll = *f_ll;
	lab2::angle_msg boat;

	//ROS_INFO("mapping");
	leftS = fll.a0;
	rightS = fll.a1;
	if (initLeftS == -100){
		initLeftS = 300;
	}
	if (initRightS == -100){
		initRightS = 300;
	}

	if(state == 0){
		doMapping();
		ROS_INFO("MAPPING");
	} else if (state == 1){
		angle = yawClose;
		turn(yawClose);
		ROS_INFO("TURN CLOSE");
	} else if (state == 2){
		angle = yawFar;
		turn(yawFar);
		ROS_INFO("TURN FAR");
	} else if (state == 3){
		reactive();
		ROS_INFO("GO TO THERE");
	}

	boat.angle = angle;
	boat.thrust = thrust;
	ROS_INFO("angle: %f", angle);
	angles_pub_.publish(boat);
}
MemoryMappedFile::MemoryMappedFile(const char *filename, size_t length, size_t offset)
{
    FileHandle fd;
    fd.handle = ::open(filename, O_RDWR, 0666);
    if (fd.handle < 0)
    {
        throw IOException(std::string("Failed to open existing file: ") + filename, SOURCEINFO);
    }

    OnScopeExit tidy([&]()
    {
        close(fd.handle);
    });

    if (0 == length && 0 == offset)
    {
        struct stat statInfo;
        ::fstat(fd.handle, &statInfo);
        length = statInfo.st_size;
    }

    m_memorySize = length;
    m_memory = doMapping(m_memorySize, fd, offset);
}