@@ -80,7 +80,7 @@ PublisherApp::PublisherApp(
8080
8181 if (publisher_ == nullptr )
8282 {
83- throw std::runtime_error (" Fast Publisher initialization failed" );
83+ throw std::runtime_error (" Publisher initialization failed" );
8484 }
8585
8686 // Create Topic
@@ -182,18 +182,27 @@ void PublisherApp::run()
182182 FlowControl msg;
183183
184184 /* Initialize your structure here */
185- uint16_t samples_fast = 0 ;
186- uint16_t samples_slow = 0 ;
187- while (!is_stopped () && ((samples_ == 0 ) || ((samples_fast < samples_) && (samples_slow < samples_))))
185+
186+ while (!is_stopped () && ((samples_ == 0 ) || (msg.index () < samples_)))
188187 {
189- if (publish (slow_writer_, samples_slow, msg))
188+ msg.index (msg.index () + 1 );
189+
190+ if (publish (slow_writer_, msg))
191+ {
192+ std::cout << " Message SENT from SLOW WRITER, count=" << msg.index () << std::endl;
193+ }
194+ else
190195 {
191- std::cout << " Message SENT from SLOW WRITER, count= " << samples_slow << std::endl ;
196+ throw std::runtime_error ( " Slow Publisher failed sending a message " ) ;
192197 }
193198
194- if (publish (fast_writer_, samples_fast, msg))
199+ if (publish (fast_writer_, msg))
200+ {
201+ std::cout << " Message SENT from FAST WRITER, count=" << msg.index () << std::endl;
202+ }
203+ else
195204 {
196- std::cout << " Message SENT from FAST WRITER, count= " << samples_fast << std::endl ;
205+ throw std::runtime_error ( " Fast Publisher failed sending a message " ) ;
197206 }
198207
199208 // Wait for period or stop event
@@ -207,7 +216,6 @@ void PublisherApp::run()
207216
208217bool PublisherApp::publish (
209218 DataWriter* writer_,
210- uint16_t & samples,
211219 FlowControl msg)
212220{
213221 bool ret = false ;
@@ -221,8 +229,6 @@ bool PublisherApp::publish(
221229
222230 if (!is_stopped ())
223231 {
224- ++samples;
225- msg.index (samples);
226232 ret = writer_->write (&msg);
227233 }
228234 return ret;
0 commit comments