source: XIOS/dev/dev_olga/src/filter/output_pin.cpp @ 1653

Last change on this file since 1653 was 1653, checked in by oabramkina, 5 years ago

Developments for visualization of XIOS workflow.

Branch is spawned from trunk r1649.

Boost library is used for producing Graphviz DOT files. Current results: a DOT file representing a static workflow. For a complete proof of concept, DOT files for each timestamp should be generated. The necessary information has been collected by XIOS, it only requires rearranging the information for graphing (changes in classes CWorkflowGraph and CGraphviz).

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