Motorcortex Core  version: 2.7.6
ps_info.h
1 /*
2  * Developer : Alexey Zakharov (alexey.zakharov@vectioneer.com)
3  * All rights reserved. Copyright (c) 2018 VECTIONEER.
4  */
5 
6 #ifndef MOTORCORTEX_CORE_PS_INFO_H
7 #define MOTORCORTEX_CORE_PS_INFO_H
8 
9 #include "ps_types.h"
10 #include <atomic>
11 #include <cstring>
12 #include <string>
13 
14 namespace mcx {
15 
16 namespace parameter_server {
17 
18 struct DataTypeInfo {
19  unsigned int data_type;
20  unsigned int data_size;
21 };
22 
24 public:
25  ParameterInfo();
26 
27  ~ParameterInfo();
28 
29  inline void getInfo(motorcortex_ParameterInfo* info) const;
30 
31  inline const DataTypeInfo& getDataTypeInfo() const;
32 
33  void setName(const char* name);
34 
35  inline const char* getName() const;
36 
37  void setPath(const char* path);
38 
39  inline const char* getPath() const;
40 
41  inline size_t getPathLength() const;
42 
43  void setId(unsigned int id);
44 
45  inline unsigned int getId() const;
46 
47  void setUserGroup(motorcortex_UserGroup user_group);
48 
49  inline motorcortex_UserGroup getUserGroup() const;
50 
51  void setUnit(motorcortex_Unit unit);
52 
53  inline motorcortex_Unit getUnit() const;
54 
55  void setDataType(unsigned int data_type);
56 
57  inline unsigned int getDataType() const;
58 
59  void setDataSize(unsigned int data_size);
60 
61  inline unsigned int getDataSize() const;
62 
63  void setFlags(unsigned int flags);
64 
65  inline unsigned int getFlags() const;
66 
67  void setPermissions(unsigned int permissions);
68 
69  inline unsigned int getPermissions() const;
70 
71  void setType(motorcortex_ParameterType& type);
72 
73  inline motorcortex_ParameterType getType() const;
74 
75  void setNumberOfElements(unsigned int number_of_elements);
76 
77  inline unsigned int getNumberOfElements() const;
78 
79  void toggleOverwrite(bool overwrite);
80 
81  inline bool hasOverwrite() const;
82 
83  void toggleLink(bool link);
84 
85  inline bool hasLink() const;
86 
87  unsigned int getHash() const;
88 
89 private:
90  unsigned int id_{};
91  DataTypeInfo data_type_info_{};
92  unsigned int number_of_elements_{};
93  std::atomic<unsigned int> flags_{};
94  unsigned int permissions_{};
95  motorcortex_ParameterType param_type_{};
96  motorcortex_UserGroup group_id_{};
97  motorcortex_Unit unit_{};
98  std::string name_;
99  std::string path_;
100 };
101 
102 inline void ParameterInfo::getInfo(motorcortex_ParameterInfo* info) const {
103  info->id = getId();
104  info->data_type = getDataType();
105  info->data_size = getDataSize();
106  info->number_of_elements = getNumberOfElements();
107  info->flags = getFlags();
108  info->permissions = getPermissions();
109  info->param_type = getType();
110  info->group_id = getUserGroup();
111  info->unit = getUnit();
112  size_t path_len = getPathLength() < (sizeof(info->path) - 1) ? getPathLength() : sizeof(info->path) - 1;
113  std::strncpy(info->path, getPath(), path_len);
114  if (path_len > 0) {
115  info->path[path_len] = 0;
116  } else {
117  info->path[0] = 0;
118  }
119 }
120 
121 inline const DataTypeInfo& ParameterInfo::getDataTypeInfo() const { return data_type_info_; }
122 
123 inline const char* ParameterInfo::getName() const { return name_.c_str(); }
124 
125 inline const char* ParameterInfo::getPath() const { return path_.c_str(); }
126 
127 inline size_t ParameterInfo::getPathLength() const { return path_.length(); }
128 
129 inline unsigned int ParameterInfo::getId() const { return id_; }
130 
131 inline motorcortex_UserGroup ParameterInfo::getUserGroup() const { return group_id_; }
132 
133 inline motorcortex_Unit ParameterInfo::getUnit() const { return unit_; }
134 
135 inline unsigned int ParameterInfo::getDataType() const { return data_type_info_.data_type; }
136 
137 inline unsigned int ParameterInfo::getDataSize() const { return data_type_info_.data_size; }
138 
139 inline unsigned int ParameterInfo::getFlags() const { return flags_.load(std::memory_order_relaxed); }
140 
141 inline unsigned int ParameterInfo::getPermissions() const { return permissions_; }
142 
143 inline void ParameterInfo::setType(motorcortex_ParameterType& type) { param_type_ = type; }
144 
145 inline motorcortex_ParameterType ParameterInfo::getType() const { return param_type_; }
146 
147 inline unsigned int ParameterInfo::getNumberOfElements() const { return number_of_elements_; }
148 
149 inline bool ParameterInfo::hasOverwrite() const {
150  return static_cast<bool>(flags_.load(std::memory_order_relaxed) & OVERWRITE_IS_ACTIVE);
151 }
152 
153 inline bool ParameterInfo::hasLink() const {
154  return static_cast<bool>(flags_.load(std::memory_order_relaxed) & motorcortex_ParameterFlag_LINK_IS_ACTIVE);
155 }
156 
157 } // namespace parameter_server
158 
159 } // namespace mcx
160 
161 #endif // MOTORCORTEX_CORE_PS_INFO_H
_motorcortex_ParameterInfo
Definition: motorcortex.pb.h:143
mcx::parameter_server::DataTypeInfo
Definition: ps_info.h:18
mcx::parameter_server::ParameterInfo
Definition: ps_info.h:23