Commit d37cd870 authored by Hugo Beauzée-Luyssen's avatar Hugo Beauzée-Luyssen

IDevice: Remove isPresent & add mountpoint method.

An absent device will simply be represented with a nullptr.
parent e5b274e8
......@@ -31,7 +31,7 @@ class IDevice
public:
virtual ~IDevice() = default;
virtual const std::string& uuid() const = 0;
virtual bool isPresent() const = 0;
virtual bool isRemovable() const = 0;
virtual const std::string& mountpoint() const = 0;
};
}
......@@ -42,6 +42,7 @@ const Device::DeviceMap Device::Cache = Device::listDevices();
Device::Device( const std::string& devicePath )
: m_device( devicePath )
, m_uuid( "fake uuid" )
, m_mountpoint( "/mnt/fixme" )
{
}
......@@ -50,14 +51,14 @@ const std::string& Device::uuid() const
return m_uuid;
}
bool Device::isPresent() const
bool Device::isRemovable() const
{
return true;
return false;
}
bool Device::isRemovable() const
const std::string&Device::mountpoint() const
{
return false;
return m_mountpoint;
}
std::shared_ptr<IDevice> Device::fromPath( const std::string& path )
......
......@@ -35,9 +35,8 @@ public:
using DeviceMap = std::unordered_map<std::string, std::shared_ptr<IDevice>>;
virtual const std::string& uuid() const override;
virtual bool isPresent() const override;
virtual bool isRemovable() const override;
virtual const std::string& mountpoint() const override;
static std::shared_ptr<IDevice> fromPath( const std::string& path );
......@@ -53,6 +52,7 @@ private:
private:
std::string m_device;
std::string m_uuid;
std::string m_mountpoint;
};
}
......@@ -89,10 +89,11 @@ public:
class Device : public fs::IDevice
{
public:
Device( const std::string& uuid ) : m_uuid( uuid ), m_present( true ), m_removable( false ) {}
Device( const std::string& mountpoint, const std::string& uuid ) : m_uuid( uuid ),
m_present( true ), m_removable( false ), m_mountpoint( mountpoint ) {}
virtual const std::string& uuid() const override { return m_uuid; }
virtual bool isPresent() const override { return m_present; }
virtual bool isRemovable() const override { return m_removable; }
virtual const std::string& mountpoint() const override { return m_mountpoint; }
void setPresent( bool value ) { m_present = value; }
void setRemovable( bool value ) { m_removable = value; }
......@@ -101,6 +102,7 @@ private:
std::string m_uuid;
bool m_present;
bool m_removable;
std::string m_mountpoint;
};
class Directory : public fs::IDirectory
......@@ -212,8 +214,8 @@ struct FileSystemFactory : public factory::IFileSystem
FileSystemFactory()
{
auto rootDevice = std::make_shared<Device>( "root" );
auto removableDevice = std::make_shared<Device>( "removable" );
auto rootDevice = std::make_shared<Device>( std::string{ Root }, "root" );
auto removableDevice = std::make_shared<Device>( std::string{ SubFolder }, "removable" );
removableDevice ->setRemovable( true );
removableDevice ->setPresent( true );
dirs[Root] = std::unique_ptr<mock::Directory>( new Directory{ nullptr, Root, 123, rootDevice } );
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment