XIOS  1.0
Xml I/O Server
 Tout Classes Espaces de nommage Fichiers Fonctions Variables Définitions de type Énumérations Valeurs énumérées Amis Macros
output_pin.cpp
Aller à la documentation de ce fichier.
1 #include "output_pin.hpp"
2 #include "exception.hpp"
3 
4 namespace xios
5 {
6  COutputPin::COutputPin(CGarbageCollector& gc, bool manualTrigger /*= false*/)
7  : gc(gc)
8  , manualTrigger(manualTrigger)
9  { /* Nothing to do */ }
10 
11  void COutputPin::connectOutput(std::shared_ptr<CInputPin> inputPin, size_t inputSlot)
12  {
13  if (!inputPin)
14  ERROR("void COutputPin::connectOutput(CInputPin* inputPin, size_t inputSlot)",
15  "The input pin cannot be null.");
16 
17  outputs.push_back(std::make_pair(inputPin, inputSlot));
18 
19  if (canBeTriggered())
20  inputPin->setInputTrigger(inputSlot, this);
21  }
22 
24  {
25  if (!packet)
26  ERROR("void COutputPin::onOutputReady(CDataPacketPtr packet)",
27  "The packet cannot be null.");
28 
29  if (manualTrigger) // Don't use canBeTriggered here, this function is virtual and can be overriden
30  {
31  outputPackets[packet->timestamp] = packet;
32  gc.registerObject(this, packet->timestamp);
33  }
34  else
35  deliverOuput(packet);
36  }
37 
39  {
40  if (!packet)
41  ERROR("void COutputPin::deliverOuput(CDataPacketPtr packet)",
42  "The packet cannot be null.");
43 
44  std::vector<std::pair<std::shared_ptr<CInputPin>, size_t> >::iterator it, itEnd;
45  for (it = outputs.begin(), itEnd = outputs.end(); it != itEnd; ++it)
46  it->first->setInput(it->second, packet);
47  }
48 
49  void COutputPin::trigger(Time timestamp)
50  {
51  if (manualTrigger) // Don't use canBeTriggered here, this function is virtual and can be overriden
52  {
53  std::map<Time, CDataPacketPtr>::iterator it = outputPackets.find(timestamp);
54  if (it != outputPackets.end())
55  {
56  gc.unregisterObject(this, timestamp);
57  deliverOuput(it->second);
58  outputPackets.erase(it);
59  }
60  }
61  }
62 
64  {
65  return manualTrigger;
66  }
67 
69  {
70  std::vector<std::pair<std::shared_ptr<CInputPin>, size_t> >::const_iterator it, itEnd;
71  for (it = outputs.begin(), itEnd = outputs.end(); it != itEnd; ++it)
72  {
73  if (it->first->mustAutoTrigger())
74  return true;
75  }
76 
77  return false;
78  }
79 
81  {
82  std::vector<std::pair<std::shared_ptr<CInputPin>, size_t> >::iterator it, itEnd;
83  for (it = outputs.begin(), itEnd = outputs.end(); it != itEnd; ++it)
84  it->first->setInputTrigger(it->second, this);
85  }
86 
87  bool COutputPin::isDataExpected(const CDate& date) const
88  {
89  std::vector<std::pair<std::shared_ptr<CInputPin>, size_t> >::const_iterator it, itEnd;
90  for (it = outputs.begin(), itEnd = outputs.end(); it != itEnd; ++it)
91  {
92  if (it->first->isDataExpected(date))
93  return true;
94  }
95 
96  return false;
97  }
98 
99  void COutputPin::invalidate(Time timestamp)
100  {
101  outputPackets.erase(outputPackets.begin(), outputPackets.lower_bound(timestamp));
102  }
103 } // namespace xios
virtual bool canBeTriggered() const
Tests if the pin can be triggered.
Definition: output_pin.cpp:63
std::shared_ptr< CDataPacket > CDataPacketPtr
Definition: data_packet.hpp:45
void deliverOuput(CDataPacketPtr packet)
Delivers an output packet to the downstreams filter.
Definition: output_pin.cpp:38
void connectOutput(std::shared_ptr< CInputPin > inputPin, size_t inputSlot)
Connects to a specific slot of the input pin of a downstream filter.
Definition: output_pin.cpp:11
COutputPin(CGarbageCollector &gc, bool manualTrigger=false)
Constructs an ouput pin with manual or automatic trigger and an associated garbage collector...
Definition: output_pin.cpp:6
void registerObject(InvalidableObject *object, Time timestamp)
Registers an object for a specified timestamp.
bool manualTrigger
The list of connected filters and the corresponding slot numbers.
Definition: output_pin.hpp:92
#define xios(arg)
long long int Time
////////////////////// Déclarations ////////////////////// ///
Definition: duration.hpp:11
void onOutputReady(CDataPacketPtr packet)
Function triggered when a packet is ready to be delivered.
Definition: output_pin.cpp:23
virtual void invalidate(Time timestamp)
Removes all pending packets which are older than the specified timestamp.
Definition: output_pin.cpp:99
virtual bool isDataExpected(const CDate &date) const
Tests whether data is expected for the specified date.
Definition: output_pin.cpp:87
CGarbageCollector & gc
The garbage collector associated to the output pin.
Definition: output_pin.hpp:89
CATCH CScalarAlgorithmReduceScalar::CScalarAlgorithmReduceScalar(CScalar *scalarDestination, CScalar *scalarSource, CReduceScalarToScalar *algo ERROR)("CScalarAlgorithmReduceScalar::CScalarAlgorithmReduceScalar(CScalar* scalarDestination, CScalar* scalarSource, CReduceScalarToScalar* algo)",<< "Operation must be defined."<< "Scalar source "<< scalarSource->getId()<< std::endl<< "Scalar destination "<< scalarDestination->getId())
void setOutputTriggers()
Informs the downstream pins that this output pin should be triggered.
Definition: output_pin.cpp:80
virtual void trigger(Time timestamp)
Triggers the output of any buffered packet for the specified timestamp.
Definition: output_pin.cpp:49
std::map< Time, CDataPacketPtr > outputPackets
Output buffer, store the packets until the output is triggered.
Definition: output_pin.hpp:98
void unregisterObject(InvalidableObject *object, Time timestamp)
Removes a object previously registered for a specified timestamp.
A basic garbage collector which ensures no old packets linger in the filter graph.
virtual bool mustAutoTrigger() const
Tests if the pin must auto-trigger.
Definition: output_pin.cpp:68
std::vector< std::pair< std::shared_ptr< CInputPin >, size_t > > outputs
Definition: output_pin.hpp:95