-
Notifications
You must be signed in to change notification settings - Fork 53
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[DynamicJSONRPCErrorMessage] add to examples
- Loading branch information
1 parent
fa8b623
commit eeba487
Showing
8 changed files
with
284 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
# If not stated otherwise in this file or this component's LICENSE file the | ||
# following copyright and licenses apply: | ||
# | ||
# Copyright 2022 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(DynamicJSONRPCErrorMessage) | ||
|
||
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}Core REQUIRED) | ||
find_package(${NAMESPACE}Plugins REQUIRED) | ||
find_package(${NAMESPACE}Definitions REQUIRED) | ||
find_package(${NAMESPACE}Messaging REQUIRED) | ||
find_package(CompileSettingsDebug REQUIRED) | ||
|
||
add_library(${MODULE_NAME} SHARED | ||
DynamicJSONRPCErrorMessage.cpp | ||
Module.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}Plugins::${NAMESPACE}Plugins | ||
${NAMESPACE}Definitions::${NAMESPACE}Definitions | ||
${NAMESPACE}Messaging::${NAMESPACE}Messaging | ||
CompileSettingsDebug::CompileSettingsDebug | ||
${PLUGIN_YIN_DEFINITIONS}) | ||
|
||
install(TARGETS ${MODULE_NAME} | ||
DESTINATION ${CMAKE_INSTALL_LIBDIR}/${STORAGE_DIRECTORY}/plugins COMPONENT ${NAMESPACE}_Runtime) | ||
|
||
write_config() |
3 changes: 3 additions & 0 deletions
3
examples/DynamicJSONRPCErrorMessage/DynamicJSONRPCErrorMessage.conf.in
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
startmode = "Activated" | ||
|
||
|
82 changes: 82 additions & 0 deletions
82
examples/DynamicJSONRPCErrorMessage/DynamicJSONRPCErrorMessage.cpp
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,82 @@ | ||
/* | ||
* If not stated otherwise in this file or this component's LICENSE file the | ||
* following copyright and licenses apply: | ||
* | ||
* Copyright 2022 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" | ||
|
||
#include "DynamicJSONRPCErrorMessage.h" | ||
#include <interfaces/json/JMath.h> | ||
|
||
#include <sstream> | ||
|
||
namespace Thunder { | ||
|
||
namespace Plugin { | ||
|
||
namespace { | ||
static Metadata<DynamicJSONRPCErrorMessage> metadata( | ||
// Version | ||
1, 0, 0, | ||
// Preconditions | ||
{ }, | ||
// Terminations | ||
{ }, | ||
// Controls | ||
{ } | ||
); | ||
} | ||
|
||
const string DynamicJSONRPCErrorMessage::Initialize(PluginHost::IShell*) | ||
{ | ||
string message{}; | ||
|
||
Exchange::JMath::Register(*this, this); | ||
|
||
return (message); | ||
} | ||
|
||
void DynamicJSONRPCErrorMessage::Deinitialize(PluginHost::IShell* service VARIABLE_IS_NOT_USED) | ||
{ | ||
Exchange::JMath::Unregister(*this); | ||
} | ||
|
||
string DynamicJSONRPCErrorMessage::Information() const | ||
{ | ||
return {}; | ||
} | ||
|
||
uint32_t DynamicJSONRPCErrorMessage::OnJSONRPCError(const Core::JSONRPC::Context&, const string& designator, const string& parameters, string& errormessage) { | ||
uint32_t result = Core::ERROR_GENERAL; | ||
|
||
string method(Core::JSONRPC::Message::Method(designator)); | ||
|
||
if(method == _T("add")) { | ||
JsonData::Math::AddParamsInfo addparams; | ||
addparams.FromString(parameters); | ||
std::stringstream message; | ||
message <<_T("Error handling add method for some peculiar reason values: ") << addparams.A << _T(" and ") << addparams.B; | ||
errormessage = message.str(); | ||
result = Core::ERROR_INVALID_PARAMETER; | ||
} | ||
return result; | ||
} | ||
|
||
|
||
} // namespace Plugin | ||
|
||
} |
72 changes: 72 additions & 0 deletions
72
examples/DynamicJSONRPCErrorMessage/DynamicJSONRPCErrorMessage.h
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
/* | ||
* If not stated otherwise in this file or this component's LICENSE file the | ||
* following copyright and licenses apply: | ||
* | ||
* Copyright 2022 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 <interfaces/IMath.h> | ||
|
||
namespace Thunder { | ||
|
||
namespace Plugin { | ||
|
||
class DynamicJSONRPCErrorMessage : public PluginHost::IPlugin | ||
, public PluginHost::JSONRPCErrorAssessor | ||
, Exchange::IMath { | ||
|
||
public: | ||
DynamicJSONRPCErrorMessage() = default; | ||
~DynamicJSONRPCErrorMessage() override = default; | ||
|
||
DynamicJSONRPCErrorMessage(const DynamicJSONRPCErrorMessage&) = delete; | ||
DynamicJSONRPCErrorMessage &operator=(const DynamicJSONRPCErrorMessage&) = delete; | ||
DynamicJSONRPCErrorMessage(DynamicJSONRPCErrorMessage&&) = delete; | ||
DynamicJSONRPCErrorMessage &operator=(DynamicJSONRPCErrorMessage&&) = delete; | ||
|
||
public: | ||
// PluginHost::IPlugin overrides | ||
const string Initialize(PluginHost::IShell *service) override; | ||
void Deinitialize(PluginHost::IShell *service) override; | ||
string Information() const override; | ||
|
||
// IMath overrides | ||
uint32_t Add(const uint16_t, const uint16_t, uint16_t&) const override { | ||
return Core::ERROR_USER_DEFINED_JSONRPC; | ||
}; | ||
|
||
uint32_t Sub(const uint16_t, const uint16_t, uint16_t&) const override { | ||
return Core::ERROR_USER_DEFINED_JSONRPC; | ||
} | ||
|
||
// JSONRPCErrorAssessor overrides | ||
uint32_t OnJSONRPCError(const Core::JSONRPC::Context& context, const string& designator, const string& parameters, string& errormessage) override; | ||
|
||
public: | ||
BEGIN_INTERFACE_MAP(DynamicJSONRPCErrorMessage) | ||
INTERFACE_ENTRY(PluginHost::IPlugin) | ||
INTERFACE_ENTRY(PluginHost::IDispatcher) | ||
INTERFACE_ENTRY(Exchange::IMath) | ||
END_INTERFACE_MAP | ||
|
||
}; // class DynamicJSONRPCErrorMessage | ||
|
||
} // namespace Plugin | ||
|
||
} |
13 changes: 13 additions & 0 deletions
13
examples/DynamicJSONRPCErrorMessage/DynamicJSONRPCErrorMessagePlugin.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
{ | ||
"$schema": "plugin.schema.json", | ||
"info": { | ||
"title": "DynamicJSONRPCErrorMessage Plugin", | ||
"callsign": "DynamicJSONRPCErrorMessage", | ||
"locator": "libThunderDynamicJSONRPCErrorMessage.so", | ||
"status": "alpha", | ||
"version": "1.0" | ||
}, | ||
"interface": { | ||
"$ref": "{cppinterfacedir}/IMath.h" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
/* | ||
* If not stated otherwise in this file or this component's LICENSE file the | ||
* following copyright and licenses apply: | ||
* | ||
* Copyright 2022 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) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
/* | ||
* If not stated otherwise in this file or this component's LICENSE file the | ||
* following copyright and licenses apply: | ||
* | ||
* Copyright 2022 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_DynamicJSONRPCErrorMessage | ||
#endif | ||
|
||
#include <core/core.h> | ||
#include <plugins/plugins.h> | ||
|
||
#undef EXTERNAL | ||
#define EXTERNAL |