From 5cee7a37946c62b72a083af6bfca300ac59e9992 Mon Sep 17 00:00:00 2001 From: MFransen69 Date: Fri, 14 Nov 2025 23:08:04 +0100 Subject: [PATCH 1/4] [CustomCode] CustomCode example and conversion lib initial commit --- .../CustomCodeToStringLibrary/CMakeLists.txt | 48 +++++ .../CustomCodeToString.cpp | 36 ++++ .../CustomCodeToStringLibrary.vcxproj | 151 ++++++++++++++ .../CustomCodeToStringLibrary.vcxproj.filters | 22 ++ .../CustomErrorCode/CMakeLists.txt | 52 +++++ .../CustomErrorCodeServer.conf.in | 2 + .../CustomErrorCode/CustomErrorCodeServer.cpp | 58 ++++++ .../CustomErrorCode/CustomErrorCodeServer.h | 102 ++++++++++ .../CustomErrorCodeServer.vcxproj | 192 ++++++++++++++++++ .../CustomErrorCode/Module.cpp | 22 ++ .../CustomErrorCodes/CustomErrorCode/Module.h | 30 +++ 11 files changed, 715 insertions(+) create mode 100644 examples/CustomErrorCodes/CustomCodeToStringLibrary/CMakeLists.txt create mode 100644 examples/CustomErrorCodes/CustomCodeToStringLibrary/CustomCodeToString.cpp create mode 100644 examples/CustomErrorCodes/CustomCodeToStringLibrary/CustomCodeToStringLibrary.vcxproj create mode 100644 examples/CustomErrorCodes/CustomCodeToStringLibrary/CustomCodeToStringLibrary.vcxproj.filters create mode 100644 examples/CustomErrorCodes/CustomErrorCode/CMakeLists.txt create mode 100644 examples/CustomErrorCodes/CustomErrorCode/CustomErrorCodeServer.conf.in create mode 100644 examples/CustomErrorCodes/CustomErrorCode/CustomErrorCodeServer.cpp create mode 100644 examples/CustomErrorCodes/CustomErrorCode/CustomErrorCodeServer.h create mode 100644 examples/CustomErrorCodes/CustomErrorCode/CustomErrorCodeServer.vcxproj create mode 100644 examples/CustomErrorCodes/CustomErrorCode/Module.cpp create mode 100644 examples/CustomErrorCodes/CustomErrorCode/Module.h diff --git a/examples/CustomErrorCodes/CustomCodeToStringLibrary/CMakeLists.txt b/examples/CustomErrorCodes/CustomCodeToStringLibrary/CMakeLists.txt new file mode 100644 index 000000000..b8b22f146 --- /dev/null +++ b/examples/CustomErrorCodes/CustomCodeToStringLibrary/CMakeLists.txt @@ -0,0 +1,48 @@ +# If not stated otherwise in this file or this component's license file the +# following copyright and licenses apply: +# +# Copyright 2020 Metrological +# +# Licensed under the Apache License, Version 2.0 (the License); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an AS IS BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +project(SimpleCOMRPCClient) + +cmake_minimum_required(VERSION 3.15) + +find_package(Thunder) + +project_version(1.0.0) + +set(MODULE_NAME ${PROJECT_NAME}) + +message("Setup ${MODULE_NAME} v${PROJECT_VERSION}") + +find_package(${NAMESPACE}Core) +find_package(${NAMESPACE}COM REQUIRED) +find_package(CompileSettingsDebug CONFIG REQUIRED) + +add_executable(${MODULE_NAME} SimpleCOMRPCClient.cpp) + +set_target_properties(${MODULE_NAME} PROPERTIES + CXX_STANDARD 11 + CXX_STANDARD_REQUIRED YES + ) + +target_link_libraries(${MODULE_NAME} + PRIVATE + ${NAMESPACE}Core::${NAMESPACE}Core + ${NAMESPACE}COM::${NAMESPACE}COM + CompileSettingsDebug::CompileSettingsDebug + ) + +install(TARGETS ${MODULE_NAME} DESTINATION ${CMAKE_INSTALL_BINDIR} COMPONENT ${NAMESPACE}_Runtime) diff --git a/examples/CustomErrorCodes/CustomCodeToStringLibrary/CustomCodeToString.cpp b/examples/CustomErrorCodes/CustomCodeToStringLibrary/CustomCodeToString.cpp new file mode 100644 index 000000000..8d04a2b42 --- /dev/null +++ b/examples/CustomErrorCodes/CustomCodeToStringLibrary/CustomCodeToString.cpp @@ -0,0 +1,36 @@ + +#if defined WIN32 || defined _WINDOWS +#define WIN32_LEAN_AND_MEAN // Exclude rarely-used stuff from Windows headers +// Windows Header Files +#include + +#include +#define VARIABLE_IS_NOT_USED + +#else + +#ifdef _UNICODE +#define _T(x) L##x +#define TCHAR wchar_t +#endif + +#ifndef _UNICODE +#define _T(x) x +#define TCHAR char +#endif + +#endif // __LINUX__ + +#include + +const TCHAR* CustomCodeToSting(int32_t code) { + const TCHAR* text = nullptr; + if (code == 100) { + text = _T("Custom Error code 100"); + } else if (code == -100) { + text = _T("Custom Error code -100"); + } + + return text; +} + diff --git a/examples/CustomErrorCodes/CustomCodeToStringLibrary/CustomCodeToStringLibrary.vcxproj b/examples/CustomErrorCodes/CustomCodeToStringLibrary/CustomCodeToStringLibrary.vcxproj new file mode 100644 index 000000000..12e59b5f2 --- /dev/null +++ b/examples/CustomErrorCodes/CustomCodeToStringLibrary/CustomCodeToStringLibrary.vcxproj @@ -0,0 +1,151 @@ + + + + + Debug + Win32 + + + Release + Win32 + + + Debug + x64 + + + Release + x64 + + + + 17.0 + Win32Proj + {143f6012-63ec-4eef-bba6-cd1c82f3e3ea} + CustomCodeToStringLibrary + 10.0 + + + + DynamicLibrary + true + v143 + Unicode + + + DynamicLibrary + false + v143 + true + Unicode + + + DynamicLibrary + true + v143 + NotSet + + + DynamicLibrary + false + v143 + true + Unicode + + + + + + + + + + + + + + + + + + + + + .so + $(SolutionDir)..\artifacts\$(Configuration)\ + $(OutDir)Plugins\$(TargetName)\ + lib$(ProjectName) + + + + Level3 + true + WIN32;_DEBUG;CUSTOMCODETOSTRINGLIBRARY_EXPORTS;_WINDOWS;_USRDLL;%(PreprocessorDefinitions) + true + Use + pch.h + + + Windows + true + false + + + + + Level3 + true + true + true + WIN32;NDEBUG;CUSTOMCODETOSTRINGLIBRARY_EXPORTS;_WINDOWS;_USRDLL;%(PreprocessorDefinitions) + true + Use + pch.h + + + Windows + true + false + + + + + Level3 + true + _DEBUG;CUSTOMCODETOSTRINGLIBRARY_EXPORTS;_WINDOWS;_USRDLL;%(PreprocessorDefinitions) + true + NotUsing + pch.h + $(FrameworkPath);$(ContractsPath);$(ClientsPath);$(WindowsPath);$(WindowsPath)zlib + false + + + Windows + true + false + + + + + Level3 + true + true + true + NDEBUG;CUSTOMCODETOSTRINGLIBRARY_EXPORTS;_WINDOWS;_USRDLL;%(PreprocessorDefinitions) + true + Use + pch.h + + + Windows + true + false + + + + + + + + + \ No newline at end of file diff --git a/examples/CustomErrorCodes/CustomCodeToStringLibrary/CustomCodeToStringLibrary.vcxproj.filters b/examples/CustomErrorCodes/CustomCodeToStringLibrary/CustomCodeToStringLibrary.vcxproj.filters new file mode 100644 index 000000000..007b45a9d --- /dev/null +++ b/examples/CustomErrorCodes/CustomCodeToStringLibrary/CustomCodeToStringLibrary.vcxproj.filters @@ -0,0 +1,22 @@ + + + + + {4FC737F1-C7A5-4376-A066-2A32D752A2FF} + cpp;c;cc;cxx;c++;cppm;ixx;def;odl;idl;hpj;bat;asm;asmx + + + {93995380-89BD-4b04-88EB-625FBE52EBFB} + h;hh;hpp;hxx;h++;hm;inl;inc;ipp;xsd + + + {67DA6AB6-F800-4c08-8B7A-83BB121AAD01} + rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms + + + + + Source Files + + + \ No newline at end of file diff --git a/examples/CustomErrorCodes/CustomErrorCode/CMakeLists.txt b/examples/CustomErrorCodes/CustomErrorCode/CMakeLists.txt new file mode 100644 index 000000000..25c537ac4 --- /dev/null +++ b/examples/CustomErrorCodes/CustomErrorCode/CMakeLists.txt @@ -0,0 +1,52 @@ +# If not stated otherwise in this file or this component's LICENSE file the +# following copyright and licenses apply: +# +# Copyright 2025 Metrological +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +project(CustomErrorCodeServer) + +cmake_minimum_required(VERSION 3.15) + +find_package(Thunder) + +project_version(1.0.0) + +set(MODULE_NAME ${NAMESPACE}${PROJECT_NAME}) + +message("Setup ${MODULE_NAME} v${PROJECT_VERSION}") + +find_package(${NAMESPACE}Plugins REQUIRED) +find_package(${NAMESPACE}Definitions REQUIRED) +find_package(CompileSettingsDebug CONFIG REQUIRED) + +add_library(${MODULE_NAME} SHARED + Module.cpp + CustomErrorCodeServer.cpp +) + +set_target_properties(${MODULE_NAME} PROPERTIES + CXX_STANDARD 11 + CXX_STANDARD_REQUIRED YES) + +target_link_libraries(${MODULE_NAME} + PRIVATE + CompileSettingsDebug::CompileSettingsDebug + ${NAMESPACE}Plugins::${NAMESPACE}Plugins + ${NAMESPACE}Definitions::${NAMESPACE}Definitions) + +install(TARGETS ${MODULE_NAME} + DESTINATION ${CMAKE_INSTALL_LIBDIR}/${STORAGE_DIRECTORY}/plugins COMPONENT ${NAMESPACE}_Runtime) + +write_config() diff --git a/examples/CustomErrorCodes/CustomErrorCode/CustomErrorCodeServer.conf.in b/examples/CustomErrorCodes/CustomErrorCode/CustomErrorCodeServer.conf.in new file mode 100644 index 000000000..aa02c8276 --- /dev/null +++ b/examples/CustomErrorCodes/CustomErrorCode/CustomErrorCodeServer.conf.in @@ -0,0 +1,2 @@ +startmode = "Activated" + diff --git a/examples/CustomErrorCodes/CustomErrorCode/CustomErrorCodeServer.cpp b/examples/CustomErrorCodes/CustomErrorCode/CustomErrorCodeServer.cpp new file mode 100644 index 000000000..0c704c532 --- /dev/null +++ b/examples/CustomErrorCodes/CustomErrorCode/CustomErrorCodeServer.cpp @@ -0,0 +1,58 @@ +/* + * If not stated otherwise in this file or this component's LICENSE file the + * following copyright and licenses apply: + * + * Copyright 2020 Metrological + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "CustomErrorCodeServer.h" +#include + +namespace Thunder { + +namespace Plugin { + + namespace { + + static Metadata metadata( + // Version + 1, 0, 0, + // Preconditions + {}, + // Terminations + {}, + // Controls + {} + ); + } + + const string CustomErrorCodeServer::Initialize(PluginHost::IShell*) + { + Exchange::JCustomErrorCode::Register(*this, this); + return (EMPTY_STRING); + } + + void CustomErrorCodeServer::Deinitialize(PluginHost::IShell*) + { + Exchange::JCustomErrorCode::Unregister(*this); + } + + string CustomErrorCodeServer::Information() const + { + return (EMPTY_STRING); + } + +} +} // namespace Plugin diff --git a/examples/CustomErrorCodes/CustomErrorCode/CustomErrorCodeServer.h b/examples/CustomErrorCodes/CustomErrorCode/CustomErrorCodeServer.h new file mode 100644 index 000000000..8066bff96 --- /dev/null +++ b/examples/CustomErrorCodes/CustomErrorCode/CustomErrorCodeServer.h @@ -0,0 +1,102 @@ +/* + * If not stated otherwise in this file or this component's LICENSE file the + * following copyright and licenses apply: + * + * Copyright 2020 Metrological + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +#pragma once + +#include "Module.h" +#include + +namespace Thunder { +namespace Plugin { + + class CustomErrorCodeServer : public Exchange::ICustomErrorCode, public PluginHost::IPlugin, public PluginHost::JSONRPC { + public: + CustomErrorCodeServer(const CustomErrorCodeServer&) = delete; + CustomErrorCodeServer& operator=(const CustomErrorCodeServer&) = delete; + CustomErrorCodeServer(CustomErrorCodeServer&&) = delete; + CustomErrorCodeServer& operator=(CustomErrorCodeServer&&) = delete; + + CustomErrorCodeServer() + : Exchange::ICustomErrorCode() + , PluginHost::IPlugin() + , PluginHost::JSONRPC() + { + } + + ~CustomErrorCodeServer() override = default; + + public: + //Service Registration + BEGIN_INTERFACE_MAP(CustomErrorCodeServer) + INTERFACE_ENTRY(IPlugin) + INTERFACE_ENTRY(IDispatcher) + INTERFACE_ENTRY(Exchange::ICustomErrorCode) + END_INTERFACE_MAP + + const string Initialize(PluginHost::IShell* service); + void Deinitialize(PluginHost::IShell* service); + string Information() const; + + Core::hresult TriggerCustomError(const int32_t errorcode) const override + { + Core::hresult result = SimulatedComRPCCall(errorcode); + + if (result != Core::ERROR_NONE) { + ExampleHandlingHResultWhichCouldContainCustomCode(result); + } + + return Core::CustomCode(errorcode); + } + + Core::hresult TriggerNonCustomError(const uint32_t errorcode) const override + { + Core::hresult result = SimulatedComRPCCall(errorcode); + + if (result != Core::ERROR_NONE) { + ExampleHandlingHResultWhichCouldContainCustomCode(result); + } + + return errorcode; + } + + private: + // simulate comrpc call that returns an error + Core::hresult SimulatedComRPCCall(const Core::hresult errorcode) const + { + return errorcode; + } + Core::hresult SimulatedComRPCCall(const int32_t customerrorcode) const + { + return Core::CustomCode(customerrorcode); + } + void ExampleHandlingHResultWhichCouldContainCustomCode(const Core::hresult errorcode) const + { + int32_t customcode = Core::IsCustomCode(errorcode); + + if (customcode == 0) { + TRACE(Trace::Information, (_T("Thunder Error received: %u"), errorcode)); + } else { + TRACE(Trace::Information, (_T("Custom Code received: %i"), customcode)); + } + + TRACE(Trace::Information, (_T("Error received: %s"), Core::ErrorToStringExtended(errorcode).c_str())); + } + + }; +} +} diff --git a/examples/CustomErrorCodes/CustomErrorCode/CustomErrorCodeServer.vcxproj b/examples/CustomErrorCodes/CustomErrorCode/CustomErrorCodeServer.vcxproj new file mode 100644 index 000000000..f10b80b5f --- /dev/null +++ b/examples/CustomErrorCodes/CustomErrorCode/CustomErrorCodeServer.vcxproj @@ -0,0 +1,192 @@ + + + + + Debug + Win32 + + + Release + Win32 + + + Debug + x64 + + + Release + x64 + + + + + + + + + + + + + + + 15.0 + {E69C85AC-B2BE-4755-80DB-5EC0306BFAE7} + Win32Proj + CustomErrorCodeServer + 10.0 + CustomErrorCodeServer + + + + DynamicLibrary + true + v143 + MultiByte + + + DynamicLibrary + false + v143 + true + MultiByte + + + DynamicLibrary + true + v143 + MultiByte + + + DynamicLibrary + false + v143 + true + MultiByte + + + + + + + + + + + + + + + + + + + + + true + $(SolutionDir)..\artifacts\$(Configuration)\ + $(OutDir)Plugins\$(TargetName)\ + lib$(ProjectName) + .so + + + true + $(SolutionDir)..\artifacts\$(Configuration)\ + $(OutDir)Plugins\$(TargetName)\ + lib$(ProjectName) + .so + + + false + $(SolutionDir)..\artifacts\$(Configuration)\ + $(OutDir)Plugins\$(TargetName)\ + lib$(ProjectName) + .so + + + false + $(SolutionDir)..\artifacts\$(Configuration)\ + $(OutDir)Plugins\$(TargetName)\ + lib$(ProjectName) + .so + + + + NotUsing + Level3 + Disabled + true + _CRT_SECURE_NO_WARNINGS;_DEBUG;OUTOFPROCESSTEST_EXPORTS;_WINDOWS;_USRDLL;%(PreprocessorDefinitions) + true + $(FrameworkPath);$(ContractsPath);$(ClientsPath);$(WindowsPath);$(WindowsPath)zlib + true + + + Windows + true + $(OutDir) + + + + + NotUsing + Level3 + Disabled + true + _CRT_SECURE_NO_WARNINGS;WIN32;_DEBUG;OUTOFPROCESSTEST_EXPORTS;_WINDOWS;_USRDLL;%(PreprocessorDefinitions) + true + $(FrameworkPath);$(ContractsPath);$(ClientsPath);$(WindowsPath);$(WindowsPath)zlib + true + + + Windows + true + $(OutDir) + + + + + NotUsing + Level3 + MaxSpeed + true + true + true + _CRT_SECURE_NO_WARNINGS;WIN32;NDEBUG;OUTOFPROCESSTEST_EXPORTS;_WINDOWS;_USRDLL;%(PreprocessorDefinitions) + true + $(FrameworkPath);$(ContractsPath);$(ClientsPath);$(WindowsPath);$(WindowsPath)zlib + true + + + Windows + true + true + true + $(OutDir) + + + + + NotUsing + Level3 + MaxSpeed + true + true + true + _CRT_SECURE_NO_WARNINGS;NDEBUG;OUTOFPROCESSTEST_EXPORTS;_WINDOWS;_USRDLL;%(PreprocessorDefinitions) + true + $(FrameworkPath);$(ContractsPath);$(ClientsPath);$(WindowsPath);$(WindowsPath)zlib + true + + + Windows + true + true + true + $(OutDir) + + + + + + \ No newline at end of file diff --git a/examples/CustomErrorCodes/CustomErrorCode/Module.cpp b/examples/CustomErrorCodes/CustomErrorCode/Module.cpp new file mode 100644 index 000000000..bbf44ccdf --- /dev/null +++ b/examples/CustomErrorCodes/CustomErrorCode/Module.cpp @@ -0,0 +1,22 @@ +/* + * If not stated otherwise in this file or this component's LICENSE file the + * following copyright and licenses apply: + * + * Copyright 2020 Metrological + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "Module.h" + +MODULE_NAME_DECLARATION(BUILD_REFERENCE) diff --git a/examples/CustomErrorCodes/CustomErrorCode/Module.h b/examples/CustomErrorCodes/CustomErrorCode/Module.h new file mode 100644 index 000000000..3b2d8b495 --- /dev/null +++ b/examples/CustomErrorCodes/CustomErrorCode/Module.h @@ -0,0 +1,30 @@ +/* + * If not stated otherwise in this file or this component's LICENSE file the + * following copyright and licenses apply: + * + * Copyright 2020 Metrological + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#pragma once + +#ifndef MODULE_NAME +#define MODULE_NAME Plugin_CustomErrorCodeServer +#endif + +#include +#include + +#undef EXTERNAL +#define EXTERNAL From 47ac24b94e436e6a0400ff18588deeaaa8172197 Mon Sep 17 00:00:00 2001 From: MFransen69 Date: Sat, 15 Nov 2025 12:20:04 +0100 Subject: [PATCH 2/4] [CustomCodeExample] added some comments --- .../CustomErrorCode/CustomErrorCodeServer.h | 30 ++++++++++++++++--- 1 file changed, 26 insertions(+), 4 deletions(-) diff --git a/examples/CustomErrorCodes/CustomErrorCode/CustomErrorCodeServer.h b/examples/CustomErrorCodes/CustomErrorCode/CustomErrorCodeServer.h index 8066bff96..df1b6f62b 100644 --- a/examples/CustomErrorCodes/CustomErrorCode/CustomErrorCodeServer.h +++ b/examples/CustomErrorCodes/CustomErrorCode/CustomErrorCodeServer.h @@ -52,21 +52,29 @@ namespace Plugin { void Deinitialize(PluginHost::IShell* service); string Information() const; + // the interface allows the json rpc call to provide the error code used which provides for easy testing Core::hresult TriggerCustomError(const int32_t errorcode) const override { + // we simulate calling aanother COMRPC call which might return a custom error code (and in this case it will return a custom code) Core::hresult result = SimulatedComRPCCall(errorcode); + // we check if there was an error, comparing to Core::ERROR_NONE is the only thing needed also with custom codes + // only if you want to deal with some specific error you need to handle that situation specifically which we wil do here as en example if (result != Core::ERROR_NONE) { ExampleHandlingHResultWhichCouldContainCustomCode(result); } - return Core::CustomCode(errorcode); + return Core::CustomCode(errorcode == 0 ? Core::ERROR_NONE : errorcode); // of course we know Core::ERROR_NONE is also 0 but semantically it is more correct like this (and will continue to work might ERROR_NONE ever be a different value) } + // the interface allows the json rpc call to provide the error code used which provides for easy testing Core::hresult TriggerNonCustomError(const uint32_t errorcode) const override { + // we simulate calling aanother COMRPC call which might return a custom error code (and in this case it wil return a non custom code) Core::hresult result = SimulatedComRPCCall(errorcode); + // we check if there was an error, comparing to Core::ERROR_NONE is the only thing needed also with custom codes + // only if you want to deal with some specific error you need to handle that situation specifically which we wil do here as en example if (result != Core::ERROR_NONE) { ExampleHandlingHResultWhichCouldContainCustomCode(result); } @@ -75,25 +83,39 @@ namespace Plugin { } private: - // simulate comrpc call that returns an error + // simulate a COMRPC call that returns an Thunder defined error Core::hresult SimulatedComRPCCall(const Core::hresult errorcode) const { return errorcode; } + // simulate a COMRPC call that returns an Custom Code Core::hresult SimulatedComRPCCall(const int32_t customerrorcode) const { - return Core::CustomCode(customerrorcode); + // when there is no error, just feed Core::ERROR_NONE into the Core::CustomCode(...) function to indicate there is no error as you would do with a normal hresult + int32_t result = Core::ERROR_NONE; + + // suppose you detect an error situation and you want to set a custom code, just set the value assigned for this error + if (customerrorcode != 0) { + result = customerrorcode; + } + + return Core::CustomCode(customerrorcode); // calling Core::CustomCode will convert the custom code into the correct hresult value so the custom code value gets stored appropriately in the hresult } void ExampleHandlingHResultWhichCouldContainCustomCode(const Core::hresult errorcode) const { + // here we handle an hresult in a detailed way in case we would like to extract the custom code for some reason (again not required, if you just want to handle an error situation you can just compare the hresult with Core::ERROR_NOE, nothing more to do + // (and if you need a text representation feed the hresult to ErrorToString or ErrorToStringExtended that will internnly handle the custom code correclty) int32_t customcode = Core::IsCustomCode(errorcode); if (customcode == 0) { - TRACE(Trace::Information, (_T("Thunder Error received: %u"), errorcode)); + TRACE(Trace::Information, (_T("Thunder defined error received: %u"), errorcode)); + } else if (customcode == std::numeric_limits::min()) { + TRACE(Trace::Information, (_T("Invalid custom code was passed"))); } else { TRACE(Trace::Information, (_T("Custom Code received: %i"), customcode)); } + // You can just feed any hresult to ErrorToString or ErrorToStringExtended, it will deal with the Custom Code internally TRACE(Trace::Information, (_T("Error received: %s"), Core::ErrorToStringExtended(errorcode).c_str())); } From 84443055509d5c2de3fde6edddae2760eade3218 Mon Sep 17 00:00:00 2001 From: MFransen Date: Sat, 15 Nov 2025 14:34:44 +0100 Subject: [PATCH 3/4] [CustomCode] make it work onm linux --- examples/CMakeLists.txt | 6 ++++++ .../CustomCodeToStringLibrary/CMakeLists.txt | 19 +++++++++---------- .../CustomCodeToString.cpp | 4 +--- .../CustomErrorCode/CMakeLists.txt | 17 ++++++++++++----- .../CustomErrorCode/CustomErrorCodeServer.cpp | 6 +++--- .../CustomErrorCode/CustomErrorCodeServer.h | 10 +++++----- 6 files changed, 36 insertions(+), 26 deletions(-) diff --git a/examples/CMakeLists.txt b/examples/CMakeLists.txt index 1bc0a3e8d..412a63258 100644 --- a/examples/CMakeLists.txt +++ b/examples/CMakeLists.txt @@ -38,6 +38,7 @@ option(EXAMPLE_SIMPLECOMRPC_TEST "Include Simple COMRPC test client" OFF) option(EXAMPLE_PLUGINSMARTINTERFACETYPE_EXAMPLE "Include PluginSmartInterfaceType examples" OFF) option(EXAMPLE_DYNAMICJSONRPCERRORMESSAGE_EXAMPLE "Include DynamicJSONRPCErrorMessage example" OFF) option(EXAMPLE_GENERATORSHOWCASE_EXAMPLE "Include GeneratorShowCase example" OFF) +option(EXAMPLE_CUSTOMCODE_EXAMPLE "Include Custom Code example" OFF) if(EXAMPLE_COMRPCCLIENT) add_subdirectory(COMRPCClient) @@ -99,3 +100,8 @@ endif() if (EXAMPLE_GENERATORSHOWCASE_EXAMPLE) add_subdirectory(GeneratorShowcase) endif() + +if (EXAMPLE_CUSTOMCODE_EXAMPLE) + add_subdirectory(CustomErrorCodes/CustomErrorCode) + add_subdirectory(CustomErrorCodes/CustomCodeToStringLibrary) +endif() diff --git a/examples/CustomErrorCodes/CustomCodeToStringLibrary/CMakeLists.txt b/examples/CustomErrorCodes/CustomCodeToStringLibrary/CMakeLists.txt index b8b22f146..ffc23cfb6 100644 --- a/examples/CustomErrorCodes/CustomCodeToStringLibrary/CMakeLists.txt +++ b/examples/CustomErrorCodes/CustomCodeToStringLibrary/CMakeLists.txt @@ -15,7 +15,7 @@ # See the License for the specific language governing permissions and # limitations under the License. -project(SimpleCOMRPCClient) +project(CustomCodeToStringLibrary) cmake_minimum_required(VERSION 3.15) @@ -23,15 +23,16 @@ find_package(Thunder) project_version(1.0.0) -set(MODULE_NAME ${PROJECT_NAME}) +set(MODULE_NAME ${NAMESPACE}${PROJECT_NAME}) message("Setup ${MODULE_NAME} v${PROJECT_VERSION}") -find_package(${NAMESPACE}Core) -find_package(${NAMESPACE}COM REQUIRED) +find_package(${NAMESPACE}Core REQUIRED) find_package(CompileSettingsDebug CONFIG REQUIRED) -add_executable(${MODULE_NAME} SimpleCOMRPCClient.cpp) +add_library(${MODULE_NAME} SHARED + CustomCodeToString.cpp +) set_target_properties(${MODULE_NAME} PROPERTIES CXX_STANDARD 11 @@ -39,10 +40,8 @@ set_target_properties(${MODULE_NAME} PROPERTIES ) target_link_libraries(${MODULE_NAME} - PRIVATE + PRIVATE ${NAMESPACE}Core::${NAMESPACE}Core - ${NAMESPACE}COM::${NAMESPACE}COM - CompileSettingsDebug::CompileSettingsDebug - ) + CompileSettingsDebug::CompileSettingsDebug) -install(TARGETS ${MODULE_NAME} DESTINATION ${CMAKE_INSTALL_BINDIR} COMPONENT ${NAMESPACE}_Runtime) +install(TARGETS ${MODULE_NAME} DESTINATION ${CMAKE_INSTALL_LIBDIR} COMPONENT ${NAMESPACE}_Runtime) \ No newline at end of file diff --git a/examples/CustomErrorCodes/CustomCodeToStringLibrary/CustomCodeToString.cpp b/examples/CustomErrorCodes/CustomCodeToStringLibrary/CustomCodeToString.cpp index 8d04a2b42..7a7fcb1e1 100644 --- a/examples/CustomErrorCodes/CustomCodeToStringLibrary/CustomCodeToString.cpp +++ b/examples/CustomErrorCodes/CustomCodeToStringLibrary/CustomCodeToString.cpp @@ -11,17 +11,15 @@ #ifdef _UNICODE #define _T(x) L##x -#define TCHAR wchar_t #endif #ifndef _UNICODE #define _T(x) x -#define TCHAR char #endif #endif // __LINUX__ -#include +#include const TCHAR* CustomCodeToSting(int32_t code) { const TCHAR* text = nullptr; diff --git a/examples/CustomErrorCodes/CustomErrorCode/CMakeLists.txt b/examples/CustomErrorCodes/CustomErrorCode/CMakeLists.txt index 25c537ac4..8b0050504 100644 --- a/examples/CustomErrorCodes/CustomErrorCode/CMakeLists.txt +++ b/examples/CustomErrorCodes/CustomErrorCode/CMakeLists.txt @@ -27,26 +27,33 @@ set(MODULE_NAME ${NAMESPACE}${PROJECT_NAME}) message("Setup ${MODULE_NAME} v${PROJECT_VERSION}") +find_package(${NAMESPACE}Core REQUIRED) find_package(${NAMESPACE}Plugins REQUIRED) find_package(${NAMESPACE}Definitions REQUIRED) -find_package(CompileSettingsDebug CONFIG REQUIRED) +find_package(${NAMESPACE}Messaging REQUIRED) +find_package(CompileSettingsDebug REQUIRED) add_library(${MODULE_NAME} SHARED Module.cpp CustomErrorCodeServer.cpp ) +target_include_directories(${MODULE_NAME} SYSTEM + PRIVATE + ".") + set_target_properties(${MODULE_NAME} PROPERTIES CXX_STANDARD 11 CXX_STANDARD_REQUIRED YES) target_link_libraries(${MODULE_NAME} PRIVATE - CompileSettingsDebug::CompileSettingsDebug + ${NAMESPACE}Core::${NAMESPACE}Core ${NAMESPACE}Plugins::${NAMESPACE}Plugins - ${NAMESPACE}Definitions::${NAMESPACE}Definitions) + ${NAMESPACE}Definitions::${NAMESPACE}Definitions + ${NAMESPACE}Messaging::${NAMESPACE}Messaging + CompileSettingsDebug::CompileSettingsDebug) -install(TARGETS ${MODULE_NAME} - DESTINATION ${CMAKE_INSTALL_LIBDIR}/${STORAGE_DIRECTORY}/plugins COMPONENT ${NAMESPACE}_Runtime) +install(TARGETS ${MODULE_NAME} DESTINATION ${CMAKE_INSTALL_LIBDIR}/${STORAGE_DIRECTORY}/plugins COMPONENT ${NAMESPACE}_Runtime) write_config() diff --git a/examples/CustomErrorCodes/CustomErrorCode/CustomErrorCodeServer.cpp b/examples/CustomErrorCodes/CustomErrorCode/CustomErrorCodeServer.cpp index 0c704c532..36f8c30fe 100644 --- a/examples/CustomErrorCodes/CustomErrorCode/CustomErrorCodeServer.cpp +++ b/examples/CustomErrorCodes/CustomErrorCode/CustomErrorCodeServer.cpp @@ -18,7 +18,7 @@ */ #include "CustomErrorCodeServer.h" -#include +#include namespace Thunder { @@ -40,13 +40,13 @@ namespace Plugin { const string CustomErrorCodeServer::Initialize(PluginHost::IShell*) { - Exchange::JCustomErrorCode::Register(*this, this); + Example::JCustomErrorCode::Register(*this, this); return (EMPTY_STRING); } void CustomErrorCodeServer::Deinitialize(PluginHost::IShell*) { - Exchange::JCustomErrorCode::Unregister(*this); + Example::JCustomErrorCode::Unregister(*this); } string CustomErrorCodeServer::Information() const diff --git a/examples/CustomErrorCodes/CustomErrorCode/CustomErrorCodeServer.h b/examples/CustomErrorCodes/CustomErrorCode/CustomErrorCodeServer.h index df1b6f62b..0651c66dc 100644 --- a/examples/CustomErrorCodes/CustomErrorCode/CustomErrorCodeServer.h +++ b/examples/CustomErrorCodes/CustomErrorCode/CustomErrorCodeServer.h @@ -19,12 +19,12 @@ #pragma once #include "Module.h" -#include +#include namespace Thunder { namespace Plugin { - class CustomErrorCodeServer : public Exchange::ICustomErrorCode, public PluginHost::IPlugin, public PluginHost::JSONRPC { + class CustomErrorCodeServer : public Example::ICustomErrorCode, public PluginHost::IPlugin, public PluginHost::JSONRPC { public: CustomErrorCodeServer(const CustomErrorCodeServer&) = delete; CustomErrorCodeServer& operator=(const CustomErrorCodeServer&) = delete; @@ -32,7 +32,7 @@ namespace Plugin { CustomErrorCodeServer& operator=(CustomErrorCodeServer&&) = delete; CustomErrorCodeServer() - : Exchange::ICustomErrorCode() + : Example::ICustomErrorCode() , PluginHost::IPlugin() , PluginHost::JSONRPC() { @@ -45,7 +45,7 @@ namespace Plugin { BEGIN_INTERFACE_MAP(CustomErrorCodeServer) INTERFACE_ENTRY(IPlugin) INTERFACE_ENTRY(IDispatcher) - INTERFACE_ENTRY(Exchange::ICustomErrorCode) + INTERFACE_ENTRY(Example::ICustomErrorCode) END_INTERFACE_MAP const string Initialize(PluginHost::IShell* service); @@ -99,7 +99,7 @@ namespace Plugin { result = customerrorcode; } - return Core::CustomCode(customerrorcode); // calling Core::CustomCode will convert the custom code into the correct hresult value so the custom code value gets stored appropriately in the hresult + return Core::CustomCode(result); // calling Core::CustomCode will convert the custom code into the correct hresult value so the custom code value gets stored appropriately in the hresult } void ExampleHandlingHResultWhichCouldContainCustomCode(const Core::hresult errorcode) const { From e26c8e1ff8730fa6af1dbb43572e96117f033c84 Mon Sep 17 00:00:00 2001 From: MFransen Date: Sat, 15 Nov 2025 15:10:53 +0100 Subject: [PATCH 4/4] [CustomCode] small fix --- .../CustomCodeToStringLibrary/CustomCodeToString.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/examples/CustomErrorCodes/CustomCodeToStringLibrary/CustomCodeToString.cpp b/examples/CustomErrorCodes/CustomCodeToStringLibrary/CustomCodeToString.cpp index 7a7fcb1e1..e145d5f9e 100644 --- a/examples/CustomErrorCodes/CustomCodeToStringLibrary/CustomCodeToString.cpp +++ b/examples/CustomErrorCodes/CustomCodeToStringLibrary/CustomCodeToString.cpp @@ -21,7 +21,7 @@ #include -const TCHAR* CustomCodeToSting(int32_t code) { +const TCHAR* CustomCodeToSting(const int32_t code) { const TCHAR* text = nullptr; if (code == 100) { text = _T("Custom Error code 100");