From 605ee9669a5cd4d2f69ca8adcbe96c9e62671b87 Mon Sep 17 00:00:00 2001 From: Alexander Gavrilov Date: Thu, 15 Mar 2012 14:06:50 +0400 Subject: [PATCH] Plugin-exported functions now actually work. --- library/CMakeLists.txt | 18 ++++++++++-------- library/RemoteClient.cpp | 4 ++-- library/RemoteServer.cpp | 1 + library/include/RemoteClient.h | 4 ++-- plugins/CMakeLists.txt | 3 ++- 5 files changed, 17 insertions(+), 13 deletions(-) diff --git a/library/CMakeLists.txt b/library/CMakeLists.txt index 0bda587a7..f062be875 100644 --- a/library/CMakeLists.txt +++ b/library/CMakeLists.txt @@ -216,10 +216,11 @@ ENDIF() ADD_LIBRARY(dfhack SHARED ${PROJECT_SOURCES}) ADD_DEPENDENCIES(dfhack generate_headers) -ADD_EXECUTABLE(dfhack-run dfhack-run.cpp - RemoteClient.cpp ColorText.cpp MiscUtils.cpp - ${PROJECT_PROTO_SRCS}) -ADD_DEPENDENCIES(dfhack-run dfhack) +ADD_LIBRARY(dfhack-client SHARED RemoteClient.cpp ColorText.cpp MiscUtils.cpp + proto/CoreProtocol.pb.cc) +ADD_DEPENDENCIES(dfhack-client dfhack) + +ADD_EXECUTABLE(dfhack-run dfhack-run.cpp) IF(BUILD_EGGY) SET_TARGET_PROPERTIES(dfhack PROPERTIES OUTPUT_NAME "egg" ) @@ -231,10 +232,10 @@ endif() IF(WIN32) SET_TARGET_PROPERTIES(dfhack PROPERTIES COMPILE_FLAGS "/FI\"Export.h\"" ) - SET_TARGET_PROPERTIES(dfhack-run PROPERTIES COMPILE_FLAGS "/FI\"Export.h\"" ) + SET_TARGET_PROPERTIES(dfhack-client PROPERTIES COMPILE_FLAGS "/FI\"Export.h\"" ) ELSE() SET_TARGET_PROPERTIES(dfhack PROPERTIES COMPILE_FLAGS "-include Export.h" ) - SET_TARGET_PROPERTIES(dfhack-run PROPERTIES COMPILE_FLAGS "-include Export.h" ) + SET_TARGET_PROPERTIES(dfhack-client PROPERTIES COMPILE_FLAGS "-include Export.h" ) ENDIF() #effectively disables debug builds... @@ -243,7 +244,8 @@ SET_TARGET_PROPERTIES(dfhack PROPERTIES DEBUG_POSTFIX "-debug" ) TARGET_LINK_LIBRARIES(dfhack protobuf-lite clsocket ${PROJECT_LIBS}) SET_TARGET_PROPERTIES(dfhack PROPERTIES LINK_INTERFACE_LIBRARIES "") -TARGET_LINK_LIBRARIES(dfhack-run protobuf-lite clsocket) +TARGET_LINK_LIBRARIES(dfhack-client protobuf-lite clsocket) +TARGET_LINK_LIBRARIES(dfhack-run dfhack-client) IF(UNIX) # On linux, copy our version of the df launch script which sets LD_PRELOAD @@ -277,7 +279,7 @@ install(FILES xml/symbols.xml install(FILES ../dfhack.init-example DESTINATION ${DFHACK_BINARY_DESTINATION}) -install(TARGETS dfhack-run +install(TARGETS dfhack-run dfhack-client LIBRARY DESTINATION ${DFHACK_LIBRARY_DESTINATION} RUNTIME DESTINATION ${DFHACK_LIBRARY_DESTINATION}) diff --git a/library/RemoteClient.cpp b/library/RemoteClient.cpp index 6f284dd15..f8d3e3e7e 100644 --- a/library/RemoteClient.cpp +++ b/library/RemoteClient.cpp @@ -215,7 +215,7 @@ bool RemoteClient::bind(color_ostream &out, RemoteFunctionBase *function, in->set_output_msg(function->p_out_template->GetTypeName()); } - if (bind_call.execute(out) != CR_OK) + if (bind_call(out) != CR_OK) return false; function->p_client = this; @@ -239,7 +239,7 @@ command_result RemoteClient::run_command(color_ostream &out, const std::string & for (size_t i = 0; i < args.size(); i++) runcmd_call.in()->add_arguments(args[i]); - return runcmd_call.execute(out); + return runcmd_call(out); } void RPCFunctionBase::reset(bool free) diff --git a/library/RemoteServer.cpp b/library/RemoteServer.cpp index 9d55da120..14b64f19e 100644 --- a/library/RemoteServer.cpp +++ b/library/RemoteServer.cpp @@ -192,6 +192,7 @@ ServerFunctionBase *ServerConnection::findFunction(color_ostream &out, const std return NULL; } + svc->finalize(this, &functions); plugin_services[plugin] = svc; } } diff --git a/library/include/RemoteClient.h b/library/include/RemoteClient.h index 1b468694d..79efff977 100644 --- a/library/include/RemoteClient.h +++ b/library/include/RemoteClient.h @@ -171,7 +171,7 @@ namespace DFHack RemoteFunction() : RemoteFunctionBase(&In::default_instance(), &Out::default_instance()) {} - command_result execute(color_ostream &stream) { + command_result operator() (color_ostream &stream) { return RemoteFunctionBase::execute(stream, in(), out()); } command_result operator() (color_ostream &stream, const In *input, Out *output) { @@ -187,7 +187,7 @@ namespace DFHack RemoteFunction() : RemoteFunctionBase(&In::default_instance(), &EmptyMessage::default_instance()) {} - command_result execute(color_ostream &stream) { + command_result operator() (color_ostream &stream) { return RemoteFunctionBase::execute(stream, in(), out()); } command_result operator() (color_ostream &stream, const In *input) { diff --git a/plugins/CMakeLists.txt b/plugins/CMakeLists.txt index fe00fbafb..1574b5a28 100644 --- a/plugins/CMakeLists.txt +++ b/plugins/CMakeLists.txt @@ -53,7 +53,8 @@ STRING(REPLACE ".proto" ".pb.h" PROJECT_PROTO_HDRS "${PROJECT_PROTOS}") ADD_CUSTOM_COMMAND( OUTPUT ${PROJECT_PROTO_SRCS} ${PROJECT_PROTO_HDRS} - COMMAND protoc-bin -I=${dfhack_SOURCE_DIR}/proto/ -I=${CMAKE_CURRENT_SOURCE_DIR}/proto/ + COMMAND protoc-bin -I=${dfhack_SOURCE_DIR}/library/proto/ + -I=${CMAKE_CURRENT_SOURCE_DIR}/proto/ --cpp_out=${CMAKE_CURRENT_SOURCE_DIR}/proto/ ${PROJECT_PROTOS} DEPENDS protoc-bin ${PROJECT_PROTOS}