@@ -364,6 +364,43 @@ StreamCommander::DefaultCallbackFunction StreamCommander::getDefaultCallback()
364364 return this ->defaultCallbackFunction ;
365365}
366366
367+ void StreamCommander::executeCommand ( String command, String arguments )
368+ {
369+ // Send an Echo
370+ if ( shouldEchoCommands () )
371+ {
372+ if ( arguments.length () )
373+ {
374+ sendEcho ( command + " " + arguments );
375+ }
376+ else
377+ {
378+ sendEcho ( command );
379+ }
380+ }
381+
382+ // Try to find our input-command and execute it
383+ CommandContainer * container = getCommandContainer ( command );
384+
385+ // If a container for this command has been found, try to call the callback
386+ if ( container != nullptr )
387+ {
388+ if ( container->callbackFunction != nullptr )
389+ {
390+ // Call our Callback-Function with the arguments and our object-instance
391+ container->callbackFunction ( arguments, this );
392+ }
393+ else
394+ {
395+ sendError ( " Command callback function for command '" + command + " ' is empty." );
396+ }
397+ }
398+ else
399+ {
400+ getDefaultCallback ()( command, arguments, this );
401+ }
402+ }
403+
367404void StreamCommander::fetchCommand ()
368405{
369406 Stream * streamInstance = getStreamInstance ();
@@ -419,39 +456,7 @@ void StreamCommander::fetchCommand()
419456
420457 command = commandBuffer.substring ( 0 , commandEnd );
421458
422- // Send an Echo
423- if ( shouldEchoCommands () )
424- {
425- if ( arguments.length () )
426- {
427- sendEcho ( command + " " + arguments );
428- }
429- else
430- {
431- sendEcho ( command );
432- }
433- }
434-
435- // Try to find our input-command and execute it
436- CommandContainer * container = getCommandContainer ( command );
437-
438- // If a container for this command has been found, try to call the callback
439- if ( container != nullptr )
440- {
441- if ( container->callbackFunction != nullptr )
442- {
443- // Call our Callback-Function with the arguments and our object-instance
444- container->callbackFunction ( arguments, this );
445- }
446- else
447- {
448- sendError ( " Command callback function for command '" + command + " ' is empty." );
449- }
450- }
451- else
452- {
453- getDefaultCallback ()( command, arguments, this );
454- }
459+ executeCommand ( command, arguments );
455460}
456461
457462void StreamCommander::sendMessage ( String type, String content )
0 commit comments