Skip to content

Commit

Permalink
Merge pull request #62 from sonndinh/update-value-reader-writer-api
Browse files Browse the repository at this point in the history
Update value reader and value writer implementation
  • Loading branch information
jrw972 authored Apr 1, 2024
2 parents 3e52b90 + 84eaad4 commit 0517ddf
Show file tree
Hide file tree
Showing 15 changed files with 362 additions and 218 deletions.
39 changes: 18 additions & 21 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,9 @@ concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: true

# The jobs with latest-release configuration are disabled until OpenDDS 3.28
# which will have the updated ValueReader and ValueWriter interfaces.

jobs:
build:
strategy:
Expand All @@ -24,27 +27,14 @@ jobs:
- 20
opendds_branch:
- master
- latest-release
#- latest-release
m:
- {os: ubuntu-22.04, dds_security: 1}
- {os: ubuntu-22.04, dds_security: 0}
- {os: macos-12, dds_security: 1}
- {os: macos-12, dds_security: 0}
- {os: windows-2022, dds_security: 1}
- {os: windows-2022, dds_security: 0}
include:
- node_version: 18
opendds_branch: latest-release
m: {os: ubuntu-22.04, security: 0}
- node_version: 18
opendds_branch: latest-release
m: {os: windows-2022, security: 0}
- node_version: 20
opendds_branch: latest-release
m: {os: ubuntu-22.04, security: 1}
- node_version: 20
opendds_branch: latest-release
m: {os: windows-2022, security: 1}

runs-on: ${{ matrix.m.os }}
steps:
Expand All @@ -65,25 +55,25 @@ jobs:
- name: 'Checkout OpenDDS'
uses: actions/checkout@v3
with:
repository: objectcomputing/OpenDDS
repository: OpenDDS/OpenDDS
ref: ${{ matrix.opendds_branch }}
path: OpenDDS
fetch-depth: 1
- name: 'Set Up node'
uses: actions/setup-node@v3
with:
node-version: ${{ matrix.node_version }}
- name: 'Install ssl and xerces (ubuntu)'
- name: 'Install xerces (ubuntu)'
if: ${{ matrix.m.dds_security == 1 && matrix.m.os == 'ubuntu-22.04' }}
run: |-
sudo apt-get update
sudo apt-get -y install libssl-dev libxerces-c-dev
sudo apt-get -y install libxerces-c-dev
- name: 'Install xerces (macos)'
if: ${{ matrix.m.dds_security == 1 && matrix.m.os == 'macos-12' }}
run: |
brew install xerces-c
- name: Setup for run-vcpkg
if: runner.os == 'Windows'
if: ${{ matrix.m.dds_security == 1 && matrix.m.os == 'windows-2022' }}
shell: cmd
run: |
echo { "name": "opendds", "version-string": "github-actions", "dependencies": [ "openssl", "xerces-c" ] } > vcpkg.json
Expand Down Expand Up @@ -136,7 +126,7 @@ jobs:
echo "npm_config_devdir=$GITHUB_WORKSPACE\\opendds-node-gyp-devdir" >> $GITHUB_ENV
if [ ${{ matrix.m.dds_security }} == 1 ]; then
CONFIG_OPTIONS+=" --security"
CONFIG_OPTIONS+=" --xerces3=$VCPKG_ROOT\\installed\\x64-windows --openssl=$VCPKG_ROOT\\installed\\x64-windows"
CONFIG_OPTIONS+=" --xerces3=$VCPKG_INSTALLED_DIR\\x64-windows --openssl=$VCPKG_INSTALLED_DIR\\x64-windows"
BUILD_TARGETS+=";OpenDDS_Security"
fi
echo "CONFIG_OPTIONS=$CONFIG_OPTIONS" >> $GITHUB_ENV
Expand All @@ -151,7 +141,7 @@ jobs:
./configure --no-tests ${{ env.CONFIG_OPTIONS }}
tools/scripts/show_build_config.pl
. setenv.sh
make -j3 ${{ env.BUILD_TARGETS }}
make -j$(getconf _NPROCESSORS_ONLN) ${{ env.BUILD_TARGETS }}
- name: 'Configure OpenDDS (windows)'
if: ${{ matrix.m.os == 'windows-2022' }}
shell: cmd
Expand All @@ -173,7 +163,14 @@ jobs:
run: |-
npm install
${{ env.ACE_ROOT }}/bin/mwc.pl -type gnuace -exclude ACE_TAO,OpenDDS
make -j2 || make
make -j$(getconf _NPROCESSORS_ONLN) || make
- name: Install gdb (ubuntu)
if: ${{ matrix.m.os == 'ubuntu-22.04' }}
shell: bash
run: |
sudo apt-get update
sudo apt-get install gdb
echo 0 | sudo tee /proc/sys/kernel/yama/ptrace_scope
- name: 'Change Core File Pattern (ubuntu)'
if: ${{ matrix.m.os == 'ubuntu-22.04' }}
shell: bash
Expand Down
14 changes: 7 additions & 7 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
},
"repository": {
"type": "git",
"url": "http://github.com/oci-labs/node-opendds.git"
"url": "https://github.com/OpenDDS/node-opendds.git"
},
"keywords": [
"dds",
Expand All @@ -27,6 +27,6 @@
"license": "BSD-3-Clause",
"gypfile": true,
"dependencies": {
"nan": "^2.16.0"
"nan": "^2.19.0"
}
}
12 changes: 11 additions & 1 deletion src/NodeDRListener.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -124,8 +124,18 @@ void NodeDRListener::push_back(const DDS::SampleInfo& src, const void* sample)
return;
}

// TODO: When OpenDDS's vwrite works with key-only samples, e.g. from a dispose or
// unregister_instance call on the writer, this can be removed so that those samples
// can be delivered to the Javascript side.
if (!src.valid_data) {
return;
}

if (vd_) {
vd_->write(nvw_, sample);
if (!vd_->write(nvw_, sample)) {
ACE_ERROR((LM_WARNING, "WARNING: ValueDispatcher write failed\n"));
return;
}
}

Local<Value> argv[] = {
Expand Down
78 changes: 64 additions & 14 deletions src/NodeValueReader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,16 +29,15 @@ struct ToFactory<v8::BigInt> : ToFactoryBase<v8::BigInt> {
namespace NodeOpenDDS {

NodeValueReader::NodeValueReader(v8::Local<v8::Object> obj)
: current_index_(0)
, use_name_(false)
{
// Nest initial object so first begin_struct behaves appropriately
current_object_ = Nan::New<v8::Object>();
Nan::Set(current_object_, 0, obj);

current_index_ = 0;
use_name_ = false;
}

bool NodeValueReader::begin_struct()
bool NodeValueReader::begin_struct(OpenDDS::DCPS::Extensibility /*extensibility*/)
{
return begin_nested();
}
Expand All @@ -49,30 +48,52 @@ bool NodeValueReader::end_struct()
}

bool NodeValueReader::begin_struct_member(OpenDDS::XTypes::MemberId& member_id, const OpenDDS::DCPS::MemberHelper& helper)
{
while (members_remaining()) {
Nan::MaybeLocal<v8::Value> mlv = Nan::Get(property_names_.ToLocalChecked(), current_index_);
// mlv is not empty at this point.
current_property_name_ = mlv.ToLocalChecked();
Nan::Utf8String name(current_property_name_);
if (helper.get_value(member_id, *name)) {
return true;
}
++current_index_;
}
return false;
}

bool NodeValueReader::members_remaining()
{
if (!property_names_.IsEmpty()) {
while (property_names_.ToLocalChecked()->Length() > current_index_) {
while (current_index_ < property_names_.ToLocalChecked()->Length()) {
Nan::MaybeLocal<v8::Value> mlv = Nan::Get(property_names_.ToLocalChecked(), current_index_);
if (!mlv.IsEmpty()) {
current_property_name_ = mlv.ToLocalChecked();
Nan::Utf8String name(current_property_name_);
if (helper.get_value(member_id, *name)) {
return true;
}
return true;
}
++current_index_;
}
}
return false;
}

bool NodeValueReader::member_has_value()
{
Nan::MaybeLocal<v8::Value> mlvai = current_property_name_.IsEmpty() ?
Nan::Get(current_object_, current_index_) : Nan::Get(current_object_, current_property_name_);
if (!mlvai.IsEmpty()) {
v8::Local<v8::Value> lvai = mlvai.ToLocalChecked();
return !lvai->IsNull();
}
return false;
}

bool NodeValueReader::end_struct_member()
{
++current_index_;
return true;
}

bool NodeValueReader::begin_union()
bool NodeValueReader::begin_union(OpenDDS::DCPS::Extensibility /*extensibility*/)
{
return begin_nested();
}
Expand Down Expand Up @@ -130,7 +151,7 @@ bool NodeValueReader::end_union_member()
return true;
}

bool NodeValueReader::begin_array()
bool NodeValueReader::begin_array(OpenDDS::XTypes::TypeKind /*elem_kind*/)
{
return begin_nested();
}
Expand All @@ -140,7 +161,7 @@ bool NodeValueReader::end_array()
return end_nested();
}

bool NodeValueReader::begin_sequence()
bool NodeValueReader::begin_sequence(OpenDDS::XTypes::TypeKind /*elem_kind*/)
{
return begin_nested();
}
Expand Down Expand Up @@ -290,7 +311,7 @@ bool NodeValueReader::read_float128(long double& value)

#endif

bool NodeValueReader::read_fixed(OpenDDS::FaceTypes::Fixed& /*value*/)
bool NodeValueReader::read_fixed(ACE_CDR::Fixed& /*value*/)
{
return false;
}
Expand Down Expand Up @@ -362,6 +383,35 @@ bool NodeValueReader::read_long_enum(ACE_CDR::Long& value, const OpenDDS::DCPS::
return false;
}

bool NodeValueReader::read_bitmask(ACE_CDR::ULongLong& value, const OpenDDS::DCPS::BitmaskHelper& helper)
{
Nan::MaybeLocal<v8::Value> mlvai = use_name_ ? Nan::Get(current_object_, current_property_name_) : Nan::Get(current_object_, current_index_);
if (!mlvai.IsEmpty() && mlvai.ToLocalChecked()->IsObject()) {
v8::Local<v8::Array> array = v8::Local<v8::Array>::Cast(mlvai.ToLocalChecked());
if (!array.IsEmpty()) {
OPENDDS_VECTOR(OpenDDS::DCPS::String) flag_names(array->Length());
for (uint32_t i = 0; i < array->Length(); ++i) {
Nan::MaybeLocal<v8::Value> mlv = Nan::Get(array, i);
if (mlv.IsEmpty()) {
return false;
}
Nan::MaybeLocal<v8::String> mlstr = Nan::To<v8::String>(mlv.ToLocalChecked());
if (mlstr.IsEmpty()) {
return false;
}
Nan::Utf8String flag(mlstr.ToLocalChecked());
flag_names[i] = *flag;
}

if (helper.get_value(value, flag_names)) {
return true;
}
}
}

return false;
}

bool NodeValueReader::begin_nested()
{
Nan::MaybeLocal<v8::Value> mlvai = use_name_ ? Nan::Get(current_object_, current_property_name_) : Nan::Get(current_object_, current_index_);
Expand Down
13 changes: 8 additions & 5 deletions src/NodeValueReader.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,21 +27,23 @@ class NodeValueReader : public OpenDDS::DCPS::ValueReader {
public:
explicit NodeValueReader(v8::Local<v8::Object> obj);

bool begin_struct();
bool begin_struct(OpenDDS::DCPS::Extensibility extensibility);
bool end_struct();
bool begin_struct_member(OpenDDS::XTypes::MemberId& member_id, const OpenDDS::DCPS::MemberHelper& helper);
bool members_remaining();
bool member_has_value();
bool end_struct_member();

bool begin_union();
bool begin_union(OpenDDS::DCPS::Extensibility extensibility);
bool end_union();
bool begin_discriminator();
bool end_discriminator();
bool begin_union_member();
bool end_union_member();

bool begin_array();
bool begin_array(OpenDDS::XTypes::TypeKind elem_kind);
bool end_array();
bool begin_sequence();
bool begin_sequence(OpenDDS::XTypes::TypeKind elem_kind);
bool elements_remaining();
bool end_sequence();
bool begin_element();
Expand All @@ -67,13 +69,14 @@ class NodeValueReader : public OpenDDS::DCPS::ValueReader {
bool read_float128(long double& value);
#endif

bool read_fixed(OpenDDS::FaceTypes::Fixed& value);
bool read_fixed(ACE_CDR::Fixed& value);
bool read_char8(ACE_CDR::Char& value);
bool read_char16(ACE_CDR::WChar& value);
bool read_string(std::string& value);
bool read_wstring(std::wstring& value);

bool read_long_enum(ACE_CDR::Long& value, const OpenDDS::DCPS::EnumHelper& helper);
bool read_bitmask(ACE_CDR::ULongLong& value, const OpenDDS::DCPS::BitmaskHelper& helper);

private:
NodeValueReader();
Expand Down
Loading

0 comments on commit 0517ddf

Please sign in to comment.