source: XIOS/dev/dev_trunk_omp/src/filter/output_pin.cpp @ 1685

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

dev for graph

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