Skip to content

Commit

Permalink
Merge branch 'master' into development/container-doc
Browse files Browse the repository at this point in the history
  • Loading branch information
pwielders authored Oct 25, 2024
2 parents 1e6bb37 + 75e5fe6 commit 4e59c67
Show file tree
Hide file tree
Showing 15 changed files with 862 additions and 18 deletions.
8 changes: 8 additions & 0 deletions Source/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,9 @@ option(EXCEPTION_CATCHING
"Enable unhandled exception handling catching." OFF)
option(DEADLOCK_DETECTION
"Enable deadlock detection tooling." OFF)
option(DISABLE_USE_COMPLEMENTARY_CODE_SET
"Disable the complementary code set" OFF)


if(HIDE_NON_EXTERNAL_SYMBOLS)
set(CMAKE_CXX_VISIBILITY_PRESET hidden)
Expand Down Expand Up @@ -84,6 +87,11 @@ else()
endif()
endif()

if(DISABLE_USE_COMPLEMENTARY_CODE_SET)
add_definitions(-D__DISABLE_USE_COMPLEMENTARY_CODE_SET__)
message(STATUS "complementary code set disabled")
endif()

if(CORE)
add_subdirectory(core)
endif()
Expand Down
4 changes: 4 additions & 0 deletions Source/Thunder/Controller.h
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,10 @@ namespace Plugin {
_parent.SubSystems();
}

string JobIdentifier() const {
return(_T("Thunder::Plugin::Controller::Sink::Job"));
}

private:
Controller& _parent;
};
Expand Down
20 changes: 18 additions & 2 deletions Source/Thunder/PluginServer.h
Original file line number Diff line number Diff line change
Expand Up @@ -2449,6 +2449,10 @@ namespace PluginHost {
return result;
}

string JobIdentifier() const {
return(_T("Thunder::PluginHost::Server::ServiceMap::CommunicatorServer"));
}

private:
ServiceMap& _parent;
const string _persistentPath;
Expand Down Expand Up @@ -2489,7 +2493,7 @@ namespace PluginHost {
_parent.Evaluate();
}
string JobIdentifier() const {
return(_T("PluginServer::SubSystems::Notification"));
return(_T("Thunder::PluginHost::Server::ServiceMap::SubSystems::Job"));
}

private:
Expand Down Expand Up @@ -2720,6 +2724,12 @@ namespace PluginHost {
POP_WARNING()
~ServiceMap()
{
Core::ProxyType<Core::IDispatch> job(_job.Revoke());

if (job.IsValid()) {
WorkerPool().Revoke(job);
_job.Revoked();
}
// Make sure all services are deactivated before we are killed (call Destroy on this object);
ASSERT(_services.size() == 0);
}
Expand Down Expand Up @@ -3429,6 +3439,11 @@ namespace PluginHost {
}

friend class Core::ThreadPool::JobType<ServiceMap&>;

string JobIdentifier() const {
return(_T("Thunder::PluginHost::Server::ServiceMap"));
}

void Dispatch()
{
_adminLock.Lock();
Expand Down Expand Up @@ -4525,8 +4540,9 @@ namespace PluginHost {
friend class Core::ThreadPool::JobType<ChannelMap&>;

string JobIdentifier() const {
return (_T("PluginServer::ChannelMap::Cleanup"));
return (_T("Thunder::PluginHost::Server::ChannelMap"));
}

void Dispatch()
{
TRACE(Activity, (string(_T("Cleanup job running..\n"))));
Expand Down
4 changes: 4 additions & 0 deletions Source/ThunderPlugin/Process.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,10 @@ POP_WARNING()
}
}

string JobIdentifier() const {
return(_T("Thunder::Process::WorkerPoolImplmenetation::Sink"));
}

private:
WorkerPoolImplementation& _parent;
Core::ThreadPool::JobType<Sink&> _job;
Expand Down
6 changes: 6 additions & 0 deletions Source/core/JSON.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,8 @@ namespace Core {
/* static */ char IElement::TrueTag[5] = { 't', 'r', 'u', 'e', '\0' };
/* static */ char IElement::FalseTag[6] = { 'f', 'a', 'l', 's', 'e', '\0' };

#ifndef __DISABLE_USE_COMPLEMENTARY_CODE_SET__

string Variant::GetDebugString(const TCHAR name[], int indent, int arrayIndex) const
{
std::stringstream ss;
Expand Down Expand Up @@ -78,6 +80,10 @@ namespace Core {
ss << iterator.Current().GetDebugString(iterator.Label(), indent);
return ss.str();
}

#endif // __DISABLE_USE_COMPLEMENTARY_CODE_SET__


}
}

Expand Down
8 changes: 8 additions & 0 deletions Source/core/JSON.h
Original file line number Diff line number Diff line change
Expand Up @@ -4192,6 +4192,8 @@ namespace Core {
mutable String _fieldName;
};

#ifndef __DISABLE_USE_COMPLEMENTARY_CODE_SET__

class VariantContainer;

class EXTERNAL Variant : public JSON::String {
Expand Down Expand Up @@ -5089,12 +5091,18 @@ namespace Core {
}
};

#endif // __DISABLE_USE_COMPLEMENTARY_CODE_SET__

} // namespace JSON
} // namespace Core
} // namespace Thunder

#ifndef __DISABLE_USE_COMPLEMENTARY_CODE_SET__

using JsonObject = Thunder::Core::JSON::VariantContainer;
using JsonValue = Thunder::Core::JSON::Variant;
using JsonArray = Thunder::Core::JSON::ArrayType<JsonValue>;

#endif // __DISABLE_USE_COMPLEMENTARY_CODE_SET__

#endif // __JSON_H
13 changes: 7 additions & 6 deletions Source/core/TypeTraits.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@

#include "Portability.h"
#include <functional>
#include <type_traits>

namespace Thunder {

Expand Down Expand Up @@ -191,14 +192,14 @@ namespace Core {
// Args: arguments that func should have, note it will also work if overrides of Func are available on T. Note: passing Args&&... itself is also allowed here to allow for variable parameters
#define IS_MEMBER_AVAILABLE_INHERITANCE_TREE(func, name) \
template <bool, typename TT> \
struct name##_IsMemberAvailableCheck : public TT { \
using type = TT; \
struct name##_IsMemberAvailableCheck : public std::remove_reference<TT>::type { \
using type = typename std::remove_reference<TT>::type; \
template <typename TTT, typename... Args2> \
auto Verify() -> decltype( (TTT::func(std::declval<Args2>()...))); \
}; \
template <typename TT> \
struct name##_IsMemberAvailableCheck<true, TT> : public TT { \
using type = const TT; \
struct name##_IsMemberAvailableCheck<true, TT> : public std::remove_reference<TT>::type { \
using type = const typename std::remove_reference<TT>::type; \
template <typename TTT, typename... Args2> \
auto Verify() const -> decltype( (TTT::func(std::declval<Args2>()...))); \
}; \
Expand All @@ -207,12 +208,12 @@ namespace Core {
typedef char yes[1]; \
typedef char no[2]; \
template <typename U, \
typename RR = decltype(std::declval<name##_IsMemberAvailableCheck<std::is_const<U>::value, U>>().template Verify<U, Args...>()), \
typename RR = decltype(std::declval<name##_IsMemberAvailableCheck<std::is_const<typename std::remove_reference<U>::type>::value, U>>().template Verify<U, Args...>()), \
typename Z = typename std::enable_if<std::is_same<R, RR>::value>::type> \
static yes& chk(int); \
template <typename U> \
static no& chk(...); \
static bool const value = sizeof(chk<T>(0)) == sizeof(yes); \
static bool const value = sizeof(chk<typename std::remove_reference<T>::type>(0)) == sizeof(yes); \
}


Expand Down
4 changes: 4 additions & 0 deletions Source/extensions/bluetooth/audio/AVDTPSocket.h
Original file line number Diff line number Diff line change
Expand Up @@ -484,6 +484,10 @@ namespace AVDTP {
}
~Socket() = default;

string JobIdentifier() const {
return(_T("Thunder::Bluetooth::AVDTP::Socket"));
}

public:
uint16_t OutputMTU() const {
return (_omtu);
Expand Down
119 changes: 112 additions & 7 deletions Source/plugins/JSONRPC.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,27 @@ namespace Thunder {

namespace PluginHost {

namespace {

template<typename JSONRPCERRORASSESSORTYPE>
uint32_t InvokeOnHandler(const Core::JSONRPC::Context& context, const string& method, const string& parameters, string& response, Core::JSONRPC::Handler& handler, JSONRPCERRORASSESSORTYPE errorhandler)
{
uint32_t result = handler.Invoke(context, method, parameters, response);
if(result != Core::ERROR_NONE) {
result = errorhandler(context, method, parameters, result, response);
}

return result;
}

template<>
uint32_t InvokeOnHandler<void*>(const Core::JSONRPC::Context& context, const string& method, const string& parameters, string& response, Core::JSONRPC::Handler& handler, void*)
{
return handler.Invoke(context, method, parameters, response);
}

}

class EXTERNAL JSONRPC : public IDispatcher {
public:
using SendIfMethod = std::function<bool(const string&)>;
Expand Down Expand Up @@ -448,6 +469,7 @@ namespace PluginHost {
return (result);
}


//
// Register/Unregister methods for incoming method handling on the "base" handler elements.
// ------------------------------------------------------------------------------------------------------------------------------
Expand All @@ -456,11 +478,17 @@ namespace PluginHost {
{
_handlers.front().Property<PARAMETER>(methodName, getter, setter, objectPtr);
}

#ifndef __DISABLE_USE_COMPLEMENTARY_CODE_SET__

template <typename METHOD, typename REALOBJECT>
void Register(const string& methodName, const METHOD& method, REALOBJECT* objectPtr)
{
_handlers.front().Register<Core::JSON::VariantContainer, Core::JSON::VariantContainer, METHOD, REALOBJECT>(methodName, method, objectPtr);
}

#endif // __DISABLE_USE_COMPLEMENTARY_CODE_SET__

template <typename INBOUND, typename OUTBOUND, typename METHOD, typename REALOBJECT>
void Register(const string& methodName, const METHOD& method, REALOBJECT* objectPtr)
{
Expand Down Expand Up @@ -587,7 +615,13 @@ namespace PluginHost {

// Inherited via IDispatcher
// ---------------------------------------------------------------------------------
uint32_t Invoke(const uint32_t channelId, const uint32_t id, const string& token, const string& method, const string& parameters, string& response) override {
uint32_t Invoke(const uint32_t channelId, const uint32_t id, const string& token, const string& method, const string& parameters, string& response) override
{
return InvokeHandler(channelId, id, token, method, parameters, response);
}

template<typename JSONRPCERRORASSESSORTYPE = void*>
uint32_t InvokeHandler(const uint32_t channelId, const uint32_t id, const string& token, const string& method, const string& parameters, string& response, JSONRPCERRORASSESSORTYPE errorhandler = nullptr) {
uint32_t result = Core::ERROR_PARSE_FAILURE;

if (method.empty() == false) {
Expand Down Expand Up @@ -649,20 +683,20 @@ namespace PluginHost {
}
else {
Core::JSONRPC::Handler* handler(Handler(realMethod));

if (handler == nullptr) {
result = Core::ERROR_INCORRECT_URL;
}
else {

if (handler != nullptr) {
Core::JSONRPC::Context context(channelId, id, token);
result = handler->Invoke(context, Core::JSONRPC::Message::FullMethod(method), parameters, response);
result = InvokeOnHandler<JSONRPCERRORASSESSORTYPE>(context, Core::JSONRPC::Message::FullMethod(method), parameters, response, *handler, errorhandler);
} else {
result = Core::ERROR_INCORRECT_URL;
}
}
}
}

return (result);
}

Core::hresult Subscribe(ICallback* callback, const string& eventId, const string& designator) override
{
uint32_t result;
Expand Down Expand Up @@ -1002,5 +1036,76 @@ namespace PluginHost {
StatusCallbackMap _observers;
};

#ifndef __DISABLE_USE_COMPLEMENTARY_CODE_SET__

namespace JSONRPCErrorAssessorTypes {

using FunctionCallbackType = uint32_t (*) (const Core::JSONRPC::Context&, const string&, const string&, const uint32_t errorcode, string&);
using StdFunctionCallbackType = std::function<int32_t(const Core::JSONRPC::Context&, const string&, const string&, const uint32_t errorcode, string&)>;
}

template<typename JSONRPCERRORASSESSORTYPE>
class EXTERNAL JSONRPCErrorAssessor : public JSONRPC {
public:

JSONRPCErrorAssessor(JSONRPCERRORASSESSORTYPE errorhandler)
: JSONRPC()
, _errorhandler(errorhandler)
{
}

~JSONRPCErrorAssessor() override = default;

JSONRPCErrorAssessor(const JSONRPCErrorAssessor&) = delete;
JSONRPCErrorAssessor &operator=(const JSONRPCErrorAssessor&) = delete;
JSONRPCErrorAssessor(JSONRPCErrorAssessor&&) = delete;
JSONRPCErrorAssessor &operator=(JSONRPCErrorAssessor&&) = delete;

uint32_t Invoke(const uint32_t channelId, const uint32_t id, const string& token, const string& method, const string& parameters, string& response) override
{
return JSONRPC::InvokeHandler<JSONRPCERRORASSESSORTYPE>(channelId, id, token, method, parameters, response, _errorhandler);
}


private:
JSONRPCERRORASSESSORTYPE _errorhandler;
};

template<>
class EXTERNAL JSONRPCErrorAssessor<JSONRPCErrorAssessorTypes::StdFunctionCallbackType> : public JSONRPC {
public:

JSONRPCErrorAssessor(const JSONRPCErrorAssessorTypes::StdFunctionCallbackType& errorhandler)
: JSONRPC()
, _errorhandler(errorhandler)
{
}

JSONRPCErrorAssessor(JSONRPCErrorAssessorTypes::StdFunctionCallbackType&& errorhandler)
: JSONRPC()
, _errorhandler(std::move(errorhandler))
{
}

~JSONRPCErrorAssessor() override = default;

JSONRPCErrorAssessor(const JSONRPCErrorAssessor&) = delete;
JSONRPCErrorAssessor &operator=(const JSONRPCErrorAssessor&) = delete;
JSONRPCErrorAssessor(JSONRPCErrorAssessor&&) = delete;
JSONRPCErrorAssessor &operator=(JSONRPCErrorAssessor&&) = delete;

uint32_t Invoke(const uint32_t channelId, const uint32_t id, const string& token, const string& method, const string& parameters, string& response) override
{
return JSONRPC::InvokeHandler<const JSONRPCErrorAssessorTypes::StdFunctionCallbackType&>(channelId, id, token, method, parameters, response, _errorhandler);
}


private:
JSONRPCErrorAssessorTypes::StdFunctionCallbackType _errorhandler;
};

#endif // __DISABLE_USE_COMPLEMENTARY_CODE_SET__

} // namespace Thunder::PluginHost
}

4 changes: 4 additions & 0 deletions Source/plugins/Types.h
Original file line number Diff line number Diff line change
Expand Up @@ -455,6 +455,10 @@ POP_WARNING()
_parent.Register();
}

string JobIdentifier() const {
return(_T("Thunder::RPC::PluginSmartInterfaceType::RegisterJob"));
}

private:
PluginSmartInterfaceType& _parent;
};
Expand Down
Loading

0 comments on commit 4e59c67

Please sign in to comment.