Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions .github/workflows/build_on_rt.yml
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,9 @@ jobs:
# improvements to hosting and exports of the NILRT toolchain are made.
- name: Install NI Linux RT CC Toolchain
run: |
wget -nv https://download.ni.com/support/softlib/labview/labview_rt/2018/Linux%20Toolchains/linux/oecore-x86_64-core2-64-toolchain-6.0.sh
sudo chmod a+x ./oecore-x86_64-core2-64-toolchain-6.0.sh
sudo ./oecore-x86_64-core2-64-toolchain-6.0.sh -y -d ${GITHUB_WORKSPACE}/nilrt-toolchain/
wget -nv https://download.ni.com/support/softlib/labview/labview_rt/2023Q4/LinuxToolchains/linux/oecore-x86_64-core2-64-toolchain-10.0.sh
sudo chmod a+x ./oecore-x86_64-core2-64-toolchain-10.0.sh
sudo ./oecore-x86_64-core2-64-toolchain-10.0.sh -y -d ${GITHUB_WORKSPACE}/nilrt-toolchain/
echo "${GITHUB_WORKSPACE}/nilrt-toolchain/sysroots/x86_64-nilrtsdk-linux/usr/bin/x86_64-nilrt-linux" >> ${GITHUB_PATH}

- name: Update Submodules
Expand Down
8 changes: 6 additions & 2 deletions .github/workflows/windows_x64_build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,17 @@ jobs:
# well on Windows or Mac. You can convert this to a matrix build if you need
# cross-platform coverage.
# See: https://docs.github.com/en/free-pro-team@latest/actions/learn-github-actions/managing-complex-workflows#using-a-build-matrix
runs-on: windows-2019
runs-on: windows-2022

steps:
- uses: actions/checkout@v4
- uses: ilammy/msvc-dev-cmd@v1
- uses: ilammy/setup-nasm@v1.5.1

- name: Install Visual Studio 2022 Build Tools
run: |
choco install visualstudio2022-workload-vctools --yes || throw "Installation failed"

- name: Update Submodules
working-directory: ${{runner.workspace}}/grpc-labview
run: git submodule update --init --recursive
Expand All @@ -32,7 +36,7 @@ jobs:

- name: Configure CMake
working-directory: ${{runner.workspace}}\grpc-labview\build
run: cmake -G "Visual Studio 16 2019" ..
run: cmake -G "Visual Studio 17 2022" -A x64 ..

- name: Build
working-directory: ${{runner.workspace}}\grpc-labview\build
Expand Down
8 changes: 6 additions & 2 deletions .github/workflows/windows_x86_build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ env:

jobs:
build:
runs-on: windows-2019
runs-on: windows-2022

steps:
- uses: actions/checkout@v4
Expand All @@ -18,6 +18,10 @@ jobs:
arch: x86
- uses: ilammy/setup-nasm@v1.5.1

- name: Install Visual Studio 2022 Build Tools
run: |
choco install visualstudio2022-workload-vctools --yes || throw "Installation failed"

- name: Update Submodules
working-directory: ${{runner.workspace}}/grpc-labview
run: git submodule update --init --recursive
Expand All @@ -27,7 +31,7 @@ jobs:

- name: Configure CMake
working-directory: ${{runner.workspace}}\grpc-labview\build
run: cmake -G "Visual Studio 16 2019" -A Win32 ..
run: cmake -G "Visual Studio 17 2022" -A Win32 ..

- name: Build
working-directory: ${{runner.workspace}}\grpc-labview\build
Expand Down
13 changes: 10 additions & 3 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,18 +1,25 @@
#----------------------------------------------------------------------
#----------------------------------------------------------------------
cmake_minimum_required(VERSION 3.5.1)
cmake_minimum_required(VERSION 3.15)

cmake_policy(SET CMP0091 NEW)

project(labview-grpc C CXX)
set(ABSL_ENABLE_INSTALL ON)

if(NOT MSVC)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++14")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++17")
# Set default visibility to hidden, only export LIBRARY_EXPORT symbols from the shared library
add_compile_options(-fvisibility=hidden)
else()
add_definitions(-D_WIN32_WINNT=0x600)
set(CMAKE_MSVC_RUNTIME_LIBRARY "MultiThreaded$<$<CONFIG:Debug>:Debug>")
set(CMAKE_MSVC_RUNTIME_LIBRARY "MultiThreaded$<$<CONFIG:Debug>:Debug>" CACHE STRING "Use static runtime" FORCE)
set(CMAKE_MSVC_RUNTIME_LIBRARY_DEFAULT "MultiThreaded$<$<CONFIG:Debug>:Debug>" CACHE STRING "Default MSVC runtime library to use static runtime")
set(gRPC_MSVC_STATIC_RUNTIME ON CACHE BOOL "Use static runtime for gRPC" FORCE)
set(protobuf_MSVC_STATIC_RUNTIME ON CACHE BOOL "Use static runtime for protobuf" FORCE)
set(ABSL_MSVC_STATIC_RUNTIME ON CACHE BOOL "Use static runtime for Abseil")
set(CARES_MSVC_STATIC_RUNTIME ON CACHE BOOL "Use static runtime for c-ares")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /std:c++17")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /wd4267 /wd4244")
add_compile_options("$<$<NOT:$<CONFIG:Debug>>:/Zi>")
add_link_options("$<$<NOT:$<CONFIG:Debug>>:/DEBUG>")
Expand Down
2 changes: 1 addition & 1 deletion nilrt-x86_64.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ set(_GRPC_DEVICE_NILRT_LEGACY_TOOLCHAIN TRUE)
#----------------------------------------------------------------------
find_program(COMPILER_PATH x86_64-nilrt-linux-gcc)
get_filename_component(toolchain_path ${COMPILER_PATH}/../../../../.. REALPATH DIRECTORY)
set(include_path core2-64-nilrt-linux/usr/include/c++/6.3.0)
set(include_path core2-64-nilrt-linux/usr/include/c++/10.0)

#----------------------------------------------------------------------
# Compilers
Expand Down
6 changes: 3 additions & 3 deletions src/cluster_copier.cc
Original file line number Diff line number Diff line change
Expand Up @@ -257,7 +257,7 @@ namespace grpc_labview {
{
if (metadata->isRepeated)
{
auto repeatedString = static_cast<const LVRepeatedMessageValue<std::string>&>(*value);
auto repeatedString = static_cast<const LVRepeatedStringMessageValue&>(*value);
if (repeatedString._value.size() != 0)
{
NumericArrayResize(GetTypeCodeForSize(sizeof(LStrHandle)), 1, start, repeatedString._value.size());
Expand Down Expand Up @@ -672,14 +672,14 @@ namespace grpc_labview {
auto arraySize = (array && *array) ? (*array)->cnt : 0;
if (arraySize != 0)
{
auto repeatedStringValue = std::make_shared<LVRepeatedMessageValue<std::string>>(metadata->protobufIndex);
auto repeatedStringValue = std::make_shared<LVRepeatedStringMessageValue>(metadata->protobufIndex);
message._values.emplace(metadata->protobufIndex, repeatedStringValue);
auto lvStr = (*array)->bytes<LStrHandle>();
repeatedStringValue->_value.Reserve(arraySize);
for (int x = 0; x < arraySize; ++x)
{
auto str = GetLVString(*lvStr);
repeatedStringValue->_value.AddAlreadyReserved(std::move(str));
repeatedStringValue->_value.Add(std::move(str));
lvStr += 1;
}
}
Expand Down
3 changes: 3 additions & 0 deletions src/feature_toggles.cc
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,9 @@ namespace grpc_labview {
}

configFile.close();
//TODO: remove this post fixing LVMessageEfficient to let enable feature. See issue: #433
if (featureFlags.find("data_EfficientMessageCopy") != featureFlags.end())
featureFlags["data_EfficientMessageCopy"] = false;
}

// Function to check if a feature is enabled
Expand Down
2 changes: 1 addition & 1 deletion src/feature_toggles.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ namespace grpc_labview {
// Constructor to initialize with default values
FeatureConfig() {
featureFlags["gRPC"] = true; // Enable gRPC by default as an example, this will never be overridden by config file
featureFlags["data_EfficientMessageCopy"] = true;
featureFlags["data_EfficientMessageCopy"] = false;
featureFlags["data_useOccurrence"] = true;
}

Expand Down
6 changes: 3 additions & 3 deletions src/lv_message.cc
Original file line number Diff line number Diff line change
Expand Up @@ -354,16 +354,16 @@ namespace grpc_labview
{
if (fieldInfo.isRepeated)
{
std::shared_ptr<LVRepeatedMessageValue<std::string>> v;
std::shared_ptr<LVRepeatedStringMessageValue> v;
auto it = _values.find(index);
if (it == _values.end())
{
v = std::make_shared<LVRepeatedMessageValue<std::string>>(index);
v = std::make_shared<LVRepeatedStringMessageValue>(index);
_values.emplace(index, v);
}
else
{
v = std::static_pointer_cast<LVRepeatedMessageValue<std::string>>((*it).second);
v = std::static_pointer_cast<LVRepeatedStringMessageValue>((*it).second);
}

auto tagSize = CalculateTagWireSize(tag);
Expand Down
6 changes: 3 additions & 3 deletions src/lv_message.h
Original file line number Diff line number Diff line change
Expand Up @@ -33,14 +33,14 @@ namespace grpc_labview

const char* _InternalParse(const char* ptr, google::protobuf::internal::ParseContext* ctx) override final;
google::protobuf::uint8* _InternalSerialize(google::protobuf::uint8* target, google::protobuf::io::EpsCopyOutputStream* stream) const override final;
void SetCachedSize(int size) const final;
int GetCachedSize(void) const final;
void SetCachedSize(int size) const ;
int GetCachedSize(void) const ;
size_t ByteSizeLong() const final;
virtual void PostInteralParseAction() {};

void MergeFrom(const google::protobuf::Message &from) final;
void MergeFrom(const LVMessage &from);
void CopyFrom(const google::protobuf::Message &from) final;
void CopyFrom(const google::protobuf::Message &from) ;
void CopyFrom(const LVMessage &from);
void CopyOneofIndicesToCluster(int8_t* cluster) const;
void InternalSwap(LVMessage *other);
Expand Down
8 changes: 4 additions & 4 deletions src/lv_message_efficient.cc
Original file line number Diff line number Diff line change
Expand Up @@ -172,9 +172,9 @@ namespace grpc_labview
auto repeatedMessageValuesIt = _repeatedMessageValuesMap.find(fieldInfo.fieldName);
if (repeatedMessageValuesIt == _repeatedMessageValuesMap.end())
{
auto m_val = std::make_shared<RepeatedMessageValue>(fieldInfo, google::protobuf::RepeatedField<char>());
auto m_val = std::make_shared<RepeatedMessageValue>(fieldInfo, google::protobuf::RepeatedPtrField<google::protobuf::Message>());
repeatedMessageValuesIt = _repeatedMessageValuesMap.emplace(fieldInfo.fieldName, m_val).first;
repeatedMessageValuesIt->second.get()->_buffer.Resize(arraySize, _fillData);
repeatedMessageValuesIt->second.get()->_buffer.Reserve(numElements);
}
else
{
Expand All @@ -196,10 +196,10 @@ namespace grpc_labview
{
numElements *= 2;
arraySize = numElements * clusterSize;
repeatedMessageValuesIt->second.get()->_buffer.Resize(arraySize, _fillData);
repeatedMessageValuesIt->second.get()->_buffer.Reserve(numElements);
}

auto nestedMessageCluster = reinterpret_cast<int8_t*>(const_cast<char*>(repeatedMessageValuesIt->second.get()->_buffer.data()));
auto nestedMessageCluster = const_cast<int8_t*>(reinterpret_cast<const int8_t*>(repeatedMessageValuesIt->second.get()->_buffer.data()));
nestedMessageCluster = nestedMessageCluster + (elementIndex * clusterSize);
LVMessageEfficient nestedMessage(metadata, nestedMessageCluster);
protobuf_ptr = ctx->ParseMessage(&nestedMessage, protobuf_ptr);
Expand Down
12 changes: 6 additions & 6 deletions src/lv_message_efficient.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,19 +29,19 @@ namespace grpc_labview
protected:
struct RepeatedMessageValue {
const MessageElementMetadata& _fieldInfo;
google::protobuf::RepeatedField<char> _buffer;
google::protobuf::RepeatedPtrField<google::protobuf::Message> _buffer;
uint64_t _numElements = 0;

RepeatedMessageValue(const MessageElementMetadata& fieldInfo, google::protobuf::RepeatedField<char> buffer) :
RepeatedMessageValue(const MessageElementMetadata& fieldInfo, google::protobuf::RepeatedPtrField<google::protobuf::Message> buffer) :
_fieldInfo(fieldInfo), _buffer(buffer) {}
};

struct RepeatedStringValue {
const MessageElementMetadata& _fieldInfo;
google::protobuf::RepeatedField<std::string> _repeatedString;
google::protobuf::RepeatedPtrField<std::string> _repeatedString;

RepeatedStringValue(const MessageElementMetadata& fieldInfo) :
_fieldInfo(fieldInfo), _repeatedString(google::protobuf::RepeatedField<std::string>()) {}
_fieldInfo(fieldInfo), _repeatedString(google::protobuf::RepeatedPtrField<std::string>()) {}
};

public:
Expand Down Expand Up @@ -91,7 +91,7 @@ namespace grpc_labview
const char* ParseAndCopyRepeatedMessage(const char* ptr, ParseContext* ctx, RepeatedMessageValuePointer v) {

uint64_t numElements;
ptr = PackedMessageType(ptr, ctx, reinterpret_cast<google::protobuf::RepeatedField<MessageType>*>(&(v->_value)));
ptr = PackedMessageType(ptr, ctx, reinterpret_cast<google::protobuf::RepeatedPtrField<MessageType>*>(&(v->_value)));
numElements = v->_value.size();
// get the LVClusterHandle

Expand All @@ -112,7 +112,7 @@ namespace grpc_labview
return ptr;
}

const char* PackedMessageType(const char* ptr, ParseContext* ctx, google::protobuf::RepeatedField<MessageType>* value)
const char* PackedMessageType(const char* ptr, ParseContext* ctx, google::protobuf::RepeatedPtrField<MessageType>* value)
{
return PackedFunc(value, ptr, ctx);
}
Expand Down
17 changes: 11 additions & 6 deletions src/lv_message_value.cc
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ namespace grpc_labview
google::protobuf::uint8* LVNestedMessageMessageValue::Serialize(google::protobuf::uint8* target, google::protobuf::io::EpsCopyOutputStream* stream) const
{
target = stream->EnsureSpace(target);
return WireFormatLite::InternalWriteMessage(_protobufId, *_value, target, stream);
return WireFormatLite::InternalWriteMessage(_protobufId, *_value, _value->GetCachedSize(), target, stream);
}

//---------------------------------------------------------------------
Expand Down Expand Up @@ -67,7 +67,7 @@ namespace grpc_labview
for (unsigned int i = 0, n = static_cast<unsigned int>(_value.size()); i < n; i++)
{
target = stream->EnsureSpace(target);
target = WireFormatLite::InternalWriteMessage(_protobufId, *_value[i], target, stream);
target = WireFormatLite::InternalWriteMessage(_protobufId, *_value[i], _value[i]->GetCachedSize(), target, stream);
}
return target;
}
Expand Down Expand Up @@ -97,8 +97,13 @@ namespace grpc_labview

//---------------------------------------------------------------------
//---------------------------------------------------------------------
template <>
size_t LVRepeatedMessageValue<std::string>::ByteSizeLong()

LVRepeatedStringMessageValue::LVRepeatedStringMessageValue(int protobufId) :
LVMessageValue(protobufId)
{
}

size_t LVRepeatedStringMessageValue::ByteSizeLong()
{
size_t totalSize = 0;
totalSize += WireFormatLite::TagSize(_protobufId, WireFormatLite::TYPE_STRING) * static_cast<unsigned int>(_value.size());
Expand All @@ -111,8 +116,8 @@ namespace grpc_labview

//---------------------------------------------------------------------
//---------------------------------------------------------------------
template <>
google::protobuf::uint8* LVRepeatedMessageValue<std::string>::Serialize(google::protobuf::uint8* target, google::protobuf::io::EpsCopyOutputStream* stream) const

google::protobuf::uint8* LVRepeatedStringMessageValue::Serialize(google::protobuf::uint8* target, google::protobuf::io::EpsCopyOutputStream* stream) const
{
for (int i = 0, n = _value.size(); i < n; i++)
{
Expand Down
15 changes: 15 additions & 0 deletions src/message_value.h
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,7 @@ namespace grpc_labview
google::protobuf::uint8* Serialize(google::protobuf::uint8* target, google::protobuf::io::EpsCopyOutputStream* stream) const override;
};


//---------------------------------------------------------------------
//---------------------------------------------------------------------
class LVRepeatedNestedMessageMessageValue : public LVMessageValue, public gRPCid
Expand Down Expand Up @@ -137,6 +138,20 @@ namespace grpc_labview
google::protobuf::uint8* Serialize(google::protobuf::uint8* target, google::protobuf::io::EpsCopyOutputStream* stream) const override;
};

class LVRepeatedStringMessageValue : public LVMessageValue
{
public:
LVRepeatedStringMessageValue(int protobufId);

public:
google::protobuf::RepeatedPtrField<std::string> _value;

public:
void* RawValue() override { return &_value; };
size_t ByteSizeLong() override;
google::protobuf::uint8* Serialize(google::protobuf::uint8* target, google::protobuf::io::EpsCopyOutputStream* stream) const override;
};


//---------------------------------------------------------------------
//---------------------------------------------------------------------
Expand Down
4 changes: 2 additions & 2 deletions src/proto_parser.cc
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ namespace grpc_labview
std::string GetLVErrorMessage();

private:
std::list<string> _errors;
std::list<std::string> _errors;
};

//---------------------------------------------------------------------
Expand Down Expand Up @@ -140,7 +140,7 @@ namespace grpc_labview

//---------------------------------------------------------------------
//---------------------------------------------------------------------
void AddFieldError(FieldDescriptor* field, string message)
void AddFieldError(FieldDescriptor* field, std::string message)
{
grpc_labview::LVProtoParser::s_Parser->m_ErrorCollector.AddError("", 0, 0, message);
}
Expand Down
6 changes: 3 additions & 3 deletions src/well_known_messages.cc
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ namespace grpc_labview
// Protect against a malformed message where the amount of data sent doesn't match the dimension sizes.
// LV will automatically pad/handle writing less data than was allocated to the array so we just need
// to make sure we don't write more data than was allocated to the array.
auto dataValue = std::static_pointer_cast<const LVRepeatedMessageValue<std::string>>(dataFieldValue);
auto dataValue = std::static_pointer_cast<const LVRepeatedStringMessageValue>(dataFieldValue);
auto stringElements = dataValue->_value.size();
auto stringsToCopy = std::min(elementCount, stringElements);
auto lvString = (*array)->bytes<LStrHandle>();
Expand All @@ -128,12 +128,12 @@ namespace grpc_labview
void String2DArray::CopyArrayFromClusterToMessage(int totalElements, LV2DArrayHandle array, const std::shared_ptr<LVMessageValue>& dataFieldValue)
{
auto lvStr = (*array)->bytes<LStrHandle>();
auto dataValue = std::static_pointer_cast<LVRepeatedMessageValue<std::string>>(dataFieldValue);
auto dataValue = std::static_pointer_cast<LVRepeatedStringMessageValue>(dataFieldValue);
dataValue->_value.Reserve(totalElements);
for (int i = 0; i < totalElements; i++)
{
auto str = GetLVString(*lvStr);
dataValue->_value.AddAlreadyReserved(std::move(str));
dataValue->_value.Add(std::move(str));
lvStr += 1;
}
}
Expand Down
12 changes: 11 additions & 1 deletion src/well_known_messages.h
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,17 @@ namespace grpc_labview
arrayMessage->_values.emplace(_rowsIndex, rowsValue);
auto columnsValue = std::make_shared<LVVariableMessageValue<int>>(_columnsIndex, columns);
arrayMessage->_values.emplace(_columnsIndex, columnsValue);
auto dataValue = std::make_shared<LVRepeatedMessageValue<TRepeatedType>>(_dataIndex);

std::shared_ptr<LVMessageValue> dataValue;
if constexpr (std::is_same<TRepeatedType, std::string>::value)
{
dataValue = std::make_shared<LVRepeatedStringMessageValue>(_dataIndex);
}
else
{
dataValue = std::make_shared<LVRepeatedMessageValue<TRepeatedType>>(_dataIndex);
}

arrayMessage->_values.emplace(_dataIndex, dataValue);

CopyArrayFromClusterToMessage(rows * columns, array, dataValue);
Expand Down
Loading
Loading