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
|
// Copyright (C) by Josh Blum. See LICENSE.txt for licensing information.
#include "element_impl.hpp"
#include <gras/block.hpp>
#include <boost/foreach.hpp>
using namespace gras;
void Block::post_output_tag(const size_t which_output, const Tag &tag)
{
(*this)->block->stats.tags_produced[which_output]++;
(*this)->block->post_downstream(which_output, InputTagMessage(tag));
}
void Block::post_output_msg(const size_t which_output, const PMCC &msg)
{
(*this)->block->stats.msgs_produced[which_output]++;
(*this)->block->post_downstream(which_output, InputMsgMessage(msg));
}
TagIter Block::get_input_tags(const size_t which_input)
{
const std::vector<Tag> &input_tags = (*this)->block->input_tags[which_input];
return TagIter(input_tags.begin(), input_tags.end());
}
PMCC Block::pop_input_msg(const size_t which_input)
{
std::vector<PMCC> &input_msgs = (*this)->block->input_msgs[which_input];
size_t &num_read = (*this)->block->num_input_msgs_read[which_input];
if (num_read >= input_msgs.size()) return PMCC();
PMCC p = input_msgs[num_read++];
(*this)->block->stats.msgs_consumed[which_input]++;
return p;
}
void Block::propagate_tags(const size_t i, const TagIter &iter)
{
const size_t num_outputs = (*this)->block->get_num_outputs();
for (size_t o = 0; o < num_outputs; o++)
{
BOOST_FOREACH(gras::Tag t, iter)
{
t.offset -= this->get_consumed(i);
t.offset += this->get_produced(o);
this->post_output_tag(o, t);
}
}
}
void Block::post_input_tag(const size_t which_input, const Tag &tag)
{
InputTagMessage message(tag);
message.index = which_input;
Theron::Actor &actor = *((*this)->block);
actor.GetFramework().Send(message, Theron::Address::Null(), actor.GetAddress());
}
void Block::post_input_msg(const size_t which_input, const PMCC &msg)
{
InputMsgMessage message(msg);
message.index = which_input;
Theron::Actor &actor = *((*this)->block);
actor.GetFramework().Send(message, Theron::Address::Null(), actor.GetAddress());
}
void Block::post_input_buffer(const size_t which_input, const SBuffer &buffer)
{
InputBufferMessage message;
message.index = which_input;
message.buffer = buffer;
Theron::Actor &actor = *((*this)->block);
actor.GetFramework().Send(message, Theron::Address::Null(), actor.GetAddress());
}
|