Bump CMake minimum to 4.0 for VoidLibrary toolchain

This commit is contained in:
faumaray committed 2026-06-22 15:53:30 +03:00
1 parent 0fa9db4691
commit 05c9f8bc6c
11 files changed
+2524 -2125

No files matched your search

+81 -66
View File
@@ -1,78 +1,93 @@
#pragma once
#include <echoion/api.hpp>
#include <dylib.hpp>
#include "FileWatcher.hpp"
#include "echoion/api/ConfigTypes.hpp"
#include <CoreInterface.hpp>
#include <PluginTypes.hpp>
#include <Types.hpp>
#include <atomic>
#include <condition_variable>
#include <dylib.hpp>
#include <filesystem>
#include <functional>
#include <memory>
#include <mutex>
#include <atomic>
#include <filesystem>
#include <thread>
#include <condition_variable>
#include <queue>
#include <functional>
#include <thread>
namespace Echoion::Plugin {
namespace Echoion::Plugin
{
class CoreLoader {
public:
CoreLoader();
~CoreLoader();
class CoreLoader
{
public:
Api::Result<void> load(const std::filesystem::path& libraryPath);
Api::Result<void> unload();
Api::Result<void> hotReload(const std::filesystem::path& newLibraryPath);
[[nodiscard]] bool isLoaded() const noexcept;
[[nodiscard]] Api::CoreInterfacePtr getCore() const;
void setConfigPath(const std::filesystem::path& configPath);
[[nodiscard]] std::filesystem::path getConfigPath() const;
[[nodiscard]] bool isHotReloading() const noexcept;
// Automatic hot reload
void enableAutoReload();
void disableAutoReload();
[[nodiscard]] bool isAutoReloadEnabled() const noexcept;
// Callback for hot reload completion (called after auto-reload finishes)
using HotReloadCallback = std::function<void()>;
void setHotReloadCallback(HotReloadCallback callback) { hotReloadCallback_ = std::move(callback); }
CoreLoader();
~CoreLoader();
private:
Api::Result<void> loadLibraryInternal(const std::filesystem::path& path);
Api::Result<void> unloadLibraryInternal();
[[nodiscard]] Api::HotReloadState saveStateInternal();
[[nodiscard]] Api::Result<void> restoreStateInternal(const Api::HotReloadState& state);
[[nodiscard]] std::filesystem::path getTempLibraryPath(const std::filesystem::path& original) const;
void cleanupTempFiles();
Api::Result<void> load(const std::filesystem::path& libraryPath);
Api::Result<void> unload();
Api::Result<void>
hotReload(const std::filesystem::path& newLibraryPath);
[[nodiscard]] bool isLoaded() const noexcept;
[[nodiscard]] Api::CoreInterfacePtr getCore() const;
void setConfigPath(const std::filesystem::path& configPath);
[[nodiscard]] std::filesystem::path getConfigPath() const;
[[nodiscard]] bool isHotReloading() const noexcept;
std::unique_ptr<dylib::library> library_;
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_;
std::atomic<bool> autoReloadEnabled_{false};
// Deferred reload - waits for current track to finish
std::thread deferredReloadThread_;
std::atomic<bool> hasPendingReload_{false};
std::filesystem::path pendingReloadPath_;
std::string pendingTrackId_; // Track ID that was playing when reload scheduled
mutable std::mutex pendingReloadMutex_;
// Hot reload completion callback
HotReloadCallback hotReloadCallback_;
void onCoreFileChanged();
void waitForTrackAndReload(const std::filesystem::path& targetPath, const std::string& trackId);
[[nodiscard]] bool isPlaybackActive() const;
[[nodiscard]] bool isSameTrackPlaying(const std::string& trackId) const;
};
// Automatic hot reload
void enableAutoReload();
void disableAutoReload();
[[nodiscard]] bool isAutoReloadEnabled() const noexcept;
// Callback for hot reload completion (called after auto-reload
// finishes)
using HotReloadCallback = std::function<void()>;
void setHotReloadCallback(HotReloadCallback callback)
{
hotReloadCallback_ = std::move(callback);
}
private:
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();
std::unique_ptr<dylib::library> library_;
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_;
std::atomic<bool> autoReloadEnabled_{false};
// Deferred reload - waits for current track to finish
std::thread deferredReloadThread_;
std::atomic<bool> hasPendingReload_{false};
std::filesystem::path pendingReloadPath_;
std::string pendingTrackId_; // Track ID that was playing when
// reload scheduled
mutable std::mutex pendingReloadMutex_;
// Hot reload completion callback
HotReloadCallback hotReloadCallback_;
void onCoreFileChanged();
void waitForTrackAndReload(const std::filesystem::path& targetPath,
const std::string& trackId);
[[nodiscard]] bool isPlaybackActive() const;
[[nodiscard]] bool
isSameTrackPlaying(const std::string& trackId) const;
};
} // namespace Echoion::Plugin
+50 -47
View File
@@ -1,62 +1,65 @@
#pragma once
#include <functional>
#include <filesystem>
#include <thread>
#include <atomic>
#include <mutex>
#include <chrono>
#include <filesystem>
#include <functional>
#include <mutex>
#include <thread>
namespace Echoion::Plugin {
namespace Echoion::Plugin
{
/**
* @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()>;
/**
* @brief Simple file watcher that monitors a file for changes
* and triggers a callback when the file is modified.
*/
class FileWatcher
{
public:
FileWatcher();
~FileWatcher();
using ChangeCallback = std::function<void()>;
// Disable copy
FileWatcher(const FileWatcher&) = delete;
FileWatcher& operator=(const FileWatcher&) = delete;
FileWatcher();
~FileWatcher();
/**
* @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)
);
// Disable copy
FileWatcher(const FileWatcher&) = delete;
FileWatcher& operator=(const FileWatcher&) = delete;
/**
* @brief Stop watching
*/
void stopWatching();
/**
* @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));
[[nodiscard]] bool isWatching() const noexcept;
/**
* @brief Stop watching
*/
void stopWatching();
private:
void watchLoop();
[[nodiscard]] bool isWatching() const noexcept;
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::uintmax_t lastFileSize_ = 0;
};
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::Plugin
+143 -116
View File
@@ -1,9 +1,10 @@
#pragma once
#include <PluginInterface.hpp>
#include <PluginTypes.hpp>
#include <Types.hpp>
#include <atomic>
#include <condition_variable>
#include <dylib.hpp>
#include <echoion/api.hpp>
#include <future>
#include <map>
#include <memory>
@@ -14,144 +15,170 @@
// TeamSpeak SDK headers
#include "ts3_functions.h"
namespace Echoion::Plugin {
namespace Echoion::Plugin
{
// Audio device configuration
struct AudioDeviceConfig {
static constexpr const char* DEVICE_ID = "echoion_audio_device";
static constexpr const char* DEVICE_NAME = "Echoion Music Bot Audio";
static constexpr int SAMPLE_RATE =
192000; // 192kHz for high quality audio (CODEC_OPUS_MUSIC)
static constexpr int CHANNELS = 2;
static constexpr int SAMPLE_SIZE = sizeof(int16_t);
};
// Audio device configuration
struct AudioDeviceConfig {
static constexpr const char* DEVICE_ID = "echoion_audio_device";
static constexpr const char* DEVICE_NAME =
"Echoion Music Bot Audio";
static constexpr int SAMPLE_RATE =
192000; // 192kHz for high quality audio (CODEC_OPUS_MUSIC)
static constexpr int CHANNELS = 2;
static constexpr int SAMPLE_SIZE = sizeof(int16_t);
};
// Server groups cache entry
struct ServerGroupsCacheEntry {
std::vector<uint64_t> groups;
std::chrono::steady_clock::time_point timestamp;
};
// Server groups cache entry
struct ServerGroupsCacheEntry {
std::vector<uint64_t> groups;
std::chrono::steady_clock::time_point timestamp;
};
// Plugin implementation of IPluginInterface for the Core to use
class PluginInterface : public Api::IPluginInterface {
public:
PluginInterface();
~PluginInterface() override;
// Plugin implementation of IPluginInterface for the Core to use
class PluginInterface : public Api::IPluginInterface
{
public:
// Initialize with TeamSpeak functions
Api::Result<void> initialize(TS3Functions* ts3Functions);
PluginInterface();
~PluginInterface() override;
// IPluginInterface implementation
Api::Result<void> initialize() override;
Api::Result<void> shutdown() override;
// Initialize with TeamSpeak functions
Api::Result<void> initialize(TS3Functions* ts3Functions);
// Client operations
[[nodiscard]] Api::Result<std::vector<Api::ClientInfo>>
getClients() override;
[[nodiscard]] Api::Result<std::optional<Api::ClientInfo>>
getClient(uint64_t clientId) override;
Api::Result<void> moveClient(uint64_t clientId,
uint64_t channelId) override;
Api::Result<void> kickClient(uint64_t clientId,
const std::string& reason) override;
// IPluginInterface implementation
Api::Result<void> initialize() override;
Api::Result<void> shutdown() override;
// Channel operations
[[nodiscard]] Api::Result<std::vector<Api::ChannelInfo>>
getChannels() const override;
[[nodiscard]] Api::Result<std::optional<Api::ChannelInfo>> getChannel(uint64_t channelId) const override;
// Client operations
[[nodiscard]] Api::Result<std::vector<Api::ClientInfo>>
getClients() override;
[[nodiscard]] Api::Result<std::optional<Api::ClientInfo>>
getClient(uint64_t clientId) override;
Api::Result<void> moveClient(uint64_t clientId,
uint64_t channelId) override;
Api::Result<void> kickClient(uint64_t clientId,
const std::string& reason) override;
// Messaging
Api::Result<void> sendTextMessage(uint64_t targetId, const std::string& message) override;
Api::Result<void> sendChannelMessage(uint64_t channelId, const std::string& message) override;
Api::Result<void> sendServerMessage(const std::string& message) override;
// Channel operations
[[nodiscard]] Api::Result<std::vector<Api::ChannelInfo>>
getChannels() const override;
[[nodiscard]] Api::Result<std::optional<Api::ChannelInfo>>
getChannel(uint64_t channelId) const override;
// Audio
Api::Result<void>
sendAudioData(const std::span<const short>& data) override;
Api::Result<void>
setWhisperList(const std::vector<uint64_t>& clientIds) override;
// Messaging
Api::Result<void>
sendTextMessage(uint64_t targetId,
const std::string& message) override;
Api::Result<void>
sendChannelMessage(uint64_t channelId,
const std::string& message) override;
Api::Result<void>
sendServerMessage(const std::string& message) override;
// Event subscription
void registerEventCallback(const Api::EventCallback& callback) override;
void unregisterEventCallback(const Api::EventCallback& callback) override;
void clearEventCallbacks();
// Audio
Api::Result<void>
sendAudioData(const std::span<const short>& data) override;
Api::Result<void>
setWhisperList(const std::vector<uint64_t>& clientIds) override;
// TeamSpeak event handlers (called by TeamSpeak SDK)
void onClientConnected(uint64_t serverConnectionHandlerId, uint64_t clientId);
void onClientDisconnected(uint64_t serverConnectionHandlerId, uint64_t clientId);
void onClientMoved(uint64_t serverConnectionHandlerId, uint64_t clientId, uint64_t newChannelId);
void onTextMessageReceived(uint64_t serverConnectionHandlerId, uint64_t targetMode,
uint64_t fromId, const std::string& message);
void onVoiceDataReceived(uint64_t serverConnectionHandlerId, uint64_t clientId,
const std::span<const uint8_t>& data);
// Event subscription
void registerEventCallback(
const Api::EventCallback& callback) override;
void unregisterEventCallback(
const Api::EventCallback& callback) override;
void clearEventCallbacks();
// Server group list callback (called by TeamSpeak SDK)
void onServerGroupByClientID(uint64_t serverConnectionHandlerId,
uint64_t clientDatabaseId,
const char* groupName, uint64_t serverGroupId,
uint64_t clientId);
// TeamSpeak event handlers (called by TeamSpeak SDK)
void onClientConnected(uint64_t serverConnectionHandlerId,
uint64_t clientId);
void onClientDisconnected(uint64_t serverConnectionHandlerId,
uint64_t clientId);
void onClientMoved(uint64_t serverConnectionHandlerId,
uint64_t clientId, uint64_t newChannelId);
void onTextMessageReceived(uint64_t serverConnectionHandlerId,
uint64_t targetMode, uint64_t fromId,
const std::string& message);
void onVoiceDataReceived(uint64_t serverConnectionHandlerId,
uint64_t clientId,
const std::span<const uint8_t>& data);
// Server connection management (IPluginInterface implementation)
Api::Result<void> connectToServer(const Api::ServerConfig& config) override;
Api::Result<void> disconnectFromServer() override;
[[nodiscard]] bool isConnected() const override;
Api::Result<void> reconnect() override;
// Server group list callback (called by TeamSpeak SDK)
void onServerGroupByClientID(uint64_t serverConnectionHandlerId,
uint64_t clientDatabaseId,
const char* groupName,
uint64_t serverGroupId,
uint64_t clientId);
// Audio device management
Api::Result<void> registerAudioDevice();
Api::Result<void> unregisterAudioDevice();
Api::Result<void> openAudioDevice();
[[nodiscard]] bool isAudioDeviceRegistered() const { return audioDeviceRegistered_; }
Api::Result<void> closeAudioDevice();
[[nodiscard]] bool isAudioDeviceOpen() const;
// Server connection management (IPluginInterface implementation)
Api::Result<void>
connectToServer(const Api::ServerConfig& config) override;
Api::Result<void> disconnectFromServer() override;
[[nodiscard]] bool isConnected() const override;
Api::Result<void> reconnect() override;
// Set server connection handler
void setServerConnectionHandlerId(uint64_t handlerId);
[[nodiscard]] uint64_t getServerConnectionHandlerId() const;
// Audio device management
Api::Result<void> registerAudioDevice();
Api::Result<void> unregisterAudioDevice();
Api::Result<void> openAudioDevice();
[[nodiscard]] bool isAudioDeviceRegistered() const noexcept
{
return audioDeviceRegistered_.load();
}
Api::Result<void> closeAudioDevice();
[[nodiscard]] bool isAudioDeviceOpen() const noexcept;
// Audio data submission (for internal use)
void submitAudioData(const std::span<const short> samples);
// Set server connection handler
void setServerConnectionHandlerId(uint64_t handlerId) noexcept;
[[nodiscard]] uint64_t
getServerConnectionHandlerId() const noexcept;
// Automatic configuration
Api::Result<void> configureAudioProfile();
Api::Result<void> checkAndHandleFirstRun();
// Audio data submission (for internal use)
void submitAudioData(std::span<const short> samples);
private:
void broadcastEvent(const Api::PluginEvent& event);
std::string getClientName(uint64_t clientId) const;
std::string getChannelName(uint64_t channelId) const;
// Automatic configuration
Api::Result<void> configureAudioProfile();
Api::Result<void> checkAndHandleFirstRun();
// Fetch server groups for a client (returns future that completes when
// groups are received)
std::future<std::vector<uint64_t>> fetchServerGroups(uint64_t clientId);
private:
// Get cached server groups (or empty if not cached)
std::vector<uint64_t> getCachedServerGroups(uint64_t clientId);
void broadcastEvent(const Api::PluginEvent& event);
[[nodiscard]] std::string getClientName(uint64_t clientId) const;
[[nodiscard]] std::string getChannelName(uint64_t channelId) const;
TS3Functions* ts3Functions_ = nullptr;
uint64_t serverConnectionHandlerId_ = 0;
std::atomic<bool> initialized_{false};
std::atomic<bool> audioDeviceRegistered_{false};
std::atomic<bool> audioDeviceOpen_{false};
// Fetch server groups for a client (returns future that completes
// when groups are received)
[[nodiscard]] std::future<std::vector<uint64_t>>
fetchServerGroups(uint64_t clientId);
std::vector<Api::EventCallback> eventCallbacks_;
mutable std::mutex eventMutex_;
// Get cached server groups (or empty if not cached)
[[nodiscard]] std::vector<uint64_t>
getCachedServerGroups(uint64_t clientId);
// Audio data queue
std::queue<std::vector<short>> audioQueue_;
std::mutex audioMutex_;
std::condition_variable audioCv_;
std::atomic<bool> stopAudioThread_{false};
std::jthread audioThread_;
TS3Functions* ts3Functions_ = nullptr;
uint64_t serverConnectionHandlerId_ = 0;
std::atomic<bool> initialized_{false};
std::atomic<bool> audioDeviceRegistered_{false};
std::atomic<bool> audioDeviceOpen_{false};
// Server groups cache
mutable std::mutex serverGroupsMutex_;
std::map<uint64_t, ServerGroupsCacheEntry> serverGroupsCache_;
std::map<uint64_t, std::promise<std::vector<uint64_t>>>
pendingServerGroupRequests_;
std::vector<Api::EventCallback> eventCallbacks_;
mutable std::mutex eventMutex_;
// Connection info
Api::ServerConfig currentServerConfig_;
};
// Audio data queue
std::queue<std::vector<short>> audioQueue_;
std::mutex audioMutex_;
std::condition_variable audioCv_;
std::atomic<bool> stopAudioThread_{false};
std::jthread audioThread_;
// Server groups cache
mutable std::mutex serverGroupsMutex_;
std::map<uint64_t, ServerGroupsCacheEntry> serverGroupsCache_;
std::map<uint64_t, std::promise<std::vector<uint64_t>>>
pendingServerGroupRequests_;
// Connection info
Api::ServerConfig currentServerConfig_;
};
} // namespace Echoion::Plugin