diff --git a/generator/CMakeLists.txt b/generator/CMakeLists.txt index 4e169859e8..d3521b1aa0 100644 --- a/generator/CMakeLists.txt +++ b/generator/CMakeLists.txt @@ -27,7 +27,7 @@ endif() function(Generate) set(oneValueArgs LIB_NAME LIB_TYPE PRINT_NAME EXECUTABLE) - set(multiValueArgs COMMAND_LINE_ARGS EXTRA_DEPS SOURCE) + set(multiValueArgs COMMAND_LINE_ARGS EXTRA_DEPS EXTRA_SOURCES) cmake_parse_arguments(G "" "${oneValueArgs}" "${multiValueArgs}" ${ARGN}) execute_process( @@ -57,7 +57,7 @@ function(Generate) ) add_library(${G_LIB_NAME} ${G_LIB_TYPE} - ${G_SOURCE} + ${G_EXTRA_SOURCES} ${OUTPUTS} ) endfunction() diff --git a/src/wire/CMakeLists.txt b/src/wire/CMakeLists.txt index f4f64bd08a..1a68638167 100644 --- a/src/wire/CMakeLists.txt +++ b/src/wire/CMakeLists.txt @@ -23,6 +23,9 @@ Generate( COMMAND_LINE_ARGS ${GENERATOR_COMMON_ARGS} -T wire + EXTRA_SOURCES + ${WIRE_DIR}/WireCmd.cpp + ${WIRE_DIR}/WireCmd.h ) target_include_directories(wire_autogen PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}) target_include_directories(wire_autogen PUBLIC ${GENERATED_DIR}) @@ -31,9 +34,9 @@ SetCXX14(wire_autogen) SetPic(wire_autogen) add_library(nxt_wire STATIC + ${WIRE_DIR}/TerribleCommandBuffer.cpp ${WIRE_DIR}/TerribleCommandBuffer.h - ${WIRE_DIR}/WireCmd.cpp - ${WIRE_DIR}/WireCmd.h + ${WIRE_DIR}/Wire.h ) target_link_libraries(nxt_wire wire_autogen) SetCXX14(nxt_wire) diff --git a/src/wire/TerribleCommandBuffer.cpp b/src/wire/TerribleCommandBuffer.cpp new file mode 100644 index 0000000000..f54f5c6dbd --- /dev/null +++ b/src/wire/TerribleCommandBuffer.cpp @@ -0,0 +1,52 @@ +// Copyright 2017 The NXT Authors +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +#include "TerribleCommandBuffer.h" + +namespace nxt { +namespace wire { + + TerribleCommandBuffer::TerribleCommandBuffer() { + } + + TerribleCommandBuffer::TerribleCommandBuffer(CommandHandler* handler) : handler(handler) { + } + + void TerribleCommandBuffer::SetHandler(CommandHandler* handler) { + this->handler = handler; + } + + void* TerribleCommandBuffer::GetCmdSpace(size_t size) { + if (size > sizeof(buffer)) { + return nullptr; + } + + uint8_t* result = &buffer[offset]; + offset += size; + + if (offset > sizeof(buffer)) { + Flush(); + return GetCmdSpace(size); + } + + return result; + } + + void TerribleCommandBuffer::Flush() { + handler->HandleCommands(buffer, offset); + offset = 0; + } + +} +} diff --git a/src/wire/TerribleCommandBuffer.h b/src/wire/TerribleCommandBuffer.h index c81263ce65..4c0ab5fe66 100644 --- a/src/wire/TerribleCommandBuffer.h +++ b/src/wire/TerribleCommandBuffer.h @@ -24,36 +24,13 @@ namespace wire { class TerribleCommandBuffer : public CommandSerializer { public: - TerribleCommandBuffer() { - } + TerribleCommandBuffer(); + TerribleCommandBuffer(CommandHandler* handler); - TerribleCommandBuffer(CommandHandler* handler) : handler(handler) { - } + void SetHandler(CommandHandler* handler); - void SetHandler(CommandHandler* handler) { - this->handler = handler; - } - - void* GetCmdSpace(size_t size) { - if (size > sizeof(buffer)) { - return nullptr; - } - - uint8_t* result = &buffer[offset]; - offset += size; - - if (offset > sizeof(buffer)) { - Flush(); - return GetCmdSpace(size); - } - - return result; - } - - void Flush() { - handler->HandleCommands(buffer, offset); - offset = 0; - } + void* GetCmdSpace(size_t size) override; + void Flush() override; private: CommandHandler* handler = nullptr;