source: XIOS/dev/branch_yushan/src/filter/input_pin.cpp @ 1056

Last change on this file since 1056 was 1056, checked in by yushan, 6 years ago

one file mode OK. Tested with test_client

File size: 1.3 KB
Line 
1#include "input_pin.hpp"
2#include "garbage_collector.hpp"
3#include "exception.hpp"
4
5namespace xios
6{
7  CInputPin::CInputPin(CGarbageCollector& gc, size_t slotsCount)
8    : gc(gc)
9    , slotsCount(slotsCount)
10  { /* Nothing to do */ }
11
12  void CInputPin::setInput(size_t inputSlot, CDataPacketPtr packet)
13  {
14    if (inputSlot >= slotsCount)
15      ERROR("void CInputPin::setInput(size_t inputSlot, CDataPacketPtr packet)",
16            "The input slot " << inputSlot << " does not exist.");
17    if (!packet)
18      ERROR("void CInputPin::setInput(size_t inputSlot, CDataPacketPtr packet)",
19            "The packet cannot be null.");
20
21    std::map<Time, InputBuffer>::iterator it = inputs.find(packet->timestamp);
22    if (it == inputs.end())
23    {
24      it = inputs.insert(std::make_pair(packet->timestamp, InputBuffer(slotsCount))).first;
25      gc.registerFilter(this, packet->timestamp);
26    }
27
28    it->second.slotsFilled++;
29    it->second.packets[inputSlot] = packet;
30
31    if (it->second.slotsFilled == slotsCount)
32    {
33      // Unregister before calling onInputReady in case the filter registers again
34      gc.unregisterFilter(this, packet->timestamp);
35      onInputReady(it->second.packets);
36      inputs.erase(it);
37    }
38  }
39
40  void CInputPin::invalidate(Time timestamp)
41  {
42    inputs.erase(inputs.begin(), inputs.lower_bound(timestamp));
43  }
44} // namespace xios
Note: See TracBrowser for help on using the repository browser.