16 template <
typename gRPCStub>
17 class gRPCHardwareAdapter;
28 static constexpr
auto UNIMPLEMENTED_ErrorMsg =
"The connected gRPC server does not implement the called gRPC stub function. Check the server configuration.";
36 gRPCException(
const grpc::Status Result,
const std::source_location Location = std::source_location::current()) noexcept;
43 template <typename gRPCStub>
52 : HardwareAdapterParamsBase(ID, Core), NetworkParams(*this) {}
56 virtual const char*
GetParamClassTag() const noexcept
override {
return "gRPCHardwareAdapterParams"; }
68 template <
typename gRPCStub>
88 template <
typename gRPCStub>
96 constexpr
static auto Name() noexcept {
return "gRPC Hardware Adapter"; }
97 constexpr
static auto Category() noexcept {
return "Communication"; }
100 : HardwareAdapterBase(OwnerThreadID, std::move(Params)) {}
103 virtual std::string
GetName()
const override {
return Name(); }
104 virtual std::string
GetCategory()
const override {
return Category(); }
124 void CheckError(
const grpc::Status Result,
const std::source_location Location = std::source_location::current())
const;
138 bool IsReadyChild() const override final;
139 bool IsConnectedChild() const noexcept override final;
165 virtual
void OpenUnsafeChild() {}
173 std::unique_ptr<typename gRPCStub::Stub>
StubPtr;
176 template <
typename gRPCStub>
183 template <
typename gRPCStub>
186 if (!IsOpenedUnsafe())
192 template <
typename gRPCStub>
199 ThrowExceptionUnsafe(std::make_exception_ptr(
gRPCException(Result, Location)));
202 template <
typename gRPCStub>
213 template <
typename gRPCStub>
216 auto lock = AcquireLock(HardwareOperationTimeout);
221 template <
typename gRPCStub>
224 auto lock = AcquireLock(HardwareOperationTimeout);
229 return IsOpenedUnsafe();
232 template <
typename gRPCStub>
237 auto lock = AcquireLock(HardwareOperationTimeout);
239 return IsOpenedUnsafe();
247 template <
typename gRPCStub>
250 if (IsOpenedUnsafe())
253 auto DerivedParams = dynamic_Params_cast<gRPCHardwareAdapter>(GetParams());
256 StubPtr = gRPCStub::NewStub(grpc::CreateChannel(DerivedParams->NetworkParams.MakeAddress(), grpc::InsecureChannelCredentials()));
261 template <
typename gRPCStub>
Implementation of a hardware adapter to communicate text-based commands over TCP sockets.
Defines an exception caused by an operation involving the gRPC library and communication over a TCP s...
static constexpr auto UNIMPLEMENTED_ErrorMsg
Message used for the grpc::StatusCode::UNIMPLEMENTED status code.
gRPCException(const grpc::Status Result, const std::source_location Location=std::source_location::current()) noexcept
Constructs a gRPCException instance.
Configurator class for gRPCHardwareAdapter.
virtual ~gRPCHardwareAdapterConfigurator()=default
virtual DynExp::ParamsBasePtrType MakeParams(DynExp::ItemIDType ID, const DynExp::DynExpCore &Core) const override
Override to make derived classes call DynExp::MakeParams with the correct configurator type derived f...
gRPCHardwareAdapterConfigurator()=default
Parameter class for gRPCHardwareAdapter.
gRPCHardwareAdapterParams(DynExp::ItemIDType ID, const DynExp::DynExpCore &Core)
Constructs the parameters for a gRPCHardwareAdapter instance.
virtual const char * GetParamClassTag() const noexcept override
This function is intended to be overridden once in each derived class returning the name of the respe...
virtual ~gRPCHardwareAdapterParams()=default
DynExp::NetworkParamsExtension NetworkParams
Bundles several parameters to describe a network connection. Use in parameter classes.
void ConfigureParamsImpl(dispatch_tag< HardwareAdapterParamsBase >) override final
virtual void ConfigureParamsImpl(dispatch_tag< gRPCHardwareAdapterParams >)
This template class provides basic functionality to design hardware adapters for instruments which co...
void EnsureReadyStateChild() override final
Ensures that this Object instance is ready by possibly starting its worker thread or by opening conne...
void OpenUnsafe()
Establishes the connection to a gRPC server creating a new gRPC stub, which is stored in StubPtr.
void CheckError(const grpc::Status Result, const std::source_location Location=std::source_location::current()) const
Checks whether Result denotes an error state. If this is the case, a respective gRPCException is cons...
virtual void ResetImpl(dispatch_tag< gRPCHardwareAdapter >)
void ResetImpl(dispatch_tag< HardwareAdapterBase >) override final
gRPCStub gRPCStubType
gRPCStub gRPC stub class which is used to transfer data.
bool IsConnectedChild() const noexcept override final
Determines the connection status of the hardware interface.
gRPCStub::Stub & GetStubUnsafe() const
Getter for the gRPC stub.
constexpr static auto Name() noexcept
Every derived class has to redefine this function.
void CloseUnsafe()
Closes the connection to a gRPC server. StubPtr becomes nullptr.
bool IsOpenedUnsafe() const noexcept
Checks whether the gRPCHardwareAdapter is connected to a server.
std::unique_ptr< typename gRPCStub::Stub > StubPtr
Pointer to the gRPC stub.
virtual std::string GetName() const override
Returns the name of this Object type.
bool IsReadyChild() const override final
Returns wheter this Object instance is ready (e.g. it is running or connected to a hardware device) a...
virtual void CloseUnsafeChild()
Override to add additional termination steps. Gets executed before the gRPC connection is disconnecte...
constexpr static auto Category() noexcept
Every derived class has to redefine this function.
virtual std::string GetCategory() const override
Returns the category of this Object type.
gRPCHardwareAdapter(const std::thread::id OwnerThreadID, DynExp::ParamsBasePtrType &&Params)
virtual ~gRPCHardwareAdapter()
DynExp's core class acts as the interface between the user interface and DynExp's internal data like ...
Defines the base class for a hardware adapter object. Hardware adapters describe interfaces/connectio...
Configurator class for HardwareAdapterBase.
Parameter class for HardwareAdapterBase.
Bundles several parameters to describe a network connection. Use in parameter classes.
Refer to ParamsBase::dispatch_tag.
Tag for function dispatching mechanism within this class used when derived classes are not intended t...
DynExp exceptions are derived from this class. It contains basic information about the cause of the e...
Exception(std::string Description, const ErrorType Type=ErrorType::Error, const int ErrorCode=-1, const std::source_location Location=std::source_location::current()) noexcept
Constructs an exception. Constructor is noexcept, although std::runtime_error() might throw std::bad_...
Thrown when some operation or feature is temporarily or permanently not available.
DynExp's hardware namespace contains the implementation of DynExp hardware adapters which extend DynE...
DynExp's main namespace contains the implementation of DynExp including classes to manage resources (...
std::unique_ptr< ParamsBase > ParamsBasePtrType
Alias for a pointer to the parameter system base class ParamsBase.
size_t ItemIDType
ID type of objects/items managed by DynExp.
void ForwardException(std::exception_ptr e)
Wraps the exception passed to the function in a ForwardedException and throws the ForwardedException....
Accumulates include statements to provide a precompiled header.