blob: e3856e713c41da0dcc42ac753f3a789c36517bbe [file] [log] [blame]
// Copyright 2019 The Fuchsia Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef SRC_DEVELOPER_CMD_EXECUTOR_H_
#define SRC_DEVELOPER_CMD_EXECUTOR_H_
#include <map>
#include <string>
#include <vector>
#include "src/developer/cmd/command.h"
#include "src/developer/cmd/tasks/task.h"
namespace cmd {
class Executor {
public:
explicit Executor(async_dispatcher_t* dispatcher);
~Executor();
// Execute the given command.
//
// Returns the |zx_status_t| from the executed |Task|. See |Task::Execute| for
// documentation.
zx_status_t Execute(Command command, Task::CompletionCallback callback);
// Terminate the task the executor is currently executing in the foreground, if any.
void KillForegroundTask();
// Offer suggestions for how to complete the given input state.
void Complete(Autocomplete* autocomplete);
private:
std::unique_ptr<Task> FindAndCreateTask(const std::string& name);
void CompleteCommand(Autocomplete* autocomplete);
async_dispatcher_t* dispatcher_;
std::map<std::string, Task::Factory> builtin_commands_;
std::unique_ptr<Task> foreground_task_;
};
} // namespace cmd
#endif // SRC_DEVELOPER_CMD_EXECUTOR_H_