REDAC HybridController
Firmware for LUCIDAC/REDAC Teensy
Loading...
Searching...
No Matches
entity_manager.h
Go to the documentation of this file.
1#pragma once
2
3#include <cassert>
4#include <unordered_map>
5
6#include <block/cblock.h>
7#include <block/ctrlblock.h>
8#include <block/iblock.h>
9#include <block/mblock.h>
10#include <block/shblock.h>
11#include <block/ublock.h>
12#include <entity/base.h>
13#include <entity/entity.h>
14
15namespace entities {
16
18public:
19 EntityClassifier read_classifier(bus::addr_t address) {
20 auto iter = entities.find(address);
21 if (iter == entities.end()) {
22 return EntityClassifier{EntityClass::UNKNOWN, 0, 0, 0, 0, 0};
23 }
24 auto entity = iter->second;
25 return entity->get_entity_classifier();
26 }
27
28 void addEntity(bus::addr_t address, EntityClassifier classifier) {
29
30 blocks::FunctionBlock *new_entity_block;
31 switch (classifier.class_enum) {
32 case EntityClass::SH_BLOCK:
33 new_entity_block = blocks::SHBlock::from_entity_classifier(classifier, address);
34 break;
35 case EntityClass::CTRL_BLOCK:
36 new_entity_block = blocks::CTRLBlock::from_entity_classifier(classifier, address);
37 break;
38 case EntityClass::M_BLOCK:
39 new_entity_block = blocks::MBlock::from_entity_classifier(classifier, address);
40 break;
41 case EntityClass::U_BLOCK:
42 new_entity_block = blocks::UBlock::from_entity_classifier(classifier, address);
43 break;
44 case EntityClass::C_BLOCK:
45 new_entity_block = blocks::CBlock::from_entity_classifier(classifier, address);
46 break;
47 case EntityClass::I_BLOCK:
48 new_entity_block = blocks::IBlock::from_entity_classifier(classifier, address);
49 break;
50 default:
51 throw std::runtime_error("runtime error");
52 }
53
54 assert(new_entity_block != nullptr);
55 entities[address] = new_entity_block;
56 }
57
58private:
59 std::unordered_map<bus::addr_t, Entity *> entities;
60};
61
62extern EntityManager_ EntityManager;
63
64} // namespace entities
EntityClassifier read_classifier(bus::addr_t address)
void addEntity(bus::addr_t address, EntityClassifier classifier)
EntityManager_ EntityManager