Skip to content

Commit

Permalink
cli: refactor cli related code (#156)
Browse files Browse the repository at this point in the history
  • Loading branch information
shengofsun authored and Wu Tao committed Sep 13, 2018
1 parent eda8d7e commit a25bc1c
Show file tree
Hide file tree
Showing 101 changed files with 282 additions and 518 deletions.
1 change: 1 addition & 0 deletions bin/dsn.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -282,6 +282,7 @@ function(dsn_setup_compiler_flags)
add_compile_options(-Wno-unused-variable)
add_compile_options(-Wno-deprecated-declarations)
add_compile_options(-Wno-inconsistent-missing-override)
add_compile_options(-Wno-attributes)

find_program(CCACHE_FOUND ccache)
if(CCACHE_FOUND)
Expand Down
8 changes: 4 additions & 4 deletions compile_thrift.py
Original file line number Diff line number Diff line change
Expand Up @@ -100,20 +100,20 @@
},
{
"name": "cli",
"path": "src/apps/cli",
"path": "src/dist/cli",
"file_move": {
".types.h _types.h": "include/dsn/tool/cli"
".types.h _types.h": "include/dsn/dist/cli"
},
"include_fix": {
"_types.h": {
"remove": ["\"dsn_types.h\""]
},
"_types.cpp": {
"add": ["<dsn/tool/cli.h>"],
"add": ["<dsn/dist/cli/cli_types.h>"],
"remove": ["\"cli_types.h\""]
},
".types.h": {
"add": ["<dsn/tool/cli/cli_types.h>"],
"add": ["<dsn/dist/cli/cli_types.h>"],
"remove": ["\"cli_types.h\""]
}
}
Expand Down
6 changes: 5 additions & 1 deletion include/dsn/cpp/message_utils.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,12 @@

#pragma once

#include <dsn/tool/cli.h>
#include <dsn/utility/string_view.h>
#include <dsn/utility/binary_writer.h>
#include <dsn/utility/binary_reader.h>
#include <dsn/cpp/rpc_stream.h>
#include <dsn/cpp/serialization.h>
#include <dsn/tool-api/rpc_message.h>

namespace dsn {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,8 @@
#include <dsn/utility/optional.h>
#include <dsn/tool-api/task_tracker.h>
#include <dsn/tool-api/async_calls.h>
#include <dsn/tool/cli.h>
#include <dsn/dist/cli/cli.code.definition.h>
#include <dsn/dist/cli/cli.types.h>
#include <iostream>

namespace dsn {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,4 @@ namespace dsn {
// define your own thread pool using DEFINE_THREAD_POOL_CODE(xxx)
// define RPC task code for service 'cli'
DEFINE_TASK_CODE_RPC(RPC_CLI_CLI_CALL, TASK_PRIORITY_COMMON, ::dsn::THREAD_POOL_DEFAULT)
// test timer task code
DEFINE_TASK_CODE(LPC_CLI_TEST_TIMER, TASK_PRIORITY_COMMON, ::dsn::THREAD_POOL_DEFAULT)
}
60 changes: 60 additions & 0 deletions include/dsn/dist/cli/cli.server.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
/*
* The MIT License (MIT)
*
* Copyright (c) 2015 Microsoft Corporation
*
* -=- Robust Distributed System Nucleus (rDSN) -=-
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/

#pragma once
#include <iostream>
#include <dsn/cpp/serverlet.h>
#include <dsn/dist/cli/cli.code.definition.h>
#include <dsn/dist/cli/cli.types.h>

namespace dsn {
class cli_service : public ::dsn::serverlet<cli_service>
{
public:
static std::unique_ptr<cli_service> create_service();

public:
cli_service() : ::dsn::serverlet<cli_service>("cli") {}
virtual ~cli_service() {}

protected:
// all service handlers to be implemented further
// RPC_CLI_CLI_CALL
virtual void on_call(const command &request, ::dsn::rpc_replier<std::string> &reply)
{
std::cout << "... exec RPC_CLI_CLI_CALL ... (not implemented) " << std::endl;
std::string resp;
reply(resp);
}

public:
void open_service()
{
this->register_async_rpc_handler(RPC_CLI_CLI_CALL, "call", &cli_service::on_call);
}
void close_service() { this->unregister_rpc_handler(RPC_CLI_CLI_CALL); }
};
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#pragma once
#include <dsn/tool/cli/cli_types.h>
#include <dsn/dist/cli/cli_types.h>
#include <dsn/service_api_cpp.h>
#include <dsn/cpp/serialization.h>

Expand All @@ -9,4 +9,4 @@
namespace dsn {
GENERATED_TYPE_SERIALIZATION(command, THRIFT)

}
}
File renamed without changes.
10 changes: 1 addition & 9 deletions include/dsn/tool-api/command_manager.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@

#include <dsn/utility/synchronize.h>
#include <dsn/utility/singleton.h>
#include <dsn/tool-api/rpc_message.h>
#include <dsn/c/api_utilities.h>
#include <map>

namespace dsn {
Expand All @@ -48,21 +48,13 @@ class command_manager : public ::dsn::utils::singleton<command_manager>
const std::string &help_long,
command_handler handler);
void deregister_command(dsn_handle_t handle);

bool run_command(const std::string &cmdline, /*out*/ std::string &output);
void start_remote_cli();
void on_remote_cli(dsn::message_ex* req);
void set_cli_target_address(dsn_handle_t handle, dsn::rpc_address address);

private:
bool run_command(const std::string &cmd,
const std::vector<std::string> &args,
/*out*/ std::string &output);

private:
struct command_instance
{
dsn::rpc_address address;
std::vector<std::string> commands;
std::string help_short;
std::string help_long;
Expand Down
5 changes: 0 additions & 5 deletions include/dsn/tool/cli.h

This file was deleted.

1 change: 0 additions & 1 deletion src/apps/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,2 @@
add_subdirectory(echo)
add_subdirectory(skv)
add_subdirectory(cli)
153 changes: 0 additions & 153 deletions src/apps/cli/cli_types.cpp

This file was deleted.

4 changes: 0 additions & 4 deletions src/apps/echo/config.ini
Original file line number Diff line number Diff line change
Expand Up @@ -83,11 +83,7 @@ aio_aspects =
; asynchonous file system provider
aio_factory_name =

; whether to enable local command line interface (cli)
cli_local = false

; whether to enable remote command line interface (using dsn.cli)
cli_remote = false

; where to put the core dump files
coredump_dir = ./coredump
Expand Down
4 changes: 0 additions & 4 deletions src/core/core/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,9 +1,5 @@
set(MY_PROJ_NAME dsn.core)

# Source files under CURRENT project directory will be automatically included.
# You can manually set MY_PROJ_SRC to include source files under other directories.
set(MY_PROJ_SRC "../../apps/cli/cli_types.cpp")

# Search mode for source files under CURRENT project directory?
# "GLOB_RECURSE" for recursive search
# "GLOB" for non-recursive search
Expand Down
Loading

0 comments on commit a25bc1c

Please sign in to comment.