Wire: Move the logic of [de]serialization in WireCmd.

This will help with follow-up changes that add support for a more
complete grammer of types, including structures containing pointers
to objects or other structures.

Instead of having the wire::Client and wire::Server directly act on
buffer memory, a couple interfaces are introduced so that WireCmd can do
things like get the object<->id mapping and temporary allocations.

While the serialization and deserialization of most commands was moved
into WireCmd, the commands that don't directly correspond to NXT methods
have their logic moved inside Client and Server and will be made to
expose the new interface in a follow-up commit.
This commit is contained in:
Corentin Wallez
2018-06-06 17:36:49 +02:00
committed by Corentin Wallez
parent 419e9841a8
commit 88fb8fa353
10 changed files with 496 additions and 351 deletions

View File

@@ -25,7 +25,6 @@ Generate(
${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})

View File

@@ -31,7 +31,7 @@ namespace nxt { namespace wire {
return nullptr;
}
uint8_t* result = &mBuffer[mOffset];
char* result = &mBuffer[mOffset];
mOffset += size;
if (mOffset > sizeof(mBuffer)) {

View File

@@ -34,7 +34,7 @@ namespace nxt { namespace wire {
private:
CommandHandler* mHandler = nullptr;
size_t mOffset = 0;
uint8_t mBuffer[10000000];
char mBuffer[10000000];
};
}} // namespace nxt::wire

View File

@@ -31,7 +31,7 @@ namespace nxt { namespace wire {
class CommandHandler {
public:
virtual ~CommandHandler() = default;
virtual const uint8_t* HandleCommands(const uint8_t* commands, size_t size) = 0;
virtual const char* HandleCommands(const char* commands, size_t size) = 0;
};
CommandHandler* NewClientDevice(nxtProcTable* procs,

View File

@@ -1,47 +0,0 @@
// 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 "wire/WireCmd.h"
namespace nxt { namespace wire {
size_t ReturnDeviceErrorCallbackCmd::GetRequiredSize() const {
return sizeof(*this) + messageStrlen + 1;
}
char* ReturnDeviceErrorCallbackCmd::GetMessage() {
return reinterpret_cast<char*>(this + 1);
}
const char* ReturnDeviceErrorCallbackCmd::GetMessage() const {
return reinterpret_cast<const char*>(this + 1);
}
size_t BufferMapReadAsyncCmd::GetRequiredSize() const {
return sizeof(*this);
}
size_t ReturnBufferMapReadAsyncCallbackCmd::GetRequiredSize() const {
return sizeof(*this) + dataLength;
}
void* ReturnBufferMapReadAsyncCallbackCmd::GetData() {
return this + 1;
}
const void* ReturnBufferMapReadAsyncCallbackCmd::GetData() const {
return this + 1;
}
}} // namespace nxt::wire

View File

@@ -15,6 +15,8 @@
#ifndef WIRE_WIRECMD_H_
#define WIRE_WIRECMD_H_
#include <nxt/nxt.h>
#include "wire/WireCmd_autogen.h"
namespace nxt { namespace wire {
@@ -23,10 +25,6 @@ namespace nxt { namespace wire {
wire::ReturnWireCmd commandId = ReturnWireCmd::DeviceErrorCallback;
size_t messageStrlen;
size_t GetRequiredSize() const;
char* GetMessage();
const char* GetMessage() const;
};
struct BufferMapReadAsyncCmd {
@@ -36,8 +34,6 @@ namespace nxt { namespace wire {
uint32_t requestSerial;
uint32_t start;
uint32_t size;
size_t GetRequiredSize() const;
};
struct ReturnBufferMapReadAsyncCallbackCmd {
@@ -48,10 +44,6 @@ namespace nxt { namespace wire {
uint32_t requestSerial;
uint32_t status;
uint32_t dataLength;
size_t GetRequiredSize() const;
void* GetData();
const void* GetData() const;
};
}} // namespace nxt::wire