d597b33024ad68e26d3d03c78225f27e0cbd12b5
Stefan Schuermans implemented priority based...

Stefan Schuermans authored 12 years ago

1) /* Blinker
2)    Copyright 2011 Stefan Schuermans <stefan@blinkenarea.org>
3)    Copyleft GNU public license - http://www.gnu.org/copyleft/gpl.html
4)    a blinkenarea.org project */
5) 
6) #include <list>
7) #include <string>
8) 
9) #include <BlinkenLib/BlinkenFrame.h>
10) 
11) #include "Directory.h"
12) #include "File.h"
Stefan Schuermans created template class for...

Stefan Schuermans authored 12 years ago

13) #include "ListTracker.h"
14) #include "ListTracker_impl.h"
Stefan Schuermans put all managers in one str...

Stefan Schuermans authored 12 years ago

15) #include "Mgrs.h"
Stefan Schuermans implemented priority based...

Stefan Schuermans authored 12 years ago

16) #include "Module.h"
17) #include "Priority.h"
18) #include "PriorityInput.h"
Stefan Schuermans implemented specialized set...

Stefan Schuermans authored 12 years ago

19) #include "OutStreamFile.h"
Stefan Schuermans implemented priority based...

Stefan Schuermans authored 12 years ago

20) #include "StreamRecv.h"
21) 
22) namespace Blinker {
23) 
24) /**
25)  * @brief constructor
Stefan Schuermans make modules know their name

Stefan Schuermans authored 12 years ago

26)  * @param[in] name module name
Stefan Schuermans put all managers in one str...

Stefan Schuermans authored 12 years ago

27)  * @param[in] mgrs managers
Stefan Schuermans implemented priority based...

Stefan Schuermans authored 12 years ago

28)  * @param[in] dirBase base directory
29)  */
Stefan Schuermans make modules know their name

Stefan Schuermans authored 12 years ago

30) Priority::Priority(const std::string &name, Mgrs &mgrs,
31)                    const Directory &dirBase):
32)   Module(name, mgrs, dirBase),
Stefan Schuermans put all managers in one str...

Stefan Schuermans authored 12 years ago

33)   m_fileOutStream(dirBase.getFile("outstream"), mgrs.m_streamMgr),
Stefan Schuermans created template class for...

Stefan Schuermans authored 12 years ago

34)   m_inListTracker(*this, dirBase.getSubdir("inputs")),
Stefan Schuermans fix problem with initializa...

Stefan Schuermans authored 12 years ago

35)   m_itCurIn(m_inListTracker.m_list.rend()),
36)   m_updateNeeded(false)
Stefan Schuermans implemented priority based...

Stefan Schuermans authored 12 years ago

37) {
Stefan Schuermans add forgotten call to init...

Stefan Schuermans authored 12 years ago

38)   m_inListTracker.init();
Stefan Schuermans fix problem with initializa...

Stefan Schuermans authored 12 years ago

39)   updateSelection();
Stefan Schuermans implemented priority based...

Stefan Schuermans authored 12 years ago

40) }
41) 
42) /// virtual destructor
43) Priority::~Priority()
44) {
Stefan Schuermans add forgotten call to init...

Stefan Schuermans authored 12 years ago

45)   m_inListTracker.clear();
Stefan Schuermans implemented priority based...

Stefan Schuermans authored 12 years ago

46) }
47) 
48) /// check for update of configuration
49) void Priority::updateConfig()
50) {
Stefan Schuermans created template class for...

Stefan Schuermans authored 12 years ago

51)   // input list update
52)   m_inListTracker.updateConfig();
Stefan Schuermans fix problem with initializa...

Stefan Schuermans authored 12 years ago

53)   updateSelection();
Stefan Schuermans implemented priority based...

Stefan Schuermans authored 12 years ago

54) 
55)   // output stream name file was modified -> re-get output stream
Stefan Schuermans implemented specialized set...

Stefan Schuermans authored 12 years ago

56)   if (m_fileOutStream.checkModified())
57)     m_fileOutStream.update();
Stefan Schuermans implemented priority based...

Stefan Schuermans authored 12 years ago

58) }
59) 
60) /**
61)  * @brief select specific input (called by inputs)
62)  * @param[in] input input to select
63)  */
64) void Priority::select(const Input *pInput)
65) {
66)   // search inputs for passed input
Stefan Schuermans created template class for...

Stefan Schuermans authored 12 years ago

67)   m_itCurIn = m_inListTracker.m_list.rbegin();
68)   while (m_itCurIn != m_inListTracker.m_list.rend() &&
69)          m_itCurIn->m_pObj != pInput)
Stefan Schuermans implemented priority based...

Stefan Schuermans authored 12 years ago

70)     ++m_itCurIn;
71) 
72)   // send current frame
73)   curFrame();
Stefan Schuermans fix problem with initializa...

Stefan Schuermans authored 12 years ago

74) 
75)   // return if required stream was successfully selected
76)   if (m_itCurIn == m_inListTracker.m_list.rend() ||
77)       m_itCurIn->m_pObj != pInput)
78)     m_updateNeeded = true;
Stefan Schuermans implemented priority based...

Stefan Schuermans authored 12 years ago

79) }
80) 
81) /// select lower priority input (called by inputs)
82) void Priority::selectLower()
83) {
84)   stBlinkenFrame *pFrame;
85) 
86)   // search inputs with lower priority until a frame is found
Stefan Schuermans created template class for...

Stefan Schuermans authored 12 years ago

87)   while (m_itCurIn != m_inListTracker.m_list.rend()) {
Stefan Schuermans implemented priority based...

Stefan Schuermans authored 12 years ago

88)     // check for frame
Stefan Schuermans created template class for...

Stefan Schuermans authored 12 years ago

89)     if ((pFrame = m_itCurIn->m_pObj->getCurFrame())) {
Stefan Schuermans implemented priority based...

Stefan Schuermans authored 12 years ago

90)       // frame found -> keep this input as current, send frame
Stefan Schuermans implemented specialized set...

Stefan Schuermans authored 12 years ago

91)       m_fileOutStream.setFrame(pFrame);
Stefan Schuermans implemented priority based...

Stefan Schuermans authored 12 years ago

92)       return;
93)     }
94)     // try next input
95)     ++m_itCurIn;
96)   }
97) 
98)   // no input has got a frame -> send no frame
Stefan Schuermans implemented specialized set...

Stefan Schuermans authored 12 years ago

99)   m_fileOutStream.setFrame(NULL);
Stefan Schuermans implemented priority based...

Stefan Schuermans authored 12 years ago

100) }
101) 
Stefan Schuermans fix problem with initializa...

Stefan Schuermans authored 12 years ago

102) /// update current selection
103) void Priority::updateSelection()
104) {
105)   if (m_updateNeeded) {
106)     m_updateNeeded = false;
107) 
108)     // search for highest priority input with a frame
109)     for (m_itCurIn = m_inListTracker.m_list.rbegin();
110)          m_itCurIn != m_inListTracker.m_list.rend(); ++m_itCurIn)
111)       if (m_itCurIn->m_pObj->getCurFrame())
112)         break;
113) 
114)     // send new frame to output stream
115)     curFrame();
116) 
117)   } // if m_updateNeeded
118) }
119) 
Stefan Schuermans implemented priority based...

Stefan Schuermans authored 12 years ago

120) /// send current frame to output stream
121) void Priority::curFrame()
122) {
123)   stBlinkenFrame *pFrame;
124) 
125)   // current input available and frame it it available -> send frame
Stefan Schuermans created template class for...

Stefan Schuermans authored 12 years ago

126)   if (m_itCurIn != m_inListTracker.m_list.rend() &&
127)       (pFrame = m_itCurIn->m_pObj->getCurFrame()))
Stefan Schuermans implemented specialized set...

Stefan Schuermans authored 12 years ago

128)     m_fileOutStream.setFrame(pFrame);
Stefan Schuermans implemented priority based...

Stefan Schuermans authored 12 years ago

129)   // no frame available -> send this information
130)   else
Stefan Schuermans implemented specialized set...

Stefan Schuermans authored 12 years ago

131)     m_fileOutStream.setFrame(NULL);