blob: 2506cc8dc776ec645d9e8e5979beca1185b767a3 (
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
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
|
// Copyright (C) by Josh Blum. See LICENSE.txt for licensing information.
#include "element_impl.hpp"
#include <gras/block.hpp>
#include <boost/thread/thread.hpp> //yield
using namespace gras;
InputPortConfig::InputPortConfig(void)
{
item_size = 1;
reserve_items = 1;
maximum_items = 0;
inline_buffer = false;
preload_items = 0;
}
OutputPortConfig::OutputPortConfig(void)
{
item_size = 1;
reserve_items = 1;
maximum_items = 0;
}
Block::Block(void)
{
//NOP
}
Block::Block(const std::string &name):
Element(name)
{
(*this)->block.reset(new BlockActor());
(*this)->block->prio_token = Token::make();
(*this)->thread_pool = (*this)->block->thread_pool; //ref copy of pool
(*this)->block->name = name; //for debug purposes
//setup some state variables
(*this)->block->block_ptr = this;
(*this)->block->block_state = BlockActor::BLOCK_STATE_INIT;
//call block methods to init stuff
this->input_config(0) = InputPortConfig();
this->output_config(0) = OutputPortConfig();
this->set_interruptible_work(false);
this->set_buffer_affinity(-1);
}
Block::~Block(void)
{
//NOP
}
void ElementImpl::block_cleanup(void)
{
//wait for actor to chew through enqueued messages
while (this->block->GetNumQueuedMessages())
{
//TODO timeout if this does not stop
boost::this_thread::yield();
}
//delete the actor
this->block.reset();
//unref actor's framework
this->thread_pool.reset(); //must be deleted after actor
}
template <typename V>
const typename V::value_type &vector_get_const(const V &v, const size_t index)
{
if (v.size() <= index)
{
return v.back();
}
return v[index];
}
template <typename V>
typename V::value_type &vector_get_resize(V &v, const size_t index)
{
if (v.size() <= index)
{
if (v.empty()) v.resize(1);
v.resize(index+1, v.back());
}
return v[index];
}
InputPortConfig &Block::input_config(const size_t which_input)
{
return vector_get_resize((*this)->block->input_configs, which_input);
}
const InputPortConfig &Block::input_config(const size_t which_input) const
{
return vector_get_const((*this)->block->input_configs, which_input);
}
OutputPortConfig &Block::output_config(const size_t which_output)
{
return vector_get_resize((*this)->block->output_configs, which_output);
}
const OutputPortConfig &Block::output_config(const size_t which_output) const
{
return vector_get_const((*this)->block->output_configs, which_output);
}
void Block::commit_config(void)
{
for (size_t i = 0; i < (*this)->block->get_num_inputs(); i++)
{
InputUpdateMessage message;
message.index = i;
(*this)->block->Push(message, Theron::Address());
}
for (size_t i = 0; i < (*this)->block->get_num_outputs(); i++)
{
OutputUpdateMessage message;
message.index = i;
(*this)->block->Push(message, Theron::Address());
}
}
void Block::notify_active(void)
{
//NOP
}
void Block::notify_inactive(void)
{
//NOP
}
void Block::notify_topology(const size_t, const size_t)
{
return;
}
void Block::set_buffer_affinity(const long affinity)
{
(*this)->block->buffer_affinity = affinity;
}
void Block::set_interruptible_work(const bool enb)
{
(*this)->block->interruptible_work = enb;
}
|