summaryrefslogtreecommitdiffstats
path: root/K2LABI/ABI/ABIFilter.h
blob: ccdda8fcfe497048074f5f638018420c0dda7421 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
#pragma once

#include "windows-adapter.h"
#include "K2LABI.h"
#include <vector>

using namespace K2L::Automotive::ABI;

class IFilterEntry
{
public:
    virtual ~IFilterEntry(){}

    virtual unsigned short Handle() = 0;
    virtual bool Match(unsigned int id) = 0;
};

class IntervalIdFilterEntry : public IFilterEntry
{
private:
    IntervalIdFilterEntry(){}

    unsigned short m_handle;
    unsigned int m_min;
    unsigned int m_max;
public:
    IntervalIdFilterEntry(unsigned short handle, unsigned int min, unsigned int max);
    virtual ~IntervalIdFilterEntry(){}

    unsigned short Handle();
    bool Match(unsigned int id);
};

class MaskedIdFilterEntry : public IFilterEntry
{
private:
    MaskedIdFilterEntry(){}

    unsigned short m_handle;
    unsigned int m_id;
    unsigned int m_mask;
public:
    MaskedIdFilterEntry(unsigned short handle, unsigned int id, unsigned int mask);
    virtual ~MaskedIdFilterEntry(){}

    unsigned short Handle();
    bool Match(unsigned int id);
};

class CIdFilter
{
private:
    std::vector<IFilterEntry*> m_filters;
    CRITICAL_SECTION m_criticalSection;

public:
    CIdFilter();
    virtual ~CIdFilter();

    void AddIntervalFilter(unsigned short handle, unsigned int min, unsigned int max);
    void AddMaskedFilter(unsigned short handle, unsigned int id, unsigned int mask);
    void RemoveFilter(unsigned short handle);
    
    bool Match(unsigned int id);
};

class CABIFilter
{
private:
    CIdFilter* m_filters[256];

public:
    CABIFilter();
    virtual ~CABIFilter();

    void AddIntervalFilter(Bus bus, unsigned short handle, unsigned int min, unsigned int max);
    void AddMaskedFilter(Bus bus, unsigned short handle, unsigned int id, unsigned int mask);
    void RemoveFilter(unsigned short handle);

    bool Match(Bus bus, unsigned int id);
};