f0c104c5056a43dc4a9f4267fd08c8b521d2f660
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 <string>
7) 
8) #include <BlinkenLib/BlinkenFrame.h>
9) 
10) #include "Directory.h"
11) #include "File.h"
Stefan Schuermans implemented specialized set...

Stefan Schuermans authored 12 years ago

12) #include "InStreamFile.h"
Stefan Schuermans implemented priority based...

Stefan Schuermans authored 12 years ago

13) #include "Priority.h"
14) #include "PriorityInput.h"
15) #include "StreamMgr.h"
16) #include "StreamRecv.h"
17) 
18) namespace Blinker {
19) 
20) /**
21)  * @brief constructor
22)  * @param[in] priority owning priority based selector
23)  * @param[in] name name of input (i.e. priority)
24)  * @param[in] dirBase base directory
25)  */
26) Priority::Input::Input(Priority &priority, const std::string &name,
27)                        const Directory &dirBase):
28)   m_priority(priority),
29)   m_name(name),
Stefan Schuermans implemented specialized set...

Stefan Schuermans authored 12 years ago

30)   m_fileInStream(dirBase.getFile("instream"), priority.m_streamMgr),
Stefan Schuermans implemented priority based...

Stefan Schuermans authored 12 years ago

31)   m_pFrame(NULL)
32) {
Stefan Schuermans implemented specialized set...

Stefan Schuermans authored 12 years ago

33)   // set up
34)   m_fileInStream.setStreamRecv(this);
Stefan Schuermans implemented priority based...

Stefan Schuermans authored 12 years ago

35) }
36) 
37) /// virtual destructor
38) Priority::Input::~Input()
39) {
Stefan Schuermans implemented specialized set...

Stefan Schuermans authored 12 years ago

40)   // clean up
41)   m_fileInStream.setStreamRecv(NULL);
Stefan Schuermans implemented priority based...

Stefan Schuermans authored 12 years ago

42) }
43) 
44) /// check for update of configuration
45) void Priority::Input::updateConfig()
46) {
47)   // input stream name file was modified -> re-get input stream
48)   if (m_fileInStream.checkModified()) {
Stefan Schuermans implemented specialized set...

Stefan Schuermans authored 12 years ago

49)     frame(NULL); // unset frame to force priority reevalulation
50)     m_fileInStream.update();
Stefan Schuermans implemented priority based...

Stefan Schuermans authored 12 years ago

51)   }
52) }
53) 
54) /**
55)  * @brief set current frame
56)  * @param[in] stream stream name
Stefan Schuermans merged frame processing wit...

Stefan Schuermans authored 12 years ago

57)  * @param[in] pFrame current frame (NULL for none)
Stefan Schuermans implemented priority based...

Stefan Schuermans authored 12 years ago

58)  */
59) void Priority::Input::setFrame(const std::string &stream, stBlinkenFrame *pFrame)
60) {
61)   frame(pFrame);
62)   (void)stream; // unused
63) }
64) 
65) /**
66)  * @brief get current frame
Stefan Schuermans simplified interface of get...

Stefan Schuermans authored 12 years ago

67)  * @return current frame (NULL if none)
Stefan Schuermans implemented priority based...

Stefan Schuermans authored 12 years ago

68)  */
Stefan Schuermans simplified interface of get...

Stefan Schuermans authored 12 years ago

69) stBlinkenFrame * Priority::Input::getCurFrame()
Stefan Schuermans implemented priority based...

Stefan Schuermans authored 12 years ago

70) {
Stefan Schuermans simplified interface of get...

Stefan Schuermans authored 12 years ago

71)   return m_pFrame;
Stefan Schuermans implemented priority based...

Stefan Schuermans authored 12 years ago

72) }
73) 
74) /**
75)  * @brief set current frame
Stefan Schuermans merged frame processing wit...

Stefan Schuermans authored 12 years ago

76)  * @param[in] pFrame current frame (NULL for none)
Stefan Schuermans implemented priority based...

Stefan Schuermans authored 12 years ago

77)  */
78) void Priority::Input::frame(stBlinkenFrame *pFrame)
79) {
80)   // save new frame
81)   m_pFrame = pFrame;
82) 
Stefan Schuermans merged frame processing wit...

Stefan Schuermans authored 12 years ago

83)   // there is a frame now
84)   if (pFrame) {
Stefan Schuermans implemented priority based...

Stefan Schuermans authored 12 years ago

85) 
Stefan Schuermans merged frame processing wit...

Stefan Schuermans authored 12 years ago

86)     // if we are current input
87)     if (m_priority.m_itCurIn != m_priority.m_inList.rend() &&
88)         m_priority.m_itCurIn->m_pInput == this)
89)       // pass on frame
Stefan Schuermans implemented specialized set...

Stefan Schuermans authored 12 years ago

90)       m_priority.m_fileOutStream.setFrame(pFrame);
Stefan Schuermans merged frame processing wit...

Stefan Schuermans authored 12 years ago

91) 
92)     // we have a higher priority than current input
93)     if (m_priority.m_itCurIn == m_priority.m_inList.rend() ||
94)         m_priority.m_itCurIn->m_name < m_name)
95)       // tell priority based selector to select us as input
96)       m_priority.select(this);
97) 
98)   }
99)   // there is no frame
100)   else {
101) 
102)     // if we are current input
103)     if (m_priority.m_itCurIn != m_priority.m_inList.rend() &&
104)         m_priority.m_itCurIn->m_pInput == this)
105)       // tell priority based selector to select lower priority input
106)       m_priority.selectLower();
107) 
108)   }