CMSDK  2.0.1
ComponentData.h
1 #if !defined(_COMPONENTDATA_H_)
2 #define _COMPONENTDATA_H_
3 
4 #include "MemoryManager.h"
5 #include "DataMessage.h"
6 
7 namespace cmlabs {
8 
9 #define PARAM_STRING 1
10 #define PARAM_INTEGER 2
11 #define PARAM_FLOAT 3
12 #define PARAM_STRING_COLL 4
13 #define PARAM_INTEGER_COLL 5
14 #define PARAM_FLOAT_COLL 6
15 #define PARAM_TYPE_COLL 3
16 
18  uint32 size; // total size of map structure in bytes
19  uint32 count; // number of entries
20  uint32 bitFieldSize; // number of bytes in the bitfield
21  // Bitfield
22  // Entries
23 };
24 
26  uint32 id; // id corresponds to the index in map
27  uint16 nodeID; // id of node component is running on currently
28  uint16 procID; // id of process component is running in currently
29  uint32 pageID; // Memory Page ID
30  uint64 time; // timestamp when entered
31  char name[MAXKEYNAMELEN+1]; // name in text
32 };
33 
35  uint64 time;
36  uint64 msgInCount;
37  uint64 msgInBytes;
38  DataMessageHeader recentInMsg[10];
39  uint64 msgOutCount;
40  uint64 msgOutBytes;
41  DataMessageHeader recentOutMsg[10];
42  uint64 runCount;
43  uint64 runUserTime;
44  uint64 runKernelTime;
45 };
46 
48  // Admin
49  uint32 size;
50  uint32 cid;
51  uint16 nodeID; // id of node component is running on currently
52  uint16 procID; // id of process component is running in currently
53  uint32 pageID;
54  // Basic data
55  uint64 createdTime;
56  uint64 migratedTime;
57  uint64 lastUpdateTime;
58  char name[MAXKEYNAMELEN]; // name in text
59  // Statistics
60  ComponentStats stats;
61  // Parameters
62  uint16 paramCount;
63  uint32 paramSize;
64  // Private Data
65  uint16 dataCount;
66  uint32 dataSize;
67 };
68 
69 struct PARAMHEADER {
70  uint32 size;
71  uint8 type;
72 };
73 
74 // -- integer --
76  int64 val;
77  int64 defaultVal;
78  int64 minVal;
79  int64 maxVal;
80  int64 interval;
81 };
82 
83 // -- float --
85  float64 val;
86  float64 defaultVal;
87  float64 minVal;
88  float64 maxVal;
89  float64 interval;
90 };
91 
92 // -- string --
93 //struct PARAMSTRINGHEADER {
94 // char* val;
95 // char* defaultVal;
96 //};
97 
98 // -- integer collection --
100  uint32 index;
101  uint32 defaultIndex;
102  uint32 count;
103 };
104 
106 public:
107  ComponentData(char* data);
108  ~ComponentData();
109 
110  static bool UnitTest();
111 
112  static ComponentData* CreateComponent(uint32 id, const char* name, uint32 size, uint16 nodeID, uint16 procID);
113  static bool RecordRemoteComponent(uint32 id, const char* name, uint16 nodeID, uint64 time);
114  static bool ReserveComponentID(uint32 id, const char* name);
115  static bool DestroyComponent(uint32 cid);
116  static ComponentData* GetComponentData(uint32 cid);
117  static bool GetComponentName(uint32 cid, char* name, uint32 maxNameLen);
118  static bool GetComponentID(const char* name, uint32 &cid);
119  static ComponentStats GetComponentStats(uint32 cid);
120  static bool SetComponentStats(uint32 cid, ComponentStats& stats);
121  static bool IsComponentLocal(uint32 cid);
122  static bool IsComponentLocal(const char* name);
123  static uint16 GetComponentNodeID(uint32 cid);
124  static uint16 GetComponentProcessID(uint32 cid);
125  static char* GetAndRemoveComponent(uint32 cid, uint32& dataSize);
126  static bool AddExistingComponent(uint32 cid, uint16 nodeID, uint16 procID, char* oldData, uint32 dataSize);
127  static bool UpdateRemoteComponent(uint32 cid, uint16 nodeID, uint16 procID, const char* name);
128  static bool AddComponentStats(uint32 cid, uint64 userCPU, uint64 kernelCPU,
129  DataMessage* inputMsg, DataMessage* outputMsg, uint32 runCount);
130 
131 
132  bool disconnect();
133  bool destroyComponent();
134  bool resize(uint32 increase);
135  uint32 getAvailableDataSize();
136 
137  // Private Data
138  bool setPrivateData(const char* name, const char* data, uint32 size);
139  uint32 getPrivateDataSize(const char* name);
140  bool getPrivateDataCopy(const char* name, char* data, uint32 maxSize);
141  bool replacePrivateData(const char* name, const char* data, uint32 size);
142  bool replacePrivateData(const char* name, const char* data, uint32 size, uint32 offset);
143  bool deletePrivateData(const char* name);
144 
145  // Parameters
146  bool createParameter(const char* name, const char* val, const char* defaultValue = NULL);
147  bool createParameter(const char* name, const char* val, uint32 count, uint32 defaultIndex);
148  bool createParameter(const char* name, std::vector<std::string> values, const char* defaultValue = NULL);
149  bool createParameter(const char* name, int64* val, uint32 count, uint32 defaultIndex);
150  bool createParameter(const char* name, std::vector<std::string> values, int64 defaultValue = 0);
151  bool createParameter(const char* name, float64* val, uint32 count, uint32 defaultIndex);
152  bool createParameter(const char* name, std::vector<std::string> values, float64 defaultValue = 0);
153  bool createParameter(const char* name, int64 val, int64 min = 0, int64 max = 0, int64 interval = 0);
154  bool createParameter(const char* name, float64 val, float64 min = 0, float64 max = 0, float64 interval = 0);
155 
156  bool hasParameter(const char* name);
157  bool deleteParameter(const char* name);
158 
159  uint8 getParameterDataType(const char* name);
160  uint32 getParameterValueSize(const char* name);
161  bool getParameter(const char* name, char* val, uint32 maxSize);
162  bool getParameter(const char* name, int64& val);
163  bool getParameter(const char* name, float64& val);
164 
165  bool setParameter(const char* name, const char* val);
166  bool setParameter(const char* name, int64 val);
167  bool setParameter(const char* name, float64 val);
168 
169  bool resetParameter(const char* name);
170  bool tweakParameter(const char* name, int32 tweak);
171 
172 private:
173  static ComponentMapEntry* GetAndLockComponentEntry(uint32 id);
174  static bool UnlockComponentMap();
175 
176  static bool InsertComponentPageID(uint32 cid, uint32 pageID, uint16 nodeID, uint16 procID, const char* name);
177  static bool GetComponentPageID(uint32 cid, uint32& pageID);
178  static bool GetNextAvailableComponentID(uint32& cid);
179  static bool FreeComponentID(uint32 cid);
180 
181  char* makeRoomForPrivateData(uint32 newSize);
182  char* makeRoomForParameter(uint32 newSize);
183  struct COMPONENTDATAHEADER* header;
184 };
185 
186 } // namespace cmlabs
187 
188 #endif //_COMPONENTDATA_H_
189 
Definition: ComponentData.h:75
Definition: ComponentData.h:99
Definition: Bitmap.h:7
Definition: DataMessage.h:54
Definition: ComponentData.h:17
Definition: ComponentData.h:47
Definition: ComponentData.h:105
Definition: ComponentData.h:34
Definition: ComponentData.h:69
Definition: ComponentData.h:25
Definition: DataMessage.h:95
Definition: ComponentData.h:84