1 parent
ccebe083e3
commit
7a1c817f90
5 files changed
+222
-414
No files matched your search
@@ -1,11 +1,11 @@
|
||||
#pragma once
|
||||
#include "echoion/host/FileWatcher.hpp"
|
||||
#include <Void/System/FileWatcher.hpp>
|
||||
#include <Void/Plugin/Manager.hpp>
|
||||
#include <CoreInterface.hpp>
|
||||
#include <PluginTypes.hpp>
|
||||
#include <Types.hpp>
|
||||
#include <atomic>
|
||||
#include <condition_variable>
|
||||
#include <dylib.hpp>
|
||||
#include <filesystem>
|
||||
#include <functional>
|
||||
#include <memory>
|
||||
@@ -32,6 +32,10 @@ namespace Echoion::Host
|
||||
void setConfigPath(const std::filesystem::path& configPath);
|
||||
[[nodiscard]] std::filesystem::path getConfigPath() const;
|
||||
[[nodiscard]] bool isHotReloading() const noexcept;
|
||||
Api::Result<void>
|
||||
checkpoint(const std::filesystem::path& destination);
|
||||
Api::Result<void>
|
||||
restoreCheckpoint(const std::filesystem::path& source);
|
||||
|
||||
// Automatic hot reload
|
||||
void enableAutoReload();
|
||||
@@ -41,6 +45,11 @@ namespace Echoion::Host
|
||||
// Callback for hot reload completion (called after auto-reload
|
||||
// finishes)
|
||||
using HotReloadCallback = std::function<void()>;
|
||||
using HotReloadPrepareCallback = std::function<void()>;
|
||||
void setHotReloadPrepareCallback(HotReloadPrepareCallback callback)
|
||||
{
|
||||
hotReloadPrepareCallback_ = std::move(callback);
|
||||
}
|
||||
void setHotReloadCallback(HotReloadCallback callback)
|
||||
{
|
||||
hotReloadCallback_ = std::move(callback);
|
||||
@@ -51,24 +60,19 @@ namespace Echoion::Host
|
||||
Api::Result<void>
|
||||
loadLibraryInternal(const std::filesystem::path& path);
|
||||
Api::Result<void> unloadLibraryInternal();
|
||||
[[nodiscard]] Api::SerializedState saveStateInternal();
|
||||
[[nodiscard]] Api::Result<void>
|
||||
restoreStateInternal(const Api::SerializedState& state);
|
||||
[[nodiscard]] std::filesystem::path
|
||||
getTempLibraryPath(const std::filesystem::path& original) const;
|
||||
void cleanupTempFiles();
|
||||
[[nodiscard]] Api::Result<void> refreshCoreHandle();
|
||||
|
||||
std::unique_ptr<dylib::library> library_;
|
||||
Void::Plugin::PluginManager pluginManager_;
|
||||
std::string pluginName_;
|
||||
Api::CoreInterfacePtr core_;
|
||||
std::filesystem::path currentLibraryPath_;
|
||||
std::filesystem::path tempLibraryPath_;
|
||||
std::filesystem::path configPath_;
|
||||
mutable std::mutex mutex_;
|
||||
std::atomic<bool> loaded_{false};
|
||||
std::atomic<bool> hotReloading_{false};
|
||||
|
||||
// Auto reload
|
||||
FileWatcher fileWatcher_;
|
||||
Void::FileSystem::FileWatcher fileWatcher_;
|
||||
std::atomic<bool> autoReloadEnabled_{false};
|
||||
|
||||
// Deferred reload - waits for current track to finish
|
||||
@@ -82,6 +86,7 @@ namespace Echoion::Host
|
||||
mutable std::mutex pendingReloadMutex_;
|
||||
|
||||
// Hot reload completion callback
|
||||
HotReloadPrepareCallback hotReloadPrepareCallback_;
|
||||
HotReloadCallback hotReloadCallback_;
|
||||
|
||||
void onCoreFileChanged();
|
||||
|
||||
@@ -1,65 +0,0 @@
|
||||
#pragma once
|
||||
|
||||
#include <atomic>
|
||||
#include <chrono>
|
||||
#include <filesystem>
|
||||
#include <functional>
|
||||
#include <mutex>
|
||||
#include <thread>
|
||||
|
||||
namespace Echoion::Host
|
||||
{
|
||||
|
||||
/**
|
||||
* @brief Simple file watcher that monitors a file for changes
|
||||
* and triggers a callback when the file is modified.
|
||||
*/
|
||||
class FileWatcher
|
||||
{
|
||||
public:
|
||||
|
||||
using ChangeCallback = std::function<void()>;
|
||||
|
||||
FileWatcher();
|
||||
~FileWatcher();
|
||||
|
||||
// Disable copy
|
||||
FileWatcher(const FileWatcher&) = delete;
|
||||
FileWatcher& operator=(const FileWatcher&) = delete;
|
||||
|
||||
/**
|
||||
* @brief Start watching a file for changes
|
||||
* @param filePath Path to the file to watch
|
||||
* @param callback Function to call when file changes
|
||||
* @param intervalMs Polling interval in milliseconds
|
||||
*/
|
||||
void startWatching(const std::filesystem::path& filePath,
|
||||
ChangeCallback callback,
|
||||
std::chrono::milliseconds intervalMs =
|
||||
std::chrono::milliseconds(1000));
|
||||
|
||||
/**
|
||||
* @brief Stop watching
|
||||
*/
|
||||
void stopWatching();
|
||||
|
||||
[[nodiscard]] bool isWatching() const noexcept;
|
||||
|
||||
private:
|
||||
|
||||
void watchLoop();
|
||||
|
||||
std::filesystem::path watchedPath_;
|
||||
ChangeCallback callback_;
|
||||
std::chrono::milliseconds intervalMs_{1000};
|
||||
std::atomic<bool> watching_{false};
|
||||
std::atomic<bool> stopRequested_{false};
|
||||
std::thread watchThread_;
|
||||
std::mutex mutex_;
|
||||
|
||||
// Store last modification time
|
||||
std::filesystem::file_time_type lastWriteTime_;
|
||||
std::uint64_t lastFileSize_ = 0;
|
||||
};
|
||||
|
||||
} // namespace Echoion::Host
|
||||
Reference in new issue
Block a user