Stefan Schuermans commited on 2011-11-22 22:43:29
Showing 2 changed files, with 33 additions and 120 deletions.
... | ... |
@@ -138,11 +138,8 @@ protected: |
138 | 138 |
/// remove timed-out dynamic destinations |
139 | 139 |
void removeTimedOutDynDests(); |
140 | 140 |
|
141 |
- /** |
|
142 |
- * @brief send frame to all destinations |
|
143 |
- * @param[in] pFrame frame to send |
|
144 |
- */ |
|
145 |
- void sendAllFrame(stBlinkenFrame *pFrame); |
|
141 |
+ /// send current protocol data to all destinations |
|
142 |
+ void sendAllProto(); |
|
146 | 143 |
|
147 | 144 |
/// send "no frame" to all destinations |
148 | 145 |
void sendAllNoFrame(); |
... | ... |
@@ -157,27 +154,11 @@ protected: |
157 | 154 |
const DynDests dynDests); |
158 | 155 |
|
159 | 156 |
/** |
160 |
- * @brief send current frame to address |
|
161 |
- * @param[in] addr address to send to |
|
162 |
- * @param[in] proto Blinken protocol identifier |
|
163 |
- TODO: still needed? |
|
164 |
- */ |
|
165 |
- void sendCurFrame(const ADDR &addr, etBlinkenProto proto) const; |
|
166 |
- |
|
167 |
- /** |
|
168 |
- * @brief send "no frame" to address |
|
169 |
- * @param[in] addr address to send to |
|
170 |
- * @param[in] proto Blinken protocol identifier |
|
171 |
- TODO: still needed? |
|
172 |
- */ |
|
173 |
- void sendNoFrame(const ADDR &addr, etBlinkenProto proto) const; |
|
174 |
- |
|
175 |
- /** |
|
176 |
- * @brief send frame to address |
|
157 |
+ * @brief send protocol data to address |
|
177 | 158 |
* @param[in] data protcol data of frame |
178 | 159 |
* @param[in] addr address to send to |
179 | 160 |
*/ |
180 |
- void sendFrame(const std::string &data, const ADDR &addr) const; |
|
161 |
+ void sendProto(const std::string &data, const ADDR &addr) const; |
|
181 | 162 |
|
182 | 163 |
/** |
183 | 164 |
* @brief convert frame to protocol data |
... | ... |
@@ -127,8 +127,13 @@ template<typename ADDR, typename SOCK> |
127 | 127 |
void Sender<ADDR, SOCK>::setFrame(const std::string &stream, |
128 | 128 |
stBlinkenFrame *pFrame) |
129 | 129 |
{ |
130 |
- // send frame to all destinations |
|
131 |
- sendAllFrame(pFrame); |
|
130 |
+ // convert new frame to protocol data |
|
131 |
+ frame2data(pFrame, BlinkenProtoBlp, m_dataBlp); |
|
132 |
+ frame2data(pFrame, BlinkenProtoEblp, m_dataEblp); |
|
133 |
+ frame2data(pFrame, BlinkenProtoMcuf, m_dataMcuf); |
|
134 |
+ |
|
135 |
+ // send new protocol data to all destinations |
|
136 |
+ sendAllProto(); |
|
132 | 137 |
|
133 | 138 |
(void)stream; // unused |
134 | 139 |
} |
... | ... |
@@ -140,8 +145,13 @@ void Sender<ADDR, SOCK>::setFrame(const std::string &stream, |
140 | 145 |
template<typename ADDR, typename SOCK> |
141 | 146 |
void Sender<ADDR, SOCK>::setNoFrame(const std::string &stream) |
142 | 147 |
{ |
143 |
- // send "no frame" to all destinations |
|
144 |
- sendAllNoFrame(); |
|
148 |
+ // set protocol data |
|
149 |
+ m_dataBlp = m_noFrameDataBlp; |
|
150 |
+ m_dataEblp = m_noFrameDataEblp; |
|
151 |
+ m_dataMcuf = m_noFrameDataMcuf; |
|
152 |
+ |
|
153 |
+ // send new protocol data to all destinations |
|
154 |
+ sendAllProto(); |
|
145 | 155 |
|
146 | 156 |
(void)stream; // unused |
147 | 157 |
} |
... | ... |
@@ -150,18 +160,8 @@ void Sender<ADDR, SOCK>::setNoFrame(const std::string &stream) |
150 | 160 |
template<typename ADDR, typename SOCK> |
151 | 161 |
void Sender<ADDR, SOCK>::timeCall() |
152 | 162 |
{ |
153 |
- stBlinkenFrame *pFrame; |
|
154 |
- std::string data; |
|
155 |
- |
|
156 |
- // get current frame from stream |
|
157 |
- if (m_pInStream && m_pInStream->getCurFrame(pFrame)) |
|
158 |
- // repeat frame to all destinations |
|
159 |
- sendAllFrame(pFrame); |
|
160 |
- |
|
161 |
- // no stream of no current frame |
|
162 |
- else |
|
163 |
- // repeat "no frame" to all destinations |
|
164 |
- sendAllNoFrame(); |
|
163 |
+ // repeat current protocol data to all destinations |
|
164 |
+ sendAllProto(); |
|
165 | 165 |
} |
166 | 166 |
|
167 | 167 |
/** |
... | ... |
@@ -266,7 +266,7 @@ void Sender<ADDR, SOCK>::destroySock() |
266 | 266 |
sendAllNoFrame(); |
267 | 267 |
|
268 | 268 |
// clear dynamic destinations |
269 |
- // (they registered with this socket adn this socket is gone) |
|
269 |
+ // (they registered with this socket and this socket is gone) |
|
270 | 270 |
m_dynDestsBlp.clear(); |
271 | 271 |
m_dynDestsEblp.clear(); |
272 | 272 |
m_dynDestsMcuf.clear(); |
... | ... |
@@ -378,29 +378,17 @@ void Sender<ADDR, SOCK>::removeTimedOutDynDests() |
378 | 378 |
++itDyn; |
379 | 379 |
} |
380 | 380 |
|
381 |
-/** |
|
382 |
- * @brief send frame to all destinations |
|
383 |
- * @param[in] pFrame frame to send |
|
384 |
- */ |
|
381 |
+/// send current protocol data to all destinations |
|
385 | 382 |
template<typename ADDR, typename SOCK> |
386 |
-void Sender<ADDR, SOCK>::sendAllFrame(stBlinkenFrame *pFrame) |
|
383 |
+void Sender<ADDR, SOCK>::sendAllProto() |
|
387 | 384 |
{ |
388 | 385 |
// remove timed-out dynamic destinations |
389 | 386 |
removeTimedOutDynDests(); |
390 | 387 |
|
391 |
- // convert frame to protocol data and send to all static/dynamic destinations |
|
392 |
- if (!m_destListBlp.empty() || !m_dynDestsBlp.empty()) { |
|
393 |
- frame2data(pFrame, BlinkenProtoBlp, m_dataBlp); |
|
388 |
+ // send current protocol data to all static/dynamic destinations |
|
394 | 389 |
sendDests(&m_dataBlp, m_destListBlp, m_dynDestsBlp); |
395 |
- } |
|
396 |
- if (!m_destListEblp.empty() || !m_dynDestsEblp.empty()) { |
|
397 |
- frame2data(pFrame, BlinkenProtoEblp, m_dataEblp); |
|
398 | 390 |
sendDests(&m_dataEblp, m_destListEblp, m_dynDestsEblp); |
399 |
- } |
|
400 |
- if (!m_destListMcuf.empty() || !m_dynDestsMcuf.empty()) { |
|
401 |
- frame2data(pFrame, BlinkenProtoMcuf, m_dataMcuf); |
|
402 | 391 |
sendDests(&m_dataMcuf, m_destListMcuf, m_dynDestsMcuf); |
403 |
- } |
|
404 | 392 |
|
405 | 393 |
// request time callback in one second |
406 | 394 |
m_callMgr.requestTimeCall(this, Time::now() + Time(1)); |
... | ... |
@@ -414,18 +402,9 @@ void Sender<ADDR, SOCK>::sendAllNoFrame() |
414 | 402 |
removeTimedOutDynDests(); |
415 | 403 |
|
416 | 404 |
// get "no frame" protocol data and send to all static/dynamic destinations |
417 |
- if (!m_destListBlp.empty() || !m_dynDestsBlp.empty()) { |
|
418 |
- noFrame2data(BlinkenProtoBlp, m_dataBlp); |
|
419 |
- sendDests(&m_dataBlp, m_destListBlp, m_dynDestsBlp); |
|
420 |
- } |
|
421 |
- if (!m_destListEblp.empty() || !m_dynDestsEblp.empty()) { |
|
422 |
- noFrame2data(BlinkenProtoEblp, m_dataEblp); |
|
423 |
- sendDests(&m_dataEblp, m_destListEblp, m_dynDestsEblp); |
|
424 |
- } |
|
425 |
- if (!m_destListMcuf.empty() || !m_dynDestsMcuf.empty()) { |
|
426 |
- noFrame2data(BlinkenProtoMcuf, m_dataMcuf); |
|
427 |
- sendDests(&m_dataMcuf, m_destListMcuf, m_dynDestsMcuf); |
|
428 |
- } |
|
405 |
+ sendDests(&m_noFrameDataBlp, m_destListBlp, m_dynDestsBlp); |
|
406 |
+ sendDests(&m_noFrameDataEblp, m_destListEblp, m_dynDestsEblp); |
|
407 |
+ sendDests(&m_noFrameDataMcuf, m_destListMcuf, m_dynDestsMcuf); |
|
429 | 408 |
|
430 | 409 |
// request time callback in one second |
431 | 410 |
m_callMgr.requestTimeCall(this, Time::now() + Time(1)); |
... | ... |
@@ -450,63 +429,16 @@ void Sender<ADDR, SOCK>::sendDests(const std::string *pData, |
450 | 429 |
// send data to all dynamic destinations |
451 | 430 |
typename DynDests::const_iterator itDyn; |
452 | 431 |
for (itDyn = dynDests.begin(); itDyn != dynDests.end(); ++itDyn) |
453 |
- sendFrame(*pData, itDyn->first); |
|
454 |
-} |
|
455 |
- |
|
456 |
-/** |
|
457 |
- * @brief send current frame to address |
|
458 |
- * @param[in] addr address to send to |
|
459 |
- * @param[in] proto Blinken protocol identifier |
|
460 |
- */ |
|
461 |
-template<typename ADDR, typename SOCK> |
|
462 |
-void Sender<ADDR, SOCK>::sendCurFrame(const ADDR &addr, |
|
463 |
- etBlinkenProto proto) const |
|
464 |
-{ |
|
465 |
- stBlinkenFrame *pFrame; |
|
466 |
- std::string data; |
|
467 |
- |
|
468 |
- // get current frame from stream |
|
469 |
- if (m_pInStream && m_pInStream->getCurFrame(pFrame)) { |
|
470 |
- // convert frame to protocal data |
|
471 |
- frame2data(pFrame, proto, data); |
|
472 |
- // send frame to address |
|
473 |
- sendFrame(data, addr); |
|
474 |
- } |
|
475 |
- |
|
476 |
- // no stream of no current frame |
|
477 |
- else { |
|
478 |
- // get "no frame" ad protocal data |
|
479 |
- noFrame2data(proto, data); |
|
480 |
- // send "no frame" to address |
|
481 |
- sendFrame(data, addr); |
|
482 |
- } |
|
483 |
-} |
|
484 |
- |
|
485 |
-/** |
|
486 |
- * @brief send "no frame" to address |
|
487 |
- * @param[in] addr address to send to |
|
488 |
- * @param[in] proto Blinken protocol identifier |
|
489 |
- */ |
|
490 |
-template<typename ADDR, typename SOCK> |
|
491 |
-void Sender<ADDR, SOCK>::sendNoFrame(const ADDR &addr, |
|
492 |
- etBlinkenProto proto) const |
|
493 |
-{ |
|
494 |
- std::string data; |
|
495 |
- |
|
496 |
- // get "no frame" ad protocal data |
|
497 |
- noFrame2data(proto, data); |
|
498 |
- |
|
499 |
- // send "no frame" to address |
|
500 |
- sendFrame(data, addr); |
|
432 |
+ sendProto(*pData, itDyn->first); |
|
501 | 433 |
} |
502 | 434 |
|
503 | 435 |
/** |
504 |
- * @brief send frame to address |
|
436 |
+ * @brief send protocol data to address |
|
505 | 437 |
* @param[in] data protocol data of frame |
506 | 438 |
* @param[in] addr address to send to |
507 | 439 |
*/ |
508 | 440 |
template<typename ADDR, typename SOCK> |
509 |
-void Sender<ADDR, SOCK>::sendFrame(const std::string &data, |
|
441 |
+void Sender<ADDR, SOCK>::sendProto(const std::string &data, |
|
510 | 442 |
const ADDR &addr) const |
511 | 443 |
{ |
512 | 444 |
if (m_pSock) { |
... | ... |
@@ -580,15 +512,15 @@ void Sender<ADDR, SOCK>::receiveFromSock() |
580 | 512 |
switch (proto) { |
581 | 513 |
case BlinkenProtoBlp: |
582 | 514 |
m_dynDestsBlp[addr] = Time::now(); |
583 |
- sendCurFrame(addr, BlinkenProtoBlp); |
|
515 |
+ sendProto(m_dataBlp, addr); |
|
584 | 516 |
break; |
585 | 517 |
case BlinkenProtoEblp: |
586 | 518 |
m_dynDestsEblp[addr] = Time::now(); |
587 |
- sendCurFrame(addr, BlinkenProtoEblp); |
|
519 |
+ sendProto(m_dataEblp, addr); |
|
588 | 520 |
break; |
589 | 521 |
case BlinkenProtoMcuf: |
590 | 522 |
m_dynDestsMcuf[addr] = Time::now(); |
591 |
- sendCurFrame(addr, BlinkenProtoMcuf); |
|
523 |
+ sendProto(m_dataMcuf, addr); |
|
592 | 524 |
break; |
593 | 525 |
default: |
594 | 526 |
break; |
595 | 527 |