source: XIOS/trunk/src/filter/output_pin.cpp @ 1704

Last change on this file since 1704 was 1704, checked in by yushan, 5 years ago

Introducing the new graph functionality. Attribute build_workflow_graph=.TRUE. is used in the field definition section in the xml file to enable the workflow graph of the field and other fields referecing to it. A more detailed document will be available soon on the graph fuctionality.

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