Skip to content

Commit

Permalink
Merge pull request #4 from CESNET/appFs
Browse files Browse the repository at this point in the history
appFs - introduce appFs library
  • Loading branch information
SiskaPavel authored Apr 24, 2024
2 parents 4466bdf + 9cdebe2 commit 080baa7
Show file tree
Hide file tree
Showing 7 changed files with 535 additions and 1 deletion.
4 changes: 3 additions & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,12 @@ set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} -g -ggdb3")
# This option ensures that standard include header paths are explicitly added
# to the generated compile_commands.json file.
# clang-tidy doesn't seem to find standard include headers otherwise.
if(CMAKE_EXPORT_COMPILE_COMMANDS)
if (CMAKE_EXPORT_COMPILE_COMMANDS)
set(CMAKE_CXX_STANDARD_INCLUDE_DIRECTORIES ${CMAKE_CXX_IMPLICIT_INCLUDE_DIRECTORIES})
endif()

include(cmake/dependencies.cmake)

add_subdirectory(src)

if (TELEMETRY_PACKAGE_BUILDER)
Expand Down
5 changes: 5 additions & 0 deletions cmake/dependencies.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# Project dependencies
find_package(PkgConfig REQUIRED)
find_package(Threads REQUIRED)

pkg_check_modules(fuse REQUIRED IMPORTED_TARGET fuse3>=3.2.1)
72 changes: 72 additions & 0 deletions include/appFs.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
/**
* @file
* @brief Definition of the AppFsFuse class for managing FUSE filesystem
* @author Pavel Siska <siska@cesnet.cz>
*
* SPDX-License-Identifier: BSD-3-Clause
*/

#pragma once

#include <fuse3/fuse.h>
#include <memory>
#include <string>
#include <telemetry.hpp>
#include <thread>

namespace telemetry::appFs {

/**
* @brief The AppFsFuse class for managing FUSE filesystem.
*/
class AppFsFuse {
public:
/**
* @brief Sets up and mount the FUSE filesystem.
*
* This method sets up the FUSE filesystem with the provided mount point directory path.
*
* @param rootDirectory A shared pointer to the telemetry root directory.
* @param mountPoint The mount point directory path.
* @param tryToUnmountOnStart Whether to attempt unmounting the mount point if it's already
*
* @throws std::runtime_error if rootDirectory is nullptr.
* @throws std::runtime_error if setup and mount process fails.
*/
AppFsFuse(
std::shared_ptr<Directory> rootDirectory,
const std::string& mountPoint,
bool tryToUnmountOnStart = true);

/**
* @brief Creates a new thread to run the FUSE event loop.
*
* After the thread is created, you can access the FUSE filesystem through the mount point.
*
* @throws std::runtime_error if the FUSE thread is already running.
*/
void start();

/**
* @brief Unmount the FUSE filesystem and join the FUSE thread.
*
* @note It's not possible to start the FUSE filesystem again after calling this method.
* If needed, a new instance of the class must be created.
*/
void stop();

/**
* @brief Destructor for AppFsFuse.
*/
~AppFsFuse();

private:
void unmount();

std::unique_ptr<struct fuse, decltype(&fuse_destroy)> m_fuse {nullptr, &fuse_destroy};
std::shared_ptr<Directory> m_rootDirectory;
bool m_isStarted = false;
std::thread m_fuseThread;
};

} // namespace telemetry::appFs
5 changes: 5 additions & 0 deletions pkg/rpm/telemetry.spec.in
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,11 @@ Source0: %{name}-%{version}.tar.gz
BuildRoot: %{_tmppath}/%{name}-%{version}-%{release}
BuildRequires: gcc-c++ >= 8
BuildRequires: make
BuildRequires: fuse3-devel >= 3.2.1
BuildRequires: cmake >= 3.12

Requires: fuse3

%description
The package contains a telemetry library for managing
telemetry data in your program.
Expand All @@ -30,5 +33,7 @@ telemetry data in your program.
%{_libdir}/libtelemetry.so
%{_includedir}/telemetry.hpp
%{_includedir}/telemetry/*.hpp
%{_libdir}/libappFs.so
%{_includedir}/appFs.hpp

%changelog
1 change: 1 addition & 0 deletions src/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
add_subdirectory(telemetry)
add_subdirectory(appFs)
20 changes: 20 additions & 0 deletions src/appFs/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
list(APPEND APPFS_SOURCE_FILES
appFs.cpp
)

if (TELEMETRY_BUILD_SHARED)
add_library(appFs SHARED ${APPFS_SOURCE_FILES})
else()
add_library(appFs STATIC ${APPFS_SOURCE_FILES})
endif()

add_library(telemetry::appFs ALIAS appFs)

target_compile_definitions(appFs PUBLIC FUSE_USE_VERSION=30 _FILE_OFFSET_BITS=64)
target_link_libraries(appFs PUBLIC telemetry PkgConfig::fuse)
target_include_directories(appFs PUBLIC ${CMAKE_SOURCE_DIR}/include)

if (TELEMETRY_INSTALL_TARGETS)
install(TARGETS appFs LIBRARY DESTINATION ${INSTALL_DIR_LIB})
install(DIRECTORY ${CMAKE_SOURCE_DIR}/include/ DESTINATION ${INSTALL_DIR_INCLUDE})
endif()
Loading

0 comments on commit 080baa7

Please sign in to comment.