Coverage Report

Created: 2026-02-26 06:37

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/opendnp3/cpp/lib/src/LayerInterfaces.h
Line
Count
Source
1
/*
2
 * Copyright 2013-2022 Step Function I/O, LLC
3
 *
4
 * Licensed to Green Energy Corp (www.greenenergycorp.com) and Step Function I/O
5
 * LLC (https://stepfunc.io) under one or more contributor license agreements.
6
 * See the NOTICE file distributed with this work for additional information
7
 * regarding copyright ownership. Green Energy Corp and Step Function I/O LLC license
8
 * this file to you under the Apache License, Version 2.0 (the "License"); you
9
 * may not use this file except in compliance with the License. You may obtain
10
 * a copy of the License at:
11
 *
12
 * http://www.apache.org/licenses/LICENSE-2.0
13
 *
14
 * Unless required by applicable law or agreed to in writing, software
15
 * distributed under the License is distributed on an "AS IS" BASIS,
16
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17
 * See the License for the specific language governing permissions and
18
 * limitations under the License.
19
 */
20
#ifndef OPENDNP3_LAYERINTERFACES_H
21
#define OPENDNP3_LAYERINTERFACES_H
22
23
#include "app/Message.h"
24
25
#include <cassert>
26
27
namespace opendnp3
28
{
29
30
/**
31
 * Describes a layer that can be opened or closed in response to the
32
 * availability of the layer below it.
33
 */
34
class IUpDown
35
{
36
37
public:
38
9.22k
    virtual ~IUpDown() {}
39
40
    // Called by a lower Layer when it is available to this layer
41
    // return false if the layer is already up
42
    virtual bool OnLowerLayerUp() = 0;
43
44
    // Called by a lower layer when it is no longer available to this layer
45
    // return false if the layer is already down
46
    virtual bool OnLowerLayerDown() = 0;
47
};
48
49
class IUpperLayer : public IUpDown
50
{
51
52
public:
53
0
    virtual ~IUpperLayer() {}
54
55
    // Called by the lower layer when data arrives
56
    // return false if the layer is down
57
    virtual bool OnReceive(const Message& message) = 0;
58
59
    // Called by the lower layer when it is ready to transmit more data
60
    virtual bool OnTxReady() = 0;
61
};
62
63
class ILowerLayer
64
{
65
66
public:
67
9.22k
    virtual ~ILowerLayer() {}
68
69
    virtual bool BeginTransmit(const Message& message) = 0;
70
};
71
72
class HasLowerLayer
73
{
74
75
public:
76
0
    HasLowerLayer() : pLowerLayer(nullptr) {}
77
78
    // Called by the lower layer when data arrives
79
80
    void SetLowerLayer(ILowerLayer& lowerLayer)
81
0
    {
82
0
        assert(!pLowerLayer);
83
0
        pLowerLayer = &lowerLayer;
84
0
    }
85
86
protected:
87
    ILowerLayer* pLowerLayer;
88
};
89
90
class HasUpperLayer
91
{
92
93
public:
94
9.22k
    HasUpperLayer() : pUpperLayer(nullptr) {}
95
96
    // Called by the lower layer when data arrives
97
98
    void SetUpperLayer(IUpperLayer& upperLayer)
99
9.22k
    {
100
9.22k
        assert(!pUpperLayer);
101
9.22k
        pUpperLayer = &upperLayer;
102
9.22k
    }
103
104
protected:
105
    IUpperLayer* pUpperLayer;
106
};
107
108
} // namespace opendnp3
109
110
#endif