class CommandContext

Defined at line 31 of file ../../src/developer/debug/zxdb/console/command_context.h

This object collects the output and errors from a command and tracks its completion.

The command implementation must keep this object alive for as long as the command executes (which

could be asynchronously). When the CommandContext is destroyed, the callbacks will executed and

the command will be considered complete.

Public Methods

void Output (const OutputBuffer & output)

Writes the given buffer to the output.

void Output (fxl::RefPtr<AsyncOutputBuffer> output)

Synchronously prints the output if the async buffer is complete. Otherwise adds a listener and

prints the output to the console when it is complete.

This call takes a reference to the CommandContext (keeping the command in a non-completed

state) for as long as the AsyncOutputBuffer remains incomplete.

Defined at line 24 of file ../../src/developer/debug/zxdb/console/command_context.cc

void Output (const std::string & s)

Convenience wrapper to output the given string.

Defined at line 37 of file ../../src/developer/debug/zxdb/console/command_context.h

void ReportError (const Err & err)

Reports that the command failed with the given error. The error will be printed to the screen.

ConsoleContext * GetConsoleContext ()

Defined at line 42 of file ../../src/developer/debug/zxdb/console/command_context.cc

Console * console ()

The Console/ConsoleContext may be null if this object has outlived the Console object. In

production this probably won't happen but can be triggered in tests more easily.

If the code calling this function is being used in a synchronous context (i.e. called directly

from a command handler and not from a callback), these pointers are guaranteed non-null.

Defined at line 54 of file ../../src/developer/debug/zxdb/console/command_context.h

bool has_error ()

Returns true if this command context has encountered any error.

Defined at line 55 of file ../../src/developer/debug/zxdb/console/command_context.cc

void SetConsoleCompletionObserver (fit::deferred_callback observer)

Sets the completion observer used by the console to tell when the command is done. This is used

for enabling and disabling input. The callback passed into the constructors of some derived

classes are instead for the creator of the CommandContext (which may not necessarily be the

console).

Since this is currently used only for console integration, it's called the "Console" completion

observer and there can be only one of them. If we have a need for more than one, we can

generalize this in the future.

Defined at line 48 of file ../../src/developer/debug/zxdb/console/command_context.cc

void SetCommandReport (CommandReport other)

Sets the command report for this command. This is called after a command has been successfully

parsed. If the command fails parsing, we use the default constructed |report_| with the error

given to |SetError| by the derived class.

Defined at line 53 of file ../../src/developer/debug/zxdb/console/command_context.cc

const CommandReport & GetCommandReport ()

Defined at line 74 of file ../../src/developer/debug/zxdb/console/command_context.h

Protected Methods

void CommandContext (Console * console)

Console may be null.

Defined at line 15 of file ../../src/developer/debug/zxdb/console/command_context.cc

void ~CommandContext ()

Defined at line 18 of file ../../src/developer/debug/zxdb/console/command_context.cc

void SetError (const Err & err)

Used by derived classes to set the offending error.

Defined at line 57 of file ../../src/developer/debug/zxdb/console/command_context.cc

Friends

class RefCountedThreadSafe