ChimeraTK-DeviceAccess-DoocsBackend  01.09.02
DoocsBackend.h
Go to the documentation of this file.
1 /*
2  * DoocsBackend.h
3  *
4  * Created on: Apr 26, 2016
5  * Author: Martin Hierholzer
6  */
7 
8 #pragma once
9 
10 #include "RegisterInfo.h"
11 
12 #include <ChimeraTK/DeviceBackendImpl.h>
13 #include <ChimeraTK/VersionNumber.h>
14 
15 #include <future>
16 #include <mutex>
17 
18 namespace ChimeraTK {
19 
20  class DoocsBackendRegisterAccessorBase;
21 
56  class DoocsBackend : public DeviceBackendImpl {
57  public:
58  ~DoocsBackend() override;
59 
61  const std::string& serverAddress, const std::string& cacheFile = {}, const std::string& updateCache = {});
62 
63  RegisterCatalogue getRegisterCatalogue() const override;
64 
66 
67  void open() override;
68 
69  void close() override;
70 
71  std::string readDeviceInfo() override { return std::string("DOOCS server address: ") + _serverAddress; }
72 
73  void setExceptionImpl() noexcept override;
74 
75  static boost::shared_ptr<DeviceBackend> createInstance(
76  std::string address, std::map<std::string, std::string> parameters);
77 
78  template<typename UserType>
79  boost::shared_ptr<NDRegisterAccessor<UserType>> getRegisterAccessor_impl(
80  const RegisterPath& registerPathName, size_t numberOfWords, size_t wordOffsetInRegister, AccessModeFlags flags);
82 
84  std::string _serverAddress;
85 
88  public:
90  };
92 
94  static bool checkZmqAvailability(const std::string& fullLocationPath, const std::string& propertyName);
95 
96  template<typename UserType>
98 
101  void informRuntimeError(const std::string& address);
102 
103  void activateAsyncRead() noexcept override;
104 
105  std::atomic<bool> _asyncReadActivated{false};
106 
107  VersionNumber getStartVersion() {
108  std::lock_guard<std::mutex> lk(_mxRecovery);
109  return _startVersion;
110  }
111 
112  static bool isCommunicationError(int doocs_error);
113 
114  private:
115  std::string _cacheFile;
116  std::promise<void> _cancelFlag{};
117  mutable std::future<DoocsBackendRegisterCatalogue> _catalogueFuture;
118  mutable DoocsBackendRegisterCatalogue catalogue;
119 
120  bool cacheFileExists();
121  bool isCachingEnabled() const;
122 
124  mutable std::mutex _mxRecovery;
125 
127  VersionNumber _startVersion{nullptr};
128 
130  std::string lastFailedAddress;
131  };
132 
133 } // namespace ChimeraTK
ChimeraTK::DoocsBackendRegisterAccessor
Definition: DoocsBackendRegisterAccessor.h:75
ChimeraTK::DoocsBackend::getRegisterAccessor_impl
boost::shared_ptr< NDRegisterAccessor< UserType > > getRegisterAccessor_impl(const RegisterPath &registerPathName, size_t numberOfWords, size_t wordOffsetInRegister, AccessModeFlags flags)
Definition: DoocsBackend.cc:246
ChimeraTK::DoocsBackend::_asyncReadActivated
std::atomic< bool > _asyncReadActivated
Definition: DoocsBackend.h:105
ChimeraTK::DoocsBackend::BackendRegisterer
Class to register the backend type with the factory.
Definition: DoocsBackend.h:87
ChimeraTK::DoocsBackend::checkZmqAvailability
static bool checkZmqAvailability(const std::string &fullLocationPath, const std::string &propertyName)
Utility function to check if a property is published by ZMQ.
ChimeraTK::DoocsBackend::close
void close() override
Definition: DoocsBackend.cc:206
ChimeraTK::DoocsBackend::informRuntimeError
void informRuntimeError(const std::string &address)
Called by accessors to inform about addess causing a runtime_error.
Definition: DoocsBackend.cc:219
ChimeraTK::DoocsBackend::createInstance
static boost::shared_ptr< DeviceBackend > createInstance(std::string address, std::map< std::string, std::string > parameters)
Definition: DoocsBackend.cc:140
ChimeraTK::DoocsBackend::setExceptionImpl
void setExceptionImpl() noexcept override
Definition: DoocsBackend.cc:228
ChimeraTK::DoocsBackend::getStartVersion
VersionNumber getStartVersion()
Definition: DoocsBackend.h:107
DoocsBackendRegisterCatalogue
Definition: RegisterInfo.h:12
ChimeraTK::DoocsBackend::readDeviceInfo
std::string readDeviceInfo() override
Definition: DoocsBackend.h:71
ChimeraTK::DoocsBackend::activateAsyncRead
void activateAsyncRead() noexcept override
Definition: DoocsBackend.cc:235
ChimeraTK::DoocsBackend::open
void open() override
Definition: DoocsBackend.cc:167
ChimeraTK::DoocsBackend::~DoocsBackend
~DoocsBackend() override
Definition: DoocsBackend.cc:110
ChimeraTK::DoocsBackend::backendRegisterer
static BackendRegisterer backendRegisterer
Definition: DoocsBackend.h:91
RegisterInfo.h
ChimeraTK::DoocsBackend::_serverAddress
std::string _serverAddress
DOOCS address component for the server (FACILITY/DEVICE)
Definition: DoocsBackend.h:84
ChimeraTK::DoocsBackend::DoocsBackend
DoocsBackend(const std::string &serverAddress, const std::string &cacheFile={}, const std::string &updateCache={})
Definition: DoocsBackend.cc:82
ChimeraTK::DoocsBackend::DEFINE_VIRTUAL_FUNCTION_TEMPLATE_VTABLE_FILLER
DEFINE_VIRTUAL_FUNCTION_TEMPLATE_VTABLE_FILLER(DoocsBackend, getRegisterAccessor_impl, 4)
ChimeraTK::DoocsBackend::isCommunicationError
static bool isCommunicationError(int doocs_error)
Definition: DoocsBackend.cc:400
ChimeraTK::DoocsBackend::getBackendRegisterCatalogue
const DoocsBackendRegisterCatalogue & getBackendRegisterCatalogue() const
Definition: DoocsBackend.cc:197
ChimeraTK::DoocsBackend::getRegisterCatalogue
RegisterCatalogue getRegisterCatalogue() const override
Definition: DoocsBackend.cc:191
ChimeraTK
Definition: spec_DoocsBackend.dox:2
ChimeraTK::DoocsBackend
Backend to access DOOCS control system servers.
Definition: DoocsBackend.h:56