Falcon
Loading...
Searching...
No Matches
portpolicy.hpp
1// ---------------------------------------------------------------------
2// This file is part of falcon-core.
3//
4// Copyright (C) 2015, 2016, 2017 Neuro-Electronics Research Flanders
5//
6// Falcon-server is free software: you can redistribute it and/or modify
7// it under the terms of the GNU General Public License as published by
8// the Free Software Foundation, either version 3 of the License, or
9// (at your option) any later version.
10//
11// Falcon-server is distributed in the hope that it will be useful,
12// but WITHOUT ANY WARRANTY; without even the implied warranty of
13// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14// GNU General Public License for more details.
15//
16// You should have received a copy of the GNU General Public License
17// along with falcon-core. If not, see <http://www.gnu.org/licenses/>.
18// ---------------------------------------------------------------------
19
20#pragma once
21
22#include "ringbuffer.hpp"
23#include "utilities/math_numeric.hpp"
24
25typedef uint16_t SlotType;
26typedef Range<SlotType> SlotRange;
27
28class PortPolicy {
29 public:
30 PortPolicy(SlotRange slot_number_range = SlotRange(1))
31 : slot_number_range_(slot_number_range) {}
32
33 const SlotRange& slot_number_range() const { return slot_number_range_; }
34 SlotType min_slot_number() const { return slot_number_range_.lower(); }
35 SlotType max_slot_number() const { return slot_number_range_.upper(); }
36
37 bool isdynamic() const { return max_slot_number() > min_slot_number(); }
38
39 protected:
40 SlotRange slot_number_range_;
41};
42
43class PortInPolicy : public PortPolicy {
44 public:
45 PortInPolicy(SlotRange slot_number_range = SlotRange(1), bool cache = false)
46 : PortPolicy(slot_number_range), cache_enabled_(cache) {}
47
48 bool cache_enabled() const { return cache_enabled_; }
49
50 protected:
51 bool cache_enabled_; // input slot only
52};
53
54class PortOutPolicy : public PortPolicy {
55 public:
56 PortOutPolicy(SlotRange slot_number_range = SlotRange(1), int buffer_size = 200,
57 WaitStrategy wait = WaitStrategy::kBlockingStrategy)
58 : PortPolicy(slot_number_range), buffer_size_(buffer_size), wait_strategy_(wait) {}
59
60 int buffer_size() const { return buffer_size_; }
61 WaitStrategy wait_strategy() const { return wait_strategy_; }
62
63 void set_buffer_size(int sz) { buffer_size_ = sz; }
64
65 protected:
66 int buffer_size_; // output slot only
67 WaitStrategy wait_strategy_; // ouput slot only
68};