ChimeraTK-DeviceAccess-DoocsBackend 01.11.02
Loading...
Searching...
No Matches
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/async/DataConsistencyRealm.h>
13#include <ChimeraTK/DeviceBackendImpl.h>
14#include <ChimeraTK/VersionNumber.h>
15
16#include <future>
17#include <mutex>
18
19namespace ChimeraTK {
20
21 class DoocsBackendRegisterAccessorBase;
22
57 class DoocsBackend : public DeviceBackendImpl {
58 public:
59 ~DoocsBackend() override;
60
61 DoocsBackend(const std::string& serverAddress, const std::string& cacheFile, const std::string& updateCache,
62 const std::string& dataConsistencyRealmName);
63
64 RegisterCatalogue getRegisterCatalogue() const override;
65
67
68 void open() override;
69
70 void close() override;
71
72 std::string readDeviceInfo() override { return std::string("DOOCS server address: ") + _serverAddress; }
73
74 void setExceptionImpl() noexcept override;
75
76 static boost::shared_ptr<DeviceBackend> createInstance(
77 std::string address, std::map<std::string, std::string> parameters);
78
79 template<typename UserType>
80 boost::shared_ptr<NDRegisterAccessor<UserType>> getRegisterAccessor_impl(
81 const RegisterPath& registerPathName, size_t numberOfWords, size_t wordOffsetInRegister, AccessModeFlags flags);
83
85 std::string _serverAddress;
86
89 public:
91 };
93
95 static bool checkZmqAvailability(const std::string& fullLocationPath, const std::string& propertyName);
96
97 template<typename UserType>
99
102 void informRuntimeError(const std::string& address);
103
104 void activateAsyncRead() noexcept override;
105
106 std::atomic<bool> _asyncReadActivated{false};
107
108 VersionNumber getStartVersion() {
109 std::lock_guard<std::mutex> lk(_mxRecovery);
110 return _startVersion;
111 }
112
113 static bool isCommunicationError(int doocs_error);
114
115 private:
116 std::string _cacheFile;
117 std::promise<void> _cancelFlag{};
118 mutable std::future<DoocsBackendRegisterCatalogue> _catalogueFuture;
119 mutable DoocsBackendRegisterCatalogue catalogue;
120 bool _catalogueFromCache{false}; // controls whether open() might re-trigger catalogue filling
121
122 bool cacheFileExists();
123 bool isCachingEnabled() const;
124
126 mutable std::mutex _mxRecovery;
127
129 VersionNumber _startVersion{nullptr};
130
132 std::string lastFailedAddress;
133
134 std::shared_ptr<async::DataConsistencyRealm> _dataConsistencyRealm;
135 };
136
137} // namespace ChimeraTK
Class to register the backend type with the factory.
Backend to access DOOCS control system servers.
static bool isCommunicationError(int doocs_error)
std::atomic< bool > _asyncReadActivated
VersionNumber getStartVersion()
std::string _serverAddress
DOOCS address component for the server (FACILITY/DEVICE)
void activateAsyncRead() noexcept override
std::string readDeviceInfo() override
static boost::shared_ptr< DeviceBackend > createInstance(std::string address, std::map< std::string, std::string > parameters)
const DoocsBackendRegisterCatalogue & getBackendRegisterCatalogue() const
void informRuntimeError(const std::string &address)
Called by accessors to inform about addess causing a runtime_error.
static BackendRegisterer backendRegisterer
RegisterCatalogue getRegisterCatalogue() const override
boost::shared_ptr< NDRegisterAccessor< UserType > > getRegisterAccessor_impl(const RegisterPath &registerPathName, size_t numberOfWords, size_t wordOffsetInRegister, AccessModeFlags flags)
static bool checkZmqAvailability(const std::string &fullLocationPath, const std::string &propertyName)
Utility function to check if a property is published by ZMQ.
void setExceptionImpl() noexcept override
DEFINE_VIRTUAL_FUNCTION_TEMPLATE_VTABLE_FILLER(DoocsBackend, getRegisterAccessor_impl, 4)