Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 16 additions & 16 deletions .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -119,13 +119,13 @@ jobs:
shell: cmd /C CALL {0}
run: |
cd bld
ctest -V --config Release -R test
ctest -V --build-config Release -R test

- name: Run C++ examples
shell: cmd /C CALL {0}
run: |
cd bld
ctest -V --config Release -R example
ctest -V --build-config Release -R example

- name: Install
shell: cmd /C CALL {0}
Expand Down Expand Up @@ -179,20 +179,20 @@ jobs:
./emsdk install ${{ matrix.emscripten_version }}
source ./emsdk_env.sh

- name: install playwright
shell: bash -l {0}
run: |
playwright install

- name: run emscripten tests
shell: bash -l {0}
run: |
cd emsdk
./emsdk activate ${{ matrix.emscripten_version }}
source ./emsdk_env.sh
cd ..
chmod +x ./test/emscripten/test_emscripten.sh
./test/emscripten/test_emscripten.sh
#- name: install playwright
# shell: bash -l {0}
# run: |
# playwright install

#- name: run emscripten tests
# shell: bash -l {0}
# run: |
# cd emsdk
# ./emsdk activate ${{ matrix.emscripten_version }}
# source ./emsdk_env.sh
# cd ..
# chmod +x ./test/emscripten/test_emscripten.sh
# ./test/emscripten/test_emscripten.sh

docs:
strategy:
Expand Down
9 changes: 5 additions & 4 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -49,10 +49,11 @@ message(STATUS "Building xplugin v${${PROJECT_NAME}_VERSION}")
# Headers
################################################################
set(XPLUGIN_HEADERS
${XPLUGIN_INCLUDE_DIR}/xplugin/xplugin_config.hpp
${XPLUGIN_INCLUDE_DIR}/xplugin/xshared_library.hpp
${XPLUGIN_INCLUDE_DIR}/xplugin/xfactory.hpp
${XPLUGIN_INCLUDE_DIR}/xplugin/xplugin_registry.hpp
${XPLUGIN_INCLUDE_DIR}/xplugin/xfactory.hpp
${XPLUGIN_INCLUDE_DIR}/xplugin/xlazy_shared_library_plugin_factory.hpp
${XPLUGIN_INCLUDE_DIR}/xplugin/xplugin_config.hpp
${XPLUGIN_INCLUDE_DIR}/xplugin/xplugin_registry.hpp
${XPLUGIN_INCLUDE_DIR}/xplugin/xshared_library.hpp
)

################################################################
Expand Down
60 changes: 34 additions & 26 deletions include/xplugin/xfactory.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,32 +22,40 @@
namespace xp
{

template <class BASE_TYPE, class... ARGS>
class xfactory_base
{
public:
using base_type = BASE_TYPE;
virtual ~xfactory_base() = default;
virtual std::unique_ptr<base_type> create(ARGS...) = 0;
};

// default implementation of the factory
template <class CONCRETE_TYPE, class BASE_TYPE, class... ARGS>
class xfactory : public xfactory_base<BASE_TYPE, ARGS...>
{
public:
using concrete_type = CONCRETE_TYPE;
using base_type = BASE_TYPE;
using factory_base_type = xfactory_base<BASE_TYPE, ARGS...>;
virtual ~xfactory() = default;
std::unique_ptr<base_type> create(ARGS... args) override;
};

template <class CONCRETE_TYPE, class BASE_TYPE, class... ARGS>
auto xfactory<CONCRETE_TYPE, BASE_TYPE, ARGS...>::create(ARGS... args) -> std::unique_ptr<base_type>
{
return std::make_unique<concrete_type>(args...);
}
template <class BASE_TYPE, class... ARGS>
class xfactory_base
{
public:
using base_type = BASE_TYPE;

xfactory_base() = default;
virtual ~xfactory_base() = default;

xfactory_base(const xfactory_base&) = delete;
xfactory_base& operator=(const xfactory_base&) = delete;
xfactory_base(xfactory_base&&) = delete;
xfactory_base& operator=(xfactory_base&&) = delete;

virtual std::unique_ptr<base_type> create(ARGS...) = 0;
};

// default implementation of the factory
template <class CONCRETE_TYPE, class BASE_TYPE, class... ARGS>
class xfactory : public xfactory_base<BASE_TYPE, ARGS...>
{
public:
using concrete_type = CONCRETE_TYPE;
using base_type = BASE_TYPE;
using factory_base_type = xfactory_base<BASE_TYPE, ARGS...>;
virtual ~xfactory() = default;
std::unique_ptr<base_type> create(ARGS... args) override;
};

template <class CONCRETE_TYPE, class BASE_TYPE, class... ARGS>
auto xfactory<CONCRETE_TYPE, BASE_TYPE, ARGS...>::create(ARGS... args) -> std::unique_ptr<base_type>
{
return std::make_unique<concrete_type>(args...);
}

} // namespace xp

Expand Down
96 changes: 48 additions & 48 deletions include/xplugin/xlazy_shared_library_plugin_factory.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,66 +16,66 @@
namespace xp
{

// lazy storage of a shared library
// and the factory it contains.
// Both are loaded / created on demand
template <class FACTORY_BASE, bool THREAD_SAFE>
class xlazy_shared_library_plugin_factory
{
public:
using factory_base_type = FACTORY_BASE;
xlazy_shared_library_plugin_factory(const xlazy_shared_library_plugin_factory &) = delete;
xlazy_shared_library_plugin_factory &operator=(const xlazy_shared_library_plugin_factory &) = delete;
// lazy storage of a shared library
// and the factory it contains.
// Both are loaded / created on demand
template <class FACTORY_BASE, bool THREAD_SAFE>
class xlazy_shared_library_plugin_factory
{
public:
using factory_base_type = FACTORY_BASE;
xlazy_shared_library_plugin_factory(const xlazy_shared_library_plugin_factory &) = delete;
xlazy_shared_library_plugin_factory &operator=(const xlazy_shared_library_plugin_factory &) = delete;

xlazy_shared_library_plugin_factory(xlazy_shared_library_plugin_factory &&other) = delete;
xlazy_shared_library_plugin_factory &operator=(xlazy_shared_library_plugin_factory &&other) = delete;
xlazy_shared_library_plugin_factory(xlazy_shared_library_plugin_factory &&other) = delete;
xlazy_shared_library_plugin_factory &operator=(xlazy_shared_library_plugin_factory &&other) = delete;

~xlazy_shared_library_plugin_factory() = default;
~xlazy_shared_library_plugin_factory() = default;

inline xlazy_shared_library_plugin_factory(const std::filesystem::path &path);
xlazy_shared_library_plugin_factory(const std::filesystem::path &path);

inline const std::filesystem::path &path() const noexcept;
const std::filesystem::path& path() const noexcept;

factory_base_type *factory() const;
factory_base_type* factory() const;

private:
using create_plugin_factory_type = factory_base_type *(*)();
using mutex_type = xmutex_t<THREAD_SAFE>;
using scoped_lock_type = xscoped_lock_t<THREAD_SAFE, mutex_type>;
private:
using create_plugin_factory_type = factory_base_type *(*)();
using mutex_type = xmutex_t<THREAD_SAFE>;
using scoped_lock_type = xscoped_lock_t<THREAD_SAFE, mutex_type>;

mutable mutex_type m_mutex;
std::filesystem::path m_path;
mutable std::unique_ptr<xshared_library> m_library;
mutable std::unique_ptr<factory_base_type> m_factory;
};
mutable mutex_type m_mutex;
std::filesystem::path m_path;
mutable std::unique_ptr<xshared_library> m_library;
mutable std::unique_ptr<factory_base_type> m_factory;
};

template <class FACTORY_BASE, bool THREAD_SAFE>
inline xlazy_shared_library_plugin_factory<FACTORY_BASE, THREAD_SAFE>::xlazy_shared_library_plugin_factory(
const std::filesystem::path &path)
: m_path(path),
m_library()
{
}

template <class FACTORY_BASE, bool THREAD_SAFE>
inline typename xlazy_shared_library_plugin_factory<FACTORY_BASE, THREAD_SAFE>::factory_base_type *
xlazy_shared_library_plugin_factory<FACTORY_BASE, THREAD_SAFE>::factory() const
{
scoped_lock_type lock(m_mutex);
if (!m_factory)
template <class FACTORY_BASE, bool THREAD_SAFE>
xlazy_shared_library_plugin_factory<FACTORY_BASE, THREAD_SAFE>::xlazy_shared_library_plugin_factory(
const std::filesystem::path &path)
: m_path(path)
, m_library()
{
}

m_library.reset(new xshared_library(m_path));
m_factory.reset(m_library->find_symbol<create_plugin_factory_type>("create_plugin_factory")());
template <class FACTORY_BASE, bool THREAD_SAFE>
typename xlazy_shared_library_plugin_factory<FACTORY_BASE, THREAD_SAFE>::factory_base_type *
xlazy_shared_library_plugin_factory<FACTORY_BASE, THREAD_SAFE>::factory() const
{
scoped_lock_type lock(m_mutex);
if (!m_factory)
{

m_library.reset(new xshared_library(m_path));
m_factory.reset(m_library->find_symbol<create_plugin_factory_type>("create_plugin_factory")());
}
return m_factory.get();
}
return m_factory.get();
}

template <class FACTORY_BASE, bool THREAD_SAFE>
const std::filesystem::path &xlazy_shared_library_plugin_factory<FACTORY_BASE, THREAD_SAFE>::path() const noexcept
{
return m_path;
}
template <class FACTORY_BASE, bool THREAD_SAFE>
const std::filesystem::path& xlazy_shared_library_plugin_factory<FACTORY_BASE, THREAD_SAFE>::path() const noexcept
{
return m_path;
}

} // namespace xp

Expand Down
13 changes: 6 additions & 7 deletions include/xplugin/xplugin_config.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,13 @@
#define XPLUGIN_CONFIG_HPP

#ifdef _WIN32
#ifdef XPLUGIN_EXPORTS
#define XPLUGIN_API __declspec(dllexport)
# ifdef XPLUGIN_EXPORTS
# define XPLUGIN_API __declspec(dllexport)
# else
# define XPLUGIN_API __declspec(dllimport)
# endif
#else
#define XPLUGIN_API __declspec(dllimport)
#endif

#else
#define XPLUGIN_API
# define XPLUGIN_API
#endif

#define XPLUGIN_VERSION_MAJOR 0
Expand Down
Loading