diff --git a/src/CoreLoader.cpp b/src/CoreLoader.cpp index 07cee64..66de25d 100644 --- a/src/CoreLoader.cpp +++ b/src/CoreLoader.cpp @@ -179,14 +179,14 @@ namespace Echoion::Plugin std::lock_guard lock(mutex_); if (loaded_) { - return std::unexpected(Api::Error(Api::ErrorCode::AlreadyExists, - "Core already loaded")); + return Api::fail(Api::ErrorCode::AlreadyExists, + "Core already loaded"); } if (!std::filesystem::exists(libraryPath)) { - return std::unexpected(Api::Error( + return Api::fail( Api::ErrorCode::NotFound, - std::format("Library not found: {}", libraryPath.string()))); + std::format("Library not found: {}", libraryPath.string())); } tempLibraryPath_ = getTempLibraryPath(libraryPath); @@ -196,9 +196,9 @@ namespace Echoion::Plugin libraryPath, tempLibraryPath_, std::filesystem::copy_options::overwrite_existing); } catch (const std::exception& e) { - return std::unexpected(Api::Error( + return Api::fail( Api::ErrorCode::UnknownError, - std::format("Failed to copy library to temp: {}", e.what()))); + std::format("Failed to copy library to temp: {}", e.what())); } auto result = loadLibraryInternal(tempLibraryPath_); @@ -232,8 +232,8 @@ namespace Echoion::Plugin std::lock_guard lock(mutex_); if (!loaded_) { - return std::unexpected(Api::Error(Api::ErrorCode::NotFound, - "No core loaded to reload")); + return Api::fail(Api::ErrorCode::NotFound, + "No core loaded to reload"); } hotReloading_ = true; @@ -254,9 +254,9 @@ namespace Echoion::Plugin if (!std::filesystem::exists(targetPath)) { hotReloading_ = false; - return std::unexpected(Api::Error( + return Api::fail( Api::ErrorCode::NotFound, - std::format("New library not found: {}", targetPath.string()))); + std::format("New library not found: {}", targetPath.string())); } std::filesystem::path newTempPath = getTempLibraryPath(targetPath); @@ -269,10 +269,9 @@ namespace Echoion::Plugin hotReloading_ = false; std::error_code ec; std::filesystem::remove(newTempPath, ec); - return std::unexpected( - Api::Error(Api::ErrorCode::UnknownError, + return Api::fail(Api::ErrorCode::UnknownError, std::format("Failed to copy new library to temp: {}", - e.what()))); + e.what())); } auto unloadResult = unloadLibraryInternal(); @@ -389,19 +388,18 @@ namespace Echoion::Plugin if (!compatibleFunc(Api::VERSION_MAJOR, Api::VERSION_MINOR)) { library_.reset(); - return std::unexpected(Api::Error( + return Api::fail( Api::ErrorCode::InvalidArgument, std::format("API version mismatch. Expected {}.{}, got {}", Api::VERSION_MAJOR, Api::VERSION_MINOR, - versionFunc()))); + versionFunc())); } core_ = createFunc(); if (!core_) { library_.reset(); - return std::unexpected( - Api::Error(Api::ErrorCode::UnknownError, - "Failed to create core instance")); + return Api::fail(Api::ErrorCode::UnknownError, + "Failed to create core instance"); } auto initResult = core_->initialize(configPath_); @@ -418,17 +416,15 @@ namespace Echoion::Plugin return {}; } catch (const dylib::load_error& e) { - return std::unexpected(Api::Error( + return Api::fail( Api::ErrorCode::PluginError, - std::format("Failed to load library: {}", e.what()))); + std::format("Failed to load library: {}", e.what())); } catch (const dylib::symbol_error& e) { - return std::unexpected( - Api::Error(Api::ErrorCode::PluginError, - std::format("Failed to find symbol: {}", e.what()))); + return Api::fail(Api::ErrorCode::PluginError, + std::format("Failed to find symbol: {}", e.what())); } catch (const std::exception& e) { - return std::unexpected( - Api::Error(Api::ErrorCode::UnknownError, - std::format("Unexpected error: {}", e.what()))); + return Api::fail(Api::ErrorCode::UnknownError, + std::format("Unexpected error: {}", e.what())); } } diff --git a/src/PluginInterface.cpp b/src/PluginInterface.cpp index 24da160..bf12928 100644 --- a/src/PluginInterface.cpp +++ b/src/PluginInterface.cpp @@ -20,9 +20,8 @@ namespace Echoion::Plugin Api::Result PluginInterface::initialize(TS3Functions* ts3Functions) { if (initialized_) { - return std::unexpected( - Api::Error(Api::ErrorCode::AlreadyExists, - "Plugin interface already initialized")); + return Api::fail(Api::ErrorCode::AlreadyExists, + "Plugin interface already initialized"); } ts3Functions_ = ts3Functions; @@ -126,9 +125,8 @@ namespace Echoion::Plugin Api::Result> PluginInterface::getClients() { if (!initialized_ || !ts3Functions_) { - return std::unexpected( - Api::Error(Api::ErrorCode::ServiceUnavailable, - "Plugin interface not initialized")); + return Api::fail(Api::ErrorCode::ServiceUnavailable, + "Plugin interface not initialized"); } std::vector clients; @@ -137,9 +135,9 @@ namespace Echoion::Plugin unsigned int error = ts3Functions_->getClientList( serverConnectionHandlerId_, &clientList); if (error != ERROR_ok) { - return std::unexpected(Api::Error( + return Api::fail( Api::ErrorCode::NetworkError, - std::format("Failed to get client list: {}", error))); + std::format("Failed to get client list: {}", error)); } if (clientList) { @@ -191,9 +189,8 @@ namespace Echoion::Plugin PluginInterface::getClient(uint64_t clientId) { if (!initialized_ || !ts3Functions_) { - return std::unexpected( - Api::Error(Api::ErrorCode::ServiceUnavailable, - "Plugin interface not initialized")); + return Api::fail(Api::ErrorCode::ServiceUnavailable, + "Plugin interface not initialized"); } Api::ClientInfo info; @@ -240,9 +237,8 @@ namespace Echoion::Plugin uint64_t channelId) { if (!initialized_ || !ts3Functions_) { - return std::unexpected( - Api::Error(Api::ErrorCode::ServiceUnavailable, - "Plugin interface not initialized")); + return Api::fail(Api::ErrorCode::ServiceUnavailable, + "Plugin interface not initialized"); } unsigned int error = ts3Functions_->requestClientMove( @@ -250,9 +246,8 @@ namespace Echoion::Plugin "", nullptr); if (error != ERROR_ok) { - return std::unexpected( - Api::Error(Api::ErrorCode::NetworkError, - std::format("Failed to move client: {}", error))); + return Api::fail(Api::ErrorCode::NetworkError, + std::format("Failed to move client: {}", error)); } return {}; @@ -262,9 +257,8 @@ namespace Echoion::Plugin const std::string& reason) { if (!initialized_ || !ts3Functions_) { - return std::unexpected( - Api::Error(Api::ErrorCode::ServiceUnavailable, - "Plugin interface not initialized")); + return Api::fail(Api::ErrorCode::ServiceUnavailable, + "Plugin interface not initialized"); } unsigned int error = ts3Functions_->requestClientKickFromServer( @@ -272,9 +266,8 @@ namespace Echoion::Plugin reason.c_str(), nullptr); if (error != ERROR_ok) { - return std::unexpected( - Api::Error(Api::ErrorCode::NetworkError, - std::format("Failed to kick client: {}", error))); + return Api::fail(Api::ErrorCode::NetworkError, + std::format("Failed to kick client: {}", error)); } return {}; @@ -284,9 +277,8 @@ namespace Echoion::Plugin PluginInterface::getChannels() const { if (!initialized_ || !ts3Functions_) { - return std::unexpected( - Api::Error(Api::ErrorCode::ServiceUnavailable, - "Plugin interface not initialized")); + return Api::fail(Api::ErrorCode::ServiceUnavailable, + "Plugin interface not initialized"); } std::vector channels; @@ -295,9 +287,9 @@ namespace Echoion::Plugin unsigned int error = ts3Functions_->getChannelList( serverConnectionHandlerId_, &channelList); if (error != ERROR_ok) { - return std::unexpected(Api::Error( + return Api::fail( Api::ErrorCode::NetworkError, - std::format("Failed to get channel list: {}", error))); + std::format("Failed to get channel list: {}", error)); } if (channelList) { @@ -333,9 +325,8 @@ namespace Echoion::Plugin PluginInterface::getChannel(uint64_t channelId) const { if (!initialized_ || !ts3Functions_) { - return std::unexpected( - Api::Error(Api::ErrorCode::ServiceUnavailable, - "Plugin interface not initialized")); + return Api::fail(Api::ErrorCode::ServiceUnavailable, + "Plugin interface not initialized"); } Api::ChannelInfo info; @@ -361,9 +352,8 @@ namespace Echoion::Plugin const std::string& message) { if (!initialized_ || !ts3Functions_) { - return std::unexpected( - Api::Error(Api::ErrorCode::ServiceUnavailable, - "Plugin interface not initialized")); + return Api::fail(Api::ErrorCode::ServiceUnavailable, + "Plugin interface not initialized"); } unsigned int error = ts3Functions_->requestSendPrivateTextMsg( @@ -371,9 +361,9 @@ namespace Echoion::Plugin static_cast(targetId), nullptr); if (error != ERROR_ok) { - return std::unexpected(Api::Error( + return Api::fail( Api::ErrorCode::NetworkError, - std::format("Failed to send text message: {}", error))); + std::format("Failed to send text message: {}", error)); } return {}; @@ -384,18 +374,17 @@ namespace Echoion::Plugin const std::string& message) { if (!initialized_ || !ts3Functions_) { - return std::unexpected( - Api::Error(Api::ErrorCode::ServiceUnavailable, - "Plugin interface not initialized")); + return Api::fail(Api::ErrorCode::ServiceUnavailable, + "Plugin interface not initialized"); } unsigned int error = ts3Functions_->requestSendChannelTextMsg( serverConnectionHandlerId_, message.c_str(), channelId, nullptr); if (error != ERROR_ok) { - return std::unexpected(Api::Error( + return Api::fail( Api::ErrorCode::NetworkError, - std::format("Failed to send channel message: {}", error))); + std::format("Failed to send channel message: {}", error)); } return {}; @@ -405,18 +394,17 @@ namespace Echoion::Plugin PluginInterface::sendServerMessage(const std::string& message) { if (!initialized_ || !ts3Functions_) { - return std::unexpected( - Api::Error(Api::ErrorCode::ServiceUnavailable, - "Plugin interface not initialized")); + return Api::fail(Api::ErrorCode::ServiceUnavailable, + "Plugin interface not initialized"); } unsigned int error = ts3Functions_->requestSendServerTextMsg( serverConnectionHandlerId_, message.c_str(), nullptr); if (error != ERROR_ok) { - return std::unexpected(Api::Error( + return Api::fail( Api::ErrorCode::NetworkError, - std::format("Failed to send server message: {}", error))); + std::format("Failed to send server message: {}", error)); } return {}; @@ -453,9 +441,8 @@ namespace Echoion::Plugin ECHOION_LOG_ERROR(std::format( "sendAudioData {}: not initialized", callCount)); } - return std::unexpected( - Api::Error(Api::ErrorCode::ServiceUnavailable, - "Plugin interface not initialized")); + return Api::fail(Api::ErrorCode::ServiceUnavailable, + "Plugin interface not initialized"); } if (!audioDeviceOpen_) { @@ -463,8 +450,8 @@ namespace Echoion::Plugin ECHOION_LOG_ERROR(std::format( "sendAudioData {}: audio device not open", callCount)); } - return std::unexpected(Api::Error( - Api::ErrorCode::ServiceUnavailable, "Audio device not open")); + return Api::fail( + Api::ErrorCode::ServiceUnavailable, "Audio device not open"); } submitAudioData(data); @@ -483,16 +470,15 @@ namespace Echoion::Plugin PluginInterface::setWhisperList(const std::vector& clientIds) { if (!initialized_ || !ts3Functions_) { - return std::unexpected( - Api::Error(Api::ErrorCode::ServiceUnavailable, - "Plugin interface not initialized")); + return Api::fail(Api::ErrorCode::ServiceUnavailable, + "Plugin interface not initialized"); } anyID clientId = 0; if (ts3Functions_->getClientID(serverConnectionHandlerId_, &clientId) != ERROR_ok) { - return std::unexpected(Api::Error(Api::ErrorCode::NetworkError, - "Failed to get own client ID")); + return Api::fail(Api::ErrorCode::NetworkError, + "Failed to get own client ID"); } // Convert to anyID array (null-terminated) @@ -507,9 +493,9 @@ namespace Echoion::Plugin nullptr); if (error != ERROR_ok) { - return std::unexpected(Api::Error( + return Api::fail( Api::ErrorCode::NetworkError, - std::format("Failed to set whisper list: {}", error))); + std::format("Failed to set whisper list: {}", error)); } return {}; @@ -616,9 +602,8 @@ namespace Echoion::Plugin PluginInterface::connectToServer(const Api::ServerConfig& config) { if (!initialized_ || !ts3Functions_) { - return std::unexpected( - Api::Error(Api::ErrorCode::ServiceUnavailable, - "Plugin interface not initialized")); + return Api::fail(Api::ErrorCode::ServiceUnavailable, + "Plugin interface not initialized"); } currentServerConfig_ = config; @@ -643,9 +628,9 @@ namespace Echoion::Plugin ts3Functions_->getErrorMessage(error, &msg); ECHOION_LOG_ERROR(std::format("GUI Connect failed: {}", msg)); ts3Functions_->freeMemory(msg); - return std::unexpected(Api::Error( + return Api::fail( Api::ErrorCode::NetworkError, - std::format("Failed to start connection: {}", error))); + std::format("Failed to start connection: {}", error)); } // Open audio device @@ -665,9 +650,8 @@ namespace Echoion::Plugin Api::Result PluginInterface::disconnectFromServer() { if (!initialized_ || !ts3Functions_) { - return std::unexpected( - Api::Error(Api::ErrorCode::ServiceUnavailable, - "Plugin interface not initialized")); + return Api::fail(Api::ErrorCode::ServiceUnavailable, + "Plugin interface not initialized"); } if (serverConnectionHandlerId_ == 0) { @@ -735,9 +719,8 @@ namespace Echoion::Plugin if (!ts3Functions_) { ECHOION_LOG_ERROR("registerAudioDevice: ts3Functions_ is null"); - return std::unexpected( - Api::Error(Api::ErrorCode::ServiceUnavailable, - "TS3 functions not available")); + return Api::fail(Api::ErrorCode::ServiceUnavailable, + "TS3 functions not available"); } if (audioDeviceRegistered_) { @@ -749,10 +732,9 @@ namespace Echoion::Plugin if (!ts3Functions_->registerCustomDevice) { ECHOION_LOG_WARNING( "registerCustomDevice not available in this TeamSpeak version"); - return std::unexpected( - Api::Error(Api::ErrorCode::NotSupported, + return Api::fail(Api::ErrorCode::NotSupported, "Custom audio devices not supported by this " - "TeamSpeak version")); + "TeamSpeak version"); } // Register custom device for both capture and playback @@ -772,10 +754,10 @@ namespace Echoion::Plugin if (error != ERROR_ok) { ECHOION_LOG_ERROR( std::format("registerCustomDevice failed: {}", error)); - return std::unexpected(Api::Error( + return Api::fail( Api::ErrorCode::PluginError, std::format("Failed to register custom audio device: {}", - error))); + error)); } audioDeviceRegistered_ = true; @@ -831,16 +813,14 @@ namespace Echoion::Plugin if (!ts3Functions_) { ECHOION_LOG_ERROR("openAudioDevice: ts3Functions_ is null"); - return std::unexpected( - Api::Error(Api::ErrorCode::ServiceUnavailable, - "TS3 functions not available")); + return Api::fail(Api::ErrorCode::ServiceUnavailable, + "TS3 functions not available"); } if (!audioDeviceRegistered_) { ECHOION_LOG_ERROR("openAudioDevice: device not registered"); - return std::unexpected( - Api::Error(Api::ErrorCode::ServiceUnavailable, - "Audio device not registered")); + return Api::fail(Api::ErrorCode::ServiceUnavailable, + "Audio device not registered"); } if (audioDeviceOpen_) { @@ -850,8 +830,8 @@ namespace Echoion::Plugin if (serverConnectionHandlerId_ == 0) { ECHOION_LOG_ERROR("openAudioDevice: not connected (handler=0)"); - return std::unexpected(Api::Error( - Api::ErrorCode::ServiceUnavailable, "Not connected to server")); + return Api::fail( + Api::ErrorCode::ServiceUnavailable, "Not connected to server"); } // Close any existing device first (in case it was left open) @@ -877,9 +857,9 @@ namespace Echoion::Plugin ts3Functions_->freeMemory(msg); ECHOION_LOG_ERROR( std::format("openPlaybackDevice failed: {}", errStr)); - return std::unexpected(Api::Error( + return Api::fail( Api::ErrorCode::PluginError, - std::format("Failed to open playback device: {}", errStr))); + std::format("Failed to open playback device: {}", errStr)); } ECHOION_LOG_DEBUG("Opening capture device..."); @@ -1098,8 +1078,8 @@ namespace Echoion::Plugin Api::Result PluginInterface::configureAudioProfile() { if (!ts3Functions_ || serverConnectionHandlerId_ == 0) { - return std::unexpected(Api::Error( - Api::ErrorCode::ServiceUnavailable, "Not connected to server")); + return Api::fail( + Api::ErrorCode::ServiceUnavailable, "Not connected to server"); } ECHOION_LOG_INFO("Configuring audio profile for music bot..."); @@ -1179,9 +1159,8 @@ namespace Echoion::Plugin Api::Result PluginInterface::checkAndHandleFirstRun() { if (!ts3Functions_) { - return std::unexpected( - Api::Error(Api::ErrorCode::ServiceUnavailable, - "TS3 functions not available")); + return Api::fail(Api::ErrorCode::ServiceUnavailable, + "TS3 functions not available"); } ECHOION_LOG_INFO("Checking for first-run setup..."); @@ -1205,10 +1184,9 @@ namespace Echoion::Plugin if (identity) { ts3Functions_->freeMemory(identity); } - return std::unexpected( - Api::Error(Api::ErrorCode::NotInitialized, + return Api::fail(Api::ErrorCode::NotInitialized, "TeamSpeak client not properly initialized. Please " - "complete first-run setup.")); + "complete first-run setup."); } if (identity) {