async part
This commit is contained in:
parent
150bbe05f7
commit
12df9de1b4
@ -1,18 +1,48 @@
|
||||
cmake_minimum_required(VERSION 3.24 FATAL_ERROR)
|
||||
|
||||
add_library(solanaceae_clamav
|
||||
# TODO: seperate interface lib
|
||||
add_library(solanaceae_clamav_interface INTERFACE
|
||||
./solanaceae/clamav/clamav_module_interface.hpp
|
||||
)
|
||||
target_include_directories(solanaceae_clamav_interface INTERFACE .)
|
||||
target_compile_features(solanaceae_clamav_interface INTERFACE cxx_std_17)
|
||||
|
||||
########################################
|
||||
|
||||
add_library(solanaceae_clamav
|
||||
./solanaceae/clamav/clamav_module.hpp
|
||||
./solanaceae/clamav/clamav_module.cpp
|
||||
)
|
||||
target_include_directories(solanaceae_clamav PUBLIC .)
|
||||
target_compile_features(solanaceae_clamav PUBLIC cxx_std_17)
|
||||
target_link_libraries(solanaceae_clamav PUBLIC
|
||||
solanaceae_clamav_interface
|
||||
EXT_SOL::libclamav
|
||||
solanaceae_util
|
||||
)
|
||||
|
||||
########################################
|
||||
|
||||
add_library(solanaceae_clamav_async_interface INTERFACE
|
||||
./solanaceae/clamav/clamav_module_async_interface.hpp
|
||||
)
|
||||
target_include_directories(solanaceae_clamav_async_interface INTERFACE .)
|
||||
target_compile_features(solanaceae_clamav_async_interface INTERFACE cxx_std_17)
|
||||
|
||||
########################################
|
||||
|
||||
add_library(solanaceae_clamav_async_wrapper
|
||||
./solanaceae/clamav/clamav_module_async_wrapper.hpp
|
||||
./solanaceae/clamav/clamav_module_async_wrapper.cpp
|
||||
)
|
||||
target_link_libraries(solanaceae_clamav_async_wrapper PUBLIC
|
||||
solanaceae_clamav_interface
|
||||
solanaceae_clamav_async_interface
|
||||
)
|
||||
|
||||
########################################
|
||||
|
||||
if (SOLANACEAE_CLAMAV_STANDALONE)
|
||||
|
||||
add_executable(solanaceae_clamav_test
|
||||
./solanaceae/clamav/test_exe.cpp
|
||||
)
|
||||
@ -23,3 +53,5 @@ target_link_libraries(solanaceae_clamav_test PUBLIC
|
||||
#solanaceae_util
|
||||
)
|
||||
|
||||
endif()
|
||||
|
||||
|
@ -18,7 +18,7 @@ class ClamAVModule : public ClamAVModuleInterface {
|
||||
ClamAVModule(ConfigModelI& conf);
|
||||
~ClamAVModule(void);
|
||||
|
||||
ScanResult scanFilePath(std::string_view path);
|
||||
ScanResult scanFilePath(std::string_view path) override;
|
||||
|
||||
};
|
||||
|
||||
|
14
src/solanaceae/clamav/clamav_module_async_interface.hpp
Normal file
14
src/solanaceae/clamav/clamav_module_async_interface.hpp
Normal file
@ -0,0 +1,14 @@
|
||||
#pragma once
|
||||
|
||||
#include "./clamav_module_interface.hpp"
|
||||
|
||||
#include <future>
|
||||
|
||||
// non-blocking
|
||||
struct ClamAVModuleAsyncInterface {
|
||||
using ScanResult = ClamAVModuleInterface::ScanResult;
|
||||
|
||||
virtual std::future<ScanResult> scanFilePath(std::string_view path) = 0;
|
||||
|
||||
};
|
||||
|
17
src/solanaceae/clamav/clamav_module_async_wrapper.cpp
Normal file
17
src/solanaceae/clamav/clamav_module_async_wrapper.cpp
Normal file
@ -0,0 +1,17 @@
|
||||
#include "./clamav_module_async_wrapper.hpp"
|
||||
|
||||
ClamAVModuleAsyncWrapper::ClamAVModuleAsyncWrapper(ClamAVModuleInterface& cavmi) : _cavmi(cavmi) {
|
||||
}
|
||||
|
||||
std::future<ClamAVModuleAsyncWrapper::ScanResult> ClamAVModuleAsyncWrapper::scanFilePath(std::string_view path) {
|
||||
return std::async(
|
||||
std::launch::async,
|
||||
[this](std::string inner_path) {
|
||||
// TODO: optimize, clamav supports multi threading
|
||||
std::lock_guard lock_guard{_cavmi_mutex};
|
||||
return _cavmi.scanFilePath(inner_path);
|
||||
},
|
||||
std::string{path} // copy
|
||||
);
|
||||
}
|
||||
|
18
src/solanaceae/clamav/clamav_module_async_wrapper.hpp
Normal file
18
src/solanaceae/clamav/clamav_module_async_wrapper.hpp
Normal file
@ -0,0 +1,18 @@
|
||||
#pragma once
|
||||
|
||||
#include "./clamav_module_async_interface.hpp"
|
||||
|
||||
#include <mutex>
|
||||
|
||||
class ClamAVModuleAsyncWrapper : public ClamAVModuleAsyncInterface {
|
||||
ClamAVModuleInterface& _cavmi;
|
||||
std::mutex _cavmi_mutex;
|
||||
|
||||
public:
|
||||
|
||||
ClamAVModuleAsyncWrapper(ClamAVModuleInterface& cavmi);
|
||||
|
||||
std::future<ScanResult> scanFilePath(std::string_view path) override;
|
||||
|
||||
};
|
||||
|
@ -2,7 +2,6 @@
|
||||
|
||||
#include <string_view>
|
||||
#include <string>
|
||||
#include <future>
|
||||
|
||||
// blocking
|
||||
struct ClamAVModuleInterface {
|
||||
@ -15,11 +14,3 @@ struct ClamAVModuleInterface {
|
||||
|
||||
};
|
||||
|
||||
// non-blocking
|
||||
struct ClamAVModuleAsyncInterface {
|
||||
using ScanResult = ClamAVModuleInterface::ScanResult;
|
||||
|
||||
virtual std::promise<ScanResult> scanFilePath(std::string_view path) = 0;
|
||||
|
||||
};
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user