@@ -409,23 +409,78 @@ String NetworkEvents::handleSpecialMessages(StringTS msg)
409409 /* * Start/stop data acquisition */
410410 String s = msg.getString ();
411411
412+ /* * Command is first substring */
413+ StringArray inputs = StringArray::fromTokens (s, " " );
414+ String cmd = String (inputs[0 ]);
415+
412416 const MessageManagerLock mmLock;
413- if (s .compareIgnoreCase (" StartAcquisition" ) == 0 )
417+ if (cmd .compareIgnoreCase (" StartAcquisition" ) == 0 )
414418 {
415419 if (!CoreServices::getAcquisitionStatus ())
416420 {
417421 CoreServices::setAcquisitionStatus (true );
418422 }
419423 return String (" StartedAcquisition" );
420424 }
421- else if (s .compareIgnoreCase (" StopAcquisition" ) == 0 )
425+ else if (cmd .compareIgnoreCase (" StopAcquisition" ) == 0 )
422426 {
423427 if (CoreServices::getAcquisitionStatus ())
424428 {
425429 CoreServices::setAcquisitionStatus (false );
426430 }
427431 return String (" StoppedAcquisition" );
428432 }
433+ else if (String (" StartRecord" ).compareIgnoreCase (cmd) == 0 )
434+ {
435+ if (!CoreServices::getRecordingStatus () && CoreServices::getAcquisitionStatus ())
436+ {
437+ /* * First set optional parameters (name/value pairs)*/
438+ if (s.contains (" =" ))
439+ {
440+ String params = s.substring (cmd.length ());
441+ StringPairArray dict = parseNetworkMessage (params);
442+
443+ StringArray keys = dict.getAllKeys ();
444+ for (int i = 0 ; i<keys.size (); i++)
445+ {
446+ String key = keys[i];
447+ String value = dict[key];
448+
449+ if (key.compareIgnoreCase (" CreateNewDir" ) == 0 )
450+ {
451+ if (value.compareIgnoreCase (" 1" ) == 0 )
452+ {
453+ CoreServices::createNewRecordingDir ();
454+ }
455+ }
456+ else if (key.compareIgnoreCase (" RecDir" ) == 0 )
457+ {
458+ CoreServices::setRecordingDirectory (value);
459+ }
460+ else if (key.compareIgnoreCase (" PrependText" ) == 0 )
461+ {
462+ CoreServices::setPrependTextToRecordingDir (value);
463+ }
464+ else if (key.compareIgnoreCase (" AppendText" ) == 0 )
465+ {
466+ CoreServices::setAppendTextToRecordingDir (value);
467+ }
468+ }
469+ }
470+
471+ /* * Start recording */
472+ CoreServices::setRecordingStatus (true );
473+ return String (" StartedRecording" );
474+ }
475+ }
476+ else if (String (" StopRecord" ).compareIgnoreCase (cmd) == 0 )
477+ {
478+ if (CoreServices::getRecordingStatus ())
479+ {
480+ CoreServices::setRecordingStatus (false );
481+ return String (" StoppedRecording" );
482+ }
483+ }
429484 else
430485 {
431486 return String (" NotHandled" );
@@ -590,3 +645,51 @@ void NetworkEvents::createZmqContext()
590645 zmqcontext = zmq_ctx_new (); // <-- this is only available in version 3+
591646#endif
592647}
648+
649+ StringPairArray NetworkEvents::parseNetworkMessage (String msg)
650+ {
651+ StringArray splitted;
652+ splitted.addTokens (msg, " =" , " " );
653+
654+ StringPairArray dict = StringPairArray ();
655+ String key = " " ;
656+ String value = " " ;
657+ for (int i = 0 ; i<splitted.size () - 1 ; i++)
658+ {
659+ String s1 = splitted[i];
660+ String s2 = splitted[i + 1 ];
661+
662+ /* * Get key */
663+ if (!key.isEmpty ())
664+ {
665+ if (s1.contains (" " ))
666+ {
667+ int i1 = s1.lastIndexOf (" " );
668+ key = s1.substring (i1 + 1 );
669+ }
670+ else
671+ {
672+ key = s1;
673+ }
674+ }
675+ else
676+ {
677+ key = s1.trim ();
678+ }
679+
680+ /* * Get value */
681+ if (i < splitted.size () - 2 )
682+ {
683+ int i1 = s2.lastIndexOf (" " );
684+ value = s2.substring (0 , i1);
685+ }
686+ else
687+ {
688+ value = s2;
689+ }
690+
691+ dict.set (key, value);
692+ }
693+
694+ return dict;
695+ }
0 commit comments