77
88
99void PolySyncEcho::initStateEvent ()
10- {
10+ {
1111 _applicationStartTime = polysync::getTimestamp ();
1212
1313 if ( _inputHandler.messageTypesWereFiltered () )
@@ -22,6 +22,18 @@ void PolySyncEcho::initStateEvent()
2222 {
2323 registerListenerToAllMessageTypes ();
2424 }
25+
26+ std::cout << " {\" polysync-echo\" :[" ;
27+
28+ if ( _inputHandler.fileWasSpecified () )
29+ {
30+ _openUserFile.open ( _inputHandler.getFileName (), std::ios::app );
31+
32+ if ( _openUserFile )
33+ {
34+ _openUserFile << " {\" polysync-echo\" :[" ;
35+ }
36+ }
2537}
2638
2739
@@ -50,6 +62,18 @@ void PolySyncEcho::okStateEvent()
5062 polysync::sleepMicro ( SecondsToMicro );
5163}
5264
65+ void PolySyncEcho::releaseStateEvent ()
66+ {
67+ std::cout << " ]}" << std::endl;
68+
69+ if ( _openUserFile )
70+ {
71+ _openUserFile << " ]}" << std::endl;
72+ }
73+
74+ _openUserFile.close ();
75+ }
76+
5377
5478void PolySyncEcho::registerFilteredMessages ()
5579{
@@ -87,7 +111,7 @@ void PolySyncEcho::messageEvent( std::shared_ptr< polysync::Message > message )
87111 return ;
88112 }
89113
90- if ( _inputHandler. fileWasSpecified () )
114+ if ( _openUserFile )
91115 {
92116 printToFile ( message );
93117 }
@@ -99,26 +123,42 @@ void PolySyncEcho::messageEvent( std::shared_ptr< polysync::Message > message )
99123void PolySyncEcho::printToFile (
100124 std::shared_ptr < polysync:: Message > message )
101125{
102- std::ofstream openUserFile ;
126+ static bool is_first_print = true ;
103127
104- openUserFile.open ( _inputHandler.getFileName (), std::ios::app );
128+ if ( is_first_print )
129+ {
130+ is_first_print = false ;
131+ }
132+ else
133+ {
134+ _openUserFile << " ," ;
135+ }
105136
106137 if ( _inputHandler.headersWereRequested () )
107138 {
108- message->printHeader ( openUserFile );
139+ message->printHeader ( _openUserFile );
109140 }
110141 else
111142 {
112- message->print ( openUserFile );
143+ message->print ( _openUserFile );
113144 }
114-
115- openUserFile.close ();
116145}
117146
118147
119148void PolySyncEcho::printMessage (
120149 std::shared_ptr < polysync:: Message > message ) const
121150{
151+ static bool is_first_print = true ;
152+
153+ if ( is_first_print )
154+ {
155+ is_first_print = false ;
156+ }
157+ else
158+ {
159+ std::cout << " ," ;
160+ }
161+
122162 if ( _inputHandler.headersWereRequested () )
123163 {
124164 message->printHeader ();
0 commit comments