OpcUaCanOpen
CANopen OPC-UA server
UserDeviceStruct.h
Go to the documentation of this file.
1 #ifndef __USERDATASTRUCT_H__
2 #define __USERDATASTRUCT_H__
3 
4 #include "userdatabase.h"
5 #include "uabasenodes.h"
6 #include "uadatavalue.h"
7 #include <xsd/cxx/tree/types.hxx>
8 #include "boost/shared_ptr.hpp"
9 #include <iostream>
10 #include <memory>
11 
12 namespace UserDevice
13 {
14 
15  class UserDeviceStruct;
16 
22  class pUserDeviceStruct : public UserDataBase
23  {
24  public:
25  std::shared_ptr<UserDeviceStruct> pPoint;
26 
28  {
29 // pPoint = std::make_shared<UserDeviceStruct>(p);
30  pPoint = std::shared_ptr<UserDeviceStruct>(p);
31  }
32 
34  {
35  pPoint = a.pPoint;
36  }
38  {
39  pPoint = a.pPoint;
40  }
41  pUserDeviceStruct() = default;
42  UserDeviceStruct * getDevice() { return pPoint.get(); }
43 
44  };
45 
47  {
49 
50  public:
58  UserDeviceStruct(pUserDeviceStruct *parent , ::xsd::cxx::tree::type *conf, UaNode *pAS, OpcUa_UInt code)
59  {
60  if (parent)
61  m_pParent = new pUserDeviceStruct(*parent);
62  else m_pParent = 0;
63 
64  OpcUa_ReferenceParameter(conf);
66  m_iCodeFunction = code;
67  if (parent) {
68  m_pSharedMutex = parent->pPoint->getShareMutex();
69  m_pSharedMutex->addReference();
70  }
71  else {
72  m_pSharedMutex = new UaMutexRefCounted();
73  }
74 
75  }
77  void lock() {
78  m_pSharedMutex->lock();
79  }
80 
82  void unlock() {
83  m_pSharedMutex->unlock();
84  }
85 
87  ::UaMutexRefCounted* getShareMutex() { return m_pSharedMutex; }
88 
89  void releaseMutex()
90  {
91  m_pSharedMutex->releaseReference();
92  if (m_pSharedMutex->referenceCount() == 0)
93  {
94  m_pSharedMutex = NULL;
95  }
96  }
97  OpcUa_Int32 countMutex()
98  {
99  return m_pSharedMutex->referenceCount();
100  }
101 
102 
103 
104  virtual ~UserDeviceStruct(void)
105  {
106  if (m_pSharedMutex)
107  {
108  // Release our local reference
109  m_pSharedMutex->releaseReference();
110  m_pSharedMutex = NULL;
111  }
112 // delete m_pParent;
113 
114  };
115 
116  OpcUa_UInt getCodeFunction() { return m_iCodeFunction; }
117 
118 
120  return m_pParent->pPoint.get();
121  }
122 
123 
125  {
127  while (top->pPoint->getParent())
128  {
129 
130  top = top->pPoint->getParent();
131  }
132  return top;
133  }
134 
136  return m_pParent;
137  }
138 
139  virtual void setInvalid()
140  {
141  std::cout << "Delete Variable " << p_mAddressSpaceEntry->displayName(0).toString().toUtf8() << std::endl;
142  }
143 
144 
146 
147  private:
148  UaNode *p_mAddressSpaceEntry; // UaNode to pass the date to client or device
149  OpcUa_UInt m_iCodeFunction; // code of function
150  pUserDeviceStruct *m_pParent; // parent device
151  protected:
152 
153  UaMutexRefCounted* m_pSharedMutex;
154 
155  };
156 
157 }
158 #endif