ChimeraTK-DeviceAccess-DoocsBackend  01.09.02
DoocsBackendStringRegisterAccessor.h
Go to the documentation of this file.
1 /*
2  * DoocsBackendStringRegisterAccessor.h
3  *
4  * Created on: May 3, 2016
5  * Author: Martin Hierholzer
6  */
7 
8 #ifndef MTCA4U_DOOCS_BACKEND_STRING_REGISTER_ACCESSOR_H
9 #define MTCA4U_DOOCS_BACKEND_STRING_REGISTER_ACCESSOR_H
10 
12 #include <doocs/EqCall.h>
13 #include <type_traits>
14 
15 namespace ChimeraTK {
16 
17  template<typename UserType>
19  public:
21 
22  protected:
23  DoocsBackendStringRegisterAccessor(boost::shared_ptr<DoocsBackend> backend, const std::string& path,
24  const std::string& registerPathName, size_t numberOfWords, size_t wordOffsetInRegister, AccessModeFlags flags);
25 
26  void doPostRead(TransferType type, bool hasNewData) override;
27 
28  void doPreWrite(TransferType type, VersionNumber version) override;
29 
30  friend class DoocsBackend;
31  };
32 
33  /**********************************************************************************************************************/
34 
35  template<typename UserType>
37  boost::shared_ptr<DoocsBackend> backend, const std::string& path, const std::string& registerPathName,
38  size_t numberOfWords, size_t wordOffsetInRegister, AccessModeFlags flags)
39  : DoocsBackendRegisterAccessor<UserType>(
40  backend, path, registerPathName, numberOfWords, wordOffsetInRegister, flags) {
41  // check UserType
42  if(typeid(UserType) != typeid(std::string)) {
43  this->shutdown();
44  throw ChimeraTK::logic_error("Trying to access a string DOOCS property with a non-string user data type.");
45  }
46  // check data type
47  if(DoocsBackendRegisterAccessor<UserType>::src.type() != DATA_TEXT &&
48  DoocsBackendRegisterAccessor<UserType>::src.type() != DATA_STRING) {
49  this->shutdown();
50  throw ChimeraTK::logic_error(std::string("DOOCS data type ") +
51  std::to_string(DoocsBackendRegisterAccessor<UserType>::dst.type()) +
52  " not supported by DoocsBackendStringRegisterAccessor."); // LCOV_EXCL_LINE (already prevented in the Backend)
53  }
54  }
55 
56  /**********************************************************************************************************************/
57 
58  template<typename UserType>
60  this->shutdown();
61  }
62 
63  /**********************************************************************************************************************/
64 
65  template<>
66  void DoocsBackendStringRegisterAccessor<std::string>::doPostRead(TransferType type, bool hasNewData) {
68  if(!hasNewData) return;
69 
70  // copy data into our buffer
71  NDRegisterAccessor<std::string>::buffer_2D[0][0] = DoocsBackendRegisterAccessor<std::string>::dst.get_string();
72  }
73 
74  /**********************************************************************************************************************/
75 
76  template<>
77  void DoocsBackendStringRegisterAccessor<std::string>::doPreWrite(TransferType type, VersionNumber version) {
79 
80  // copy data into our buffer
81  DoocsBackendRegisterAccessor<std::string>::src.set(NDRegisterAccessor<std::string>::buffer_2D[0][0].c_str());
82  }
83 
84  /**********************************************************************************************************************/
85 
86  template<typename UserType>
88  TransferType, bool) { // LCOV_EXCL_LINE (already prevented in constructor)
89  throw ChimeraTK::logic_error("Trying to access a string DOOCS property with a non-string user data "
90  "type."); // LCOV_EXCL_LINE
91  } // LCOV_EXCL_LINE
92 
93  /**********************************************************************************************************************/
94 
95  template<typename UserType>
97  TransferType, VersionNumber) { // LCOV_EXCL_LINE (already prevented in constructor)
98  throw ChimeraTK::logic_error("Trying to access a string DOOCS property with a non-string user data "
99  "type."); // LCOV_EXCL_LINE
100  } // LCOV_EXCL_LINE
101 
102 } // namespace ChimeraTK
103 
104 #endif /* MTCA4U_DOOCS_BACKEND_STRING_REGISTER_ACCESSOR_H */
ChimeraTK::DoocsBackendRegisterAccessor
Definition: DoocsBackendRegisterAccessor.h:75
ChimeraTK::DoocsBackendStringRegisterAccessor::~DoocsBackendStringRegisterAccessor
virtual ~DoocsBackendStringRegisterAccessor()
Definition: DoocsBackendStringRegisterAccessor.h:59
ChimeraTK::DoocsBackendStringRegisterAccessor::doPreWrite
void doPreWrite(TransferType type, VersionNumber version) override
Definition: DoocsBackendStringRegisterAccessor.h:96
ChimeraTK::DoocsBackendStringRegisterAccessor::doPostRead
void doPostRead(TransferType type, bool hasNewData) override
Definition: DoocsBackendStringRegisterAccessor.h:87
ChimeraTK::DoocsBackendRegisterAccessor::doPostRead
void doPostRead(TransferType, bool hasNewData) override
Definition: DoocsBackendRegisterAccessor.h:108
ChimeraTK::DoocsBackendRegisterAccessor::doPreWrite
void doPreWrite(TransferType, VersionNumber) override
Definition: DoocsBackendRegisterAccessor.h:103
ChimeraTK::DoocsBackendStringRegisterAccessor::DoocsBackendStringRegisterAccessor
DoocsBackendStringRegisterAccessor(boost::shared_ptr< DoocsBackend > backend, const std::string &path, const std::string &registerPathName, size_t numberOfWords, size_t wordOffsetInRegister, AccessModeFlags flags)
Definition: DoocsBackendStringRegisterAccessor.h:36
ChimeraTK::DoocsBackendRegisterAccessor::shutdown
void shutdown()
All implementations must call this function in their destructor.
Definition: DoocsBackendRegisterAccessor.h:84
ChimeraTK::DoocsBackendStringRegisterAccessor
Definition: DoocsBackendStringRegisterAccessor.h:18
ChimeraTK
Definition: spec_DoocsBackend.dox:2
ChimeraTK::DoocsBackend
Backend to access DOOCS control system servers.
Definition: DoocsBackend.h:56
DoocsBackendRegisterAccessor.h