Line data Source code
1 : /********************************************************************************
2 : * Copyright (c) 2024 Accenture
3 : *
4 : * This program and the accompanying materials are made available under the
5 : * terms of the Apache License Version 2.0 which is available at
6 : * https://www.apache.org/licenses/LICENSE-2.0
7 : *
8 : * SPDX-License-Identifier: Apache-2.0
9 : ********************************************************************************/
10 :
11 : #include "console/AsyncCommandWrapper.h"
12 :
13 : #include "console/AsyncConsole.h"
14 :
15 : #include <async/Async.h>
16 :
17 : namespace console
18 : {
19 1 : AsyncCommandWrapper::AsyncCommandWrapper(
20 1 : ::util::command::ICommand& command, ::async::ContextType context)
21 1 : : fCommand(command), fArguments(), fpSharedOutputStream(nullptr), fContext(context)
22 : {
23 1 : AsyncConsole::addCommand(*this);
24 1 : }
25 :
26 1 : char const* AsyncCommandWrapper::getId() const { return fCommand.getId(); }
27 :
28 0 : void AsyncCommandWrapper::getHelp(::util::command::ICommand::IHelpCallback& callback) const
29 : {
30 0 : fCommand.getHelp(callback);
31 0 : }
32 :
33 0 : ::util::command::ICommand::ExecuteResult AsyncCommandWrapper::execute(
34 : ::util::string::ConstString const& arguments,
35 : ::util::stream::ISharedOutputStream* sharedOutputStream)
36 : {
37 0 : fArguments = arguments;
38 0 : fpSharedOutputStream = sharedOutputStream;
39 :
40 0 : ::async::execute(fContext, *this);
41 :
42 0 : return ::util::command::ICommand::ExecuteResult(::util::command::ICommand::Result::OK);
43 : }
44 :
45 0 : void AsyncCommandWrapper::execute()
46 : {
47 : ::util::command::ICommand::ExecuteResult const result
48 0 : = fCommand.execute(fArguments, fpSharedOutputStream);
49 0 : AsyncConsole::commandExecuted(result);
50 0 : }
51 :
52 : } /* namespace console */
|