1 | #include "output_pin.hpp" |
---|
2 | #include "exception.hpp" |
---|
3 | #include "workflow_graph.hpp" |
---|
4 | |
---|
5 | namespace xios |
---|
6 | { |
---|
7 | |
---|
8 | |
---|
9 | COutputPin::COutputPin(CGarbageCollector& gc, bool manualTrigger /*= false*/, bool buildWorkflowGraph /* =false */) |
---|
10 | : gc(gc) |
---|
11 | , manualTrigger(manualTrigger) |
---|
12 | , buildWorkflowGraph(buildWorkflowGraph) |
---|
13 | { |
---|
14 | // parent_filter = new std::vector< void >(0); |
---|
15 | } |
---|
16 | |
---|
17 | StdString COutputPin::GetName(void) |
---|
18 | { |
---|
19 | return StdString("Output pin"); |
---|
20 | } |
---|
21 | |
---|
22 | void COutputPin::connectOutput(std::shared_ptr<CInputPin> inputPin, size_t inputSlot) |
---|
23 | { |
---|
24 | if (!inputPin) |
---|
25 | ERROR("void COutputPin::connectOutput(CInputPin* inputPin, size_t inputSlot)", |
---|
26 | "The input pin cannot be null."); |
---|
27 | |
---|
28 | outputs.push_back(std::make_pair(inputPin, inputSlot)); |
---|
29 | |
---|
30 | if (canBeTriggered()) |
---|
31 | inputPin->setInputTrigger(inputSlot, this); |
---|
32 | } |
---|
33 | |
---|
34 | void COutputPin::onOutputReady(CDataPacketPtr packet) |
---|
35 | { |
---|
36 | if (!packet) |
---|
37 | ERROR("void COutputPin::onOutputReady(CDataPacketPtr packet)", |
---|
38 | "The packet cannot be null."); |
---|
39 | |
---|
40 | //if(CXios::isClient) std::cout<<"onOutputReady"<<std::endl; |
---|
41 | |
---|
42 | |
---|
43 | if (manualTrigger) // Don't use canBeTriggered here, this function is virtual and can be overriden |
---|
44 | { |
---|
45 | outputPackets[packet->timestamp] = packet; |
---|
46 | gc.registerObject(this, packet->timestamp); |
---|
47 | } |
---|
48 | else |
---|
49 | deliverOuput(packet); |
---|
50 | } |
---|
51 | |
---|
52 | void COutputPin::deliverOuput(CDataPacketPtr packet) |
---|
53 | { |
---|
54 | if (!packet) |
---|
55 | ERROR("void COutputPin::deliverOuput(CDataPacketPtr packet)", |
---|
56 | "The packet cannot be null."); |
---|
57 | |
---|
58 | std::vector<std::pair<std::shared_ptr<CInputPin>, size_t> >::iterator it, itEnd; |
---|
59 | for (it = outputs.begin(), itEnd = outputs.end(); it != itEnd; ++it) |
---|
60 | it->first->setInput(it->second, packet); |
---|
61 | } |
---|
62 | |
---|
63 | void COutputPin::trigger(Time timestamp) |
---|
64 | { |
---|
65 | if (manualTrigger) // Don't use canBeTriggered here, this function is virtual and can be overriden |
---|
66 | { |
---|
67 | std::map<Time, CDataPacketPtr>::iterator it = outputPackets.find(timestamp); |
---|
68 | if (it != outputPackets.end()) |
---|
69 | { |
---|
70 | gc.unregisterObject(this, timestamp); |
---|
71 | deliverOuput(it->second); |
---|
72 | outputPackets.erase(it); |
---|
73 | } |
---|
74 | } |
---|
75 | } |
---|
76 | |
---|
77 | bool COutputPin::canBeTriggered() const |
---|
78 | { |
---|
79 | return manualTrigger; |
---|
80 | } |
---|
81 | |
---|
82 | bool COutputPin::mustAutoTrigger() const |
---|
83 | { |
---|
84 | std::vector<std::pair<std::shared_ptr<CInputPin>, size_t> >::const_iterator it, itEnd; |
---|
85 | for (it = outputs.begin(), itEnd = outputs.end(); it != itEnd; ++it) |
---|
86 | { |
---|
87 | if (it->first->mustAutoTrigger()) |
---|
88 | return true; |
---|
89 | } |
---|
90 | |
---|
91 | return false; |
---|
92 | } |
---|
93 | |
---|
94 | void COutputPin::setOutputTriggers() |
---|
95 | { |
---|
96 | std::vector<std::pair<std::shared_ptr<CInputPin>, size_t> >::iterator it, itEnd; |
---|
97 | for (it = outputs.begin(), itEnd = outputs.end(); it != itEnd; ++it) |
---|
98 | it->first->setInputTrigger(it->second, this); |
---|
99 | } |
---|
100 | |
---|
101 | bool COutputPin::isDataExpected(const CDate& date) const |
---|
102 | { |
---|
103 | std::vector<std::pair<std::shared_ptr<CInputPin>, size_t> >::const_iterator it, itEnd; |
---|
104 | for (it = outputs.begin(), itEnd = outputs.end(); it != itEnd; ++it) |
---|
105 | { |
---|
106 | if (it->first->isDataExpected(date)) |
---|
107 | return true; |
---|
108 | } |
---|
109 | |
---|
110 | return false; |
---|
111 | } |
---|
112 | |
---|
113 | void COutputPin::invalidate(Time timestamp) |
---|
114 | { |
---|
115 | outputPackets.erase(outputPackets.begin(), outputPackets.lower_bound(timestamp)); |
---|
116 | } |
---|
117 | |
---|
118 | void COutputPin::setParentFiltersTag() |
---|
119 | { |
---|
120 | for(int i=0; i<parent_filters.size(); i++) |
---|
121 | { |
---|
122 | parent_filters[i]->tag += tag; |
---|
123 | parent_filters[i]->setParentFiltersTag(); |
---|
124 | } |
---|
125 | } |
---|
126 | |
---|
127 | |
---|
128 | } // namespace xios |
---|