54 lines
1.9 KiB
C++
54 lines
1.9 KiB
C++
#include "source/solar/cbf_cache.h"
|
|
|
|
namespace solar
|
|
{
|
|
static const int comparecolumns[] = {cbf_store::sisortframe, cbf_store::sisortrtr, 0};
|
|
|
|
void cbf_cache::clear()
|
|
{
|
|
cache_map.clear();
|
|
}
|
|
int cbf_cache::size() const
|
|
{
|
|
return cache_map.size();
|
|
}
|
|
bool cbf_cache::hasitem(uint32_t can_id) const
|
|
{
|
|
return cache_map.find(can_id) != cache_map.end();
|
|
}
|
|
cbf_cache_item& cbf_cache::getitem(uint32_t can_id)
|
|
{
|
|
return cache_map.at(can_id);
|
|
}
|
|
const cbf_cache_item& cbf_cache::getitem(uint32_t can_id) const
|
|
{
|
|
return cache_map.at(can_id);
|
|
}
|
|
bool cbf_cache::additem(const cbf_store& storeitem)
|
|
{
|
|
const auto& ret = cache_map.emplace(storeitem.can_id, cbf_cache_item(storeitem));
|
|
if(ret.second) {
|
|
return false; // new item inserted, no publish
|
|
}
|
|
auto& kvp = *ret.first;
|
|
auto& item = kvp.second;
|
|
bool publish = false;
|
|
if(item.update(storeitem, publish, comparecolumns, 1)) {
|
|
// ESP_LOGI(item.store0.tag("== ST1 DUP == ").c_str(), item.store0.to_string().c_str());
|
|
return publish;
|
|
}
|
|
// try next store to see if it has a duplicate of new item
|
|
if(item.update(storeitem, publish, comparecolumns, 2)) {
|
|
// ESP_LOGI(item.store1.tag("== ST2 DUP == ").c_str(), item.store1.to_string().c_str());
|
|
return publish;
|
|
}
|
|
item.update(storeitem);
|
|
//cache_map.erase(kvp.first);
|
|
//ret = cache_map.emplace(storeitem.can_id, item);
|
|
//if(!ret.second) {
|
|
// ESP_LOGE(item.store0.tag("== ST1 ERR == ").c_str(), "Error re-inserting item into cache_map");
|
|
// ESP_LOGE(item.store1.tag("== ST2 ERR == ").c_str(), "Error re-inserting item into cache_map");
|
|
//}
|
|
return publish;
|
|
}
|
|
} // namespace solar
|