17#include "Common.grpc.pb.h"
21 template <
typename BaseInstr,
typename std::enable_if_t<std::is_base_of_v<DynExp::InstrumentBase, BaseInstr>,
int>,
typename... gRPCStubs>
37 default:
throw Util::InvalidDataException(
"The given unit is not supported here. Did you forget to adjust this function or the UnitType enumeration in file \"Units.h\"?");
58 default:
throw Util::InvalidDataException(
"The given unit is not supported here. Did you forget to adjust this function or the UnitType enumeration in file \"Units.h\"?");
65 namespace gRPCInstrumentTasks
71 template <
typename BaseInstr, std::enable_if_t<std::is_base_of_v<DynExp::InstrumentBase, BaseInstr>,
int>,
typename... gRPCStubs>
72 class InitTask :
public BaseInstr::InitTaskType
78 template <
typename Type>
93 InstrData->StubPtrs = std::make_tuple(gRPCStubs::NewStub(grpc::CreateChannel(InstrParams->NetworkParams.MakeAddress(), grpc::InsecureChannelCredentials()))...);
109 template <
typename BaseInstr, std::enable_if_t<std::is_base_of_v<DynExp::InstrumentBase, BaseInstr>,
int>,
typename... gRPCStubs>
116 template <
typename Type>
131 InstrData->ResetStubPtrs();
150 template <
typename BaseInstr, std::enable_if_t<std::is_base_of_v<DynExp::InstrumentBase, BaseInstr>,
int>,
typename... gRPCStubs>
157 template <
typename Type>
180 template <
typename gRPCStub>
187 template <
typename BaseInstr,
typename std::enable_if_t<std::is_base_of_v<DynExp::InstrumentBase, BaseInstr>,
int>,
typename... gRPCStubs>
200 template <
typename... ArgTs>
211 template <
size_t Index>
220 template <
typename T>
254 template <
typename BaseInstr,
typename std::enable_if_t<std::is_base_of_v<DynExp::InstrumentBase, BaseInstr>,
int>,
typename... gRPCStubs>
270 virtual const char*
GetParamClassTag() const noexcept
override {
return "gRPCInstrumentParams"; }
298 template <
typename BaseInstr,
typename std::enable_if_t<std::is_base_of_v<DynExp::InstrumentBase, BaseInstr>,
int>,
typename... gRPCStubs>
329 template <
typename BaseInstr,
typename std::enable_if_t<std::is_base_of_v<DynExp::InstrumentBase, BaseInstr>,
int>,
typename... gRPCStubs>
337 constexpr static auto Name() noexcept {
return "gRPC Instrument"; }
338 constexpr static auto Category() noexcept {
return "Network Instruments (Clients)"; }
345 : BaseInstr(OwnerThreadID, std::move(Params)) {}
389 template <
typename gRPCStub,
typename RequestMsgType,
typename ResponseMsgType>
390 using StubFuncPtrType = grpc::Status(gRPCStub::*)(grpc::ClientContext*, const RequestMsgType&, ResponseMsgType*);
410 template <
typename gRPCStub,
typename RequestMsgType,
typename ResponseMsgType>
413 grpc::ClientContext Context;
414 ResponseMsgType ReplyMsg;
421 static const auto Timeout = std::chrono::milliseconds(2000);
422 Context.set_deadline(std::chrono::system_clock::now() + Timeout);
424 auto Result = (*StubPtr.*StubFunc)(&Context, RequestMsg, &ReplyMsg);
Implementation of a data stream meta instrument and of data streams input/output devices might work o...
Defines DynExp's core module as an interface between the UI and DynExp objects.
Implementation of a hardware adapter to communicate over TCP sockets using gRPC.
Defines an exception caused by an operation involving the gRPC library and communication over a TCP s...
Configurator class for gRPCInstrument.
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...
gRPCInstrumentConfigurator()=default
virtual ~gRPCInstrumentConfigurator()=default
Data class for gRPCInstrument.
virtual ~gRPCInstrumentData()=default
virtual void ResetImpl(DynExp::InstrumentDataBase::dispatch_tag< gRPCInstrumentData >)
Refer to DynExp::InstrumentDataBase::Reset(). Using tag dispatch mechanism to ensure that ResetImpl()...
gRPCInstrumentData(ArgTs &&...Args)
Constructs a gRPCInstrumentData instance and forwards all arguments passed to the constructor to the ...
auto GetStub() const noexcept
Returns a stub pointer this gRPCInstrument uses selected by the stub index in the gRPCStubs list of g...
void ResetImpl(DynExp::InstrumentDataBase::dispatch_tag< typename BaseInstr::InstrumentDataType >) override final
Refer to DynExp::InstrumentDataBase::Reset(). Using tag dispatch mechanism to ensure that ResetImpl()...
void ResetStubPtrs()
Sets all pointers contained in StubPtrs to nullptr.
std::tuple< StubPtrType< gRPCStubs >... > StubPtrs
Tuple of pointers to all the stubs this gRPCInstrument uses.
Parameter class for gRPCInstrument.
virtual ~gRPCInstrumentParams()=default
gRPCInstrumentParams(DynExp::ItemIDType ID, const DynExp::DynExpCore &Core)
Constructs the parameters for a gRPCInstrument instance.
DynExp::NetworkParamsExtension NetworkParams
Network address of the gRPC server to connect to.
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 const DynExp::NetworkParamsExtension * GetNetworkAddressParamsChild() const noexcept override
Returns the network address parameters of a derived gRPC instrument. Override GetNetworkAddressParams...
virtual void ConfigureParamsImpl(DynExp::InstrumentParamsBase::dispatch_tag< gRPCInstrumentParams >)
Called by DynExp::ParamsBase::ConfigureParams() as a starting point for the tag dispatch mechanism to...
void ConfigureParamsImpl(DynExp::InstrumentParamsBase::dispatch_tag< typename BaseInstr::ParamsType >) override final
Called by DynExp::ParamsBase::ConfigureParams() as a starting point for the tag dispatch mechanism to...
Defines a task for deinitializing an instrument within an instrument inheritance hierarchy....
virtual void ExitFuncImpl(dispatch_tag< ExitTask >, DynExp::InstrumentInstance &Instance)
Deinitializes the respective instrument within the instrument inheritance hierarchy....
void ExitFuncImpl(dispatch_tag< typename BaseInstr::ExitTaskType >, DynExp::InstrumentInstance &Instance) override final
Deinitializes the respective instrument within the instrument inheritance hierarchy....
Defines a task for initializing an instrument within an instrument inheritance hierarchy....
virtual void InitFuncImpl(dispatch_tag< InitTask< BaseInstr, 0, gRPCStubs... > >, DynExp::InstrumentInstance &Instance)
Initializes the respective instrument within the instrument inheritance hierarchy....
void InitFuncImpl(dispatch_tag< typename BaseInstr::InitTaskType >, DynExp::InstrumentInstance &Instance) override final
Initializes the respective instrument within the instrument inheritance hierarchy....
Defines a task for updating an instrument within an instrument inheritance hierarchy....
void UpdateFuncImpl(dispatch_tag< typename BaseInstr::UpdateTaskType >, DynExp::InstrumentInstance &Instance) override final
Updates the respective instrument within the instrument inheritance hierarchy. Call UpdateFuncImpl() ...
Meta instrument template for transforming meta instruments into network instruments,...
void ResetImpl(DynExp::Object::dispatch_tag< BaseInstr >) override final
Refer to DynExp::Object::Reset(). Using tag dispatch mechanism to ensure that ResetImpl() of every de...
virtual void ResetImpl(DynExp::Object::dispatch_tag< gRPCInstrument >)
Refer to DynExp::Object::Reset(). Using tag dispatch mechanism to ensure that ResetImpl() of every de...
virtual std::string GetCategory() const override
Returns the category of this Object type.
virtual ~gRPCInstrument()
virtual std::unique_ptr< DynExp::InitTaskBase > MakeInitTask() const override
Factory function for an init task (InitTaskBase). Override to define the desired initialization task ...
static constexpr auto Category() noexcept
Every derived class has to redefine this function.
virtual std::unique_ptr< DynExp::UpdateTaskBase > MakeUpdateTask() const override
Factory function for an update task (UpdateTaskBase). Override to define the desired update task in d...
virtual std::string GetName() const override
Returns the name of this Object type.
static constexpr auto Name() noexcept
Every derived class has to redefine this function.
gRPCInstrument(const std::thread::id OwnerThreadID, DynExp::ParamsBasePtrType &&Params)
Constructs an instrument instance.
virtual std::unique_ptr< DynExp::ExitTaskBase > MakeExitTask() const override
Factory function for an exit task (ExitTaskBase). Override to define the desired deinitialization tas...
DynExp's core class acts as the interface between the user interface and DynExp's internal data like ...
Refer to DynExp::ParamsBase::dispatch_tag.
Refer to DynExp::ParamsBase::dispatch_tag.
Refer to ParamsBase::dispatch_tag.
Defines data for a thread belonging to a InstrumentBase instance. Refer to RunnableInstance.
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...
Refer to DynExp::ParamsBase::dispatch_tag.
An invalid argument like a null pointer has been passed to a function.
Data to operate on is invalid for a specific purpose. This indicates a corrupted data structure or fu...
An operation cannot be performed currently since the related object is in an invalid state like an er...
DynExp's instrument namespace contains the implementation of DynExp instruments which extend DynExp's...
constexpr DynExpProto::Common::IntensityUnitType ToProtoIntensityUnitType(DynExp::Units::UnitType Unit)
Converts a physical unit of type DynExp::Units::UnitType to a unit defined in the IntensityUnitType e...
constexpr DynExpProto::Common::FrequencyUnitType ToProtoFrequencyUnitType(DynExp::Units::UnitType Unit)
Converts a physical unit of type DynExp::Units::UnitType to a unit defined in the FrequencyUnitType e...
ResponseMsgType InvokeStubFunc(StubPtrType< gRPCStub > StubPtr, StubFuncPtrType< gRPCStub, RequestMsgType, ResponseMsgType > StubFunc, const RequestMsgType &RequestMsg)
Invokes a gRPC stub function as a remote procedure call. Waits for a fixed amount of time (2 seconds)...
std::shared_ptr< typename gRPCStub::Stub > StubPtrType
Alias for a pointer to a gRPC stub.
grpc::Status(gRPCStub::*)(grpc::ClientContext *, const RequestMsgType &, ResponseMsgType *) StubFuncPtrType
Alias for a pointer to a gRPC stub function, which can be invoked as a remote procedure call.
UnitType
Units which can be used with DynExp instruments.
@ Ampere
Electric current in Ampere (A)
@ Inv_cm
Wavenumber in 1/cm.
@ Arbitrary
Arbitrary units (a.u.)
@ LogicLevel
Logic level (TTL) units (1 or 0)
@ Freq_Hz
Frequency in Hz.
@ Wavelength_nm
Wavelength in nm.
@ Power_W
Power in Watt (W)
@ Volt
Voltage in Volt (V)
@ Counts
Count rate in counts per second (cps)
auto dynamic_InstrumentData_cast(Util::SynchronizedPointer< From > &&InstrumentDataPtr)
Casts the data base class From into a derived InstrumentBase's (To) data class keeping the data locke...
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.
std::unique_ptr< TaskT > MakeTask(ArgTs &&...Args)
Factory function to create a task to be enqueued in an instrument's task queue.
T::ParamsType * dynamic_Params_cast(ParamsBasePtrType::element_type *Params)
Casts the parameter base class to a derived Object's parameter class.
Accumulates include statements to provide a precompiled header.