Device.h 2.67 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27
/*****************************************************************************
 * Media Library
 *****************************************************************************
 * Copyright (C) 2015 Hugo Beauzée-Luyssen, Videolabs
 *
 * Authors: Hugo Beauzée-Luyssen<hugo@beauzee.fr>
 *
 * This program is free software; you can redistribute it and/or modify it
 * under the terms of the GNU Lesser General Public License as published by
 * the Free Software Foundation; either version 2.1 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
 * GNU Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public License
 * along with this program; if not, write to the Free Software Foundation,
 * Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
 *****************************************************************************/

#pragma once

#include "Types.h"
#include "database/DatabaseHelpers.h"

28 29 30
namespace medialibrary
{

31
class Device;
32 33 34

namespace policy
{
35
struct DeviceTable
36 37 38
{
    static const std::string Name;
    static const std::string PrimaryKeyColumn;
39
    static int64_t Device::*const PrimaryKey;
40 41 42
};
}

43
class Device : public DatabaseHelpers<Device, policy::DeviceTable>
44 45
{
public:
Hugo Beauzée-Luyssen's avatar
Hugo Beauzée-Luyssen committed
46
    Device( MediaLibraryPtr ml, const std::string& uuid, const std::string& scheme, bool isRemovable );
47
    Device( MediaLibraryPtr ml, sqlite::Row& row );
48
    int64_t id() const;
49 50 51 52
    const std::string& uuid() const;
    bool isRemovable() const;
    bool isPresent() const;
    void setPresent( bool value );
Hugo Beauzée-Luyssen's avatar
Hugo Beauzée-Luyssen committed
53 54 55 56 57 58 59
    ///
    /// \brief scheme returns the scheme that was used for this device when it was
    /// originally created. This allows to use the apropriate IFileSystemFactory to find the
    /// recreate a IDevice based on its id or UUID
    /// \return
    ///
    const std::string& scheme() const;
60

Hugo Beauzée-Luyssen's avatar
Hugo Beauzée-Luyssen committed
61
    static std::shared_ptr<Device> create( MediaLibraryPtr ml, const std::string& uuid, const std::string& scheme, bool isRemovable );
62
    static void createTable( sqlite::Connection* connection );
63
    static std::shared_ptr<Device> fromUuid( MediaLibraryPtr ml, const std::string& uuid );
64 65

private:
66
    MediaLibraryPtr m_ml;
67
    // This is a database ID
68
    int64_t m_id;
69 70 71
    // This is a unique ID on the system side, in the /dev/disk/by-uuid sense.
    // It can be a name or what not, depending on the OS.
    std::string m_uuid;
Hugo Beauzée-Luyssen's avatar
Hugo Beauzée-Luyssen committed
72
    std::string m_scheme;
73 74 75
    bool m_isRemovable;
    bool m_isPresent;

76
    friend struct policy::DeviceTable;
77
};
78 79

}