blob: f22c0a2752ba3d4200da0641bc6bb40f170e1f39 [file] [log] [blame]
brians343bc112013-02-10 01:53:46 +00001#ifndef AOS_CRIO_MOTOR_SERVER_CONTROL_LOOP_GOAL_H_
2#define AOS_CRIO_MOTOR_SERVER_CONTROL_LOOP_GOAL_H_
3
4#include <vector>
5#include <semLib.h>
6
7namespace aos {
8
9// This class is used to keep track of all the control loop goals. It exists
10// because of several bugs discovered in the std::map implementation.
11class ControlLoopGoals {
12 public:
13 struct Goal {
14 const char *const name;
15 const size_t length;
16 void (*const zero)();
17 void (*const ntoh)(const char *);
18 Goal(const char *name, size_t length, void (*zero)(), void (*ntoh)(const char *)) :
19 name(name), length(length), zero(zero), ntoh(ntoh) {}
20 };
21
22 private:
23 std::vector<Goal *> goals_;
24
25 public:
26 ControlLoopGoals() {}
27 void Add(const char *name, size_t length, void (*zero)(), void (*ntoh)(const char *)) {
28 char *storage = new char[10];
29 memcpy(storage, name, sizeof(storage));
30 goals_.push_back(new Goal(storage, length, zero, ntoh));
31 }
32 const Goal *Get(const char *name) {
33 for (auto it = goals_.begin(); it != goals_.end(); ++it) {
34 if (memcmp((*it)->name, name, sizeof((*it)->name)) == 0) {
35 return *it;
36 }
37 }
38 return NULL;
39 }
40};
41
42} // namespace aos
43
44#endif