From 19f7a5f1082148b4241333deb6ffe266a806a775 Mon Sep 17 00:00:00 2001 From: Tyler Veness Date: Sat, 19 Aug 2017 23:08:27 -0700 Subject: [PATCH] Set up wpiformat --- .clang-format | 24 +++- .styleguide | 26 ++++ .styleguide-license | 6 + .travis-scripts/install.sh | 11 ++ .travis-scripts/wpiformat.sh | 9 ++ .travis.yml | 5 + CONTRIBUTING.md | 2 +- README.md | 2 +- license.txt | 4 +- manualTests/java/Client.java | 7 + manualTests/java/Server.java | 7 + manualTests/native/client.cpp | 22 +-- manualTests/native/rpc_local.cpp | 22 +-- manualTests/native/rpc_speed.cpp | 29 ++-- manualTests/native/server.cpp | 20 ++- publish.gradle | 4 +- .../java/edu/wpi/first/ntcore/DevMain.java | 31 +++-- src/dev/native/cpp/main.cpp | 16 ++- .../networktables/PersistentException.java | 2 +- .../edu/wpi/first/wpilibj/tables/IRemote.java | 7 + .../tables/IRemoteConnectionListener.java | 7 + .../edu/wpi/first/wpilibj/tables/ITable.java | 7 + .../first/wpilibj/tables/ITableListener.java | 7 + src/main/native/cpp/CallbackManager.h | 26 ++-- src/main/native/cpp/ConnectionNotifier.cpp | 2 +- src/main/native/cpp/ConnectionNotifier.h | 13 +- src/main/native/cpp/Dispatcher.cpp | 11 +- src/main/native/cpp/Dispatcher.h | 19 +-- src/main/native/cpp/DsClient.cpp | 13 +- src/main/native/cpp/DsClient.h | 10 +- src/main/native/cpp/EntryNotifier.cpp | 2 +- src/main/native/cpp/EntryNotifier.h | 17 +-- src/main/native/cpp/Handle.h | 12 +- src/main/native/cpp/IConnectionNotifier.h | 6 +- src/main/native/cpp/IDispatcher.h | 6 +- src/main/native/cpp/IEntryNotifier.h | 7 +- src/main/native/cpp/INetworkConnection.h | 6 +- src/main/native/cpp/IRpcServer.h | 6 +- src/main/native/cpp/IStorage.h | 14 +- src/main/native/cpp/InstanceImpl.h | 10 +- src/main/native/cpp/Log.h | 10 +- src/main/native/cpp/LoggerImpl.cpp | 10 +- src/main/native/cpp/LoggerImpl.h | 13 +- src/main/native/cpp/Message.cpp | 12 +- src/main/native/cpp/Message.h | 8 +- src/main/native/cpp/NetworkConnection.cpp | 15 ++- src/main/native/cpp/NetworkConnection.h | 26 ++-- src/main/native/cpp/RpcServer.cpp | 2 +- src/main/native/cpp/RpcServer.h | 14 +- src/main/native/cpp/SequenceNumber.cpp | 2 +- src/main/native/cpp/SequenceNumber.h | 8 +- src/main/native/cpp/Storage.cpp | 12 +- src/main/native/cpp/Storage.h | 43 +++--- src/main/native/cpp/Storage_load.cpp | 57 ++++---- src/main/native/cpp/Storage_save.cpp | 19 ++- src/main/native/cpp/Value.cpp | 27 ++-- src/main/native/cpp/Value_internal.h | 11 +- src/main/native/cpp/WireDecoder.cpp | 17 +-- src/main/native/cpp/WireDecoder.h | 37 ++--- src/main/native/cpp/WireEncoder.cpp | 57 ++++---- src/main/native/cpp/WireEncoder.h | 38 +++--- .../native/cpp/networktables/NetworkTable.cpp | 36 +++-- .../networktables/NetworkTableInstance.cpp | 3 +- src/main/native/cpp/ntcore_c.cpp | 102 +++++++------- src/main/native/cpp/ntcore_cpp.cpp | 19 +-- src/main/native/cpp/ntcore_test.cpp | 48 +++---- src/main/native/cpp/tables/ITableListener.cpp | 7 + .../networktables/EntryListenerFlags.h | 6 +- .../include/networktables/NetworkTable.h | 20 +-- .../include/networktables/NetworkTableEntry.h | 15 ++- .../networktables/NetworkTableEntry.inl | 2 +- .../networktables/NetworkTableInstance.h | 24 ++-- .../include/networktables/NetworkTableType.h | 6 +- .../include/networktables/NetworkTableValue.h | 82 ++++++------ .../native/include/networktables/RpcCall.h | 9 +- .../networktables/TableEntryListener.h | 8 +- .../include/networktables/TableListener.h | 8 +- src/main/native/include/ntcore.h | 8 +- src/main/native/include/ntcore_c.h | 121 ++++++++--------- src/main/native/include/ntcore_cpp.h | 26 ++-- src/main/native/include/ntcore_test.h | 55 ++++---- src/main/native/include/tables/ITable.h | 18 +-- .../native/include/tables/ITableListener.h | 20 +-- .../networktables/ConnectionListenerTest.java | 7 + .../networktables/EntryListenerTest.java | 7 + .../edu/wpi/first/networktables/JNITest.java | 31 +++-- .../wpi/first/networktables/LoggerTest.java | 7 + .../first/networktables/NetworkTableTest.java | 7 + .../native/cpp/ConnectionListenerTest.cpp | 3 +- src/test/native/cpp/EntryListenerTest.cpp | 3 +- src/test/native/cpp/EntryNotifierTest.cpp | 26 ++-- src/test/native/cpp/MessageMatcher.h | 15 +-- src/test/native/cpp/MockConnectionNotifier.h | 9 +- src/test/native/cpp/MockDispatcher.h | 9 +- src/test/native/cpp/MockEntryNotifier.h | 9 +- src/test/native/cpp/MockNetworkConnection.h | 9 +- src/test/native/cpp/MockRpcServer.h | 9 +- src/test/native/cpp/NetworkTableTest.cpp | 7 +- src/test/native/cpp/StorageTest.cpp | 54 +++----- src/test/native/cpp/StorageTest.h | 15 +-- src/test/native/cpp/TestPrinters.cpp | 1 - src/test/native/cpp/TestPrinters.h | 12 +- src/test/native/cpp/ValueMatcher.h | 9 +- src/test/native/cpp/ValueTest.cpp | 31 +++-- src/test/native/cpp/WireDecoderTest.cpp | 103 +++++++------- src/test/native/cpp/WireEncoderTest.cpp | 126 +++++++++--------- src/test/native/cpp/main.cpp | 5 +- 107 files changed, 1144 insertions(+), 908 deletions(-) create mode 100644 .styleguide create mode 100644 .styleguide-license create mode 100755 .travis-scripts/wpiformat.sh diff --git a/.clang-format b/.clang-format index ed38227..92b4049 100644 --- a/.clang-format +++ b/.clang-format @@ -5,7 +5,7 @@ AccessModifierOffset: -1 AlignAfterOpenBracket: Align AlignConsecutiveAssignments: false AlignConsecutiveDeclarations: false -AlignEscapedNewlinesLeft: true +AlignEscapedNewlines: Left AlignOperands: true AlignTrailingComments: true AllowAllParametersOfDeclarationOnNextLine: true @@ -32,12 +32,20 @@ BraceWrapping: BeforeCatch: false BeforeElse: false IndentBraces: false + SplitEmptyFunction: true + SplitEmptyRecord: true + SplitEmptyNamespace: true BreakBeforeBinaryOperators: None BreakBeforeBraces: Attach +BreakBeforeInheritanceComma: false BreakBeforeTernaryOperators: true BreakConstructorInitializersBeforeComma: false +BreakConstructorInitializers: BeforeColon +BreakAfterJavaFieldAnnotations: false +BreakStringLiterals: true ColumnLimit: 80 CommentPragmas: '^ IWYU pragma:' +CompactNamespaces: false ConstructorInitializerAllOnOneLineOrOnePerLine: true ConstructorInitializerIndentWidth: 4 ContinuationIndentWidth: 4 @@ -45,7 +53,11 @@ Cpp11BracedListStyle: true DerivePointerAlignment: false DisableFormat: false ExperimentalAutoDetectBinPacking: false -ForEachMacros: [ foreach, Q_FOREACH, BOOST_FOREACH ] +FixNamespaceComments: true +ForEachMacros: + - foreach + - Q_FOREACH + - BOOST_FOREACH IncludeCategories: - Regex: '^<.*\.h>' Priority: 1 @@ -53,9 +65,12 @@ IncludeCategories: Priority: 2 - Regex: '.*' Priority: 3 +IncludeIsMainRegex: '([-_](test|unittest))?$' IndentCaseLabels: true IndentWidth: 2 IndentWrappedFunctionNames: false +JavaScriptQuotes: Leave +JavaScriptWrapImports: true KeepEmptyLinesAtTheStartOfBlocks: false MacroBlockBegin: '' MacroBlockEnd: '' @@ -64,6 +79,7 @@ NamespaceIndentation: None ObjCBlockIndentWidth: 2 ObjCSpaceAfterProperty: false ObjCSpaceBeforeProtocolList: false +PenaltyBreakAssignment: 2 PenaltyBreakBeforeFirstCallParameter: 1 PenaltyBreakComment: 300 PenaltyBreakFirstLessLess: 120 @@ -72,8 +88,10 @@ PenaltyExcessCharacter: 1000000 PenaltyReturnTypeOnItsOwnLine: 200 PointerAlignment: Left ReflowComments: true -SortIncludes: true +SortIncludes: false +SortUsingDeclarations: true SpaceAfterCStyleCast: false +SpaceAfterTemplateKeyword: true SpaceBeforeAssignmentOperators: true SpaceBeforeParens: ControlStatements SpaceInEmptyParentheses: false diff --git a/.styleguide b/.styleguide new file mode 100644 index 0000000..9f55f35 --- /dev/null +++ b/.styleguide @@ -0,0 +1,26 @@ +cppHeaderFileInclude { + \.h$ + \.inc$ +} + +cppSrcFileInclude { + \.cpp$ +} + +generatedFileExclude { + gmock/ + llvm/ + src/arm-linux-jni/ + src/main/native/cpp/jni/ +} + +includeGuardRoots { + src/main/native/cpp/ + src/main/native/include/ + src/test/native/cpp/ +} + +includeOtherLibs { + ^llvm/ + ^support/ +} diff --git a/.styleguide-license b/.styleguide-license new file mode 100644 index 0000000..0bb7710 --- /dev/null +++ b/.styleguide-license @@ -0,0 +1,6 @@ +/*----------------------------------------------------------------------------*/ +/* Copyright (c) FIRST {year}. All Rights Reserved.{padding}*/ +/* Open Source Software - may be modified and shared by FRC teams. The code */ +/* must be accompanied by the FIRST BSD license file in the root directory of */ +/* the project. */ +/*----------------------------------------------------------------------------*/ diff --git a/.travis-scripts/install.sh b/.travis-scripts/install.sh index 75d95ce..ff02ce4 100755 --- a/.travis-scripts/install.sh +++ b/.travis-scripts/install.sh @@ -2,7 +2,18 @@ if [[ $TRAVIS_OS_NAME != 'osx' ]]; then # Install custom requirements on Linux + sudo sh -c 'echo "deb http://apt.llvm.org/trusty/ llvm-toolchain-trusty-5.0 main" > /etc/apt/sources.list.d/llvm.list' + wget -O - https://apt.llvm.org/llvm-snapshot.gpg.key|sudo apt-key add - sudo add-apt-repository ppa:wpilib/toolchain -y sudo apt-get update -q sudo apt-get install frc-toolchain -y + + wget https://bootstrap.pypa.io/get-pip.py + sudo python3.5 get-pip.py + python3.5 -m pip install --user wpiformat +else + brew update + brew install python3 clang-format + + pip3 install --user wpiformat fi diff --git a/.travis-scripts/wpiformat.sh b/.travis-scripts/wpiformat.sh new file mode 100755 index 0000000..fc6e646 --- /dev/null +++ b/.travis-scripts/wpiformat.sh @@ -0,0 +1,9 @@ +#!/bin/bash + +if [[ $TRAVIS_OS_NAME != 'osx' ]]; then + python3.5 -m wpiformat -y 2017 -clang 5.0 +else + python3 -m wpiformat -y 2017 +fi + +git --no-pager diff --exit-code HEAD # Ensure formatter made no changes diff --git a/.travis.yml b/.travis.yml index cc60cf2..f84b50c 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,3 +1,4 @@ +sudo: true language: java matrix: @@ -10,9 +11,12 @@ matrix: addons: apt: + sources: + - deadsnakes packages: - g++-multilib - lib32stdc++6 + - python3.5 before_install: - .travis-scripts/install.sh @@ -21,6 +25,7 @@ install: - ./gradlew build -PbuildAll script: + - .travis-scripts/wpiformat.sh - ./gradlew build -PbuildAll before_cache: diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index aae5b31..12aff9e 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -50,4 +50,4 @@ When you first submit changes, Travis-CI will attempt to run `./gradlew check` o ## Licensing -By contributing to ntcore, you agree that your code will be distributed with ntcore, and licensed under the license for the ntcore project. You should not contribute code that you do not have permission to relicense in this manner. This includes code that is licensed under the GPL that you do not have permission to relicense, as ntcore is not released under a copyleft license. Our license is the 3-clause BSD license, which you can find [here](license.txt). \ No newline at end of file +By contributing to ntcore, you agree that your code will be distributed with ntcore, and licensed under the license for the ntcore project. You should not contribute code that you do not have permission to relicense in this manner. This includes code that is licensed under the GPL that you do not have permission to relicense, as ntcore is not released under a copyleft license. Our license is the 3-clause BSD license, which you can find [here](license.txt). diff --git a/README.md b/README.md index 6ad7d58..0f45826 100644 --- a/README.md +++ b/README.md @@ -73,6 +73,6 @@ The `ntcore-java` artifact will contain a jar with no classifiers. This is the j All of these artifacts by default are published to `~/releases/maven/development`. To switch to the release repository (`~/release/maven/release`), use the flag `-PreleaseType=OFFICIAL`. -All downstream projects are configured to use the individual classifier artifacts. The previouse `desktop` classifier does not exist anymore. +All downstream projects are configured to use the individual classifier artifacts. The previouse `desktop` classifier does not exist anymore. When you do a publish of ntcore locally, the locally built copy will override all references to networktables dependencies from the FRC Maven server. To undo this, you must delete `~/releases/maven//edu/wpi/first/ntcore`. diff --git a/license.txt b/license.txt index 5d3484b..9c33de4 100644 --- a/license.txt +++ b/license.txt @@ -14,8 +14,8 @@ * * THIS SOFTWARE IS PROVIDED BY FIRST AND CONTRIBUTORS``AS IS'' AND ANY * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED -* WARRANTIES OF MERCHANTABILITY NONINFRINGEMENT AND FITNESS FOR A PARTICULAR -* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL FIRST OR CONTRIBUTORS BE LIABLE FOR +* WARRANTIES OF MERCHANTABILITY NONINFRINGEMENT AND FITNESS FOR A PARTICULAR +* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL FIRST OR CONTRIBUTORS BE LIABLE FOR * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND diff --git a/manualTests/java/Client.java b/manualTests/java/Client.java index 7f18690..34f0d54 100644 --- a/manualTests/java/Client.java +++ b/manualTests/java/Client.java @@ -1,3 +1,10 @@ +/*----------------------------------------------------------------------------*/ +/* Copyright (c) FIRST 2017. All Rights Reserved. */ +/* Open Source Software - may be modified and shared by FRC teams. The code */ +/* must be accompanied by the FIRST BSD license file in the root directory of */ +/* the project. */ +/*----------------------------------------------------------------------------*/ + import edu.wpi.first.wpilibj.networktables.*; import edu.wpi.first.wpilibj.tables.*; diff --git a/manualTests/java/Server.java b/manualTests/java/Server.java index 33844fb..7d4cefc 100644 --- a/manualTests/java/Server.java +++ b/manualTests/java/Server.java @@ -1,3 +1,10 @@ +/*----------------------------------------------------------------------------*/ +/* Copyright (c) FIRST 2017. All Rights Reserved. */ +/* Open Source Software - may be modified and shared by FRC teams. The code */ +/* must be accompanied by the FIRST BSD license file in the root directory of */ +/* the project. */ +/*----------------------------------------------------------------------------*/ + import edu.wpi.first.wpilibj.networktables.*; import edu.wpi.first.wpilibj.tables.*; diff --git a/manualTests/native/client.cpp b/manualTests/native/client.cpp index a5ab584..24e7dd7 100644 --- a/manualTests/native/client.cpp +++ b/manualTests/native/client.cpp @@ -1,3 +1,10 @@ +/*----------------------------------------------------------------------------*/ +/* Copyright (c) FIRST 2017. All Rights Reserved. */ +/* Open Source Software - may be modified and shared by FRC teams. The code */ +/* must be accompanied by the FIRST BSD license file in the root directory of */ +/* the project. */ +/*----------------------------------------------------------------------------*/ + #include #include #include @@ -7,20 +14,19 @@ int main() { auto inst = nt::GetDefaultInstance(); - nt::AddLogger( - inst, - [](const nt::LogMessage& msg) { - std::fputs(msg.message.c_str(), stderr); - std::fputc('\n', stderr); - }, - 0, UINT_MAX); + nt::AddLogger(inst, + [](const nt::LogMessage& msg) { + std::fputs(msg.message.c_str(), stderr); + std::fputc('\n', stderr); + }, + 0, UINT_MAX); nt::StartClient(inst, "127.0.0.1", 10000); std::this_thread::sleep_for(std::chrono::seconds(2)); auto foo = nt::GetEntry(inst, "/foo"); auto foo_val = nt::GetEntryValue(foo); if (foo_val && foo_val->IsDouble()) - printf("Got foo: %g\n", foo_val->GetDouble()); + std::printf("Got foo: %g\n", foo_val->GetDouble()); auto bar = nt::GetEntry(inst, "/bar"); nt::SetEntryValue(bar, nt::Value::MakeBoolean(false)); diff --git a/manualTests/native/rpc_local.cpp b/manualTests/native/rpc_local.cpp index 914145c..5e91742 100644 --- a/manualTests/native/rpc_local.cpp +++ b/manualTests/native/rpc_local.cpp @@ -1,9 +1,16 @@ +/*----------------------------------------------------------------------------*/ +/* Copyright (c) FIRST 2017. All Rights Reserved. */ +/* Open Source Software - may be modified and shared by FRC teams. The code */ +/* must be accompanied by the FIRST BSD license file in the root directory of */ +/* the project. */ +/*----------------------------------------------------------------------------*/ + #include #include #include #include -#include "support/json.h" +#include #include "ntcore.h" @@ -27,13 +34,12 @@ void callback1(const nt::RpcAnswer& answer) { int main() { auto inst = nt::GetDefaultInstance(); - nt::AddLogger( - inst, - [](const nt::LogMessage& msg) { - std::fputs(msg.message.c_str(), stderr); - std::fputc('\n', stderr); - }, - 0, UINT_MAX); + nt::AddLogger(inst, + [](const nt::LogMessage& msg) { + std::fputs(msg.message.c_str(), stderr); + std::fputc('\n', stderr); + }, + 0, UINT_MAX); nt::StartServer(inst, "rpc_local.ini", "", 10000); auto entry = nt::GetEntry(inst, "func1"); diff --git a/manualTests/native/rpc_speed.cpp b/manualTests/native/rpc_speed.cpp index a6ee2f0..0d27987 100644 --- a/manualTests/native/rpc_speed.cpp +++ b/manualTests/native/rpc_speed.cpp @@ -1,10 +1,17 @@ +/*----------------------------------------------------------------------------*/ +/* Copyright (c) FIRST 2017. All Rights Reserved. */ +/* Open Source Software - may be modified and shared by FRC teams. The code */ +/* must be accompanied by the FIRST BSD license file in the root directory of */ +/* the project. */ +/*----------------------------------------------------------------------------*/ + #include #include #include -#include #include +#include -#include "support/json.h" +#include #include "ntcore.h" @@ -33,7 +40,7 @@ int main() { auto start2 = std::chrono::high_resolution_clock::now(); auto start = nt::Now(); - for (int i=0; i<10000; ++i) { + for (int i = 0; i < 10000; ++i) { unsigned int call1_uid = nt::CallRpc(entry, wpi::json::to_cbor(i)); nt::GetRpcResult(entry, call1_uid, &call1_result_str); wpi::json call1_result; @@ -51,11 +58,17 @@ int main() { auto end2 = std::chrono::high_resolution_clock::now(); auto end = nt::Now(); std::cerr << "nt::Now start=" << start << " end=" << end << '\n'; - std::cerr << "std::chrono start=" << - std::chrono::duration_cast(start2.time_since_epoch()).count() << " end=" << - std::chrono::duration_cast(end2.time_since_epoch()).count() << '\n'; - std::fprintf(stderr, "time/call = %g us\n", (end-start) / 10.0 / 10000.0); - std::chrono::duration diff = end2-start2; + std::cerr << "std::chrono start=" + << std::chrono::duration_cast( + start2.time_since_epoch()) + .count() + << " end=" + << std::chrono::duration_cast( + end2.time_since_epoch()) + .count() + << '\n'; + std::fprintf(stderr, "time/call = %g us\n", (end - start) / 10.0 / 10000.0); + std::chrono::duration diff = end2 - start2; std::cerr << "time/call = " << (diff.count() / 10000.0) << " us\n"; return 0; diff --git a/manualTests/native/server.cpp b/manualTests/native/server.cpp index 8775aed..8d8954d 100644 --- a/manualTests/native/server.cpp +++ b/manualTests/native/server.cpp @@ -1,3 +1,10 @@ +/*----------------------------------------------------------------------------*/ +/* Copyright (c) FIRST 2017. All Rights Reserved. */ +/* Open Source Software - may be modified and shared by FRC teams. The code */ +/* must be accompanied by the FIRST BSD license file in the root directory of */ +/* the project. */ +/*----------------------------------------------------------------------------*/ + #include #include #include @@ -7,13 +14,12 @@ int main() { auto inst = nt::GetDefaultInstance(); - nt::AddLogger( - inst, - [](const nt::LogMessage& msg) { - std::fputs(msg.message.c_str(), stderr); - std::fputc('\n', stderr); - }, - 0, UINT_MAX); + nt::AddLogger(inst, + [](const nt::LogMessage& msg) { + std::fputs(msg.message.c_str(), stderr); + std::fputc('\n', stderr); + }, + 0, UINT_MAX); nt::StartServer(inst, "persistent.ini", "", 10000); std::this_thread::sleep_for(std::chrono::seconds(1)); diff --git a/publish.gradle b/publish.gradle index 6b1b231..7df5cef 100644 --- a/publish.gradle +++ b/publish.gradle @@ -191,7 +191,7 @@ model { destinationDir = outputsFolder duplicatesStrategy = 'exclude' - ntcoreJNITaskList.each { + ntcoreJNITaskList.each { it.outputs.files.each { from project.zipTree(it) } @@ -210,7 +210,7 @@ model { destinationDir = outputsFolder duplicatesStrategy = 'exclude' - ntcoreTaskList.each { + ntcoreTaskList.each { it.outputs.files.each { from project.zipTree(it) } diff --git a/src/dev/java/edu/wpi/first/ntcore/DevMain.java b/src/dev/java/edu/wpi/first/ntcore/DevMain.java index 99166d2..340e563 100644 --- a/src/dev/java/edu/wpi/first/ntcore/DevMain.java +++ b/src/dev/java/edu/wpi/first/ntcore/DevMain.java @@ -1,12 +1,19 @@ -package edu.wpi.first.ntcore; - -import edu.wpi.first.networktables.NetworkTablesJNI; -import edu.wpi.first.wpiutil.RuntimeDetector; - -public class DevMain { - public static void main(String[] args) { - System.out.println("Hello World!"); - System.out.println(RuntimeDetector.getPlatformPath()); - NetworkTablesJNI.flush(NetworkTablesJNI.getDefaultInstance()); - } -} +/*----------------------------------------------------------------------------*/ +/* Copyright (c) FIRST 2017. All Rights Reserved. */ +/* Open Source Software - may be modified and shared by FRC teams. The code */ +/* must be accompanied by the FIRST BSD license file in the root directory of */ +/* the project. */ +/*----------------------------------------------------------------------------*/ + +package edu.wpi.first.ntcore; + +import edu.wpi.first.networktables.NetworkTablesJNI; +import edu.wpi.first.wpiutil.RuntimeDetector; + +public class DevMain { + public static void main(String[] args) { + System.out.println("Hello World!"); + System.out.println(RuntimeDetector.getPlatformPath()); + NetworkTablesJNI.flush(NetworkTablesJNI.getDefaultInstance()); + } +} diff --git a/src/dev/native/cpp/main.cpp b/src/dev/native/cpp/main.cpp index 0b93cef..227b436 100644 --- a/src/dev/native/cpp/main.cpp +++ b/src/dev/native/cpp/main.cpp @@ -1,10 +1,18 @@ -#include "ntcore.h" +/*----------------------------------------------------------------------------*/ +/* Copyright (c) FIRST 2017. All Rights Reserved. */ +/* Open Source Software - may be modified and shared by FRC teams. The code */ +/* must be accompanied by the FIRST BSD license file in the root directory of */ +/* the project. */ +/*----------------------------------------------------------------------------*/ + #include +#include "ntcore.h" + int main() { - auto myValue = nt::GetEntry(nt::GetDefaultInstance(), "MyValue"); + auto myValue = nt::GetEntry(nt::GetDefaultInstance(), "MyValue"); - nt::SetEntryValue(myValue, nt::Value::MakeString("Hello World")); + nt::SetEntryValue(myValue, nt::Value::MakeString("Hello World")); - std::cout << nt::GetEntryValue(myValue)->GetString() << std::endl; + std::cout << nt::GetEntryValue(myValue)->GetString() << std::endl; } diff --git a/src/main/java/edu/wpi/first/networktables/PersistentException.java b/src/main/java/edu/wpi/first/networktables/PersistentException.java index 22b07d8..41d7748 100644 --- a/src/main/java/edu/wpi/first/networktables/PersistentException.java +++ b/src/main/java/edu/wpi/first/networktables/PersistentException.java @@ -11,7 +11,7 @@ /** * An exception thrown when persistent load/save fails in a {@link NetworkTable} - * + * */ public final class PersistentException extends IOException { public static final long serialVersionUID = 0; diff --git a/src/main/java/edu/wpi/first/wpilibj/tables/IRemote.java b/src/main/java/edu/wpi/first/wpilibj/tables/IRemote.java index 52ab5ee..eee5e52 100644 --- a/src/main/java/edu/wpi/first/wpilibj/tables/IRemote.java +++ b/src/main/java/edu/wpi/first/wpilibj/tables/IRemote.java @@ -1,3 +1,10 @@ +/*----------------------------------------------------------------------------*/ +/* Copyright (c) FIRST 2017. All Rights Reserved. */ +/* Open Source Software - may be modified and shared by FRC teams. The code */ +/* must be accompanied by the FIRST BSD license file in the root directory of */ +/* the project. */ +/*----------------------------------------------------------------------------*/ + package edu.wpi.first.wpilibj.tables; diff --git a/src/main/java/edu/wpi/first/wpilibj/tables/IRemoteConnectionListener.java b/src/main/java/edu/wpi/first/wpilibj/tables/IRemoteConnectionListener.java index fcb884e..5fe22c0 100644 --- a/src/main/java/edu/wpi/first/wpilibj/tables/IRemoteConnectionListener.java +++ b/src/main/java/edu/wpi/first/wpilibj/tables/IRemoteConnectionListener.java @@ -1,3 +1,10 @@ +/*----------------------------------------------------------------------------*/ +/* Copyright (c) FIRST 2017. All Rights Reserved. */ +/* Open Source Software - may be modified and shared by FRC teams. The code */ +/* must be accompanied by the FIRST BSD license file in the root directory of */ +/* the project. */ +/*----------------------------------------------------------------------------*/ + package edu.wpi.first.wpilibj.tables; import edu.wpi.first.networktables.ConnectionInfo; diff --git a/src/main/java/edu/wpi/first/wpilibj/tables/ITable.java b/src/main/java/edu/wpi/first/wpilibj/tables/ITable.java index 86311cd..5aa2de4 100644 --- a/src/main/java/edu/wpi/first/wpilibj/tables/ITable.java +++ b/src/main/java/edu/wpi/first/wpilibj/tables/ITable.java @@ -1,3 +1,10 @@ +/*----------------------------------------------------------------------------*/ +/* Copyright (c) FIRST 2017. All Rights Reserved. */ +/* Open Source Software - may be modified and shared by FRC teams. The code */ +/* must be accompanied by the FIRST BSD license file in the root directory of */ +/* the project. */ +/*----------------------------------------------------------------------------*/ + package edu.wpi.first.wpilibj.tables; import java.nio.ByteBuffer; diff --git a/src/main/java/edu/wpi/first/wpilibj/tables/ITableListener.java b/src/main/java/edu/wpi/first/wpilibj/tables/ITableListener.java index 9b1304b..7f7e03d 100644 --- a/src/main/java/edu/wpi/first/wpilibj/tables/ITableListener.java +++ b/src/main/java/edu/wpi/first/wpilibj/tables/ITableListener.java @@ -1,3 +1,10 @@ +/*----------------------------------------------------------------------------*/ +/* Copyright (c) FIRST 2017. All Rights Reserved. */ +/* Open Source Software - may be modified and shared by FRC teams. The code */ +/* must be accompanied by the FIRST BSD license file in the root directory of */ +/* the project. */ +/*----------------------------------------------------------------------------*/ + package edu.wpi.first.wpilibj.tables; /** diff --git a/src/main/native/cpp/CallbackManager.h b/src/main/native/cpp/CallbackManager.h index 425af28..72adbd6 100644 --- a/src/main/native/cpp/CallbackManager.h +++ b/src/main/native/cpp/CallbackManager.h @@ -5,20 +5,22 @@ /* the project. */ /*----------------------------------------------------------------------------*/ -#ifndef NT_CALLBACKMANAGER_H_ -#define NT_CALLBACKMANAGER_H_ +#ifndef NTCORE_CALLBACKMANAGER_H_ +#define NTCORE_CALLBACKMANAGER_H_ #include #include #include +#include #include #include +#include -#include "llvm/raw_ostream.h" -#include "support/condition_variable.h" -#include "support/mutex.h" -#include "support/SafeThread.h" -#include "support/UidVector.h" +#include +#include +#include +#include +#include namespace nt { @@ -28,8 +30,8 @@ template class ListenerData { public: ListenerData() = default; - ListenerData(Callback callback_) : callback(callback_) {} - ListenerData(unsigned int poller_uid_) : poller_uid(poller_uid_) {} + explicit ListenerData(Callback callback_) : callback(callback_) {} + explicit ListenerData(unsigned int poller_uid_) : poller_uid(poller_uid_) {} explicit operator bool() const { return callback || poller_uid != UINT_MAX; } @@ -57,7 +59,7 @@ class CallbackThread : public wpi::SafeThread { ~CallbackThread() { // Wake up any blocked pollers - for (std::size_t i = 0; i < m_pollers.size(); ++i) { + for (size_t i = 0; i < m_pollers.size(); ++i) { if (auto poller = m_pollers[i]) poller->Terminate(); } } @@ -187,7 +189,7 @@ class CallbackManager { if (!thr) return; // Remove any listeners that are associated with this poller - for (std::size_t i = 0; i < thr->m_listeners.size(); ++i) { + for (size_t i = 0; i < thr->m_listeners.size(); ++i) { if (thr->m_listeners[i].poller_uid == poller_uid) thr->m_listeners.erase(i); } @@ -335,4 +337,4 @@ class CallbackManager { } // namespace nt -#endif // NT_CALLBACKMANAGER_H_ +#endif // NTCORE_CALLBACKMANAGER_H_ diff --git a/src/main/native/cpp/ConnectionNotifier.cpp b/src/main/native/cpp/ConnectionNotifier.cpp index e3a6284..7ad882e 100644 --- a/src/main/native/cpp/ConnectionNotifier.cpp +++ b/src/main/native/cpp/ConnectionNotifier.cpp @@ -1,5 +1,5 @@ /*----------------------------------------------------------------------------*/ -/* Copyright (c) FIRST 2015. All Rights Reserved. */ +/* Copyright (c) FIRST 2015-2017. All Rights Reserved. */ /* Open Source Software - may be modified and shared by FRC teams. The code */ /* must be accompanied by the FIRST BSD license file in the root directory of */ /* the project. */ diff --git a/src/main/native/cpp/ConnectionNotifier.h b/src/main/native/cpp/ConnectionNotifier.h index de94149..cfdcbe9 100644 --- a/src/main/native/cpp/ConnectionNotifier.h +++ b/src/main/native/cpp/ConnectionNotifier.h @@ -1,18 +1,17 @@ /*----------------------------------------------------------------------------*/ -/* Copyright (c) FIRST 2015. All Rights Reserved. */ +/* Copyright (c) FIRST 2015-2017. All Rights Reserved. */ /* Open Source Software - may be modified and shared by FRC teams. The code */ /* must be accompanied by the FIRST BSD license file in the root directory of */ /* the project. */ /*----------------------------------------------------------------------------*/ -#ifndef NT_CONNECTIONNOTIFIER_H_ -#define NT_CONNECTIONNOTIFIER_H_ - -#include "ntcore_cpp.h" +#ifndef NTCORE_CONNECTIONNOTIFIER_H_ +#define NTCORE_CONNECTIONNOTIFIER_H_ #include "CallbackManager.h" #include "Handle.h" #include "IConnectionNotifier.h" +#include "ntcore_cpp.h" namespace nt { @@ -21,7 +20,7 @@ namespace impl { class ConnectionNotifierThread : public CallbackThread { public: - ConnectionNotifierThread(int inst) : m_inst(inst) {} + explicit ConnectionNotifierThread(int inst) : m_inst(inst) {} bool Matches(const ListenerData& listener, const ConnectionNotification& data) { @@ -70,4 +69,4 @@ class ConnectionNotifier } // namespace nt -#endif // NT_CONNECTIONNOTIFIER_H_ +#endif // NTCORE_CONNECTIONNOTIFIER_H_ diff --git a/src/main/native/cpp/Dispatcher.cpp b/src/main/native/cpp/Dispatcher.cpp index 31b6a4e..34b74d8 100644 --- a/src/main/native/cpp/Dispatcher.cpp +++ b/src/main/native/cpp/Dispatcher.cpp @@ -1,5 +1,5 @@ /*----------------------------------------------------------------------------*/ -/* Copyright (c) FIRST 2015. All Rights Reserved. */ +/* Copyright (c) FIRST 2015-2017. All Rights Reserved. */ /* Open Source Software - may be modified and shared by FRC teams. The code */ /* must be accompanied by the FIRST BSD license file in the root directory of */ /* the project. */ @@ -10,13 +10,12 @@ #include #include -#include "tcpsockets/TCPAcceptor.h" -#include "tcpsockets/TCPConnector.h" - #include "IConnectionNotifier.h" -#include "Log.h" #include "IStorage.h" +#include "Log.h" #include "NetworkConnection.h" +#include "tcpsockets/TCPAcceptor.h" +#include "tcpsockets/TCPConnector.h" using namespace nt; @@ -132,7 +131,7 @@ void DispatcherBase::StartServer( !persist_filename.getSingleStringRef().empty())) { bool first = true; m_storage.LoadPersistent( - persist_filename, [&](std::size_t line, const char* msg) { + persist_filename, [&](size_t line, const char* msg) { if (first) { first = false; WARNING("When reading initial persistent values from '" diff --git a/src/main/native/cpp/Dispatcher.h b/src/main/native/cpp/Dispatcher.h index 288dc51..2dff7fa 100644 --- a/src/main/native/cpp/Dispatcher.h +++ b/src/main/native/cpp/Dispatcher.h @@ -1,12 +1,12 @@ /*----------------------------------------------------------------------------*/ -/* Copyright (c) FIRST 2015. All Rights Reserved. */ +/* Copyright (c) FIRST 2015-2017. All Rights Reserved. */ /* Open Source Software - may be modified and shared by FRC teams. The code */ /* must be accompanied by the FIRST BSD license file in the root directory of */ /* the project. */ /*----------------------------------------------------------------------------*/ -#ifndef NT_DISPATCHER_H_ -#define NT_DISPATCHER_H_ +#ifndef NTCORE_DISPATCHER_H_ +#define NTCORE_DISPATCHER_H_ #include #include @@ -14,12 +14,13 @@ #include #include #include +#include #include -#include "llvm/StringRef.h" -#include "llvm/Twine.h" -#include "support/condition_variable.h" -#include "support/mutex.h" +#include +#include +#include +#include #include "IDispatcher.h" #include "INetworkConnection.h" @@ -28,7 +29,7 @@ namespace wpi { class Logger; class NetworkAcceptor; class NetworkStream; -} +} // namespace wpi namespace nt { @@ -147,4 +148,4 @@ class Dispatcher : public DispatcherBase { } // namespace nt -#endif // NT_DISPATCHER_H_ +#endif // NTCORE_DISPATCHER_H_ diff --git a/src/main/native/cpp/DsClient.cpp b/src/main/native/cpp/DsClient.cpp index 6b7eb99..9d70e4b 100644 --- a/src/main/native/cpp/DsClient.cpp +++ b/src/main/native/cpp/DsClient.cpp @@ -1,5 +1,5 @@ /*----------------------------------------------------------------------------*/ -/* Copyright (c) FIRST 2015. All Rights Reserved. */ +/* Copyright (c) FIRST 2015-2017. All Rights Reserved. */ /* Open Source Software - may be modified and shared by FRC teams. The code */ /* must be accompanied by the FIRST BSD license file in the root directory of */ /* the project. */ @@ -7,13 +7,13 @@ #include "DsClient.h" -#include "llvm/raw_ostream.h" -#include "llvm/SmallString.h" -#include "support/raw_socket_istream.h" -#include "tcpsockets/TCPConnector.h" +#include +#include +#include #include "Dispatcher.h" #include "Log.h" +#include "tcpsockets/TCPConnector.h" using namespace nt; @@ -70,8 +70,7 @@ void DsClient::Thread::Main() { if (!m_active) goto done; // Try to connect to DS on the local machine - m_stream = - wpi::TCPConnector::connect("127.0.0.1", 1742, nolog, 1); + m_stream = wpi::TCPConnector::connect("127.0.0.1", 1742, nolog, 1); if (!m_active) goto done; if (!m_stream) continue; diff --git a/src/main/native/cpp/DsClient.h b/src/main/native/cpp/DsClient.h index fdf1f39..db71436 100644 --- a/src/main/native/cpp/DsClient.h +++ b/src/main/native/cpp/DsClient.h @@ -1,14 +1,14 @@ /*----------------------------------------------------------------------------*/ -/* Copyright (c) FIRST 2016. All Rights Reserved. */ +/* Copyright (c) FIRST 2016-2017. All Rights Reserved. */ /* Open Source Software - may be modified and shared by FRC teams. The code */ /* must be accompanied by the FIRST BSD license file in the root directory of */ /* the project. */ /*----------------------------------------------------------------------------*/ -#ifndef NT_DSCLIENT_H_ -#define NT_DSCLIENT_H_ +#ifndef NTCORE_DSCLIENT_H_ +#define NTCORE_DSCLIENT_H_ -#include "support/SafeThread.h" +#include #include "Log.h" @@ -33,4 +33,4 @@ class DsClient { } // namespace nt -#endif // NT_DSCLIENT_H_ +#endif // NTCORE_DSCLIENT_H_ diff --git a/src/main/native/cpp/EntryNotifier.cpp b/src/main/native/cpp/EntryNotifier.cpp index 1cd2441..0eb37c1 100644 --- a/src/main/native/cpp/EntryNotifier.cpp +++ b/src/main/native/cpp/EntryNotifier.cpp @@ -1,5 +1,5 @@ /*----------------------------------------------------------------------------*/ -/* Copyright (c) FIRST 2015. All Rights Reserved. */ +/* Copyright (c) FIRST 2015-2017. All Rights Reserved. */ /* Open Source Software - may be modified and shared by FRC teams. The code */ /* must be accompanied by the FIRST BSD license file in the root directory of */ /* the project. */ diff --git a/src/main/native/cpp/EntryNotifier.h b/src/main/native/cpp/EntryNotifier.h index 0fcdce5..df4814f 100644 --- a/src/main/native/cpp/EntryNotifier.h +++ b/src/main/native/cpp/EntryNotifier.h @@ -1,24 +1,25 @@ /*----------------------------------------------------------------------------*/ -/* Copyright (c) FIRST 2015. All Rights Reserved. */ +/* Copyright (c) FIRST 2015-2017. All Rights Reserved. */ /* Open Source Software - may be modified and shared by FRC teams. The code */ /* must be accompanied by the FIRST BSD license file in the root directory of */ /* the project. */ /*----------------------------------------------------------------------------*/ -#ifndef NT_ENTRYNOTIFIER_H_ -#define NT_ENTRYNOTIFIER_H_ - -#include "ntcore_cpp.h" +#ifndef NTCORE_ENTRYNOTIFIER_H_ +#define NTCORE_ENTRYNOTIFIER_H_ #include +#include +#include #include "CallbackManager.h" #include "Handle.h" #include "IEntryNotifier.h" +#include "ntcore_cpp.h" namespace wpi { class Logger; -} +} // namespace wpi namespace nt { @@ -51,7 +52,7 @@ class EntryNotifierThread : public CallbackThread { public: - EntryNotifierThread(int inst) : m_inst(inst) {} + explicit EntryNotifierThread(int inst) : m_inst(inst) {} bool Matches(const EntryListenerData& listener, const EntryNotification& data); @@ -105,4 +106,4 @@ class EntryNotifier } // namespace nt -#endif // NT_ENTRYNOTIFIER_H_ +#endif // NTCORE_ENTRYNOTIFIER_H_ diff --git a/src/main/native/cpp/Handle.h b/src/main/native/cpp/Handle.h index 5383c0c..b2186b6 100644 --- a/src/main/native/cpp/Handle.h +++ b/src/main/native/cpp/Handle.h @@ -5,8 +5,8 @@ /* the project. */ /*----------------------------------------------------------------------------*/ -#ifndef NT_HANDLE_H_ -#define NT_HANDLE_H_ +#ifndef NTCORE_HANDLE_H_ +#define NTCORE_HANDLE_H_ #include "ntcore_c.h" @@ -33,7 +33,7 @@ class Handle { }; enum { kIndexMax = 0xfffff }; - Handle(NT_Handle handle) : m_handle(handle) {} + explicit Handle(NT_Handle handle) : m_handle(handle) {} operator NT_Handle() const { return m_handle; } NT_Handle handle() const { return m_handle; } @@ -43,8 +43,8 @@ class Handle { m_handle = 0; return; } - m_handle = ((static_cast(type) & 0xf) << 27) | - ((inst & 0x7f) << 20) | (index & 0xfffff); + m_handle = ((static_cast(type) & 0xf) << 27) | ((inst & 0x7f) << 20) | + (index & 0xfffff); } int GetIndex() const { return static_cast(m_handle) & 0xfffff; } @@ -62,4 +62,4 @@ class Handle { } // namespace nt -#endif // NT_HANDLE_H_ +#endif // NTCORE_HANDLE_H_ diff --git a/src/main/native/cpp/IConnectionNotifier.h b/src/main/native/cpp/IConnectionNotifier.h index c4c9636..a618653 100644 --- a/src/main/native/cpp/IConnectionNotifier.h +++ b/src/main/native/cpp/IConnectionNotifier.h @@ -5,8 +5,8 @@ /* the project. */ /*----------------------------------------------------------------------------*/ -#ifndef NT_ICONNECTIONNOTIFIER_H_ -#define NT_ICONNECTIONNOTIFIER_H_ +#ifndef NTCORE_ICONNECTIONNOTIFIER_H_ +#define NTCORE_ICONNECTIONNOTIFIER_H_ #include @@ -29,4 +29,4 @@ class IConnectionNotifier { } // namespace nt -#endif // NT_ICONNECTIONNOTIFIER_H_ +#endif // NTCORE_ICONNECTIONNOTIFIER_H_ diff --git a/src/main/native/cpp/IDispatcher.h b/src/main/native/cpp/IDispatcher.h index bbe4aa4..c13827c 100644 --- a/src/main/native/cpp/IDispatcher.h +++ b/src/main/native/cpp/IDispatcher.h @@ -5,8 +5,8 @@ /* the project. */ /*----------------------------------------------------------------------------*/ -#ifndef NT_IDISPATCHER_H_ -#define NT_IDISPATCHER_H_ +#ifndef NTCORE_IDISPATCHER_H_ +#define NTCORE_IDISPATCHER_H_ #include @@ -31,4 +31,4 @@ class IDispatcher { } // namespace nt -#endif // NT_IDISPATCHER_H_ +#endif // NTCORE_IDISPATCHER_H_ diff --git a/src/main/native/cpp/IEntryNotifier.h b/src/main/native/cpp/IEntryNotifier.h index 741f573..2943431 100644 --- a/src/main/native/cpp/IEntryNotifier.h +++ b/src/main/native/cpp/IEntryNotifier.h @@ -5,10 +5,11 @@ /* the project. */ /*----------------------------------------------------------------------------*/ -#ifndef NT_IENTRYNOTIFIER_H_ -#define NT_IENTRYNOTIFIER_H_ +#ifndef NTCORE_IENTRYNOTIFIER_H_ +#define NTCORE_IENTRYNOTIFIER_H_ #include +#include #include "ntcore_cpp.h" @@ -41,4 +42,4 @@ class IEntryNotifier { } // namespace nt -#endif // NT_IENTRYNOTIFIER_H_ +#endif // NTCORE_IENTRYNOTIFIER_H_ diff --git a/src/main/native/cpp/INetworkConnection.h b/src/main/native/cpp/INetworkConnection.h index e7deba5..c80121c 100644 --- a/src/main/native/cpp/INetworkConnection.h +++ b/src/main/native/cpp/INetworkConnection.h @@ -5,8 +5,8 @@ /* the project. */ /*----------------------------------------------------------------------------*/ -#ifndef NT_INETWORKCONNECTION_H_ -#define NT_INETWORKCONNECTION_H_ +#ifndef NTCORE_INETWORKCONNECTION_H_ +#define NTCORE_INETWORKCONNECTION_H_ #include @@ -38,4 +38,4 @@ class INetworkConnection { } // namespace nt -#endif // NT_INETWORKCONNECTION_H_ +#endif // NTCORE_INETWORKCONNECTION_H_ diff --git a/src/main/native/cpp/IRpcServer.h b/src/main/native/cpp/IRpcServer.h index 8a4f22e..1f25eb5 100644 --- a/src/main/native/cpp/IRpcServer.h +++ b/src/main/native/cpp/IRpcServer.h @@ -5,8 +5,8 @@ /* the project. */ /*----------------------------------------------------------------------------*/ -#ifndef NT_IRPCSERVER_H_ -#define NT_IRPCSERVER_H_ +#ifndef NTCORE_IRPCSERVER_H_ +#define NTCORE_IRPCSERVER_H_ #include @@ -35,4 +35,4 @@ class IRpcServer { } // namespace nt -#endif // NT_IRPCSERVER_H_ +#endif // NTCORE_IRPCSERVER_H_ diff --git a/src/main/native/cpp/IStorage.h b/src/main/native/cpp/IStorage.h index 0d872f5..54048d5 100644 --- a/src/main/native/cpp/IStorage.h +++ b/src/main/native/cpp/IStorage.h @@ -1,19 +1,19 @@ /*----------------------------------------------------------------------------*/ -/* Copyright (c) FIRST 2015. All Rights Reserved. */ +/* Copyright (c) FIRST 2015-2017. All Rights Reserved. */ /* Open Source Software - may be modified and shared by FRC teams. The code */ /* must be accompanied by the FIRST BSD license file in the root directory of */ /* the project. */ /*----------------------------------------------------------------------------*/ -#ifndef NT_ISTORAGE_H_ -#define NT_ISTORAGE_H_ +#ifndef NTCORE_ISTORAGE_H_ +#define NTCORE_ISTORAGE_H_ #include #include #include -#include "llvm/ArrayRef.h" -#include "llvm/Twine.h" +#include +#include #include "Message.h" #include "ntcore_cpp.h" @@ -57,9 +57,9 @@ class IStorage { bool periodic) const = 0; virtual const char* LoadPersistent( const Twine& filename, - std::function warn) = 0; + std::function warn) = 0; }; } // namespace nt -#endif // NT_ISTORAGE_H_ +#endif // NTCORE_ISTORAGE_H_ diff --git a/src/main/native/cpp/InstanceImpl.h b/src/main/native/cpp/InstanceImpl.h index 4d191af..39d74c0 100644 --- a/src/main/native/cpp/InstanceImpl.h +++ b/src/main/native/cpp/InstanceImpl.h @@ -5,14 +5,14 @@ /* the project. */ /*----------------------------------------------------------------------------*/ -#ifndef NT_INSTANCEIMPL_H_ -#define NT_INSTANCEIMPL_H_ +#ifndef NTCORE_INSTANCEIMPL_H_ +#define NTCORE_INSTANCEIMPL_H_ #include #include -#include "support/mutex.h" -#include "support/UidVector.h" +#include +#include #include "ConnectionNotifier.h" #include "Dispatcher.h" @@ -57,4 +57,4 @@ class InstanceImpl { } // namespace nt -#endif // NT_INSTANCEIMPL_H_ +#endif // NTCORE_INSTANCEIMPL_H_ diff --git a/src/main/native/cpp/Log.h b/src/main/native/cpp/Log.h index 221e8cc..5f1729e 100644 --- a/src/main/native/cpp/Log.h +++ b/src/main/native/cpp/Log.h @@ -1,14 +1,14 @@ /*----------------------------------------------------------------------------*/ -/* Copyright (c) FIRST 2015. All Rights Reserved. */ +/* Copyright (c) FIRST 2015-2017. All Rights Reserved. */ /* Open Source Software - may be modified and shared by FRC teams. The code */ /* must be accompanied by the FIRST BSD license file in the root directory of */ /* the project. */ /*----------------------------------------------------------------------------*/ -#ifndef NT_LOG_H_ -#define NT_LOG_H_ +#ifndef NTCORE_LOG_H_ +#define NTCORE_LOG_H_ -#include "support/Logger.h" +#include #define LOG(level, x) WPI_LOG(m_logger, level, x) @@ -23,4 +23,4 @@ #define DEBUG3(x) WPI_DEBUG3(m_logger, x) #define DEBUG4(x) WPI_DEBUG4(m_logger, x) -#endif // NT_LOG_H_ +#endif // NTCORE_LOG_H_ diff --git a/src/main/native/cpp/LoggerImpl.cpp b/src/main/native/cpp/LoggerImpl.cpp index 0019d50..78fece6 100644 --- a/src/main/native/cpp/LoggerImpl.cpp +++ b/src/main/native/cpp/LoggerImpl.cpp @@ -1,5 +1,5 @@ /*----------------------------------------------------------------------------*/ -/* Copyright (c) FIRST 2015. All Rights Reserved. */ +/* Copyright (c) FIRST 2015-2017. All Rights Reserved. */ /* Open Source Software - may be modified and shared by FRC teams. The code */ /* must be accompanied by the FIRST BSD license file in the root directory of */ /* the project. */ @@ -7,10 +7,10 @@ #include "LoggerImpl.h" -#include "llvm/Path.h" -#include "llvm/SmallString.h" -#include "llvm/StringRef.h" -#include "llvm/raw_ostream.h" +#include +#include +#include +#include using namespace nt; diff --git a/src/main/native/cpp/LoggerImpl.h b/src/main/native/cpp/LoggerImpl.h index ccfe4ce..519817b 100644 --- a/src/main/native/cpp/LoggerImpl.h +++ b/src/main/native/cpp/LoggerImpl.h @@ -1,17 +1,16 @@ /*----------------------------------------------------------------------------*/ -/* Copyright (c) FIRST 2015. All Rights Reserved. */ +/* Copyright (c) FIRST 2015-2017. All Rights Reserved. */ /* Open Source Software - may be modified and shared by FRC teams. The code */ /* must be accompanied by the FIRST BSD license file in the root directory of */ /* the project. */ /*----------------------------------------------------------------------------*/ -#ifndef NT_LOGGERIMPL_H_ -#define NT_LOGGERIMPL_H_ - -#include "ntcore_cpp.h" +#ifndef NTCORE_LOGGERIMPL_H_ +#define NTCORE_LOGGERIMPL_H_ #include "CallbackManager.h" #include "Handle.h" +#include "ntcore_cpp.h" namespace nt { @@ -36,7 +35,7 @@ struct LoggerListenerData class LoggerThread : public CallbackThread { public: - LoggerThread(int inst) : m_inst(inst) {} + explicit LoggerThread(int inst) : m_inst(inst) {} bool Matches(const LoggerListenerData& listener, const LogMessage& data) { return data.level >= listener.min_level && data.level <= listener.max_level; @@ -81,4 +80,4 @@ class LoggerImpl : public CallbackManager { } // namespace nt -#endif // NT_CONNECTIONNOTIFIER_H_ +#endif // NTCORE_LOGGERIMPL_H_ diff --git a/src/main/native/cpp/Message.cpp b/src/main/native/cpp/Message.cpp index 52790d6..9b2fa13 100644 --- a/src/main/native/cpp/Message.cpp +++ b/src/main/native/cpp/Message.cpp @@ -1,5 +1,5 @@ /*----------------------------------------------------------------------------*/ -/* Copyright (c) FIRST 2015. All Rights Reserved. */ +/* Copyright (c) FIRST 2015-2017. All Rights Reserved. */ /* Open Source Software - may be modified and shared by FRC teams. The code */ /* must be accompanied by the FIRST BSD license file in the root directory of */ /* the project. */ @@ -7,6 +7,8 @@ #include "Message.h" +#include + #include "Log.h" #include "WireDecoder.h" #include "WireEncoder.h" @@ -56,7 +58,7 @@ std::shared_ptr Message::Read(WireDecoder& decoder, } break; case kEntryAssign: { - if (!decoder.ReadString(&msg->m_str)) return nullptr; // name + if (!decoder.ReadString(&msg->m_str)) return nullptr; // name NT_Type type; if (!decoder.ReadType(&type)) return nullptr; // entry type if (!decoder.Read16(&msg->m_id)) return nullptr; // id @@ -104,7 +106,7 @@ std::shared_ptr Message::Read(WireDecoder& decoder, decoder.set_error("received CLEAR_ENTRIES in protocol < 3.0"); return nullptr; } - unsigned long magic; + uint32_t magic; if (!decoder.Read32(&magic)) return nullptr; if (magic != kClearAllMagic) { decoder.set_error( @@ -120,7 +122,7 @@ std::shared_ptr Message::Read(WireDecoder& decoder, } if (!decoder.Read16(&msg->m_id)) return nullptr; if (!decoder.Read16(&msg->m_seq_num_uid)) return nullptr; // uid - unsigned long size; + uint64_t size; if (!decoder.ReadUleb128(&size)) return nullptr; const char* params; if (!decoder.Read(¶ms, size)) return nullptr; @@ -134,7 +136,7 @@ std::shared_ptr Message::Read(WireDecoder& decoder, } if (!decoder.Read16(&msg->m_id)) return nullptr; if (!decoder.Read16(&msg->m_seq_num_uid)) return nullptr; // uid - unsigned long size; + uint64_t size; if (!decoder.ReadUleb128(&size)) return nullptr; const char* results; if (!decoder.Read(&results, size)) return nullptr; diff --git a/src/main/native/cpp/Message.h b/src/main/native/cpp/Message.h index 46baebd..b232012 100644 --- a/src/main/native/cpp/Message.h +++ b/src/main/native/cpp/Message.h @@ -1,12 +1,12 @@ /*----------------------------------------------------------------------------*/ -/* Copyright (c) FIRST 2015. All Rights Reserved. */ +/* Copyright (c) FIRST 2015-2017. All Rights Reserved. */ /* Open Source Software - may be modified and shared by FRC teams. The code */ /* must be accompanied by the FIRST BSD license file in the root directory of */ /* the project. */ /*----------------------------------------------------------------------------*/ -#ifndef NT_MESSAGE_H_ -#define NT_MESSAGE_H_ +#ifndef NTCORE_MESSAGE_H_ +#define NTCORE_MESSAGE_H_ #include #include @@ -114,4 +114,4 @@ class Message { } // namespace nt -#endif // NT_MESSAGE_H_ +#endif // NTCORE_MESSAGE_H_ diff --git a/src/main/native/cpp/NetworkConnection.cpp b/src/main/native/cpp/NetworkConnection.cpp index 9435106..f3e4c66 100644 --- a/src/main/native/cpp/NetworkConnection.cpp +++ b/src/main/native/cpp/NetworkConnection.cpp @@ -1,5 +1,5 @@ /*----------------------------------------------------------------------------*/ -/* Copyright (c) FIRST 2015. All Rights Reserved. */ +/* Copyright (c) FIRST 2015-2017. All Rights Reserved. */ /* Open Source Software - may be modified and shared by FRC teams. The code */ /* must be accompanied by the FIRST BSD license file in the root directory of */ /* the project. */ @@ -7,14 +7,14 @@ #include "NetworkConnection.h" -#include "support/raw_socket_istream.h" -#include "support/timestamp.h" -#include "tcpsockets/NetworkStream.h" +#include +#include #include "IConnectionNotifier.h" #include "Log.h" #include "WireDecoder.h" #include "WireEncoder.h" +#include "tcpsockets/NetworkStream.h" using namespace nt; @@ -241,11 +241,12 @@ void NetworkConnection::QueueOutgoing(std::shared_ptr msg) { // need to update assignment with new seq_num and value oldmsg = Message::EntryAssign(oldmsg->str(), id, msg->seq_num_uid(), msg->value(), oldmsg->flags()); - } else + } else { oldmsg = msg; // easy update + } } else { // new, but remember it - std::size_t pos = m_pending_outgoing.size(); + size_t pos = m_pending_outgoing.size(); m_pending_outgoing.push_back(msg); if (id >= m_pending_update.size()) m_pending_update.resize(id + 1); m_pending_update[id].first = pos + 1; @@ -288,7 +289,7 @@ void NetworkConnection::QueueOutgoing(std::shared_ptr msg) { m_pending_outgoing[m_pending_update[id].second - 1] = msg; } else { // new, but remember it - std::size_t pos = m_pending_outgoing.size(); + size_t pos = m_pending_outgoing.size(); m_pending_outgoing.push_back(msg); if (id >= m_pending_update.size()) m_pending_update.resize(id + 1); m_pending_update[id].second = pos + 1; diff --git a/src/main/native/cpp/NetworkConnection.h b/src/main/native/cpp/NetworkConnection.h index 720b7b3..caced0d 100644 --- a/src/main/native/cpp/NetworkConnection.h +++ b/src/main/native/cpp/NetworkConnection.h @@ -1,21 +1,27 @@ /*----------------------------------------------------------------------------*/ -/* Copyright (c) FIRST 2015. All Rights Reserved. */ +/* Copyright (c) FIRST 2015-2017. All Rights Reserved. */ /* Open Source Software - may be modified and shared by FRC teams. The code */ /* must be accompanied by the FIRST BSD license file in the root directory of */ /* the project. */ /*----------------------------------------------------------------------------*/ -#ifndef NT_NETWORKCONNECTION_H_ -#define NT_NETWORKCONNECTION_H_ +#ifndef NTCORE_NETWORKCONNECTION_H_ +#define NTCORE_NETWORKCONNECTION_H_ + +#include #include #include #include +#include #include +#include +#include + +#include +#include +#include -#include "support/condition_variable.h" -#include "support/mutex.h" -#include "support/ConcurrentQueue.h" #include "INetworkConnection.h" #include "Message.h" #include "ntcore_cpp.h" @@ -23,7 +29,7 @@ namespace wpi { class Logger; class NetworkStream; -} +} // namespace wpi namespace nt { @@ -76,7 +82,7 @@ class NetworkConnection : public INetworkConnection { std::string remote_id() const; void set_remote_id(StringRef remote_id); - unsigned long long last_update() const { return m_last_update; } + uint64_t last_update() const { return m_last_update; } NetworkConnection(const NetworkConnection&) = delete; NetworkConnection& operator=(const NetworkConnection&) = delete; @@ -106,7 +112,7 @@ class NetworkConnection : public INetworkConnection { wpi::mutex m_pending_mutex; Outgoing m_pending_outgoing; - std::vector> m_pending_update; + std::vector> m_pending_update; // Condition variables for shutdown wpi::mutex m_shutdown_mutex; @@ -118,4 +124,4 @@ class NetworkConnection : public INetworkConnection { } // namespace nt -#endif // NT_NETWORKCONNECTION_H_ +#endif // NTCORE_NETWORKCONNECTION_H_ diff --git a/src/main/native/cpp/RpcServer.cpp b/src/main/native/cpp/RpcServer.cpp index b6fa712..1aa65bc 100644 --- a/src/main/native/cpp/RpcServer.cpp +++ b/src/main/native/cpp/RpcServer.cpp @@ -1,5 +1,5 @@ /*----------------------------------------------------------------------------*/ -/* Copyright (c) FIRST 2015. All Rights Reserved. */ +/* Copyright (c) FIRST 2015-2017. All Rights Reserved. */ /* Open Source Software - may be modified and shared by FRC teams. The code */ /* must be accompanied by the FIRST BSD license file in the root directory of */ /* the project. */ diff --git a/src/main/native/cpp/RpcServer.h b/src/main/native/cpp/RpcServer.h index 97d10db..601e431 100644 --- a/src/main/native/cpp/RpcServer.h +++ b/src/main/native/cpp/RpcServer.h @@ -1,15 +1,17 @@ /*----------------------------------------------------------------------------*/ -/* Copyright (c) FIRST 2015. All Rights Reserved. */ +/* Copyright (c) FIRST 2015-2017. All Rights Reserved. */ /* Open Source Software - may be modified and shared by FRC teams. The code */ /* must be accompanied by the FIRST BSD license file in the root directory of */ /* the project. */ /*----------------------------------------------------------------------------*/ -#ifndef NT_RPCSERVER_H_ -#define NT_RPCSERVER_H_ +#ifndef NTCORE_RPCSERVER_H_ +#define NTCORE_RPCSERVER_H_ -#include "llvm/DenseMap.h" -#include "support/mutex.h" +#include + +#include +#include #include "CallbackManager.h" #include "Handle.h" @@ -107,4 +109,4 @@ class RpcServer : public IRpcServer, } // namespace nt -#endif // NT_RPCSERVER_H_ +#endif // NTCORE_RPCSERVER_H_ diff --git a/src/main/native/cpp/SequenceNumber.cpp b/src/main/native/cpp/SequenceNumber.cpp index b22bfec..a6ad2bf 100644 --- a/src/main/native/cpp/SequenceNumber.cpp +++ b/src/main/native/cpp/SequenceNumber.cpp @@ -1,5 +1,5 @@ /*----------------------------------------------------------------------------*/ -/* Copyright (c) FIRST 2015. All Rights Reserved. */ +/* Copyright (c) FIRST 2015-2017. All Rights Reserved. */ /* Open Source Software - may be modified and shared by FRC teams. The code */ /* must be accompanied by the FIRST BSD license file in the root directory of */ /* the project. */ diff --git a/src/main/native/cpp/SequenceNumber.h b/src/main/native/cpp/SequenceNumber.h index a8f85a4..cde7029 100644 --- a/src/main/native/cpp/SequenceNumber.h +++ b/src/main/native/cpp/SequenceNumber.h @@ -1,12 +1,12 @@ /*----------------------------------------------------------------------------*/ -/* Copyright (c) FIRST 2015. All Rights Reserved. */ +/* Copyright (c) FIRST 2015-2017. All Rights Reserved. */ /* Open Source Software - may be modified and shared by FRC teams. The code */ /* must be accompanied by the FIRST BSD license file in the root directory of */ /* the project. */ /*----------------------------------------------------------------------------*/ -#ifndef NT_SEQNUM_H_ -#define NT_SEQNUM_H_ +#ifndef NTCORE_SEQUENCENUMBER_H_ +#define NTCORE_SEQUENCENUMBER_H_ namespace nt { @@ -60,4 +60,4 @@ inline bool operator!=(const SequenceNumber& lhs, const SequenceNumber& rhs) { } // namespace nt -#endif // NT_SEQNUM_H_ +#endif // NTCORE_SEQUENCENUMBER_H_ diff --git a/src/main/native/cpp/Storage.cpp b/src/main/native/cpp/Storage.cpp index b70f0b8..c486cac 100644 --- a/src/main/native/cpp/Storage.cpp +++ b/src/main/native/cpp/Storage.cpp @@ -1,5 +1,5 @@ /*----------------------------------------------------------------------------*/ -/* Copyright (c) FIRST 2015. All Rights Reserved. */ +/* Copyright (c) FIRST 2015-2017. All Rights Reserved. */ /* Open Source Software - may be modified and shared by FRC teams. The code */ /* must be accompanied by the FIRST BSD license file in the root directory of */ /* the project. */ @@ -7,7 +7,7 @@ #include "Storage.h" -#include "support/timestamp.h" +#include #include "Handle.h" #include "IDispatcher.h" @@ -461,9 +461,9 @@ void Storage::ApplyInitialAssignments( // if we have written the value locally, we send an assign message to the // server instead of deleting if (entry->local_write) { - out_msgs->emplace_back( - Message::EntryAssign(entry->name, entry->id, entry->seq_num.value(), - entry->value, entry->flags)); + out_msgs->emplace_back(Message::EntryAssign(entry->name, entry->id, + entry->seq_num.value(), + entry->value, entry->flags)); return false; } // otherwise delete @@ -827,7 +827,7 @@ NT_Type Storage::GetEntryType(unsigned int local_id) const { return entry->value->type(); } -unsigned long long Storage::GetEntryLastChange(unsigned int local_id) const { +uint64_t Storage::GetEntryLastChange(unsigned int local_id) const { std::unique_lock lock(m_mutex); if (local_id >= m_localmap.size()) return 0; Entry* entry = m_localmap[local_id].get(); diff --git a/src/main/native/cpp/Storage.h b/src/main/native/cpp/Storage.h index 1d9937d..c25608f 100644 --- a/src/main/native/cpp/Storage.h +++ b/src/main/native/cpp/Storage.h @@ -1,37 +1,42 @@ /*----------------------------------------------------------------------------*/ -/* Copyright (c) FIRST 2015. All Rights Reserved. */ +/* Copyright (c) FIRST 2015-2017. All Rights Reserved. */ /* Open Source Software - may be modified and shared by FRC teams. The code */ /* must be accompanied by the FIRST BSD license file in the root directory of */ /* the project. */ /*----------------------------------------------------------------------------*/ -#ifndef NT_STORAGE_H_ -#define NT_STORAGE_H_ +#ifndef NTCORE_STORAGE_H_ +#define NTCORE_STORAGE_H_ + +#include #include #include #include #include +#include +#include +#include -#include "llvm/DenseMap.h" -#include "llvm/SmallSet.h" -#include "llvm/StringMap.h" -#include "support/condition_variable.h" -#include "support/mutex.h" -#include "Message.h" -#include "ntcore_cpp.h" -#include "SequenceNumber.h" +#include +#include +#include +#include +#include #include "IStorage.h" +#include "Message.h" +#include "SequenceNumber.h" +#include "ntcore_cpp.h" namespace llvm { class raw_ostream; -} +} // namespace llvm namespace wpi { class Logger; class raw_istream; -} +} // namespace wpi namespace nt { @@ -120,7 +125,7 @@ class Storage : public IStorage { EntryInfo GetEntryInfo(int inst, unsigned int local_id) const; std::string GetEntryName(unsigned int local_id) const; NT_Type GetEntryType(unsigned int local_id) const; - unsigned long long GetEntryLastChange(unsigned int local_id) const; + uint64_t GetEntryLastChange(unsigned int local_id) const; // Filename-based save/load functions. Used both by periodic saves and // accessible directly via the user API. @@ -128,18 +133,18 @@ class Storage : public IStorage { bool periodic) const override; const char* LoadPersistent( const Twine& filename, - std::function warn) override; + std::function warn) override; const char* SaveEntries(const Twine& filename, const Twine& prefix) const; const char* LoadEntries( const Twine& filename, const Twine& prefix, - std::function warn); + std::function warn); // Stream-based save/load functions (exposed for testing purposes). These // implement the guts of the filename-based functions. void SavePersistent(llvm::raw_ostream& os, bool periodic) const; bool LoadEntries(wpi::raw_istream& is, const Twine& prefix, bool persistent, - std::function warn); + std::function warn); void SaveEntries(llvm::raw_ostream& os, const Twine& prefix) const; @@ -156,7 +161,7 @@ class Storage : public IStorage { private: // Data for each table entry. struct Entry { - Entry(llvm::StringRef name_) : name(name_) {} + explicit Entry(llvm::StringRef name_) : name(name_) {} bool IsPersistent() const { return (flags & NT_PERSISTENT) != 0; } // We redundantly store the name so that it's available when accessing the @@ -257,4 +262,4 @@ class Storage : public IStorage { } // namespace nt -#endif // NT_STORAGE_H_ +#endif // NTCORE_STORAGE_H_ diff --git a/src/main/native/cpp/Storage_load.cpp b/src/main/native/cpp/Storage_load.cpp index 72bcd53..93469c5 100644 --- a/src/main/native/cpp/Storage_load.cpp +++ b/src/main/native/cpp/Storage_load.cpp @@ -1,22 +1,21 @@ /*----------------------------------------------------------------------------*/ -/* Copyright (c) FIRST 2015. All Rights Reserved. */ +/* Copyright (c) FIRST 2015-2017. All Rights Reserved. */ /* Open Source Software - may be modified and shared by FRC teams. The code */ /* must be accompanied by the FIRST BSD license file in the root directory of */ /* the project. */ /*----------------------------------------------------------------------------*/ -#include "Storage.h" - #include #include -#include "llvm/SmallString.h" -#include "llvm/StringExtras.h" -#include "support/Base64.h" -#include "support/raw_istream.h" +#include +#include +#include +#include #include "IDispatcher.h" #include "IEntryNotifier.h" +#include "Storage.h" using namespace nt; @@ -25,7 +24,7 @@ namespace { class LoadPersistentImpl { public: typedef std::pair> Entry; - typedef std::function WarnFunc; + typedef std::function WarnFunc; LoadPersistentImpl(wpi::raw_istream& is, WarnFunc warn) : m_is(is), m_warn(warn) {} @@ -55,14 +54,14 @@ class LoadPersistentImpl { llvm::StringRef m_line; llvm::SmallString<128> m_line_buf; - std::size_t m_line_num = 0; + size_t m_line_num = 0; std::vector m_buf_boolean_array; std::vector m_buf_double_array; std::vector m_buf_string_array; }; -} // anonymous namespace +} // namespace /* Extracts an escaped string token. Does not unescape the string. * If a string cannot be matched, an empty string is returned. @@ -79,8 +78,8 @@ static std::pair ReadStringToken( return std::make_pair(llvm::StringRef(), source); // Scan for ending double quote, checking for escaped as we go. - std::size_t size = source.size(); - std::size_t pos; + size_t size = source.size(); + size_t pos; for (pos = 1; pos < size; ++pos) { if (source[pos] == '"' && source[pos - 1] != '\\') { ++pos; // we want to include the trailing quote in the result @@ -126,7 +125,7 @@ static llvm::StringRef UnescapeString(llvm::StringRef source, break; } int ch = fromxdigit(*++s); - if (isxdigit(*(s + 1))) { + if (std::isxdigit(*(s + 1))) { ch <<= 4; ch |= fromxdigit(*++s); } @@ -197,15 +196,15 @@ bool LoadPersistentImpl::ReadHeader() { NT_Type LoadPersistentImpl::ReadType() { llvm::StringRef tok; std::tie(tok, m_line) = m_line.split(' '); - if (tok == "boolean") + if (tok == "boolean") { return NT_BOOLEAN; - else if (tok == "double") + } else if (tok == "double") { return NT_DOUBLE; - else if (tok == "string") + } else if (tok == "string") { return NT_STRING; - else if (tok == "raw") + } else if (tok == "raw") { return NT_RAW; - else if (tok == "array") { + } else if (tok == "array") { llvm::StringRef array_tok; std::tie(array_tok, m_line) = m_line.split(' '); if (array_tok == "boolean") @@ -262,7 +261,7 @@ std::shared_ptr LoadPersistentImpl::ReadBooleanValue() { } std::shared_ptr LoadPersistentImpl::ReadDoubleValue() { - // need to convert to null-terminated string for strtod() + // need to convert to null-terminated string for std::strtod() llvm::SmallString<64> buf; char* end; double v = std::strtod(m_line.c_str(buf), &end); @@ -290,7 +289,7 @@ std::shared_ptr LoadPersistentImpl::ReadStringValue() { std::shared_ptr LoadPersistentImpl::ReadRawValue() { llvm::SmallString<128> buf; - std::size_t nr; + size_t nr; return Value::MakeRaw(wpi::Base64Decode(m_line, &nr, buf)); } @@ -300,11 +299,11 @@ std::shared_ptr LoadPersistentImpl::ReadBooleanArrayValue() { llvm::StringRef tok; std::tie(tok, m_line) = m_line.split(','); tok = tok.trim(" \t"); - if (tok == "true") + if (tok == "true") { m_buf_boolean_array.push_back(1); - else if (tok == "false") + } else if (tok == "false") { m_buf_boolean_array.push_back(0); - else { + } else { Warn("unrecognized boolean value, not 'true' or 'false'"); return nullptr; } @@ -318,7 +317,7 @@ std::shared_ptr LoadPersistentImpl::ReadDoubleArrayValue() { llvm::StringRef tok; std::tie(tok, m_line) = m_line.split(','); tok = tok.trim(" \t"); - // need to convert to null-terminated string for strtod() + // need to convert to null-terminated string for std::strtod() llvm::SmallString<64> buf; char* end; double v = std::strtod(tok.c_str(buf), &end); @@ -363,7 +362,7 @@ std::shared_ptr LoadPersistentImpl::ReadStringArrayValue() { bool Storage::LoadEntries( wpi::raw_istream& is, const Twine& prefix, bool persistent, - std::function warn) { + std::function warn) { llvm::SmallString<128> prefixBuf; StringRef prefixStr = prefix.toStringRef(prefixBuf); @@ -410,10 +409,10 @@ bool Storage::LoadEntries( ++entry->seq_num; // put on update queue - if (!old_value || old_value->type() != i.second->type()) + if (!old_value || old_value->type() != i.second->type()) { msgs.emplace_back(Message::EntryAssign( i.first, entry->id, entry->seq_num.value(), i.second, entry->flags)); - else if (entry->id != 0xffff) { + } else if (entry->id != 0xffff) { // don't send an update if we don't have an assigned id yet if (*old_value != *i.second) msgs.emplace_back( @@ -435,7 +434,7 @@ bool Storage::LoadEntries( const char* Storage::LoadPersistent( const Twine& filename, - std::function warn) { + std::function warn) { std::error_code ec; wpi::raw_fd_istream is(filename, ec); if (ec.value() != 0) return "could not open file"; @@ -445,7 +444,7 @@ const char* Storage::LoadPersistent( const char* Storage::LoadEntries( const Twine& filename, const Twine& prefix, - std::function warn) { + std::function warn) { std::error_code ec; wpi::raw_fd_istream is(filename, ec); if (ec.value() != 0) return "could not open file"; diff --git a/src/main/native/cpp/Storage_save.cpp b/src/main/native/cpp/Storage_save.cpp index 601adcc..e227367 100644 --- a/src/main/native/cpp/Storage_save.cpp +++ b/src/main/native/cpp/Storage_save.cpp @@ -1,22 +1,21 @@ /*----------------------------------------------------------------------------*/ -/* Copyright (c) FIRST 2015. All Rights Reserved. */ +/* Copyright (c) FIRST 2015-2017. All Rights Reserved. */ /* Open Source Software - may be modified and shared by FRC teams. The code */ /* must be accompanied by the FIRST BSD license file in the root directory of */ /* the project. */ /*----------------------------------------------------------------------------*/ -#include "Storage.h" - #include #include -#include "llvm/Format.h" -#include "llvm/SmallString.h" -#include "llvm/StringExtras.h" -#include "llvm/raw_ostream.h" -#include "support/Base64.h" +#include +#include +#include +#include +#include #include "Log.h" +#include "Storage.h" using namespace nt; @@ -26,7 +25,7 @@ class SavePersistentImpl { public: typedef std::pair> Entry; - SavePersistentImpl(llvm::raw_ostream& os) : m_os(os) {} + explicit SavePersistentImpl(llvm::raw_ostream& os) : m_os(os) {} void Save(llvm::ArrayRef entries); @@ -41,7 +40,7 @@ class SavePersistentImpl { llvm::raw_ostream& m_os; }; -} // anonymous namespace +} // namespace /* Escapes and writes a string, including start and end double quotes */ void SavePersistentImpl::WriteString(llvm::StringRef str) { diff --git a/src/main/native/cpp/Value.cpp b/src/main/native/cpp/Value.cpp index 5e065cb..7bc3ae2 100644 --- a/src/main/native/cpp/Value.cpp +++ b/src/main/native/cpp/Value.cpp @@ -1,13 +1,16 @@ /*----------------------------------------------------------------------------*/ -/* Copyright (c) FIRST 2015. All Rights Reserved. */ +/* Copyright (c) FIRST 2015-2017. All Rights Reserved. */ /* Open Source Software - may be modified and shared by FRC teams. The code */ /* must be accompanied by the FIRST BSD license file in the root directory of */ /* the project. */ /*----------------------------------------------------------------------------*/ -#include "networktables/NetworkTableValue.h" +#include + +#include + #include "Value_internal.h" -#include "support/timestamp.h" +#include "networktables/NetworkTableValue.h" using namespace nt; @@ -16,7 +19,7 @@ Value::Value() { m_val.last_change = wpi::Now(); } -Value::Value(NT_Type type, unsigned long long time, const private_init&) { +Value::Value(NT_Type type, uint64_t time, const private_init&) { m_val.type = type; if (time == 0) m_val.last_change = wpi::Now(); @@ -40,7 +43,7 @@ Value::~Value() { } std::shared_ptr Value::MakeBooleanArray(llvm::ArrayRef value, - unsigned long long time) { + uint64_t time) { auto val = std::make_shared(NT_BOOLEAN_ARRAY, time, private_init()); val->m_val.data.arr_boolean.arr = new int[value.size()]; val->m_val.data.arr_boolean.size = value.size(); @@ -49,7 +52,7 @@ std::shared_ptr Value::MakeBooleanArray(llvm::ArrayRef value, } std::shared_ptr Value::MakeDoubleArray(llvm::ArrayRef value, - unsigned long long time) { + uint64_t time) { auto val = std::make_shared(NT_DOUBLE_ARRAY, time, private_init()); val->m_val.data.arr_double.arr = new double[value.size()]; val->m_val.data.arr_double.size = value.size(); @@ -57,29 +60,29 @@ std::shared_ptr Value::MakeDoubleArray(llvm::ArrayRef value, return val; } -std::shared_ptr Value::MakeStringArray( - llvm::ArrayRef value, unsigned long long time) { +std::shared_ptr Value::MakeStringArray(llvm::ArrayRef value, + uint64_t time) { auto val = std::make_shared(NT_STRING_ARRAY, time, private_init()); val->m_string_array = value; // point NT_Value to the contents in the vector. val->m_val.data.arr_string.arr = new NT_String[value.size()]; val->m_val.data.arr_string.size = val->m_string_array.size(); - for (std::size_t i = 0; i < value.size(); ++i) { + for (size_t i = 0; i < value.size(); ++i) { val->m_val.data.arr_string.arr[i].str = const_cast(value[i].c_str()); val->m_val.data.arr_string.arr[i].len = value[i].size(); } return val; } -std::shared_ptr Value::MakeStringArray( - std::vector&& value, unsigned long long time) { +std::shared_ptr Value::MakeStringArray(std::vector&& value, + uint64_t time) { auto val = std::make_shared(NT_STRING_ARRAY, time, private_init()); val->m_string_array = std::move(value); value.clear(); // point NT_Value to the contents in the vector. val->m_val.data.arr_string.arr = new NT_String[val->m_string_array.size()]; val->m_val.data.arr_string.size = val->m_string_array.size(); - for (std::size_t i = 0; i < val->m_string_array.size(); ++i) { + for (size_t i = 0; i < val->m_string_array.size(); ++i) { val->m_val.data.arr_string.arr[i].str = const_cast(val->m_string_array[i].c_str()); val->m_val.data.arr_string.arr[i].len = val->m_string_array[i].size(); diff --git a/src/main/native/cpp/Value_internal.h b/src/main/native/cpp/Value_internal.h index f09748c..104fe12 100644 --- a/src/main/native/cpp/Value_internal.h +++ b/src/main/native/cpp/Value_internal.h @@ -1,17 +1,18 @@ /*----------------------------------------------------------------------------*/ -/* Copyright (c) FIRST 2015. All Rights Reserved. */ +/* Copyright (c) FIRST 2015-2017. All Rights Reserved. */ /* Open Source Software - may be modified and shared by FRC teams. The code */ /* must be accompanied by the FIRST BSD license file in the root directory of */ /* the project. */ /*----------------------------------------------------------------------------*/ -#ifndef NT_VALUE_INTERNAL_H_ -#define NT_VALUE_INTERNAL_H_ +#ifndef NTCORE_VALUE_INTERNAL_H_ +#define NTCORE_VALUE_INTERNAL_H_ #include #include -#include "llvm/StringRef.h" +#include + #include "ntcore_c.h" namespace nt { @@ -27,4 +28,4 @@ inline llvm::StringRef ConvertFromC(const NT_String& str) { } // namespace nt -#endif // NT_VALUE_INTERNAL_H_ +#endif // NTCORE_VALUE_INTERNAL_H_ diff --git a/src/main/native/cpp/WireDecoder.cpp b/src/main/native/cpp/WireDecoder.cpp index 6a087e1..81aeda9 100644 --- a/src/main/native/cpp/WireDecoder.cpp +++ b/src/main/native/cpp/WireDecoder.cpp @@ -1,5 +1,5 @@ /*----------------------------------------------------------------------------*/ -/* Copyright (c) FIRST 2015. All Rights Reserved. */ +/* Copyright (c) FIRST 2015-2017. All Rights Reserved. */ /* Open Source Software - may be modified and shared by FRC teams. The code */ /* must be accompanied by the FIRST BSD license file in the root directory of */ /* the project. */ @@ -7,19 +7,20 @@ #include "WireDecoder.h" +#include + #include -#include #include #include -#include "llvm/MathExtras.h" -#include "support/leb128.h" +#include +#include using namespace nt; static double ReadDouble(const char*& buf) { // Fast but non-portable! - std::uint64_t val = (*reinterpret_cast(buf)) & 0xff; + uint64_t val = (*reinterpret_cast(buf)) & 0xff; ++buf; val <<= 8; val |= (*reinterpret_cast(buf)) & 0xff; @@ -65,10 +66,10 @@ bool WireDecoder::ReadDouble(double* val) { return true; } -void WireDecoder::Realloc(std::size_t len) { +void WireDecoder::Realloc(size_t len) { // Double current buffer size until we have enough space. if (m_allocated >= len) return; - std::size_t newlen = m_allocated * 2; + size_t newlen = m_allocated * 2; while (newlen < len) newlen *= 2; m_buf = static_cast(std::realloc(m_buf, newlen)); m_allocated = newlen; @@ -195,7 +196,7 @@ bool WireDecoder::ReadString(std::string* str) { if (!Read16(&v)) return false; len = v; } else { - unsigned long v; + uint64_t v; if (!ReadUleb128(&v)) return false; len = v; } diff --git a/src/main/native/cpp/WireDecoder.h b/src/main/native/cpp/WireDecoder.h index c9d45af..483d85b 100644 --- a/src/main/native/cpp/WireDecoder.h +++ b/src/main/native/cpp/WireDecoder.h @@ -1,19 +1,24 @@ /*----------------------------------------------------------------------------*/ -/* Copyright (c) FIRST 2015. All Rights Reserved. */ +/* Copyright (c) FIRST 2015-2017. All Rights Reserved. */ /* Open Source Software - may be modified and shared by FRC teams. The code */ /* must be accompanied by the FIRST BSD license file in the root directory of */ /* the project. */ /*----------------------------------------------------------------------------*/ -#ifndef NT_WIREDECODER_H_ -#define NT_WIREDECODER_H_ +#ifndef NTCORE_WIREDECODER_H_ +#define NTCORE_WIREDECODER_H_ + +#include #include +#include +#include + +#include +#include -#include "networktables/NetworkTableValue.h" -#include "support/leb128.h" -#include "support/raw_istream.h" #include "Log.h" +#include "networktables/NetworkTableValue.h" namespace nt { @@ -53,7 +58,7 @@ class WireDecoder { * @param len number of bytes to read * Caution: the buffer is only temporarily valid. */ - bool Read(const char** buf, std::size_t len) { + bool Read(const char** buf, size_t len) { if (len > m_allocated) Realloc(len); *buf = m_buf; m_is.read(m_buf, len); @@ -61,11 +66,11 @@ class WireDecoder { if (m_logger.min_level() <= NT_LOG_DEBUG4 && m_logger.HasLogger()) { std::ostringstream oss; oss << "read " << len << " bytes:" << std::hex; - if (!rv) + if (!rv) { oss << "error"; - else { - for (std::size_t i=0; i < len; ++i) - oss << ' ' << (unsigned int)((*buf)[i]); + } else { + for (size_t i = 0; i < len; ++i) + oss << ' ' << static_cast((*buf)[i]); } m_logger.Log(NT_LOG_DEBUG4, __FILE__, __LINE__, oss.str().c_str()); } @@ -94,7 +99,7 @@ class WireDecoder { } /* Reads a 32-bit word. */ - bool Read32(unsigned long* val) { + bool Read32(uint32_t* val) { const char* buf; if (!Read(&buf, 4)) return false; unsigned int v = (*reinterpret_cast(buf)) & 0xff; @@ -115,7 +120,7 @@ class WireDecoder { bool ReadDouble(double* val); /* Reads an ULEB128-encoded unsigned integer. */ - bool ReadUleb128(unsigned long* val) { return wpi::ReadUleb128(m_is, val); } + bool ReadUleb128(uint64_t* val) { return wpi::ReadUleb128(m_is, val); } bool ReadType(NT_Type* type); bool ReadString(std::string* str); @@ -133,7 +138,7 @@ class WireDecoder { private: /* Reallocate temporary buffer to specified length. */ - void Realloc(std::size_t len); + void Realloc(size_t len); /* input stream */ wpi::raw_istream& m_is; @@ -145,9 +150,9 @@ class WireDecoder { char* m_buf; /* allocated size of temporary buffer */ - std::size_t m_allocated; + size_t m_allocated; }; } // namespace nt -#endif // NT_WIREDECODER_H_ +#endif // NTCORE_WIREDECODER_H_ diff --git a/src/main/native/cpp/WireEncoder.cpp b/src/main/native/cpp/WireEncoder.cpp index 884d4b8..e5247ab 100644 --- a/src/main/native/cpp/WireEncoder.cpp +++ b/src/main/native/cpp/WireEncoder.cpp @@ -1,5 +1,5 @@ /*----------------------------------------------------------------------------*/ -/* Copyright (c) FIRST 2015. All Rights Reserved. */ +/* Copyright (c) FIRST 2015-2017. All Rights Reserved. */ /* Open Source Software - may be modified and shared by FRC teams. The code */ /* must be accompanied by the FIRST BSD license file in the root directory of */ /* the project. */ @@ -7,13 +7,14 @@ #include "WireEncoder.h" +#include + #include -#include #include #include -#include "llvm/MathExtras.h" -#include "support/leb128.h" +#include +#include using namespace nt; @@ -24,16 +25,15 @@ WireEncoder::WireEncoder(unsigned int proto_rev) { void WireEncoder::WriteDouble(double val) { // The highest performance way to do this, albeit non-portable. - std::uint64_t v = llvm::DoubleToBits(val); - m_data.append({(char)((v >> 56) & 0xff), (char)((v >> 48) & 0xff), - (char)((v >> 40) & 0xff), (char)((v >> 32) & 0xff), - (char)((v >> 24) & 0xff), (char)((v >> 16) & 0xff), - (char)((v >> 8) & 0xff), (char)(v & 0xff)}); + uint64_t v = llvm::DoubleToBits(val); + m_data.append( + {static_cast((v >> 56) & 0xff), static_cast((v >> 48) & 0xff), + static_cast((v >> 40) & 0xff), static_cast((v >> 32) & 0xff), + static_cast((v >> 24) & 0xff), static_cast((v >> 16) & 0xff), + static_cast((v >> 8) & 0xff), static_cast(v & 0xff)}); } -void WireEncoder::WriteUleb128(unsigned long val) { - wpi::WriteUleb128(m_data, val); -} +void WireEncoder::WriteUleb128(uint32_t val) { wpi::WriteUleb128(m_data, val); } void WireEncoder::WriteType(NT_Type type) { char ch; @@ -78,7 +78,7 @@ void WireEncoder::WriteType(NT_Type type) { m_data.push_back(ch); } -std::size_t WireEncoder::GetValueSize(const Value& value) const { +size_t WireEncoder::GetValueSize(const Value& value) const { switch (value.type()) { case NT_BOOLEAN: return 1; @@ -94,22 +94,22 @@ std::size_t WireEncoder::GetValueSize(const Value& value) const { return GetStringSize(value.GetRpc()); case NT_BOOLEAN_ARRAY: { // 1-byte size, 1 byte per element - std::size_t size = value.GetBooleanArray().size(); + size_t size = value.GetBooleanArray().size(); if (size > 0xff) size = 0xff; // size is only 1 byte, truncate return 1 + size; } case NT_DOUBLE_ARRAY: { // 1-byte size, 8 bytes per element - std::size_t size = value.GetDoubleArray().size(); + size_t size = value.GetDoubleArray().size(); if (size > 0xff) size = 0xff; // size is only 1 byte, truncate return 1 + size * 8; } case NT_STRING_ARRAY: { auto v = value.GetStringArray(); - std::size_t size = v.size(); + size_t size = v.size(); if (size > 0xff) size = 0xff; // size is only 1 byte, truncate - std::size_t len = 1; // 1-byte size - for (std::size_t i = 0; i < size; ++i) len += GetStringSize(v[i]); + size_t len = 1; // 1-byte size + for (size_t i = 0; i < size; ++i) len += GetStringSize(v[i]); return len; } default: @@ -144,29 +144,29 @@ void WireEncoder::WriteValue(const Value& value) { break; case NT_BOOLEAN_ARRAY: { auto v = value.GetBooleanArray(); - std::size_t size = v.size(); + size_t size = v.size(); if (size > 0xff) size = 0xff; // size is only 1 byte, truncate Write8(size); - for (std::size_t i = 0; i < size; ++i) Write8(v[i] ? 1 : 0); + for (size_t i = 0; i < size; ++i) Write8(v[i] ? 1 : 0); break; } case NT_DOUBLE_ARRAY: { auto v = value.GetDoubleArray(); - std::size_t size = v.size(); + size_t size = v.size(); if (size > 0xff) size = 0xff; // size is only 1 byte, truncate Write8(size); - for (std::size_t i = 0; i < size; ++i) WriteDouble(v[i]); + for (size_t i = 0; i < size; ++i) WriteDouble(v[i]); break; } case NT_STRING_ARRAY: { auto v = value.GetStringArray(); - std::size_t size = v.size(); + size_t size = v.size(); if (size > 0xff) size = 0xff; // size is only 1 byte, truncate Write8(size); - for (std::size_t i = 0; i < size; ++i) WriteString(v[i]); + for (size_t i = 0; i < size; ++i) WriteString(v[i]); break; } default: @@ -175,9 +175,9 @@ void WireEncoder::WriteValue(const Value& value) { } } -std::size_t WireEncoder::GetStringSize(llvm::StringRef str) const { +size_t WireEncoder::GetStringSize(llvm::StringRef str) const { if (m_proto_rev < 0x0300u) { - std::size_t len = str.size(); + size_t len = str.size(); if (len > 0xffff) len = 0xffff; // Limited to 64K length; truncate return 2 + len; } @@ -186,12 +186,13 @@ std::size_t WireEncoder::GetStringSize(llvm::StringRef str) const { void WireEncoder::WriteString(llvm::StringRef str) { // length - std::size_t len = str.size(); + size_t len = str.size(); if (m_proto_rev < 0x0300u) { if (len > 0xffff) len = 0xffff; // Limited to 64K length; truncate Write16(len); - } else + } else { WriteUleb128(len); + } // contents m_data.append(str.data(), str.data() + len); diff --git a/src/main/native/cpp/WireEncoder.h b/src/main/native/cpp/WireEncoder.h index 48ea9b6..90f78cd 100644 --- a/src/main/native/cpp/WireEncoder.h +++ b/src/main/native/cpp/WireEncoder.h @@ -1,18 +1,21 @@ /*----------------------------------------------------------------------------*/ -/* Copyright (c) FIRST 2015. All Rights Reserved. */ +/* Copyright (c) FIRST 2015-2017. All Rights Reserved. */ /* Open Source Software - may be modified and shared by FRC teams. The code */ /* must be accompanied by the FIRST BSD license file in the root directory of */ /* the project. */ /*----------------------------------------------------------------------------*/ -#ifndef NT_WIREENCODER_H_ -#define NT_WIREENCODER_H_ +#ifndef NTCORE_WIREENCODER_H_ +#define NTCORE_WIREENCODER_H_ + +#include #include #include -#include "llvm/SmallVector.h" -#include "llvm/StringRef.h" +#include +#include + #include "networktables/NetworkTableValue.h" namespace nt { @@ -47,31 +50,36 @@ class WireEncoder { const char* data() const { return m_data.data(); } /* Returns number of bytes written to memory buffer. */ - std::size_t size() const { return m_data.size(); } + size_t size() const { return m_data.size(); } llvm::StringRef ToStringRef() const { return llvm::StringRef(m_data.data(), m_data.size()); } /* Writes a single byte. */ - void Write8(unsigned int val) { m_data.push_back((char)(val & 0xff)); } + void Write8(unsigned int val) { + m_data.push_back(static_cast(val & 0xff)); + } /* Writes a 16-bit word. */ void Write16(unsigned int val) { - m_data.append({(char)((val >> 8) & 0xff), (char)(val & 0xff)}); + m_data.append( + {static_cast((val >> 8) & 0xff), static_cast(val & 0xff)}); } /* Writes a 32-bit word. */ - void Write32(unsigned long val) { - m_data.append({(char)((val >> 24) & 0xff), (char)((val >> 16) & 0xff), - (char)((val >> 8) & 0xff), (char)(val & 0xff)}); + void Write32(uint32_t val) { + m_data.append({static_cast((val >> 24) & 0xff), + static_cast((val >> 16) & 0xff), + static_cast((val >> 8) & 0xff), + static_cast(val & 0xff)}); } /* Writes a double. */ void WriteDouble(double val); /* Writes an ULEB128-encoded unsigned integer. */ - void WriteUleb128(unsigned long val); + void WriteUleb128(uint32_t val); void WriteType(NT_Type type); void WriteValue(const Value& value); @@ -80,12 +88,12 @@ class WireEncoder { /* Utility function to get the written size of a value (without actually * writing it). */ - std::size_t GetValueSize(const Value& value) const; + size_t GetValueSize(const Value& value) const; /* Utility function to get the written size of a string (without actually * writing it). */ - std::size_t GetStringSize(llvm::StringRef str) const; + size_t GetStringSize(llvm::StringRef str) const; protected: /* The protocol revision. E.g. 0x0200 for version 2.0. */ @@ -100,4 +108,4 @@ class WireEncoder { } // namespace nt -#endif // NT_WIREENCODER_H_ +#endif // NTCORE_WIREENCODER_H_ diff --git a/src/main/native/cpp/networktables/NetworkTable.cpp b/src/main/native/cpp/networktables/NetworkTable.cpp index 69d8e4e..babc61f 100644 --- a/src/main/native/cpp/networktables/NetworkTable.cpp +++ b/src/main/native/cpp/networktables/NetworkTable.cpp @@ -1,10 +1,18 @@ +/*----------------------------------------------------------------------------*/ +/* Copyright (c) FIRST 2017. All Rights Reserved. */ +/* Open Source Software - may be modified and shared by FRC teams. The code */ +/* must be accompanied by the FIRST BSD license file in the root directory of */ +/* the project. */ +/*----------------------------------------------------------------------------*/ + #include "networktables/NetworkTable.h" #include -#include "llvm/SmallString.h" -#include "llvm/StringMap.h" -#include "llvm/raw_ostream.h" +#include +#include +#include + #include "networktables/NetworkTableInstance.h" #include "ntcore.h" #include "tables/ITableListener.h" @@ -83,8 +91,9 @@ void NetworkTable::Initialize() { if (s_client) { inst.StartClient(); if (s_enable_ds) inst.StartDSClient(s_port); - } else + } else { inst.StartServer(s_persistent_filename, "", s_port); + } s_running = true; } @@ -94,8 +103,9 @@ void NetworkTable::Shutdown() { if (s_client) { inst.StopDSClient(); inst.StopClient(); - } else + } else { inst.StopServer(); + } s_running = false; } @@ -203,7 +213,7 @@ NetworkTableEntry NetworkTable::GetEntry(const Twine& key) const { NT_EntryListener NetworkTable::AddEntryListener(TableEntryListener listener, unsigned int flags) const { - std::size_t prefix_len = m_path.size() + 1; + size_t prefix_len = m_path.size() + 1; return nt::AddEntryListener( m_inst, m_path + Twine(PATH_SEPARATOR_CHAR), [=](const EntryNotification& event) { @@ -218,7 +228,7 @@ NT_EntryListener NetworkTable::AddEntryListener(TableEntryListener listener, NT_EntryListener NetworkTable::AddEntryListener(const Twine& key, TableEntryListener listener, unsigned int flags) const { - std::size_t prefix_len = m_path.size() + 1; + size_t prefix_len = m_path.size() + 1; auto entry = GetEntry(key); return nt::AddEntryListener(entry.GetHandle(), [=](const EntryNotification& event) { @@ -249,7 +259,7 @@ void NetworkTable::AddTableListenerEx(ITableListener* listener, std::lock_guard lock(m_mutex); llvm::SmallString<128> path(m_path); path += PATH_SEPARATOR_CHAR; - std::size_t prefix_len = path.size(); + size_t prefix_len = path.size(); NT_EntryListener id = nt::AddEntryListener( m_inst, path, [=](const EntryNotification& event) { @@ -271,7 +281,7 @@ void NetworkTable::AddTableListener(StringRef key, ITableListener* listener, void NetworkTable::AddTableListenerEx(StringRef key, ITableListener* listener, unsigned int flags) { std::lock_guard lock(m_mutex); - std::size_t prefix_len = m_path.size() + 1; + size_t prefix_len = m_path.size() + 1; auto entry = GetEntry(key); NT_EntryListener id = nt::AddEntryListener( entry.GetHandle(), @@ -290,7 +300,7 @@ void NetworkTable::AddSubTableListener(ITableListener* listener) { void NetworkTable::AddSubTableListener(ITableListener* listener, bool localNotify) { std::lock_guard lock(m_mutex); - std::size_t prefix_len = m_path.size() + 1; + size_t prefix_len = m_path.size() + 1; // The lambda needs to be copyable, but StringMap is not, so use // a shared_ptr to it. @@ -366,7 +376,7 @@ std::vector NetworkTable::GetSubTables() const { for (auto& entry : GetEntryInfo(m_inst, m_path + Twine(PATH_SEPARATOR_CHAR), 0)) { auto relative_key = StringRef(entry.name).substr(prefix_len); - std::size_t end_subtable = relative_key.find(PATH_SEPARATOR_CHAR); + size_t end_subtable = relative_key.find(PATH_SEPARATOR_CHAR); if (end_subtable == StringRef::npos) continue; keys.push_back(relative_key.substr(0, end_subtable)); } @@ -468,8 +478,8 @@ bool NetworkTable::PutStringArray(StringRef key, ArrayRef value) { return GetEntry(key).SetStringArray(value); } -bool NetworkTable::SetDefaultStringArray( - StringRef key, ArrayRef defaultValue) { +bool NetworkTable::SetDefaultStringArray(StringRef key, + ArrayRef defaultValue) { return GetEntry(key).SetDefaultStringArray(defaultValue); } diff --git a/src/main/native/cpp/networktables/NetworkTableInstance.cpp b/src/main/native/cpp/networktables/NetworkTableInstance.cpp index 39b7908..4ef796f 100644 --- a/src/main/native/cpp/networktables/NetworkTableInstance.cpp +++ b/src/main/native/cpp/networktables/NetworkTableInstance.cpp @@ -4,9 +4,10 @@ /* must be accompanied by the FIRST BSD license file in the root directory of */ /* the project. */ /*----------------------------------------------------------------------------*/ + #include "networktables/NetworkTableInstance.h" -#include "llvm/SmallString.h" +#include using namespace nt; diff --git a/src/main/native/cpp/ntcore_c.cpp b/src/main/native/cpp/ntcore_c.cpp index 68df49c..49c9bab 100644 --- a/src/main/native/cpp/ntcore_c.cpp +++ b/src/main/native/cpp/ntcore_c.cpp @@ -1,18 +1,19 @@ /*----------------------------------------------------------------------------*/ -/* Copyright (c) FIRST 2015. All Rights Reserved. */ +/* Copyright (c) FIRST 2015-2017. All Rights Reserved. */ /* Open Source Software - may be modified and shared by FRC teams. The code */ /* must be accompanied by the FIRST BSD license file in the root directory of */ /* the project. */ /*----------------------------------------------------------------------------*/ -#include "ntcore.h" +#include #include #include -#include "support/timestamp.h" +#include #include "Value_internal.h" +#include "ntcore.h" using namespace nt; @@ -205,7 +206,7 @@ char* NT_GetEntryName(NT_Entry entry, size_t* name_len) { enum NT_Type NT_GetEntryType(NT_Entry entry) { return nt::GetEntryType(entry); } -unsigned long long NT_GetEntryLastChange(NT_Entry entry) { +uint64_t NT_GetEntryLastChange(NT_Entry entry) { return nt::GetEntryLastChange(entry); } @@ -660,7 +661,7 @@ const char* NT_LoadEntries(NT_Inst inst, const char* filename, * Utility Functions */ -unsigned long long NT_Now() { return wpi::Now(); } +uint64_t NT_Now(void) { return wpi::Now(); } NT_Logger NT_AddLogger(NT_Inst inst, void* data, NT_LogFunc func, unsigned int min_level, unsigned int max_level) { @@ -866,8 +867,8 @@ void NT_FreeStringArray(struct NT_String* v_string, size_t arr_size) { std::free(v_string); } -NT_Bool NT_SetEntryDouble(NT_Entry entry, unsigned long long time, - double v_double, NT_Bool force) { +NT_Bool NT_SetEntryDouble(NT_Entry entry, uint64_t time, double v_double, + NT_Bool force) { if (force != 0) { nt::SetEntryTypeValue(entry, Value::MakeDouble(v_double, time)); return 1; @@ -876,8 +877,8 @@ NT_Bool NT_SetEntryDouble(NT_Entry entry, unsigned long long time, } } -NT_Bool NT_SetEntryBoolean(NT_Entry entry, unsigned long long time, - NT_Bool v_boolean, NT_Bool force) { +NT_Bool NT_SetEntryBoolean(NT_Entry entry, uint64_t time, NT_Bool v_boolean, + NT_Bool force) { if (force != 0) { nt::SetEntryTypeValue(entry, Value::MakeBoolean(v_boolean != 0, time)); return 1; @@ -886,8 +887,8 @@ NT_Bool NT_SetEntryBoolean(NT_Entry entry, unsigned long long time, } } -NT_Bool NT_SetEntryString(NT_Entry entry, unsigned long long time, - const char* str, size_t str_len, NT_Bool force) { +NT_Bool NT_SetEntryString(NT_Entry entry, uint64_t time, const char* str, + size_t str_len, NT_Bool force) { if (force != 0) { nt::SetEntryTypeValue(entry, Value::MakeString(StringRef(str, str_len), time)); @@ -898,7 +899,7 @@ NT_Bool NT_SetEntryString(NT_Entry entry, unsigned long long time, } } -NT_Bool NT_SetEntryRaw(NT_Entry entry, unsigned long long time, const char* raw, +NT_Bool NT_SetEntryRaw(NT_Entry entry, uint64_t time, const char* raw, size_t raw_len, NT_Bool force) { if (force != 0) { nt::SetEntryTypeValue(entry, Value::MakeRaw(StringRef(raw, raw_len), time)); @@ -909,7 +910,7 @@ NT_Bool NT_SetEntryRaw(NT_Entry entry, unsigned long long time, const char* raw, } } -NT_Bool NT_SetEntryBooleanArray(NT_Entry entry, unsigned long long time, +NT_Bool NT_SetEntryBooleanArray(NT_Entry entry, uint64_t time, const NT_Bool* arr, size_t size, NT_Bool force) { if (force != 0) { @@ -922,8 +923,8 @@ NT_Bool NT_SetEntryBooleanArray(NT_Entry entry, unsigned long long time, } } -NT_Bool NT_SetEntryDoubleArray(NT_Entry entry, unsigned long long time, - const double* arr, size_t size, NT_Bool force) { +NT_Bool NT_SetEntryDoubleArray(NT_Entry entry, uint64_t time, const double* arr, + size_t size, NT_Bool force) { if (force != 0) { nt::SetEntryTypeValue( entry, Value::MakeDoubleArray(llvm::makeArrayRef(arr, size), time)); @@ -934,7 +935,7 @@ NT_Bool NT_SetEntryDoubleArray(NT_Entry entry, unsigned long long time, } } -NT_Bool NT_SetEntryStringArray(NT_Entry entry, unsigned long long time, +NT_Bool NT_SetEntryStringArray(NT_Entry entry, uint64_t time, const struct NT_String* arr, size_t size, NT_Bool force) { std::vector v; @@ -954,8 +955,7 @@ enum NT_Type NT_GetValueType(const struct NT_Value* value) { return value->type; } -NT_Bool NT_GetValueBoolean(const struct NT_Value* value, - unsigned long long* last_change, +NT_Bool NT_GetValueBoolean(const struct NT_Value* value, uint64_t* last_change, NT_Bool* v_boolean) { if (!value || value->type != NT_Type::NT_BOOLEAN) return 0; *v_boolean = value->data.v_boolean; @@ -963,63 +963,60 @@ NT_Bool NT_GetValueBoolean(const struct NT_Value* value, return 1; } -NT_Bool NT_GetValueDouble(const struct NT_Value* value, - unsigned long long* last_change, double* v_double) { +NT_Bool NT_GetValueDouble(const struct NT_Value* value, uint64_t* last_change, + double* v_double) { if (!value || value->type != NT_Type::NT_DOUBLE) return 0; *last_change = value->last_change; *v_double = value->data.v_double; return 1; } -char* NT_GetValueString(const struct NT_Value* value, - unsigned long long* last_change, size_t* str_len) { +char* NT_GetValueString(const struct NT_Value* value, uint64_t* last_change, + size_t* str_len) { if (!value || value->type != NT_Type::NT_STRING) return nullptr; *last_change = value->last_change; *str_len = value->data.v_string.len; - char* str = (char*)std::malloc(value->data.v_string.len + 1); + char* str = static_cast(std::malloc(value->data.v_string.len + 1)); std::memcpy(str, value->data.v_string.str, value->data.v_string.len + 1); return str; } -char* NT_GetValueRaw(const struct NT_Value* value, - unsigned long long* last_change, size_t* raw_len) { +char* NT_GetValueRaw(const struct NT_Value* value, uint64_t* last_change, + size_t* raw_len) { if (!value || value->type != NT_Type::NT_RAW) return nullptr; *last_change = value->last_change; *raw_len = value->data.v_string.len; - char* raw = (char*)std::malloc(value->data.v_string.len + 1); + char* raw = static_cast(std::malloc(value->data.v_string.len + 1)); std::memcpy(raw, value->data.v_string.str, value->data.v_string.len + 1); return raw; } NT_Bool* NT_GetValueBooleanArray(const struct NT_Value* value, - unsigned long long* last_change, - size_t* arr_size) { + uint64_t* last_change, size_t* arr_size) { if (!value || value->type != NT_Type::NT_BOOLEAN_ARRAY) return nullptr; *last_change = value->last_change; *arr_size = value->data.arr_boolean.size; - NT_Bool* arr = - (int*)std::malloc(value->data.arr_boolean.size * sizeof(NT_Bool)); + NT_Bool* arr = static_cast( + std::malloc(value->data.arr_boolean.size * sizeof(NT_Bool))); std::memcpy(arr, value->data.arr_boolean.arr, value->data.arr_boolean.size * sizeof(NT_Bool)); return arr; } double* NT_GetValueDoubleArray(const struct NT_Value* value, - unsigned long long* last_change, - size_t* arr_size) { + uint64_t* last_change, size_t* arr_size) { if (!value || value->type != NT_Type::NT_DOUBLE_ARRAY) return nullptr; *last_change = value->last_change; *arr_size = value->data.arr_double.size; - double* arr = - (double*)std::malloc(value->data.arr_double.size * sizeof(double)); + double* arr = static_cast( + std::malloc(value->data.arr_double.size * sizeof(double))); std::memcpy(arr, value->data.arr_double.arr, value->data.arr_double.size * sizeof(double)); return arr; } NT_String* NT_GetValueStringArray(const struct NT_Value* value, - unsigned long long* last_change, - size_t* arr_size) { + uint64_t* last_change, size_t* arr_size) { if (!value || value->type != NT_Type::NT_STRING_ARRAY) return nullptr; *last_change = value->last_change; *arr_size = value->data.arr_string.size; @@ -1028,38 +1025,38 @@ NT_String* NT_GetValueStringArray(const struct NT_Value* value, for (size_t i = 0; i < value->data.arr_string.size; ++i) { size_t len = value->data.arr_string.arr[i].len; arr[i].len = len; - arr[i].str = (char*)std::malloc(len + 1); + arr[i].str = static_cast(std::malloc(len + 1)); std::memcpy(arr[i].str, value->data.arr_string.arr[i].str, len + 1); } return arr; } -NT_Bool NT_SetDefaultEntryBoolean(NT_Entry entry, unsigned long long time, +NT_Bool NT_SetDefaultEntryBoolean(NT_Entry entry, uint64_t time, NT_Bool default_boolean) { return nt::SetDefaultEntryValue( entry, Value::MakeBoolean(default_boolean != 0, time)); } -NT_Bool NT_SetDefaultEntryDouble(NT_Entry entry, unsigned long long time, +NT_Bool NT_SetDefaultEntryDouble(NT_Entry entry, uint64_t time, double default_double) { return nt::SetDefaultEntryValue(entry, Value::MakeDouble(default_double, time)); } -NT_Bool NT_SetDefaultEntryString(NT_Entry entry, unsigned long long time, +NT_Bool NT_SetDefaultEntryString(NT_Entry entry, uint64_t time, const char* default_value, size_t default_len) { return nt::SetDefaultEntryValue( entry, Value::MakeString(StringRef(default_value, default_len), time)); } -NT_Bool NT_SetDefaultEntryRaw(NT_Entry entry, unsigned long long time, +NT_Bool NT_SetDefaultEntryRaw(NT_Entry entry, uint64_t time, const char* default_value, size_t default_len) { return nt::SetDefaultEntryValue( entry, Value::MakeRaw(StringRef(default_value, default_len), time)); } -NT_Bool NT_SetDefaultEntryBooleanArray(NT_Entry entry, unsigned long long time, +NT_Bool NT_SetDefaultEntryBooleanArray(NT_Entry entry, uint64_t time, const NT_Bool* default_value, size_t default_size) { return nt::SetDefaultEntryValue( @@ -1067,7 +1064,7 @@ NT_Bool NT_SetDefaultEntryBooleanArray(NT_Entry entry, unsigned long long time, llvm::makeArrayRef(default_value, default_size), time)); } -NT_Bool NT_SetDefaultEntryDoubleArray(NT_Entry entry, unsigned long long time, +NT_Bool NT_SetDefaultEntryDoubleArray(NT_Entry entry, uint64_t time, const double* default_value, size_t default_size) { return nt::SetDefaultEntryValue( @@ -1075,7 +1072,7 @@ NT_Bool NT_SetDefaultEntryDoubleArray(NT_Entry entry, unsigned long long time, llvm::makeArrayRef(default_value, default_size), time)); } -NT_Bool NT_SetDefaultEntryStringArray(NT_Entry entry, unsigned long long time, +NT_Bool NT_SetDefaultEntryStringArray(NT_Entry entry, uint64_t time, const struct NT_String* default_value, size_t default_size) { std::vector vec; @@ -1087,7 +1084,7 @@ NT_Bool NT_SetDefaultEntryStringArray(NT_Entry entry, unsigned long long time, Value::MakeStringArray(std::move(vec), time)); } -NT_Bool NT_GetEntryBoolean(NT_Entry entry, unsigned long long* last_change, +NT_Bool NT_GetEntryBoolean(NT_Entry entry, uint64_t* last_change, NT_Bool* v_boolean) { auto v = nt::GetEntryValue(entry); if (!v || !v->IsBoolean()) return 0; @@ -1096,7 +1093,7 @@ NT_Bool NT_GetEntryBoolean(NT_Entry entry, unsigned long long* last_change, return 1; } -NT_Bool NT_GetEntryDouble(NT_Entry entry, unsigned long long* last_change, +NT_Bool NT_GetEntryDouble(NT_Entry entry, uint64_t* last_change, double* v_double) { auto v = nt::GetEntryValue(entry); if (!v || !v->IsDouble()) return 0; @@ -1105,7 +1102,7 @@ NT_Bool NT_GetEntryDouble(NT_Entry entry, unsigned long long* last_change, return 1; } -char* NT_GetEntryString(NT_Entry entry, unsigned long long* last_change, +char* NT_GetEntryString(NT_Entry entry, uint64_t* last_change, size_t* str_len) { auto v = nt::GetEntryValue(entry); if (!v || !v->IsString()) return nullptr; @@ -1116,8 +1113,7 @@ char* NT_GetEntryString(NT_Entry entry, unsigned long long* last_change, return v_string.str; } -char* NT_GetEntryRaw(NT_Entry entry, unsigned long long* last_change, - size_t* raw_len) { +char* NT_GetEntryRaw(NT_Entry entry, uint64_t* last_change, size_t* raw_len) { auto v = nt::GetEntryValue(entry); if (!v || !v->IsRaw()) return nullptr; *last_change = v->last_change(); @@ -1127,8 +1123,7 @@ char* NT_GetEntryRaw(NT_Entry entry, unsigned long long* last_change, return v_raw.str; } -NT_Bool* NT_GetEntryBooleanArray(NT_Entry entry, - unsigned long long* last_change, +NT_Bool* NT_GetEntryBooleanArray(NT_Entry entry, uint64_t* last_change, size_t* arr_size) { auto v = nt::GetEntryValue(entry); if (!v || !v->IsBooleanArray()) return nullptr; @@ -1140,7 +1135,7 @@ NT_Bool* NT_GetEntryBooleanArray(NT_Entry entry, return arr; } -double* NT_GetEntryDoubleArray(NT_Entry entry, unsigned long long* last_change, +double* NT_GetEntryDoubleArray(NT_Entry entry, uint64_t* last_change, size_t* arr_size) { auto v = nt::GetEntryValue(entry); if (!v || !v->IsDoubleArray()) return nullptr; @@ -1152,8 +1147,7 @@ double* NT_GetEntryDoubleArray(NT_Entry entry, unsigned long long* last_change, return arr; } -NT_String* NT_GetEntryStringArray(NT_Entry entry, - unsigned long long* last_change, +NT_String* NT_GetEntryStringArray(NT_Entry entry, uint64_t* last_change, size_t* arr_size) { auto v = nt::GetEntryValue(entry); if (!v || !v->IsStringArray()) return nullptr; diff --git a/src/main/native/cpp/ntcore_cpp.cpp b/src/main/native/cpp/ntcore_cpp.cpp index 6077e94..d27594a 100644 --- a/src/main/native/cpp/ntcore_cpp.cpp +++ b/src/main/native/cpp/ntcore_cpp.cpp @@ -1,23 +1,24 @@ /*----------------------------------------------------------------------------*/ -/* Copyright (c) FIRST 2015. All Rights Reserved. */ +/* Copyright (c) FIRST 2015-2017. All Rights Reserved. */ /* Open Source Software - may be modified and shared by FRC teams. The code */ /* must be accompanied by the FIRST BSD license file in the root directory of */ /* the project. */ /*----------------------------------------------------------------------------*/ -#include "ntcore.h" +#include #include #include #include -#include "support/timestamp.h" +#include #include "Handle.h" #include "InstanceImpl.h" #include "Log.h" #include "WireDecoder.h" #include "WireEncoder.h" +#include "ntcore.h" namespace nt { @@ -92,7 +93,7 @@ NT_Type GetEntryType(NT_Entry entry) { return ii->storage.GetEntryType(id); } -unsigned long long GetEntryLastChange(NT_Entry entry) { +uint64_t GetEntryLastChange(NT_Entry entry) { Handle handle{entry}; int id = handle.GetTypedIndex(Handle::kEntry); auto ii = InstanceImpl::Get(handle.GetInst()); @@ -638,7 +639,7 @@ std::string PackRpcDefinition(const RpcDefinition& def) { unsigned int params_size = def.params.size(); if (params_size > 0xff) params_size = 0xff; enc.Write8(params_size); - for (std::size_t i = 0; i < params_size; ++i) { + for (size_t i = 0; i < params_size; ++i) { enc.WriteType(def.params[i].def_value->type()); enc.WriteString(def.params[i].name); enc.WriteValue(*def.params[i].def_value); @@ -648,7 +649,7 @@ std::string PackRpcDefinition(const RpcDefinition& def) { unsigned int results_size = def.results.size(); if (results_size > 0xff) results_size = 0xff; enc.Write8(results_size); - for (std::size_t i = 0; i < results_size; ++i) { + for (size_t i = 0; i < results_size; ++i) { enc.WriteType(def.results[i].type); enc.WriteString(def.results[i].name); } @@ -668,7 +669,7 @@ bool UnpackRpcDefinition(StringRef packed, RpcDefinition* def) { if (!dec.Read8(¶ms_size)) return false; def->params.resize(0); def->params.reserve(params_size); - for (std::size_t i = 0; i < params_size; ++i) { + for (size_t i = 0; i < params_size; ++i) { RpcParamDef pdef; NT_Type type; if (!dec.ReadType(&type)) return false; @@ -683,7 +684,7 @@ bool UnpackRpcDefinition(StringRef packed, RpcDefinition* def) { if (!dec.Read8(&results_size)) return false; def->results.resize(0); def->results.reserve(results_size); - for (std::size_t i = 0; i < results_size; ++i) { + for (size_t i = 0; i < results_size; ++i) { RpcResultDef rdef; if (!dec.ReadType(&rdef.type)) return false; if (!dec.ReadString(&rdef.name)) return false; @@ -713,7 +714,7 @@ std::vector> UnpackRpcValues(StringRef packed, return vec; } -unsigned long long Now() { return wpi::Now(); } +uint64_t Now() { return wpi::Now(); } /* * Client/Server Functions diff --git a/src/main/native/cpp/ntcore_test.cpp b/src/main/native/cpp/ntcore_test.cpp index 88af6ca..22f3758 100644 --- a/src/main/native/cpp/ntcore_test.cpp +++ b/src/main/native/cpp/ntcore_test.cpp @@ -1,5 +1,5 @@ /*----------------------------------------------------------------------------*/ -/* Copyright (c) FIRST 2016. All Rights Reserved. */ +/* Copyright (c) FIRST 2016-2017. All Rights Reserved. */ /* Open Source Software - may be modified and shared by FRC teams. The code */ /* must be accompanied by the FIRST BSD license file in the root directory of */ /* the project. */ @@ -21,7 +21,7 @@ struct NT_String* NT_GetStringForTesting(const char* string, int* struct_size) { struct NT_EntryInfo* NT_GetEntryInfoForTesting(const char* name, enum NT_Type type, unsigned int flags, - unsigned long long last_change, + uint64_t last_change, int* struct_size) { struct NT_EntryInfo* entry_info = static_cast(std::calloc(1, sizeof(NT_EntryInfo))); @@ -40,8 +40,7 @@ void NT_FreeEntryInfoForTesting(struct NT_EntryInfo* info) { struct NT_ConnectionInfo* NT_GetConnectionInfoForTesting( const char* remote_id, const char* remote_ip, unsigned int remote_port, - unsigned long long last_update, unsigned int protocol_version, - int* struct_size) { + uint64_t last_update, unsigned int protocol_version, int* struct_size) { struct NT_ConnectionInfo* conn_info = static_cast( std::calloc(1, sizeof(NT_ConnectionInfo))); nt::ConvertToC(llvm::StringRef(remote_id), &conn_info->remote_id); @@ -59,8 +58,8 @@ void NT_FreeConnectionInfoForTesting(struct NT_ConnectionInfo* info) { std::free(info); } -struct NT_Value* NT_GetValueBooleanForTesting(unsigned long long last_change, - int val, int* struct_size) { +struct NT_Value* NT_GetValueBooleanForTesting(uint64_t last_change, int val, + int* struct_size) { struct NT_Value* value = static_cast(std::calloc(1, sizeof(NT_Value))); value->type = NT_BOOLEAN; @@ -70,8 +69,8 @@ struct NT_Value* NT_GetValueBooleanForTesting(unsigned long long last_change, return value; } -struct NT_Value* NT_GetValueDoubleForTesting(unsigned long long last_change, - double val, int* struct_size) { +struct NT_Value* NT_GetValueDoubleForTesting(uint64_t last_change, double val, + int* struct_size) { struct NT_Value* value = static_cast(std::calloc(1, sizeof(NT_Value))); value->type = NT_DOUBLE; @@ -81,7 +80,7 @@ struct NT_Value* NT_GetValueDoubleForTesting(unsigned long long last_change, return value; } -struct NT_Value* NT_GetValueStringForTesting(unsigned long long last_change, +struct NT_Value* NT_GetValueStringForTesting(uint64_t last_change, const char* str, int* struct_size) { struct NT_Value* value = @@ -93,9 +92,8 @@ struct NT_Value* NT_GetValueStringForTesting(unsigned long long last_change, return value; } -struct NT_Value* NT_GetValueRawForTesting(unsigned long long last_change, - const char* raw, int raw_len, - int* struct_size) { +struct NT_Value* NT_GetValueRawForTesting(uint64_t last_change, const char* raw, + int raw_len, int* struct_size) { struct NT_Value* value = static_cast(std::calloc(1, sizeof(NT_Value))); value->type = NT_RAW; @@ -105,9 +103,10 @@ struct NT_Value* NT_GetValueRawForTesting(unsigned long long last_change, return value; } -struct NT_Value* NT_GetValueBooleanArrayForTesting( - unsigned long long last_change, const int* arr, size_t array_len, - int* struct_size) { +struct NT_Value* NT_GetValueBooleanArrayForTesting(uint64_t last_change, + const int* arr, + size_t array_len, + int* struct_size) { struct NT_Value* value = static_cast(std::calloc(1, sizeof(NT_Value))); value->type = NT_BOOLEAN_ARRAY; @@ -120,9 +119,10 @@ struct NT_Value* NT_GetValueBooleanArrayForTesting( return value; } -struct NT_Value* NT_GetValueDoubleArrayForTesting( - unsigned long long last_change, const double* arr, size_t array_len, - int* struct_size) { +struct NT_Value* NT_GetValueDoubleArrayForTesting(uint64_t last_change, + const double* arr, + size_t array_len, + int* struct_size) { struct NT_Value* value = static_cast(std::calloc(1, sizeof(NT_Value))); value->type = NT_BOOLEAN; @@ -135,9 +135,10 @@ struct NT_Value* NT_GetValueDoubleArrayForTesting( return value; } -struct NT_Value* NT_GetValueStringArrayForTesting( - unsigned long long last_change, const struct NT_String* arr, - size_t array_len, int* struct_size) { +struct NT_Value* NT_GetValueStringArrayForTesting(uint64_t last_change, + const struct NT_String* arr, + size_t array_len, + int* struct_size) { struct NT_Value* value = static_cast(std::calloc(1, sizeof(NT_Value))); value->type = NT_BOOLEAN; @@ -147,7 +148,8 @@ struct NT_Value* NT_GetValueStringArrayForTesting( for (size_t i = 0; i < value->data.arr_string.size; ++i) { size_t len = arr[i].len; value->data.arr_string.arr[i].len = len; - value->data.arr_string.arr[i].str = (char*)std::malloc(len + 1); + value->data.arr_string.arr[i].str = + static_cast(std::malloc(len + 1)); std::memcpy(value->data.arr_string.arr[i].str, arr[i].str, len + 1); } *struct_size = sizeof(NT_Value); @@ -239,4 +241,4 @@ struct NT_RpcAnswer* NT_GetRpcAnswerForTesting( return info; } // No need for free as one already exists in the main library -} +} // extern "C" diff --git a/src/main/native/cpp/tables/ITableListener.cpp b/src/main/native/cpp/tables/ITableListener.cpp index df1f273..f4e5a3b 100644 --- a/src/main/native/cpp/tables/ITableListener.cpp +++ b/src/main/native/cpp/tables/ITableListener.cpp @@ -1,3 +1,10 @@ +/*----------------------------------------------------------------------------*/ +/* Copyright (c) FIRST 2017. All Rights Reserved. */ +/* Open Source Software - may be modified and shared by FRC teams. The code */ +/* must be accompanied by the FIRST BSD license file in the root directory of */ +/* the project. */ +/*----------------------------------------------------------------------------*/ + #include "tables/ITableListener.h" #include "ntcore_c.h" diff --git a/src/main/native/include/networktables/EntryListenerFlags.h b/src/main/native/include/networktables/EntryListenerFlags.h index 8e82013..f3c3691 100644 --- a/src/main/native/include/networktables/EntryListenerFlags.h +++ b/src/main/native/include/networktables/EntryListenerFlags.h @@ -5,8 +5,8 @@ /* the project. */ /*----------------------------------------------------------------------------*/ -#ifndef NT_ENTRYLISTENERFLAGS_H_ -#define NT_ENTRYLISTENERFLAGS_H_ +#ifndef NTCORE_NETWORKTABLES_ENTRYLISTENERFLAGS_H_ +#define NTCORE_NETWORKTABLES_ENTRYLISTENERFLAGS_H_ #include "ntcore_c.h" @@ -70,4 +70,4 @@ enum { } // namespace nt -#endif // NT_ENTRYLISTENERFLAGS_H_ +#endif // NTCORE_NETWORKTABLES_ENTRYLISTENERFLAGS_H_ diff --git a/src/main/native/include/networktables/NetworkTable.h b/src/main/native/include/networktables/NetworkTable.h index d2b77ad..8ec29f9 100644 --- a/src/main/native/include/networktables/NetworkTable.h +++ b/src/main/native/include/networktables/NetworkTable.h @@ -1,23 +1,27 @@ /*----------------------------------------------------------------------------*/ -/* Copyright (c) FIRST 2015. All Rights Reserved. */ +/* Copyright (c) FIRST 2015-2017. All Rights Reserved. */ /* Open Source Software - may be modified and shared by FRC teams. The code */ /* must be accompanied by the FIRST BSD license file in the root directory of */ /* the project. */ /*----------------------------------------------------------------------------*/ -#ifndef NETWORKTABLE_H_ -#define NETWORKTABLE_H_ +#ifndef NTCORE_NETWORKTABLES_NETWORKTABLE_H_ +#define NTCORE_NETWORKTABLES_NETWORKTABLE_H_ #include +#include +#include +#include #include -#include "llvm/ArrayRef.h" -#include "llvm/StringMap.h" -#include "llvm/Twine.h" +#include +#include +#include +#include + #include "networktables/NetworkTableEntry.h" #include "networktables/TableEntryListener.h" #include "networktables/TableListener.h" -#include "support/mutex.h" #include "ntcore_c.h" #include "tables/ITable.h" @@ -727,4 +731,4 @@ class NetworkTable final : public ITable { using nt::NetworkTable; // NOLINT #endif -#endif // NETWORKTABLE_H_ +#endif // NTCORE_NETWORKTABLES_NETWORKTABLE_H_ diff --git a/src/main/native/include/networktables/NetworkTableEntry.h b/src/main/native/include/networktables/NetworkTableEntry.h index ef708a0..c06ad49 100644 --- a/src/main/native/include/networktables/NetworkTableEntry.h +++ b/src/main/native/include/networktables/NetworkTableEntry.h @@ -5,14 +5,17 @@ /* the project. */ /*----------------------------------------------------------------------------*/ -#ifndef NT_ENTRY_H_ -#define NT_ENTRY_H_ +#ifndef NTCORE_NETWORKTABLES_NETWORKTABLEENTRY_H_ +#define NTCORE_NETWORKTABLES_NETWORKTABLEENTRY_H_ + +#include #include #include +#include -#include "llvm/StringRef.h" -#include "llvm/Twine.h" +#include +#include #include "networktables/NetworkTableType.h" #include "networktables/NetworkTableValue.h" @@ -93,7 +96,7 @@ class NetworkTableEntry final { * Gets the last time the entry's value was changed. * @return Entry last change time */ - unsigned long long GetLastChange() const; + uint64_t GetLastChange() const; /** * Gets combined information about the entry. @@ -448,4 +451,4 @@ class NetworkTableEntry final { #include "networktables/NetworkTableEntry.inl" -#endif // NT_ENTRY_H_ +#endif // NTCORE_NETWORKTABLES_NETWORKTABLEENTRY_H_ diff --git a/src/main/native/include/networktables/NetworkTableEntry.inl b/src/main/native/include/networktables/NetworkTableEntry.inl index 8f67e67..f95b1a8 100644 --- a/src/main/native/include/networktables/NetworkTableEntry.inl +++ b/src/main/native/include/networktables/NetworkTableEntry.inl @@ -33,7 +33,7 @@ inline unsigned int NetworkTableEntry::GetFlags() const { return GetEntryFlags(m_handle); } -inline unsigned long long NetworkTableEntry::GetLastChange() const { +inline uint64_t NetworkTableEntry::GetLastChange() const { return GetEntryLastChange(m_handle); } diff --git a/src/main/native/include/networktables/NetworkTableInstance.h b/src/main/native/include/networktables/NetworkTableInstance.h index 68f9e1f..3fe9bfa 100644 --- a/src/main/native/include/networktables/NetworkTableInstance.h +++ b/src/main/native/include/networktables/NetworkTableInstance.h @@ -5,17 +5,18 @@ /* the project. */ /*----------------------------------------------------------------------------*/ -#ifndef NT_INSTANCE_H_ -#define NT_INSTANCE_H_ +#ifndef NTCORE_NETWORKTABLES_NETWORKTABLEINSTANCE_H_ +#define NTCORE_NETWORKTABLES_NETWORKTABLEINSTANCE_H_ #include #include #include +#include #include -#include "llvm/ArrayRef.h" -#include "llvm/StringRef.h" -#include "llvm/Twine.h" +#include +#include +#include #include "networktables/NetworkTable.h" #include "networktables/NetworkTableEntry.h" @@ -212,7 +213,7 @@ class NetworkTableInstance final { * @param timeout timeout, in seconds. Set to 0 for non-blocking behavior, * or a negative value to block indefinitely * @return False if timed out, otherwise true. - */ + */ bool WaitForEntryListenerQueue(double timeout); /** @} */ @@ -240,8 +241,10 @@ class NetworkTableInstance final { static void RemoveConnectionListener(NT_ConnectionListener conn_listener); /** - * Wait for the connection listener queue to be empty. This is primarily useful - * for deterministic testing. This blocks until either the connection listener + * Wait for the connection listener queue to be empty. This is primarily + * useful + * for deterministic testing. This blocks until either the connection + * listener * queue is empty (e.g. there are no more events that need to be passed along * to callbacks or poll queues) or the timeout expires. * @param timeout timeout, in seconds. Set to 0 for non-blocking behavior, @@ -507,7 +510,8 @@ class NetworkTableInstance final { static void RemoveLogger(NT_Logger logger); /** - * Wait for the incoming log event queue to be empty. This is primarily useful + * Wait for the incoming log event queue to be empty. This is primarily + * useful * for deterministic testing. This blocks until either the log event * queue is empty (e.g. there are no more events that need to be passed along * to callbacks or poll queues) or the timeout expires. @@ -541,4 +545,4 @@ class NetworkTableInstance final { #include "networktables/NetworkTableInstance.inl" -#endif // NT_INSTANCE_H_ +#endif // NTCORE_NETWORKTABLES_NETWORKTABLEINSTANCE_H_ diff --git a/src/main/native/include/networktables/NetworkTableType.h b/src/main/native/include/networktables/NetworkTableType.h index 62b9b58..9c526f9 100644 --- a/src/main/native/include/networktables/NetworkTableType.h +++ b/src/main/native/include/networktables/NetworkTableType.h @@ -5,8 +5,8 @@ /* the project. */ /*----------------------------------------------------------------------------*/ -#ifndef NT_TYPE_H_ -#define NT_TYPE_H_ +#ifndef NTCORE_NETWORKTABLES_NETWORKTABLETYPE_H_ +#define NTCORE_NETWORKTABLES_NETWORKTABLETYPE_H_ #include "ntcore_c.h" @@ -26,4 +26,4 @@ enum class NetworkTableType { } // namespace nt -#endif // NT_TYPE_H_ +#endif // NTCORE_NETWORKTABLES_NETWORKTABLETYPE_H_ diff --git a/src/main/native/include/networktables/NetworkTableValue.h b/src/main/native/include/networktables/NetworkTableValue.h index cacabe1..73e7af2 100644 --- a/src/main/native/include/networktables/NetworkTableValue.h +++ b/src/main/native/include/networktables/NetworkTableValue.h @@ -1,22 +1,25 @@ /*----------------------------------------------------------------------------*/ -/* Copyright (c) FIRST 2015. All Rights Reserved. */ +/* Copyright (c) FIRST 2015-2017. All Rights Reserved. */ /* Open Source Software - may be modified and shared by FRC teams. The code */ /* must be accompanied by the FIRST BSD license file in the root directory of */ /* the project. */ /*----------------------------------------------------------------------------*/ -#ifndef NT_VALUE_H_ -#define NT_VALUE_H_ +#ifndef NTCORE_NETWORKTABLES_NETWORKTABLEVALUE_H_ +#define NTCORE_NETWORKTABLES_NETWORKTABLEVALUE_H_ + +#include #include #include #include #include +#include #include -#include "llvm/ArrayRef.h" -#include "llvm/StringRef.h" -#include "llvm/Twine.h" +#include +#include +#include #include "ntcore_c.h" @@ -34,7 +37,7 @@ class Value final { public: Value(); - Value(NT_Type type, unsigned long long time, const private_init&); + Value(NT_Type type, uint64_t time, const private_init&); ~Value(); /** @@ -53,13 +56,13 @@ class Value final { * Get the creation time of the value. * @return The time, in the units returned by nt::Now(). */ - unsigned long long last_change() const { return m_val.last_change; } + uint64_t last_change() const { return m_val.last_change; } /** * Get the creation time of the value. * @return The time, in the units returned by nt::Now(). */ - unsigned long long time() const { return m_val.last_change; } + uint64_t time() const { return m_val.last_change; } /** * @defgroup TypeCheckers Type Checkers @@ -215,8 +218,7 @@ class Value final { * time) * @return The entry value */ - static std::shared_ptr MakeBoolean(bool value, - unsigned long long time = 0) { + static std::shared_ptr MakeBoolean(bool value, uint64_t time = 0) { auto val = std::make_shared(NT_BOOLEAN, time, private_init()); val->m_val.data.v_boolean = value; return val; @@ -229,8 +231,7 @@ class Value final { * time) * @return The entry value */ - static std::shared_ptr MakeDouble(double value, - unsigned long long time = 0) { + static std::shared_ptr MakeDouble(double value, uint64_t time = 0) { auto val = std::make_shared(NT_DOUBLE, time, private_init()); val->m_val.data.v_double = value; return val; @@ -244,7 +245,7 @@ class Value final { * @return The entry value */ static std::shared_ptr MakeString(const Twine& value, - unsigned long long time = 0) { + uint64_t time = 0) { auto val = std::make_shared(NT_STRING, time, private_init()); val->m_string = value.str(); val->m_val.data.v_string.str = const_cast(val->m_string.c_str()); @@ -252,13 +253,13 @@ class Value final { return val; } - /** - * Creates a string entry value. - * @param value the value - * @param time if nonzero, the creation time to use (instead of the current - * time) - * @return The entry value - */ +/** + * Creates a string entry value. + * @param value the value + * @param time if nonzero, the creation time to use (instead of the current + * time) + * @return The entry value + */ #ifdef _MSC_VER template >> @@ -266,8 +267,7 @@ class Value final { template ::value>::type> #endif - static std::shared_ptr MakeString(T&& value, - unsigned long long time = 0) { + static std::shared_ptr MakeString(T&& value, uint64_t time = 0) { auto val = std::make_shared(NT_STRING, time, private_init()); val->m_string = std::move(value); val->m_val.data.v_string.str = const_cast(val->m_string.c_str()); @@ -282,8 +282,7 @@ class Value final { * time) * @return The entry value */ - static std::shared_ptr MakeRaw(StringRef value, - unsigned long long time = 0) { + static std::shared_ptr MakeRaw(StringRef value, uint64_t time = 0) { auto val = std::make_shared(NT_RAW, time, private_init()); val->m_string = value; val->m_val.data.v_raw.str = const_cast(val->m_string.c_str()); @@ -291,13 +290,13 @@ class Value final { return val; } - /** - * Creates a raw entry value. - * @param value the value - * @param time if nonzero, the creation time to use (instead of the current - * time) - * @return The entry value - */ +/** + * Creates a raw entry value. + * @param value the value + * @param time if nonzero, the creation time to use (instead of the current + * time) + * @return The entry value + */ #ifdef _MSC_VER template >> @@ -305,8 +304,7 @@ class Value final { template ::value>::type> #endif - static std::shared_ptr MakeRaw(T&& value, - unsigned long long time = 0) { + static std::shared_ptr MakeRaw(T&& value, uint64_t time = 0) { auto val = std::make_shared(NT_RAW, time, private_init()); val->m_string = std::move(value); val->m_val.data.v_raw.str = const_cast(val->m_string.c_str()); @@ -321,8 +319,7 @@ class Value final { * time) * @return The entry value */ - static std::shared_ptr MakeRpc(StringRef value, - unsigned long long time = 0) { + static std::shared_ptr MakeRpc(StringRef value, uint64_t time = 0) { auto val = std::make_shared(NT_RPC, time, private_init()); val->m_string = value; val->m_val.data.v_raw.str = const_cast(val->m_string.c_str()); @@ -338,8 +335,7 @@ class Value final { * @return The entry value */ template - static std::shared_ptr MakeRpc(T&& value, - unsigned long long time = 0) { + static std::shared_ptr MakeRpc(T&& value, uint64_t time = 0) { auto val = std::make_shared(NT_RPC, time, private_init()); val->m_string = std::move(value); val->m_val.data.v_raw.str = const_cast(val->m_string.c_str()); @@ -355,7 +351,7 @@ class Value final { * @return The entry value */ static std::shared_ptr MakeBooleanArray(ArrayRef value, - unsigned long long time = 0); + uint64_t time = 0); /** * Creates a double array entry value. @@ -365,7 +361,7 @@ class Value final { * @return The entry value */ static std::shared_ptr MakeDoubleArray(ArrayRef value, - unsigned long long time = 0); + uint64_t time = 0); /** * Creates a string array entry value. @@ -375,11 +371,11 @@ class Value final { * @return The entry value */ static std::shared_ptr MakeStringArray(ArrayRef value, - unsigned long long time = 0); + uint64_t time = 0); // Note: This function moves the values out of the vector. static std::shared_ptr MakeStringArray( - std::vector&& value, unsigned long long time = 0); + std::vector&& value, uint64_t time = 0); /** @} */ @@ -403,4 +399,4 @@ typedef Value NetworkTableValue; } // namespace nt -#endif // NT_VALUE_H_ +#endif // NTCORE_NETWORKTABLES_NETWORKTABLEVALUE_H_ diff --git a/src/main/native/include/networktables/RpcCall.h b/src/main/native/include/networktables/RpcCall.h index d189306..a8f09c1 100644 --- a/src/main/native/include/networktables/RpcCall.h +++ b/src/main/native/include/networktables/RpcCall.h @@ -5,8 +5,8 @@ /* the project. */ /*----------------------------------------------------------------------------*/ -#ifndef NT_RPCCALL_H_ -#define NT_RPCCALL_H_ +#ifndef NTCORE_NETWORKTABLES_RPCCALL_H_ +#define NTCORE_NETWORKTABLES_RPCCALL_H_ #include #include @@ -30,8 +30,7 @@ class RpcCall final { * @param entry Entry handle * @param call Call handle */ - RpcCall(NT_Entry entry, NT_RpcCall call) - : m_entry(entry), m_call(call) {} + RpcCall(NT_Entry entry, NT_RpcCall call) : m_entry(entry), m_call(call) {} RpcCall(RpcCall&& other); RpcCall(const RpcCall&) = delete; @@ -98,4 +97,4 @@ class RpcCall final { #include "networktables/RpcCall.inl" -#endif // NT_RPCCALL_H_ +#endif // NTCORE_NETWORKTABLES_RPCCALL_H_ diff --git a/src/main/native/include/networktables/TableEntryListener.h b/src/main/native/include/networktables/TableEntryListener.h index 3aac451..ee4bd69 100644 --- a/src/main/native/include/networktables/TableEntryListener.h +++ b/src/main/native/include/networktables/TableEntryListener.h @@ -5,13 +5,13 @@ /* the project. */ /*----------------------------------------------------------------------------*/ -#ifndef NT_TABLEENTRYLISTENER_H_ -#define NT_TABLEENTRYLISTENER_H_ +#ifndef NTCORE_NETWORKTABLES_TABLEENTRYLISTENER_H_ +#define NTCORE_NETWORKTABLES_TABLEENTRYLISTENER_H_ #include #include -#include "llvm/StringRef.h" +#include namespace nt { @@ -40,4 +40,4 @@ typedef std::function #include -#include "llvm/StringRef.h" +#include namespace nt { @@ -34,4 +34,4 @@ typedef std::function +#include -#include "support/deprecated.h" +#include + +#include #ifdef __cplusplus extern "C" { @@ -93,7 +95,7 @@ struct NT_String { * String contents (UTF-8). * The string is NOT required to be zero-terminated. * When returned by the library, this is zero-terminated and allocated with - * malloc(). + * std::malloc(). */ char* str; @@ -107,7 +109,7 @@ struct NT_String { /** NetworkTables Entry Value. Note this is a typed union. */ struct NT_Value { enum NT_Type type; - unsigned long long last_change; + uint64_t last_change; union { NT_Bool v_boolean; double v_double; @@ -143,7 +145,7 @@ struct NT_EntryInfo { unsigned int flags; /** Timestamp of last change to entry (type or value). */ - unsigned long long last_change; + uint64_t last_change; }; /** NetworkTables Connection Information */ @@ -164,7 +166,7 @@ struct NT_ConnectionInfo { * The last time any update was received from the remote node (same scale as * returned by nt::Now()). */ - unsigned long long last_update; + uint64_t last_update; /** * The protocol version being used for this connection. This in protocol @@ -341,7 +343,7 @@ enum NT_Type NT_GetEntryType(NT_Entry entry); * @param entry entry handle * @return Entry last change time */ -unsigned long long NT_GetEntryLastChange(NT_Entry entry); +uint64_t NT_GetEntryLastChange(NT_Entry entry); /** * Get Entry Value. @@ -559,9 +561,9 @@ NT_EntryListener NT_AddPolledEntryListenerSingle(NT_EntryListenerPoller poller, /** * Get the next entry listener event. This blocks until the next event occurs. - * This is intended to be used with NT_AddPolledEntryListener(); entry listeners - * created using NT_AddEntryListener() will not be serviced through this - * function. + * This is intended to be used with NT_AddPolledEntryListener(void); entry + * listeners created using NT_AddEntryListener() will not be serviced through + * this function. * @param poller poller handle * @param len length of returned array (output) * @return Array of information on the entry listener events. Returns NULL if @@ -788,7 +790,7 @@ void NT_CreatePolledRpc(NT_Entry entry, const char* def, size_t def_len, /** * Get the next incoming RPC call. This blocks until the next incoming RPC - * call is received. This is intended to be used with NT_CreatePolledRpc(); + * call is received. This is intended to be used with NT_CreatePolledRpc(void); * RPC calls created using NT_CreateRpc() will not be serviced through this * function. Upon successful return, NT_PostRpcResponse() must be called to * send the return value to the caller. The returned array must be freed @@ -897,7 +899,7 @@ void NT_CancelRpcResult(NT_Entry entry, NT_RpcCall call); * Pack a RPC version 1 definition. * @param def RPC version 1 definition * @param packed_len length of return value in bytes - * @return Raw packed bytes. Use C standard library free() to release. + * @return Raw packed bytes. Use C standard library std::free() to release. */ char* NT_PackRpcDefinition(const struct NT_RpcDefinition* def, size_t* packed_len); @@ -918,7 +920,7 @@ NT_Bool NT_UnpackRpcDefinition(const char* packed, size_t packed_len, * @param values array of values to pack * @param values_len length of values * @param packed_len length of return value in bytes - * @return Raw packed bytes. Use C standard library free() to release. + * @return Raw packed bytes. Use C standard library std::free() to release. */ char* NT_PackRpcValues(const struct NT_Value** values, size_t values_len, size_t* packed_len); @@ -1292,7 +1294,7 @@ void NT_DisposeLogMessage(struct NT_LogMessage* info); * This function is a compatibility wrapper around WPI_Now(). * @return Timestamp */ -unsigned long long NT_Now(void); +uint64_t NT_Now(void); /** @} */ @@ -1522,8 +1524,8 @@ enum NT_Type NT_GetValueType(const struct NT_Value* value); * @param v_boolean returns the boolean assigned to the name * @return 1 if successful, or 0 if value is null or not a boolean */ -NT_Bool NT_GetValueBoolean(const struct NT_Value* value, - unsigned long long* last_change, NT_Bool* v_boolean); +NT_Bool NT_GetValueBoolean(const struct NT_Value* value, uint64_t* last_change, + NT_Bool* v_boolean); /** * Returns the double from the NT_Value. @@ -1534,8 +1536,8 @@ NT_Bool NT_GetValueBoolean(const struct NT_Value* value, * @param v_double returns the boolean assigned to the name * @return 1 if successful, or 0 if value is null or not a double */ -NT_Bool NT_GetValueDouble(const struct NT_Value* value, - unsigned long long* last_change, double* v_double); +NT_Bool NT_GetValueDouble(const struct NT_Value* value, uint64_t* last_change, + double* v_double); /** * Returns a copy of the string from the NT_Value. @@ -1551,8 +1553,8 @@ NT_Bool NT_GetValueDouble(const struct NT_Value* value, * returned string is a copy of the string in the value, and must be freed * separately. */ -char* NT_GetValueString(const struct NT_Value* value, - unsigned long long* last_change, size_t* str_len); +char* NT_GetValueString(const struct NT_Value* value, uint64_t* last_change, + size_t* str_len); /** * Returns a copy of the raw value from the NT_Value. @@ -1568,8 +1570,8 @@ char* NT_GetValueString(const struct NT_Value* value, * returned string is a copy of the string in the value, and must be freed * separately. */ -char* NT_GetValueRaw(const struct NT_Value* value, - unsigned long long* last_change, size_t* raw_len); +char* NT_GetValueRaw(const struct NT_Value* value, uint64_t* last_change, + size_t* raw_len); /** * Returns a copy of the boolean array from the NT_Value. @@ -1586,8 +1588,7 @@ char* NT_GetValueRaw(const struct NT_Value* value, * freed separately. */ NT_Bool* NT_GetValueBooleanArray(const struct NT_Value* value, - unsigned long long* last_change, - size_t* arr_size); + uint64_t* last_change, size_t* arr_size); /** * Returns a copy of the double array from the NT_Value. @@ -1604,8 +1605,7 @@ NT_Bool* NT_GetValueBooleanArray(const struct NT_Value* value, * freed separately. */ double* NT_GetValueDoubleArray(const struct NT_Value* value, - unsigned long long* last_change, - size_t* arr_size); + uint64_t* last_change, size_t* arr_size); /** * Returns a copy of the NT_String array from the NT_Value. @@ -1624,8 +1624,7 @@ double* NT_GetValueDoubleArray(const struct NT_Value* value, * function will free all the NT_Strings. */ NT_String* NT_GetValueStringArray(const struct NT_Value* value, - unsigned long long* last_change, - size_t* arr_size); + uint64_t* last_change, size_t* arr_size); /** * Returns the boolean currently assigned to the entry name. @@ -1638,7 +1637,7 @@ NT_String* NT_GetValueStringArray(const struct NT_Value* value, * @return 1 if successful, or 0 if value is unassigned or not a * boolean */ -NT_Bool NT_GetEntryBoolean(NT_Entry entry, unsigned long long* last_change, +NT_Bool NT_GetEntryBoolean(NT_Entry entry, uint64_t* last_change, NT_Bool* v_boolean); /** @@ -1652,7 +1651,7 @@ NT_Bool NT_GetEntryBoolean(NT_Entry entry, unsigned long long* last_change, * @return 1 if successful, or 0 if value is unassigned or not a * double */ -NT_Bool NT_GetEntryDouble(NT_Entry entry, unsigned long long* last_change, +NT_Bool NT_GetEntryDouble(NT_Entry entry, uint64_t* last_change, double* v_double); /** @@ -1668,8 +1667,7 @@ NT_Bool NT_GetEntryDouble(NT_Entry entry, unsigned long long* last_change, * It is the caller's responsibility to free the string once its no longer * needed. The NT_FreeCharArray() function is useful for this purpose. */ -char* NT_GetEntryString(NT_Entry entry, unsigned long long* last_change, - size_t* str_len); +char* NT_GetEntryString(NT_Entry entry, uint64_t* last_change, size_t* str_len); /** * Returns a copy of the raw value assigned to the entry name. @@ -1684,8 +1682,7 @@ char* NT_GetEntryString(NT_Entry entry, unsigned long long* last_change, * It is the caller's responsibility to free the raw value once its no longer * needed. The NT_FreeCharArray() function is useful for this purpose. */ -char* NT_GetEntryRaw(NT_Entry entry, unsigned long long* last_change, - size_t* raw_len); +char* NT_GetEntryRaw(NT_Entry entry, uint64_t* last_change, size_t* raw_len); /** * Returns a copy of the boolean array assigned to the entry name. @@ -1700,8 +1697,7 @@ char* NT_GetEntryRaw(NT_Entry entry, unsigned long long* last_change, * It is the caller's responsibility to free the array once its no longer * needed. The NT_FreeBooleanArray() function is useful for this purpose. */ -NT_Bool* NT_GetEntryBooleanArray(NT_Entry entry, - unsigned long long* last_change, +NT_Bool* NT_GetEntryBooleanArray(NT_Entry entry, uint64_t* last_change, size_t* arr_size); /** @@ -1717,7 +1713,7 @@ NT_Bool* NT_GetEntryBooleanArray(NT_Entry entry, * It is the caller's responsibility to free the array once its no longer * needed. The NT_FreeDoubleArray() function is useful for this purpose. */ -double* NT_GetEntryDoubleArray(NT_Entry entry, unsigned long long* last_change, +double* NT_GetEntryDoubleArray(NT_Entry entry, uint64_t* last_change, size_t* arr_size); /** @@ -1736,8 +1732,7 @@ double* NT_GetEntryDoubleArray(NT_Entry entry, unsigned long long* last_change, * should be freed at once. The NT_FreeStringArray() function will free all the * NT_Strings. */ -NT_String* NT_GetEntryStringArray(NT_Entry entry, - unsigned long long* last_change, +NT_String* NT_GetEntryStringArray(NT_Entry entry, uint64_t* last_change, size_t* arr_size); /** @} */ @@ -1757,7 +1752,7 @@ NT_String* NT_GetEntryStringArray(NT_Entry entry, * @param default_boolean value to be set if name does not exist * @return 0 on error (value not set), 1 on success */ -NT_Bool NT_SetDefaultEntryBoolean(NT_Entry entry, unsigned long long time, +NT_Bool NT_SetDefaultEntryBoolean(NT_Entry entry, uint64_t time, NT_Bool default_boolean); /** Set Default Entry Double. @@ -1770,7 +1765,7 @@ NT_Bool NT_SetDefaultEntryBoolean(NT_Entry entry, unsigned long long time, * @param default_double value to be set if name does not exist * @return 0 on error (value not set), 1 on success */ -NT_Bool NT_SetDefaultEntryDouble(NT_Entry entry, unsigned long long time, +NT_Bool NT_SetDefaultEntryDouble(NT_Entry entry, uint64_t time, double default_double); /** Set Default Entry String. @@ -1784,7 +1779,7 @@ NT_Bool NT_SetDefaultEntryDouble(NT_Entry entry, unsigned long long time, * @param default_len length of value * @return 0 on error (value not set), 1 on success */ -NT_Bool NT_SetDefaultEntryString(NT_Entry entry, unsigned long long time, +NT_Bool NT_SetDefaultEntryString(NT_Entry entry, uint64_t time, const char* default_value, size_t default_len); /** Set Default Entry Raw. @@ -1798,7 +1793,7 @@ NT_Bool NT_SetDefaultEntryString(NT_Entry entry, unsigned long long time, * @param default_len length of value array * @return 0 on error (value not set), 1 on success */ -NT_Bool NT_SetDefaultEntryRaw(NT_Entry entry, unsigned long long time, +NT_Bool NT_SetDefaultEntryRaw(NT_Entry entry, uint64_t time, const char* default_value, size_t default_len); /** Set Default Entry Boolean Array. @@ -1812,7 +1807,7 @@ NT_Bool NT_SetDefaultEntryRaw(NT_Entry entry, unsigned long long time, * @param default_size size of value array * @return 0 on error (value not set), 1 on success */ -NT_Bool NT_SetDefaultEntryBooleanArray(NT_Entry entry, unsigned long long time, +NT_Bool NT_SetDefaultEntryBooleanArray(NT_Entry entry, uint64_t time, const int* default_value, size_t default_size); @@ -1827,7 +1822,7 @@ NT_Bool NT_SetDefaultEntryBooleanArray(NT_Entry entry, unsigned long long time, * @param default_size size of value array * @return 0 on error (value not set), 1 on success */ -NT_Bool NT_SetDefaultEntryDoubleArray(NT_Entry entry, unsigned long long time, +NT_Bool NT_SetDefaultEntryDoubleArray(NT_Entry entry, uint64_t time, const double* default_value, size_t default_size); @@ -1842,7 +1837,7 @@ NT_Bool NT_SetDefaultEntryDoubleArray(NT_Entry entry, unsigned long long time, * @param default_size size of value array * @return 0 on error (value not set), 1 on success */ -NT_Bool NT_SetDefaultEntryStringArray(NT_Entry entry, unsigned long long time, +NT_Bool NT_SetDefaultEntryStringArray(NT_Entry entry, uint64_t time, const struct NT_String* default_value, size_t default_size); @@ -1863,8 +1858,8 @@ NT_Bool NT_SetDefaultEntryStringArray(NT_Entry entry, unsigned long long time, * @param force 1 to force the entry to get overwritten, otherwise 0 * @return 0 on error (type mismatch), 1 on success */ -NT_Bool NT_SetEntryBoolean(NT_Entry entry, unsigned long long time, - NT_Bool v_boolean, NT_Bool force); +NT_Bool NT_SetEntryBoolean(NT_Entry entry, uint64_t time, NT_Bool v_boolean, + NT_Bool force); /** Set Entry Double * Sets an entry double. If the entry name is not currently assigned to a @@ -1876,8 +1871,8 @@ NT_Bool NT_SetEntryBoolean(NT_Entry entry, unsigned long long time, * @param force 1 to force the entry to get overwritten, otherwise 0 * @return 0 on error (type mismatch), 1 on success */ -NT_Bool NT_SetEntryDouble(NT_Entry entry, unsigned long long time, - double v_double, NT_Bool force); +NT_Bool NT_SetEntryDouble(NT_Entry entry, uint64_t time, double v_double, + NT_Bool force); /** Set Entry String * Sets an entry string. If the entry name is not currently assigned to a @@ -1890,8 +1885,8 @@ NT_Bool NT_SetEntryDouble(NT_Entry entry, unsigned long long time, * @param force 1 to force the entry to get overwritten, otherwise 0 * @return 0 on error (type mismatch), 1 on success */ -NT_Bool NT_SetEntryString(NT_Entry entry, unsigned long long time, - const char* str, size_t str_len, NT_Bool force); +NT_Bool NT_SetEntryString(NT_Entry entry, uint64_t time, const char* str, + size_t str_len, NT_Bool force); /** Set Entry Raw * Sets the raw value of an entry. If the entry name is not currently assigned @@ -1904,7 +1899,7 @@ NT_Bool NT_SetEntryString(NT_Entry entry, unsigned long long time, * @param force 1 to force the entry to get overwritten, otherwise 0 * @return 0 on error (type mismatch), 1 on success */ -NT_Bool NT_SetEntryRaw(NT_Entry entry, unsigned long long time, const char* raw, +NT_Bool NT_SetEntryRaw(NT_Entry entry, uint64_t time, const char* raw, size_t raw_len, NT_Bool force); /** Set Entry Boolean Array @@ -1918,8 +1913,8 @@ NT_Bool NT_SetEntryRaw(NT_Entry entry, unsigned long long time, const char* raw, * @param force 1 to force the entry to get overwritten, otherwise 0 * @return 0 on error (type mismatch), 1 on success */ -NT_Bool NT_SetEntryBooleanArray(NT_Entry entry, unsigned long long time, - const int* arr, size_t size, NT_Bool force); +NT_Bool NT_SetEntryBooleanArray(NT_Entry entry, uint64_t time, const int* arr, + size_t size, NT_Bool force); /** Set Entry Double Array * Sets an entry double array. If the entry name is not currently assigned to @@ -1932,8 +1927,8 @@ NT_Bool NT_SetEntryBooleanArray(NT_Entry entry, unsigned long long time, * @param force 1 to force the entry to get overwritten, otherwise 0 * @return 0 on error (type mismatch), 1 on success */ -NT_Bool NT_SetEntryDoubleArray(NT_Entry entry, unsigned long long time, - const double* arr, size_t size, NT_Bool force); +NT_Bool NT_SetEntryDoubleArray(NT_Entry entry, uint64_t time, const double* arr, + size_t size, NT_Bool force); /** Set Entry String Array * Sets an entry string array. If the entry name is not currently assigned to @@ -1946,7 +1941,7 @@ NT_Bool NT_SetEntryDoubleArray(NT_Entry entry, unsigned long long time, * @param force 1 to force the entry to get overwritten, otherwise 0 * @return 0 on error (type mismatch), 1 on success */ -NT_Bool NT_SetEntryStringArray(NT_Entry entry, unsigned long long time, +NT_Bool NT_SetEntryStringArray(NT_Entry entry, uint64_t time, const struct NT_String* arr, size_t size, NT_Bool force); @@ -1954,7 +1949,7 @@ NT_Bool NT_SetEntryStringArray(NT_Entry entry, unsigned long long time, /** @} */ #ifdef __cplusplus -} +} // extern "C" #endif -#endif /* NTCORE_C_H_ */ +#endif // NTCORE_NTCORE_C_H_ diff --git a/src/main/native/include/ntcore_cpp.h b/src/main/native/include/ntcore_cpp.h index 04bbaf2..8296db4 100644 --- a/src/main/native/include/ntcore_cpp.h +++ b/src/main/native/include/ntcore_cpp.h @@ -1,12 +1,14 @@ /*----------------------------------------------------------------------------*/ -/* Copyright (c) FIRST 2015. All Rights Reserved. */ +/* Copyright (c) FIRST 2015-2017. All Rights Reserved. */ /* Open Source Software - may be modified and shared by FRC teams. The code */ /* must be accompanied by the FIRST BSD license file in the root directory of */ /* the project. */ /*----------------------------------------------------------------------------*/ -#ifndef NTCORE_CPP_H_ -#define NTCORE_CPP_H_ +#ifndef NTCORE_NTCORE_CPP_H_ +#define NTCORE_NTCORE_CPP_H_ + +#include #include #include @@ -15,10 +17,10 @@ #include #include -#include "llvm/ArrayRef.h" -#include "llvm/StringRef.h" -#include "llvm/Twine.h" -#include "support/deprecated.h" +#include +#include +#include +#include #include "networktables/NetworkTableValue.h" @@ -43,7 +45,7 @@ struct EntryInfo { unsigned int flags; /** Timestamp of last change to entry (type or value). */ - unsigned long long last_change; + uint64_t last_change; friend void swap(EntryInfo& first, EntryInfo& second) { using std::swap; @@ -73,7 +75,7 @@ struct ConnectionInfo { * The last time any update was received from the remote node (same scale as * returned by nt::Now()). */ - unsigned long long last_update; + uint64_t last_update; /** * The protocol version being used for this connection. This in protocol @@ -351,7 +353,7 @@ NT_Type GetEntryType(NT_Entry entry); * @param entry entry handle * @return Entry last change time */ -unsigned long long GetEntryLastChange(NT_Entry entry); +uint64_t GetEntryLastChange(NT_Entry entry); /** * Get Entry Value. @@ -1353,7 +1355,7 @@ const char* LoadEntries(NT_Inst inst, const Twine& filename, * This function is a compatibility wrapper around wpi::Now(). * @return Timestamp */ -unsigned long long Now(); +uint64_t Now(); /** @} */ @@ -1484,4 +1486,4 @@ inline void RpcAnswer::PostResponse(StringRef result) const { } // namespace nt -#endif /* NTCORE_CPP_H_ */ +#endif // NTCORE_NTCORE_CPP_H_ diff --git a/src/main/native/include/ntcore_test.h b/src/main/native/include/ntcore_test.h index 08e0fa6..2e99697 100644 --- a/src/main/native/include/ntcore_test.h +++ b/src/main/native/include/ntcore_test.h @@ -1,12 +1,16 @@ /*----------------------------------------------------------------------------*/ -/* Copyright (c) FIRST 2016. All Rights Reserved. */ +/* Copyright (c) FIRST 2016-2017. All Rights Reserved. */ /* Open Source Software - may be modified and shared by FRC teams. The code */ /* must be accompanied by the FIRST BSD license file in the root directory of */ /* the project. */ /*----------------------------------------------------------------------------*/ -#ifndef NTCORE_TEST_H_ -#define NTCORE_TEST_H_ +#ifndef NTCORE_NTCORE_TEST_H_ +#define NTCORE_NTCORE_TEST_H_ + +#include + +#include #include "ntcore.h" @@ -19,42 +23,43 @@ struct NT_String* NT_GetStringForTesting(const char* string, int* struct_size); struct NT_EntryInfo* NT_GetEntryInfoForTesting(const char* name, enum NT_Type type, unsigned int flags, - unsigned long long last_change, + uint64_t last_change, int* struct_size); void NT_FreeEntryInfoForTesting(struct NT_EntryInfo* info); struct NT_ConnectionInfo* NT_GetConnectionInfoForTesting( const char* remote_id, const char* remote_ip, unsigned int remote_port, - unsigned long long last_update, unsigned int protocol_version, - int* struct_size); + uint64_t last_update, unsigned int protocol_version, int* struct_size); void NT_FreeConnectionInfoForTesting(struct NT_ConnectionInfo* info); -struct NT_Value* NT_GetValueBooleanForTesting(unsigned long long last_change, - int val, int* struct_size); +struct NT_Value* NT_GetValueBooleanForTesting(uint64_t last_change, int val, + int* struct_size); -struct NT_Value* NT_GetValueDoubleForTesting(unsigned long long last_change, - double val, int* struct_size); +struct NT_Value* NT_GetValueDoubleForTesting(uint64_t last_change, double val, + int* struct_size); -struct NT_Value* NT_GetValueStringForTesting(unsigned long long last_change, +struct NT_Value* NT_GetValueStringForTesting(uint64_t last_change, const char* str, int* struct_size); -struct NT_Value* NT_GetValueRawForTesting(unsigned long long last_change, - const char* raw, int raw_len, - int* struct_size); +struct NT_Value* NT_GetValueRawForTesting(uint64_t last_change, const char* raw, + int raw_len, int* struct_size); -struct NT_Value* NT_GetValueBooleanArrayForTesting( - unsigned long long last_change, const int* arr, size_t array_len, - int* struct_size); +struct NT_Value* NT_GetValueBooleanArrayForTesting(uint64_t last_change, + const int* arr, + size_t array_len, + int* struct_size); -struct NT_Value* NT_GetValueDoubleArrayForTesting( - unsigned long long last_change, const double* arr, size_t array_len, - int* struct_size); +struct NT_Value* NT_GetValueDoubleArrayForTesting(uint64_t last_change, + const double* arr, + size_t array_len, + int* struct_size); -struct NT_Value* NT_GetValueStringArrayForTesting( - unsigned long long last_change, const struct NT_String* arr, - size_t array_len, int* struct_size); +struct NT_Value* NT_GetValueStringArrayForTesting(uint64_t last_change, + const struct NT_String* arr, + size_t array_len, + int* struct_size); // No need for free as one already exists in the main library struct NT_RpcParamDef* NT_GetRpcParamDefForTesting(const char* name, @@ -79,6 +84,6 @@ struct NT_RpcCallInfo* NT_GetRpcCallInfoForTesting( unsigned int rpc_id, unsigned int call_uid, const char* name, const char* params, size_t params_len, int* struct_size); // No need for free as one already exists in the main library -} +} // extern "C" -#endif /* NTCORE_TEST_H_ */ +#endif // NTCORE_NTCORE_TEST_H_ diff --git a/src/main/native/include/tables/ITable.h b/src/main/native/include/tables/ITable.h index 9702592..7a00b25 100644 --- a/src/main/native/include/tables/ITable.h +++ b/src/main/native/include/tables/ITable.h @@ -1,19 +1,22 @@ /*----------------------------------------------------------------------------*/ -/* Copyright (c) FIRST 2015. All Rights Reserved. */ +/* Copyright (c) FIRST 2015-2017. All Rights Reserved. */ /* Open Source Software - may be modified and shared by FRC teams. The code */ /* must be accompanied by the FIRST BSD license file in the root directory of */ /* the project. */ /*----------------------------------------------------------------------------*/ -#ifndef ITABLE_H_ -#define ITABLE_H_ +#ifndef NTCORE_TABLES_ITABLE_H_ +#define NTCORE_TABLES_ITABLE_H_ #include +#include +#include + +#include +#include +#include -#include "llvm/StringRef.h" -#include "llvm/Twine.h" #include "networktables/NetworkTableValue.h" -#include "support/deprecated.h" namespace nt { class NetworkTable; @@ -448,7 +451,6 @@ class WPI_DEPRECATED("Use NetworkTable directly") ITable { * Gets the full path of this table. */ virtual llvm::StringRef GetPath() const = 0; - }; -#endif // ITABLE_H_ +#endif // NTCORE_TABLES_ITABLE_H_ diff --git a/src/main/native/include/tables/ITableListener.h b/src/main/native/include/tables/ITableListener.h index 818b500..b19a9ef 100644 --- a/src/main/native/include/tables/ITableListener.h +++ b/src/main/native/include/tables/ITableListener.h @@ -1,15 +1,19 @@ -/* - * ITableListener.h - */ +/*----------------------------------------------------------------------------*/ +/* Copyright (c) FIRST 2017. All Rights Reserved. */ +/* Open Source Software - may be modified and shared by FRC teams. The code */ +/* must be accompanied by the FIRST BSD license file in the root directory of */ +/* the project. */ +/*----------------------------------------------------------------------------*/ -#ifndef ITABLELISTENER_H_ -#define ITABLELISTENER_H_ +#ifndef NTCORE_TABLES_ITABLELISTENER_H_ +#define NTCORE_TABLES_ITABLELISTENER_H_ #include -#include "llvm/StringRef.h" +#include +#include + #include "networktables/NetworkTableValue.h" -#include "support/deprecated.h" #ifdef __GNUC__ #pragma GCC diagnostic push @@ -56,4 +60,4 @@ class WPI_DEPRECATED( #pragma GCC diagnostic pop #endif -#endif /* ITABLELISTENER_H_ */ +#endif // NTCORE_TABLES_ITABLELISTENER_H_ diff --git a/src/test/java/edu/wpi/first/networktables/ConnectionListenerTest.java b/src/test/java/edu/wpi/first/networktables/ConnectionListenerTest.java index c2bc171..b3760f2 100644 --- a/src/test/java/edu/wpi/first/networktables/ConnectionListenerTest.java +++ b/src/test/java/edu/wpi/first/networktables/ConnectionListenerTest.java @@ -1,3 +1,10 @@ +/*----------------------------------------------------------------------------*/ +/* Copyright (c) FIRST 2017. All Rights Reserved. */ +/* Open Source Software - may be modified and shared by FRC teams. The code */ +/* must be accompanied by the FIRST BSD license file in the root directory of */ +/* the project. */ +/*----------------------------------------------------------------------------*/ + package edu.wpi.first.networktables; import java.util.ArrayList; diff --git a/src/test/java/edu/wpi/first/networktables/EntryListenerTest.java b/src/test/java/edu/wpi/first/networktables/EntryListenerTest.java index 3c7df8e..0fcf222 100644 --- a/src/test/java/edu/wpi/first/networktables/EntryListenerTest.java +++ b/src/test/java/edu/wpi/first/networktables/EntryListenerTest.java @@ -1,3 +1,10 @@ +/*----------------------------------------------------------------------------*/ +/* Copyright (c) FIRST 2017. All Rights Reserved. */ +/* Open Source Software - may be modified and shared by FRC teams. The code */ +/* must be accompanied by the FIRST BSD license file in the root directory of */ +/* the project. */ +/*----------------------------------------------------------------------------*/ + package edu.wpi.first.networktables; import java.util.ArrayList; diff --git a/src/test/java/edu/wpi/first/networktables/JNITest.java b/src/test/java/edu/wpi/first/networktables/JNITest.java index 449ca06..5603d4a 100644 --- a/src/test/java/edu/wpi/first/networktables/JNITest.java +++ b/src/test/java/edu/wpi/first/networktables/JNITest.java @@ -1,12 +1,19 @@ -package edu.wpi.first.networktables; - -import org.junit.Test; - -public class JNITest { - @Test - public void jniLinkTest() { - // Test to verify that the JNI test link works correctly. - int inst = NetworkTablesJNI.getDefaultInstance(); - NetworkTablesJNI.flush(inst); - } -} +/*----------------------------------------------------------------------------*/ +/* Copyright (c) FIRST 2017. All Rights Reserved. */ +/* Open Source Software - may be modified and shared by FRC teams. The code */ +/* must be accompanied by the FIRST BSD license file in the root directory of */ +/* the project. */ +/*----------------------------------------------------------------------------*/ + +package edu.wpi.first.networktables; + +import org.junit.Test; + +public class JNITest { + @Test + public void jniLinkTest() { + // Test to verify that the JNI test link works correctly. + int inst = NetworkTablesJNI.getDefaultInstance(); + NetworkTablesJNI.flush(inst); + } +} diff --git a/src/test/java/edu/wpi/first/networktables/LoggerTest.java b/src/test/java/edu/wpi/first/networktables/LoggerTest.java index faac049..b663246 100644 --- a/src/test/java/edu/wpi/first/networktables/LoggerTest.java +++ b/src/test/java/edu/wpi/first/networktables/LoggerTest.java @@ -1,3 +1,10 @@ +/*----------------------------------------------------------------------------*/ +/* Copyright (c) FIRST 2017. All Rights Reserved. */ +/* Open Source Software - may be modified and shared by FRC teams. The code */ +/* must be accompanied by the FIRST BSD license file in the root directory of */ +/* the project. */ +/*----------------------------------------------------------------------------*/ + package edu.wpi.first.networktables; import java.util.ArrayList; diff --git a/src/test/java/edu/wpi/first/networktables/NetworkTableTest.java b/src/test/java/edu/wpi/first/networktables/NetworkTableTest.java index 4a91911..fdbba60 100644 --- a/src/test/java/edu/wpi/first/networktables/NetworkTableTest.java +++ b/src/test/java/edu/wpi/first/networktables/NetworkTableTest.java @@ -1,3 +1,10 @@ +/*----------------------------------------------------------------------------*/ +/* Copyright (c) FIRST 2017. All Rights Reserved. */ +/* Open Source Software - may be modified and shared by FRC teams. The code */ +/* must be accompanied by the FIRST BSD license file in the root directory of */ +/* the project. */ +/*----------------------------------------------------------------------------*/ + package edu.wpi.first.networktables; import java.util.ArrayList; diff --git a/src/test/native/cpp/ConnectionListenerTest.cpp b/src/test/native/cpp/ConnectionListenerTest.cpp index 70710cc..9dd774a 100644 --- a/src/test/native/cpp/ConnectionListenerTest.cpp +++ b/src/test/native/cpp/ConnectionListenerTest.cpp @@ -5,13 +5,12 @@ /* the project. */ /*----------------------------------------------------------------------------*/ -#include "ntcore_cpp.h" - #include #include #include "TestPrinters.h" #include "gtest/gtest.h" +#include "ntcore_cpp.h" class ConnectionListenerTest : public ::testing::Test { public: diff --git a/src/test/native/cpp/EntryListenerTest.cpp b/src/test/native/cpp/EntryListenerTest.cpp index 0dbd691..cb21a3c 100644 --- a/src/test/native/cpp/EntryListenerTest.cpp +++ b/src/test/native/cpp/EntryListenerTest.cpp @@ -5,14 +5,13 @@ /* the project. */ /*----------------------------------------------------------------------------*/ -#include "ntcore_cpp.h" - #include #include #include "TestPrinters.h" #include "ValueMatcher.h" #include "gtest/gtest.h" +#include "ntcore_cpp.h" class EntryListenerTest : public ::testing::Test { public: diff --git a/src/test/native/cpp/EntryNotifierTest.cpp b/src/test/native/cpp/EntryNotifierTest.cpp index b5d44a4..5880522 100644 --- a/src/test/native/cpp/EntryNotifierTest.cpp +++ b/src/test/native/cpp/EntryNotifierTest.cpp @@ -5,19 +5,17 @@ /* the project. */ /*----------------------------------------------------------------------------*/ -#include "EntryNotifier.h" - -#include "gtest/gtest.h" - -#include "support/Logger.h" +#include +#include "EntryNotifier.h" #include "TestPrinters.h" #include "ValueMatcher.h" +#include "gtest/gtest.h" -using ::testing::_; using ::testing::AnyNumber; using ::testing::IsNull; using ::testing::Return; +using ::testing::_; namespace nt { @@ -128,16 +126,16 @@ TEST_F(EntryNotifierTest, PollEntryBasic) { EXPECT_EQ(Handle{result.entry}.GetIndex(), 6); EXPECT_EQ(Handle{result.listener}.GetType(), Handle::kEntryListener); EXPECT_EQ(Handle{result.listener}.GetInst(), 1); - if (Handle{result.listener}.GetIndex() == (int)g1) { + if (Handle{result.listener}.GetIndex() == static_cast(g1)) { ++g1count; EXPECT_TRUE((result.flags & NT_NOTIFY_NEW) != 0); - } else if (Handle{result.listener}.GetIndex() == (int)g2) { + } else if (Handle{result.listener}.GetIndex() == static_cast(g2)) { ++g2count; EXPECT_TRUE((result.flags & NT_NOTIFY_DELETE) != 0); - } else if (Handle{result.listener}.GetIndex() == (int)g3) { + } else if (Handle{result.listener}.GetIndex() == static_cast(g3)) { ++g3count; EXPECT_TRUE((result.flags & NT_NOTIFY_UPDATE) != 0); - } else if (Handle{result.listener}.GetIndex() == (int)g4) { + } else if (Handle{result.listener}.GetIndex() == static_cast(g4)) { ++g4count; EXPECT_TRUE((result.flags & NT_NOTIFY_FLAGS) != 0); } else { @@ -257,16 +255,16 @@ TEST_F(EntryNotifierTest, PollPrefixBasic) { EXPECT_EQ(Handle{result.entry}.GetIndex(), 5); EXPECT_EQ(Handle{result.listener}.GetType(), Handle::kEntryListener); EXPECT_EQ(Handle{result.listener}.GetInst(), 1); - if (Handle{result.listener}.GetIndex() == (int)g1) { + if (Handle{result.listener}.GetIndex() == static_cast(g1)) { ++g1count; EXPECT_TRUE((result.flags & NT_NOTIFY_NEW) != 0); - } else if (Handle{result.listener}.GetIndex() == (int)g2) { + } else if (Handle{result.listener}.GetIndex() == static_cast(g2)) { ++g2count; EXPECT_TRUE((result.flags & NT_NOTIFY_DELETE) != 0); - } else if (Handle{result.listener}.GetIndex() == (int)g3) { + } else if (Handle{result.listener}.GetIndex() == static_cast(g3)) { ++g3count; EXPECT_TRUE((result.flags & NT_NOTIFY_UPDATE) != 0); - } else if (Handle{result.listener}.GetIndex() == (int)g4) { + } else if (Handle{result.listener}.GetIndex() == static_cast(g4)) { ++g4count; EXPECT_TRUE((result.flags & NT_NOTIFY_FLAGS) != 0); } else { diff --git a/src/test/native/cpp/MessageMatcher.h b/src/test/native/cpp/MessageMatcher.h index cf959e1..b30883e 100644 --- a/src/test/native/cpp/MessageMatcher.h +++ b/src/test/native/cpp/MessageMatcher.h @@ -5,24 +5,23 @@ /* the project. */ /*----------------------------------------------------------------------------*/ -#ifndef NT_TEST_MESSAGEMATCHER_H_ -#define NT_TEST_MESSAGEMATCHER_H_ +#ifndef NTCORE_MESSAGEMATCHER_H_ +#define NTCORE_MESSAGEMATCHER_H_ #include #include -#include "gmock/gmock.h" - -#include "TestPrinters.h" - #include "Message.h" +#include "TestPrinters.h" +#include "gmock/gmock.h" namespace nt { class MessageMatcher : public ::testing::MatcherInterface> { public: - MessageMatcher(std::shared_ptr goodmsg_) : goodmsg(goodmsg_) {} + explicit MessageMatcher(std::shared_ptr goodmsg_) + : goodmsg(goodmsg_) {} bool MatchAndExplain(std::shared_ptr msg, ::testing::MatchResultListener* listener) const override; @@ -40,4 +39,4 @@ inline ::testing::Matcher> MessageEq( } // namespace nt -#endif // NT_TEST_MESSAGEMATCHER_H_ +#endif // NTCORE_MESSAGEMATCHER_H_ diff --git a/src/test/native/cpp/MockConnectionNotifier.h b/src/test/native/cpp/MockConnectionNotifier.h index 7db4a76..38fd9dd 100644 --- a/src/test/native/cpp/MockConnectionNotifier.h +++ b/src/test/native/cpp/MockConnectionNotifier.h @@ -5,12 +5,11 @@ /* the project. */ /*----------------------------------------------------------------------------*/ -#ifndef NT_TEST_MOCKCONNECTIONNOTIFIER_H_ -#define NT_TEST_MOCKCONNECTIONNOTIFIER_H_ - -#include "gmock/gmock.h" +#ifndef NTCORE_MOCKCONNECTIONNOTIFIER_H_ +#define NTCORE_MOCKCONNECTIONNOTIFIER_H_ #include "IConnectionNotifier.h" +#include "gmock/gmock.h" namespace nt { @@ -28,4 +27,4 @@ class MockConnectionNotifier : public IConnectionNotifier { } // namespace nt -#endif // NT_TEST_MOCKCONNECTIONNOTIFIER_H_ +#endif // NTCORE_MOCKCONNECTIONNOTIFIER_H_ diff --git a/src/test/native/cpp/MockDispatcher.h b/src/test/native/cpp/MockDispatcher.h index 20551f2..565c7b2 100644 --- a/src/test/native/cpp/MockDispatcher.h +++ b/src/test/native/cpp/MockDispatcher.h @@ -5,12 +5,13 @@ /* the project. */ /*----------------------------------------------------------------------------*/ -#ifndef NT_TEST_MOCKDISPATCHER_H_ -#define NT_TEST_MOCKDISPATCHER_H_ +#ifndef NTCORE_MOCKDISPATCHER_H_ +#define NTCORE_MOCKDISPATCHER_H_ -#include "gmock/gmock.h" +#include #include "IDispatcher.h" +#include "gmock/gmock.h" namespace nt { @@ -23,4 +24,4 @@ class MockDispatcher : public IDispatcher { } // namespace nt -#endif // NT_TEST_MOCKDISPATCHER_H_ +#endif // NTCORE_MOCKDISPATCHER_H_ diff --git a/src/test/native/cpp/MockEntryNotifier.h b/src/test/native/cpp/MockEntryNotifier.h index 7c29880..eff2df8 100644 --- a/src/test/native/cpp/MockEntryNotifier.h +++ b/src/test/native/cpp/MockEntryNotifier.h @@ -5,12 +5,13 @@ /* the project. */ /*----------------------------------------------------------------------------*/ -#ifndef NT_TEST_MOCKENTRYNOTIFIER_H_ -#define NT_TEST_MOCKENTRYNOTIFIER_H_ +#ifndef NTCORE_MOCKENTRYNOTIFIER_H_ +#define NTCORE_MOCKENTRYNOTIFIER_H_ -#include "gmock/gmock.h" +#include #include "IEntryNotifier.h" +#include "gmock/gmock.h" namespace nt { @@ -39,4 +40,4 @@ class MockEntryNotifier : public IEntryNotifier { } // namespace nt -#endif // NT_TEST_MOCKENTRYNOTIFIER_H_ +#endif // NTCORE_MOCKENTRYNOTIFIER_H_ diff --git a/src/test/native/cpp/MockNetworkConnection.h b/src/test/native/cpp/MockNetworkConnection.h index 51d3ecd..e7dd055 100644 --- a/src/test/native/cpp/MockNetworkConnection.h +++ b/src/test/native/cpp/MockNetworkConnection.h @@ -5,12 +5,13 @@ /* the project. */ /*----------------------------------------------------------------------------*/ -#ifndef NT_TEST_MOCKNETWORKCONNECTION_H_ -#define NT_TEST_MOCKNETWORKCONNECTION_H_ +#ifndef NTCORE_MOCKNETWORKCONNECTION_H_ +#define NTCORE_MOCKNETWORKCONNECTION_H_ -#include "gmock/gmock.h" +#include #include "INetworkConnection.h" +#include "gmock/gmock.h" namespace nt { @@ -30,4 +31,4 @@ class MockNetworkConnection : public INetworkConnection { } // namespace nt -#endif // NT_TEST_MOCKNETWORKCONNECTION_H_ +#endif // NTCORE_MOCKNETWORKCONNECTION_H_ diff --git a/src/test/native/cpp/MockRpcServer.h b/src/test/native/cpp/MockRpcServer.h index fcf8248..46fbce7 100644 --- a/src/test/native/cpp/MockRpcServer.h +++ b/src/test/native/cpp/MockRpcServer.h @@ -5,12 +5,11 @@ /* the project. */ /*----------------------------------------------------------------------------*/ -#ifndef NT_TEST_MOCKRPCSERVER_H_ -#define NT_TEST_MOCKRPCSERVER_H_ - -#include "gmock/gmock.h" +#ifndef NTCORE_MOCKRPCSERVER_H_ +#define NTCORE_MOCKRPCSERVER_H_ #include "IRpcServer.h" +#include "gmock/gmock.h" namespace nt { @@ -27,4 +26,4 @@ class MockRpcServer : public IRpcServer { } // namespace nt -#endif // NT_TEST_MOCKRPCSERVER_H_ +#endif // NTCORE_MOCKRPCSERVER_H_ diff --git a/src/test/native/cpp/NetworkTableTest.cpp b/src/test/native/cpp/NetworkTableTest.cpp index 044eaf1..ea698a9 100644 --- a/src/test/native/cpp/NetworkTableTest.cpp +++ b/src/test/native/cpp/NetworkTableTest.cpp @@ -1,16 +1,15 @@ /*----------------------------------------------------------------------------*/ -/* Copyright (c) FIRST 2015. All Rights Reserved. */ +/* Copyright (c) FIRST 2015-2017. All Rights Reserved. */ /* Open Source Software - may be modified and shared by FRC teams. The code */ /* must be accompanied by the FIRST BSD license file in the root directory of */ /* the project. */ /*----------------------------------------------------------------------------*/ +#include "TestPrinters.h" +#include "gtest/gtest.h" #include "networktables/NetworkTable.h" #include "networktables/NetworkTableInstance.h" -#include "gtest/gtest.h" -#include "TestPrinters.h" - class NetworkTableTest : public ::testing::Test {}; TEST_F(NetworkTableTest, BasenameKey) { diff --git a/src/test/native/cpp/StorageTest.cpp b/src/test/native/cpp/StorageTest.cpp index 603489b..1089877 100644 --- a/src/test/native/cpp/StorageTest.cpp +++ b/src/test/native/cpp/StorageTest.cpp @@ -1,27 +1,27 @@ /*----------------------------------------------------------------------------*/ -/* Copyright (c) FIRST 2015. All Rights Reserved. */ +/* Copyright (c) FIRST 2015-2017. All Rights Reserved. */ /* Open Source Software - may be modified and shared by FRC teams. The code */ /* must be accompanied by the FIRST BSD license file in the root directory of */ /* the project. */ /*----------------------------------------------------------------------------*/ #include "StorageTest.h" -#include "Storage.h" -#include "gmock/gmock.h" -#include "gtest/gtest.h" -#include "llvm/raw_ostream.h" -#include "support/raw_istream.h" +#include +#include #include "MessageMatcher.h" #include "MockNetworkConnection.h" +#include "Storage.h" #include "TestPrinters.h" #include "ValueMatcher.h" +#include "gmock/gmock.h" +#include "gtest/gtest.h" -using ::testing::_; using ::testing::AnyNumber; using ::testing::IsNull; using ::testing::Return; +using ::testing::_; namespace nt { @@ -128,7 +128,7 @@ class StorageTestPersistent : public StorageTestEmpty { class MockLoadWarn { public: - MOCK_METHOD2(Warn, void(std::size_t line, llvm::StringRef msg)); + MOCK_METHOD2(Warn, void(size_t line, llvm::StringRef msg)); }; TEST_P(StorageTestEmpty, Construct) { @@ -558,7 +558,7 @@ TEST_P(StorageTestPersistent, SavePersistent) { llvm::raw_svector_ostream oss(buf); storage.SavePersistent(oss, false); llvm::StringRef out = oss.str(); - // fputs(out.c_str(), stderr); + // std::fputs(out.c_str(), stderr); llvm::StringRef line, rem = out; std::tie(line, rem) = rem.split('\n'); ASSERT_EQ("[NetworkTables Storage 3.0]", line); @@ -616,9 +616,7 @@ TEST_P(StorageTestPersistent, SavePersistent) { TEST_P(StorageTestEmpty, LoadPersistentBadHeader) { MockLoadWarn warn; - auto warn_func = [&](std::size_t line, const char* msg) { - warn.Warn(line, msg); - }; + auto warn_func = [&](size_t line, const char* msg) { warn.Warn(line, msg); }; wpi::raw_mem_istream iss(""); EXPECT_CALL( @@ -638,9 +636,7 @@ TEST_P(StorageTestEmpty, LoadPersistentBadHeader) { TEST_P(StorageTestEmpty, LoadPersistentCommentHeader) { MockLoadWarn warn; - auto warn_func = [&](std::size_t line, const char* msg) { - warn.Warn(line, msg); - }; + auto warn_func = [&](size_t line, const char* msg) { warn.Warn(line, msg); }; wpi::raw_mem_istream iss( "\n; comment\n# comment\n[NetworkTables Storage 3.0]\n"); @@ -651,9 +647,7 @@ TEST_P(StorageTestEmpty, LoadPersistentCommentHeader) { TEST_P(StorageTestEmpty, LoadPersistentEmptyName) { MockLoadWarn warn; - auto warn_func = [&](std::size_t line, const char* msg) { - warn.Warn(line, msg); - }; + auto warn_func = [&](size_t line, const char* msg) { warn.Warn(line, msg); }; wpi::raw_mem_istream iss("[NetworkTables Storage 3.0]\nboolean \"\"=true\n"); EXPECT_TRUE(storage.LoadEntries(iss, "", true, warn_func)); @@ -663,9 +657,7 @@ TEST_P(StorageTestEmpty, LoadPersistentEmptyName) { TEST_P(StorageTestEmpty, LoadPersistentAssign) { MockLoadWarn warn; - auto warn_func = [&](std::size_t line, const char* msg) { - warn.Warn(line, msg); - }; + auto warn_func = [&](size_t line, const char* msg) { warn.Warn(line, msg); }; auto value = Value::MakeBoolean(true); @@ -688,9 +680,7 @@ TEST_P(StorageTestEmpty, LoadPersistentAssign) { TEST_P(StorageTestPopulated, LoadPersistentUpdateFlags) { MockLoadWarn warn; - auto warn_func = [&](std::size_t line, const char* msg) { - warn.Warn(line, msg); - }; + auto warn_func = [&](size_t line, const char* msg) { warn.Warn(line, msg); }; // client shouldn't send an update as id not assigned yet if (GetParam()) { @@ -713,9 +703,7 @@ TEST_P(StorageTestPopulated, LoadPersistentUpdateFlags) { TEST_P(StorageTestPopulated, LoadPersistentUpdateValue) { MockLoadWarn warn; - auto warn_func = [&](std::size_t line, const char* msg) { - warn.Warn(line, msg); - }; + auto warn_func = [&](size_t line, const char* msg) { warn.Warn(line, msg); }; GetEntry("foo2")->flags = NT_PERSISTENT; @@ -747,9 +735,7 @@ TEST_P(StorageTestPopulated, LoadPersistentUpdateValue) { TEST_P(StorageTestPopulated, LoadPersistentUpdateValueFlags) { MockLoadWarn warn; - auto warn_func = [&](std::size_t line, const char* msg) { - warn.Warn(line, msg); - }; + auto warn_func = [&](size_t line, const char* msg) { warn.Warn(line, msg); }; auto value = Value::MakeDouble(1.0); @@ -783,9 +769,7 @@ TEST_P(StorageTestPopulated, LoadPersistentUpdateValueFlags) { TEST_P(StorageTestEmpty, LoadPersistent) { MockLoadWarn warn; - auto warn_func = [&](std::size_t line, const char* msg) { - warn.Warn(line, msg); - }; + auto warn_func = [&](size_t line, const char* msg) { warn.Warn(line, msg); }; std::string in = "[NetworkTables Storage 3.0]\n"; in += "boolean \"\\x00\\x03\\x05\\n\"=true\n"; @@ -861,9 +845,7 @@ TEST_P(StorageTestEmpty, LoadPersistent) { TEST_P(StorageTestEmpty, LoadPersistentWarn) { MockLoadWarn warn; - auto warn_func = [&](std::size_t line, const char* msg) { - warn.Warn(line, msg); - }; + auto warn_func = [&](size_t line, const char* msg) { warn.Warn(line, msg); }; wpi::raw_mem_istream iss( "[NetworkTables Storage 3.0]\nboolean \"foo\"=foo\n"); diff --git a/src/test/native/cpp/StorageTest.h b/src/test/native/cpp/StorageTest.h index 6dfc3ab..21338a5 100644 --- a/src/test/native/cpp/StorageTest.h +++ b/src/test/native/cpp/StorageTest.h @@ -1,23 +1,22 @@ /*----------------------------------------------------------------------------*/ -/* Copyright (c) FIRST 2015. All Rights Reserved. */ +/* Copyright (c) FIRST 2015-2017. All Rights Reserved. */ /* Open Source Software - may be modified and shared by FRC teams. The code */ /* must be accompanied by the FIRST BSD license file in the root directory of */ /* the project. */ /*----------------------------------------------------------------------------*/ -#ifndef NT_TEST_STORAGETEST_H_ -#define NT_TEST_STORAGETEST_H_ +#ifndef NTCORE_STORAGETEST_H_ +#define NTCORE_STORAGETEST_H_ #include #include #include #include "Log.h" -#include "Storage.h" - #include "MockDispatcher.h" #include "MockEntryNotifier.h" #include "MockRpcServer.h" +#include "Storage.h" namespace nt { @@ -33,9 +32,7 @@ class StorageTest { return i == storage.m_entries.end() ? &tmp_entry : i->getValue(); } - void HookOutgoing(bool server) { - storage.SetDispatcher(&dispatcher, server); - } + void HookOutgoing(bool server) { storage.SetDispatcher(&dispatcher, server); } wpi::Logger logger; ::testing::StrictMock notifier; @@ -47,4 +44,4 @@ class StorageTest { } // namespace nt -#endif // NT_TEST_STORAGETEST_H_ +#endif // NTCORE_STORAGETEST_H_ diff --git a/src/test/native/cpp/TestPrinters.cpp b/src/test/native/cpp/TestPrinters.cpp index a98477c..e9ffb74 100644 --- a/src/test/native/cpp/TestPrinters.cpp +++ b/src/test/native/cpp/TestPrinters.cpp @@ -133,7 +133,6 @@ void PrintTo(const Value& value, std::ostream* os) { break; case NT_RAW: *os << ::testing::PrintToString(value.GetRaw()); - ; break; case NT_BOOLEAN_ARRAY: *os << ::testing::PrintToString(value.GetBooleanArray()); diff --git a/src/test/native/cpp/TestPrinters.h b/src/test/native/cpp/TestPrinters.h index e5a6358..03663be 100644 --- a/src/test/native/cpp/TestPrinters.h +++ b/src/test/native/cpp/TestPrinters.h @@ -5,19 +5,19 @@ /* the project. */ /*----------------------------------------------------------------------------*/ -#ifndef NT_TEST_TESTPRINTERS_H_ -#define NT_TEST_TESTPRINTERS_H_ +#ifndef NTCORE_TESTPRINTERS_H_ +#define NTCORE_TESTPRINTERS_H_ #include #include -#include "gtest/gtest.h" +#include -#include "llvm/StringRef.h" +#include "gtest/gtest.h" namespace llvm { -inline void PrintTo(StringRef str, ::std::ostream *os) { +inline void PrintTo(StringRef str, ::std::ostream* os) { ::testing::internal::PrintStringTo(str.str(), os); } @@ -51,4 +51,4 @@ inline void PrintTo(std::shared_ptr value, std::ostream* os) { } // namespace nt -#endif // NT_TEST_TESTPRINTERS_H_ +#endif // NTCORE_TESTPRINTERS_H_ diff --git a/src/test/native/cpp/ValueMatcher.h b/src/test/native/cpp/ValueMatcher.h index 981dc76..fae81d8 100644 --- a/src/test/native/cpp/ValueMatcher.h +++ b/src/test/native/cpp/ValueMatcher.h @@ -5,14 +5,13 @@ /* the project. */ /*----------------------------------------------------------------------------*/ -#ifndef NT_TEST_VALUEMATCHER_H_ -#define NT_TEST_VALUEMATCHER_H_ +#ifndef NTCORE_VALUEMATCHER_H_ +#define NTCORE_VALUEMATCHER_H_ #include #include #include "gmock/gmock.h" - #include "networktables/NetworkTableValue.h" namespace nt { @@ -20,7 +19,7 @@ namespace nt { class ValueMatcher : public ::testing::MatcherInterface> { public: - ValueMatcher(std::shared_ptr goodval_) : goodval(goodval_) {} + explicit ValueMatcher(std::shared_ptr goodval_) : goodval(goodval_) {} bool MatchAndExplain(std::shared_ptr msg, ::testing::MatchResultListener* listener) const override; @@ -38,4 +37,4 @@ inline ::testing::Matcher> ValueEq( } // namespace nt -#endif // NT_TEST_VALUEMATCHER_H_ +#endif // NTCORE_VALUEMATCHER_H_ diff --git a/src/test/native/cpp/ValueTest.cpp b/src/test/native/cpp/ValueTest.cpp index 442597c..cc6627f 100644 --- a/src/test/native/cpp/ValueTest.cpp +++ b/src/test/native/cpp/ValueTest.cpp @@ -1,15 +1,14 @@ /*----------------------------------------------------------------------------*/ -/* Copyright (c) FIRST 2015. All Rights Reserved. */ +/* Copyright (c) FIRST 2015-2017. All Rights Reserved. */ /* Open Source Software - may be modified and shared by FRC teams. The code */ /* must be accompanied by the FIRST BSD license file in the root directory of */ /* the project. */ /*----------------------------------------------------------------------------*/ -#include "networktables/NetworkTableValue.h" +#include "TestPrinters.h" #include "Value_internal.h" - #include "gtest/gtest.h" -#include "TestPrinters.h" +#include "networktables/NetworkTableValue.h" namespace nt { @@ -107,7 +106,7 @@ TEST_F(ValueTest, Raw) { } TEST_F(ValueTest, BooleanArray) { - std::vector vec{1,0,1}; + std::vector vec{1, 0, 1}; auto v = Value::MakeBooleanArray(vec); ASSERT_EQ(NT_BOOLEAN_ARRAY, v->type()); ASSERT_EQ(llvm::ArrayRef(vec), v->GetBooleanArray()); @@ -121,7 +120,7 @@ TEST_F(ValueTest, BooleanArray) { ASSERT_EQ(vec[2], cv.data.arr_boolean.arr[2]); // assign with same size - vec = {0,1,0}; + vec = {0, 1, 0}; v = Value::MakeBooleanArray(vec); ASSERT_EQ(NT_BOOLEAN_ARRAY, v->type()); ASSERT_EQ(llvm::ArrayRef(vec), v->GetBooleanArray()); @@ -133,7 +132,7 @@ TEST_F(ValueTest, BooleanArray) { ASSERT_EQ(vec[2], cv.data.arr_boolean.arr[2]); // assign with different size - vec = {1,0}; + vec = {1, 0}; v = Value::MakeBooleanArray(vec); ASSERT_EQ(NT_BOOLEAN_ARRAY, v->type()); ASSERT_EQ(llvm::ArrayRef(vec), v->GetBooleanArray()); @@ -147,7 +146,7 @@ TEST_F(ValueTest, BooleanArray) { } TEST_F(ValueTest, DoubleArray) { - std::vector vec{0.5,0.25,0.5}; + std::vector vec{0.5, 0.25, 0.5}; auto v = Value::MakeDoubleArray(vec); ASSERT_EQ(NT_DOUBLE_ARRAY, v->type()); ASSERT_EQ(llvm::ArrayRef(vec), v->GetDoubleArray()); @@ -161,7 +160,7 @@ TEST_F(ValueTest, DoubleArray) { ASSERT_EQ(vec[2], cv.data.arr_double.arr[2]); // assign with same size - vec = {0.25,0.5,0.25}; + vec = {0.25, 0.5, 0.25}; v = Value::MakeDoubleArray(vec); ASSERT_EQ(NT_DOUBLE_ARRAY, v->type()); ASSERT_EQ(llvm::ArrayRef(vec), v->GetDoubleArray()); @@ -173,7 +172,7 @@ TEST_F(ValueTest, DoubleArray) { ASSERT_EQ(vec[2], cv.data.arr_double.arr[2]); // assign with different size - vec = {0.5,0.25}; + vec = {0.5, 0.25}; v = Value::MakeDoubleArray(vec); ASSERT_EQ(NT_DOUBLE_ARRAY, v->type()); ASSERT_EQ(llvm::ArrayRef(vec), v->GetDoubleArray()); @@ -293,35 +292,35 @@ TEST_F(ValueTest, StringComparison) { } TEST_F(ValueTest, BooleanArrayComparison) { - std::vector vec{1,0,1}; + std::vector vec{1, 0, 1}; auto v1 = Value::MakeBooleanArray(vec); auto v2 = Value::MakeBooleanArray(vec); ASSERT_EQ(*v1, *v2); // different contents - vec = {1,1,1}; + vec = {1, 1, 1}; v2 = Value::MakeBooleanArray(vec); ASSERT_NE(*v1, *v2); // different size - vec = {1,0}; + vec = {1, 0}; v2 = Value::MakeBooleanArray(vec); ASSERT_NE(*v1, *v2); } TEST_F(ValueTest, DoubleArrayComparison) { - std::vector vec{0.5,0.25,0.5}; + std::vector vec{0.5, 0.25, 0.5}; auto v1 = Value::MakeDoubleArray(vec); auto v2 = Value::MakeDoubleArray(vec); ASSERT_EQ(*v1, *v2); // different contents - vec = {0.5,0.5,0.5}; + vec = {0.5, 0.5, 0.5}; v2 = Value::MakeDoubleArray(vec); ASSERT_NE(*v1, *v2); // different size - vec = {0.5,0.25}; + vec = {0.5, 0.25}; v2 = Value::MakeDoubleArray(vec); ASSERT_NE(*v1, *v2); } diff --git a/src/test/native/cpp/WireDecoderTest.cpp b/src/test/native/cpp/WireDecoderTest.cpp index 9c91a31..ac50014 100644 --- a/src/test/native/cpp/WireDecoderTest.cpp +++ b/src/test/native/cpp/WireDecoderTest.cpp @@ -1,20 +1,21 @@ /*----------------------------------------------------------------------------*/ -/* Copyright (c) FIRST 2015. All Rights Reserved. */ +/* Copyright (c) FIRST 2015-2017. All Rights Reserved. */ /* Open Source Software - may be modified and shared by FRC teams. The code */ /* must be accompanied by the FIRST BSD license file in the root directory of */ /* the project. */ /*----------------------------------------------------------------------------*/ -#include "WireDecoder.h" - -#include "gtest/gtest.h" -#include "TestPrinters.h" +#include #include #include #include -#include "llvm/StringRef.h" +#include + +#include "TestPrinters.h" +#include "WireDecoder.h" +#include "gtest/gtest.h" namespace nt { @@ -36,8 +37,7 @@ class WireDecoderTest : public ::testing::Test { v_string_array = Value::MakeStringArray(std::move(sa)); sa.clear(); - for (int i=0; i<255; ++i) - sa.push_back("h"); + for (int i = 0; i < 255; ++i) sa.push_back("h"); v_string_array_big = Value::MakeStringArray(std::move(sa)); s_normal = std::string("hello"); @@ -118,7 +118,7 @@ TEST_F(WireDecoderTest, Read32) { 20); wpi::Logger logger; WireDecoder d(is, 0x0300u, logger); - unsigned long val; + uint32_t val; ASSERT_TRUE(d.Read32(&val)); EXPECT_EQ(5ul, val); ASSERT_TRUE(d.Read32(&val)); @@ -164,14 +164,14 @@ TEST_F(WireDecoderTest, ReadUleb128) { wpi::raw_mem_istream is("\x00\x7f\x80\x01\x80", 5); wpi::Logger logger; WireDecoder d(is, 0x0300u, logger); - unsigned long val; + uint64_t val; ASSERT_TRUE(d.ReadUleb128(&val)); EXPECT_EQ(0ul, val); ASSERT_TRUE(d.ReadUleb128(&val)); EXPECT_EQ(0x7ful, val); ASSERT_TRUE(d.ReadUleb128(&val)); EXPECT_EQ(0x80ul, val); - ASSERT_FALSE(d.ReadUleb128(&val)); // partial + ASSERT_FALSE(d.ReadUleb128(&val)); // partial ASSERT_EQ(nullptr, d.error()); } @@ -227,12 +227,12 @@ TEST_F(WireDecoderTest, ReadBooleanValue2) { wpi::Logger logger; WireDecoder d(is, 0x0200u, logger); auto val = d.ReadValue(NT_BOOLEAN); - ASSERT_TRUE(bool(val)); + ASSERT_TRUE(static_cast(val)); EXPECT_EQ(*v_boolean, *val); auto v_false = Value::MakeBoolean(false); val = d.ReadValue(NT_BOOLEAN); - ASSERT_TRUE(bool(val)); + ASSERT_TRUE(static_cast(val)); EXPECT_EQ(*v_false, *val); ASSERT_FALSE(d.ReadValue(NT_BOOLEAN)); @@ -247,11 +247,11 @@ TEST_F(WireDecoderTest, ReadDoubleValue2) { wpi::Logger logger; WireDecoder d(is, 0x0200u, logger); auto val = d.ReadValue(NT_DOUBLE); - ASSERT_TRUE(bool(val)); + ASSERT_TRUE(static_cast(val)); EXPECT_EQ(*v_double, *val); val = d.ReadValue(NT_DOUBLE); - ASSERT_TRUE(bool(val)); + ASSERT_TRUE(static_cast(val)); EXPECT_EQ(*v_double, *val); ASSERT_FALSE(d.ReadValue(NT_DOUBLE)); @@ -259,16 +259,19 @@ TEST_F(WireDecoderTest, ReadDoubleValue2) { } TEST_F(WireDecoderTest, ReadStringValue2) { - wpi::raw_mem_istream is("\x00\x05hello\x00\x03" "bye\x55", 13); + wpi::raw_mem_istream is( + "\x00\x05hello\x00\x03" + "bye\x55", + 13); wpi::Logger logger; WireDecoder d(is, 0x0200u, logger); auto val = d.ReadValue(NT_STRING); - ASSERT_TRUE(bool(val)); + ASSERT_TRUE(static_cast(val)); EXPECT_EQ(*v_string, *val); auto v_bye = Value::MakeString(llvm::StringRef("bye")); val = d.ReadValue(NT_STRING); - ASSERT_TRUE(bool(val)); + ASSERT_TRUE(static_cast(val)); EXPECT_EQ(*v_bye, *val); unsigned int b; @@ -284,12 +287,12 @@ TEST_F(WireDecoderTest, ReadBooleanArrayValue2) { wpi::Logger logger; WireDecoder d(is, 0x0200u, logger); auto val = d.ReadValue(NT_BOOLEAN_ARRAY); - ASSERT_TRUE(bool(val)); + ASSERT_TRUE(static_cast(val)); EXPECT_EQ(*v_boolean_array, *val); auto v_boolean_array2 = Value::MakeBooleanArray(std::vector{1, 0}); val = d.ReadValue(NT_BOOLEAN_ARRAY); - ASSERT_TRUE(bool(val)); + ASSERT_TRUE(static_cast(val)); EXPECT_EQ(*v_boolean_array2, *val); ASSERT_FALSE(d.ReadValue(NT_BOOLEAN_ARRAY)); @@ -304,7 +307,7 @@ TEST_F(WireDecoderTest, ReadBooleanArrayBigValue2) { wpi::Logger logger; WireDecoder d(is, 0x0200u, logger); auto val = d.ReadValue(NT_BOOLEAN_ARRAY); - ASSERT_TRUE(bool(val)); + ASSERT_TRUE(static_cast(val)); EXPECT_EQ(*v_boolean_array_big, *val); ASSERT_FALSE(d.ReadValue(NT_BOOLEAN_ARRAY)); @@ -319,7 +322,7 @@ TEST_F(WireDecoderTest, ReadDoubleArrayValue2) { wpi::Logger logger; WireDecoder d(is, 0x0200u, logger); auto val = d.ReadValue(NT_DOUBLE_ARRAY); - ASSERT_TRUE(bool(val)); + ASSERT_TRUE(static_cast(val)); EXPECT_EQ(*v_double_array, *val); unsigned int b; @@ -333,12 +336,12 @@ TEST_F(WireDecoderTest, ReadDoubleArrayValue2) { TEST_F(WireDecoderTest, ReadDoubleArrayBigValue2) { std::string s; s.push_back('\xff'); - s.append(255*8, '\x00'); + s.append(255 * 8, '\x00'); wpi::raw_mem_istream is(s.data(), s.size()); wpi::Logger logger; WireDecoder d(is, 0x0200u, logger); auto val = d.ReadValue(NT_DOUBLE_ARRAY); - ASSERT_TRUE(bool(val)); + ASSERT_TRUE(static_cast(val)); EXPECT_EQ(*v_double_array_big, *val); ASSERT_FALSE(d.ReadValue(NT_DOUBLE_ARRAY)); @@ -350,7 +353,7 @@ TEST_F(WireDecoderTest, ReadStringArrayValue2) { wpi::Logger logger; WireDecoder d(is, 0x0200u, logger); auto val = d.ReadValue(NT_STRING_ARRAY); - ASSERT_TRUE(bool(val)); + ASSERT_TRUE(static_cast(val)); EXPECT_EQ(*v_string_array, *val); unsigned int b; @@ -364,13 +367,12 @@ TEST_F(WireDecoderTest, ReadStringArrayValue2) { TEST_F(WireDecoderTest, ReadStringArrayBigValue2) { std::string s; s.push_back('\xff'); - for (int i=0; i<255; ++i) - s.append("\x00\x01h", 3); + for (int i = 0; i < 255; ++i) s.append("\x00\x01h", 3); wpi::raw_mem_istream is(s.data(), s.size()); wpi::Logger logger; WireDecoder d(is, 0x0200u, logger); auto val = d.ReadValue(NT_STRING_ARRAY); - ASSERT_TRUE(bool(val)); + ASSERT_TRUE(static_cast(val)); EXPECT_EQ(*v_string_array_big, *val); ASSERT_FALSE(d.ReadValue(NT_STRING_ARRAY)); @@ -398,12 +400,12 @@ TEST_F(WireDecoderTest, ReadBooleanValue3) { wpi::Logger logger; WireDecoder d(is, 0x0300u, logger); auto val = d.ReadValue(NT_BOOLEAN); - ASSERT_TRUE(bool(val)); + ASSERT_TRUE(static_cast(val)); EXPECT_EQ(*v_boolean, *val); auto v_false = Value::MakeBoolean(false); val = d.ReadValue(NT_BOOLEAN); - ASSERT_TRUE(bool(val)); + ASSERT_TRUE(static_cast(val)); EXPECT_EQ(*v_false, *val); ASSERT_FALSE(d.ReadValue(NT_BOOLEAN)); @@ -418,11 +420,11 @@ TEST_F(WireDecoderTest, ReadDoubleValue3) { wpi::Logger logger; WireDecoder d(is, 0x0300u, logger); auto val = d.ReadValue(NT_DOUBLE); - ASSERT_TRUE(bool(val)); + ASSERT_TRUE(static_cast(val)); EXPECT_EQ(*v_double, *val); val = d.ReadValue(NT_DOUBLE); - ASSERT_TRUE(bool(val)); + ASSERT_TRUE(static_cast(val)); EXPECT_EQ(*v_double, *val); ASSERT_FALSE(d.ReadValue(NT_DOUBLE)); @@ -430,16 +432,19 @@ TEST_F(WireDecoderTest, ReadDoubleValue3) { } TEST_F(WireDecoderTest, ReadStringValue3) { - wpi::raw_mem_istream is("\x05hello\x03" "bye\x55", 11); + wpi::raw_mem_istream is( + "\x05hello\x03" + "bye\x55", + 11); wpi::Logger logger; WireDecoder d(is, 0x0300u, logger); auto val = d.ReadValue(NT_STRING); - ASSERT_TRUE(bool(val)); + ASSERT_TRUE(static_cast(val)); EXPECT_EQ(*v_string, *val); auto v_bye = Value::MakeString(llvm::StringRef("bye")); val = d.ReadValue(NT_STRING); - ASSERT_TRUE(bool(val)); + ASSERT_TRUE(static_cast(val)); EXPECT_EQ(*v_bye, *val); unsigned int b; @@ -451,16 +456,19 @@ TEST_F(WireDecoderTest, ReadStringValue3) { } TEST_F(WireDecoderTest, ReadRawValue3) { - wpi::raw_mem_istream is("\x05hello\x03" "bye\x55", 11); + wpi::raw_mem_istream is( + "\x05hello\x03" + "bye\x55", + 11); wpi::Logger logger; WireDecoder d(is, 0x0300u, logger); auto val = d.ReadValue(NT_RAW); - ASSERT_TRUE(bool(val)); + ASSERT_TRUE(static_cast(val)); EXPECT_EQ(*v_raw, *val); auto v_bye = Value::MakeRaw(llvm::StringRef("bye")); val = d.ReadValue(NT_RAW); - ASSERT_TRUE(bool(val)); + ASSERT_TRUE(static_cast(val)); EXPECT_EQ(*v_bye, *val); unsigned int b; @@ -476,12 +484,12 @@ TEST_F(WireDecoderTest, ReadBooleanArrayValue3) { wpi::Logger logger; WireDecoder d(is, 0x0300u, logger); auto val = d.ReadValue(NT_BOOLEAN_ARRAY); - ASSERT_TRUE(bool(val)); + ASSERT_TRUE(static_cast(val)); EXPECT_EQ(*v_boolean_array, *val); auto v_boolean_array2 = Value::MakeBooleanArray(std::vector{1, 0}); val = d.ReadValue(NT_BOOLEAN_ARRAY); - ASSERT_TRUE(bool(val)); + ASSERT_TRUE(static_cast(val)); EXPECT_EQ(*v_boolean_array2, *val); ASSERT_FALSE(d.ReadValue(NT_BOOLEAN_ARRAY)); @@ -496,7 +504,7 @@ TEST_F(WireDecoderTest, ReadBooleanArrayBigValue3) { wpi::Logger logger; WireDecoder d(is, 0x0300u, logger); auto val = d.ReadValue(NT_BOOLEAN_ARRAY); - ASSERT_TRUE(bool(val)); + ASSERT_TRUE(static_cast(val)); EXPECT_EQ(*v_boolean_array_big, *val); ASSERT_FALSE(d.ReadValue(NT_BOOLEAN_ARRAY)); @@ -511,7 +519,7 @@ TEST_F(WireDecoderTest, ReadDoubleArrayValue3) { wpi::Logger logger; WireDecoder d(is, 0x0300u, logger); auto val = d.ReadValue(NT_DOUBLE_ARRAY); - ASSERT_TRUE(bool(val)); + ASSERT_TRUE(static_cast(val)); EXPECT_EQ(*v_double_array, *val); unsigned int b; @@ -525,12 +533,12 @@ TEST_F(WireDecoderTest, ReadDoubleArrayValue3) { TEST_F(WireDecoderTest, ReadDoubleArrayBigValue3) { std::string s; s.push_back('\xff'); - s.append(255*8, '\x00'); + s.append(255 * 8, '\x00'); wpi::raw_mem_istream is(s.data(), s.size()); wpi::Logger logger; WireDecoder d(is, 0x0300u, logger); auto val = d.ReadValue(NT_DOUBLE_ARRAY); - ASSERT_TRUE(bool(val)); + ASSERT_TRUE(static_cast(val)); EXPECT_EQ(*v_double_array_big, *val); ASSERT_FALSE(d.ReadValue(NT_DOUBLE_ARRAY)); @@ -542,7 +550,7 @@ TEST_F(WireDecoderTest, ReadStringArrayValue3) { wpi::Logger logger; WireDecoder d(is, 0x0300u, logger); auto val = d.ReadValue(NT_STRING_ARRAY); - ASSERT_TRUE(bool(val)); + ASSERT_TRUE(static_cast(val)); EXPECT_EQ(*v_string_array, *val); unsigned int b; @@ -556,13 +564,12 @@ TEST_F(WireDecoderTest, ReadStringArrayValue3) { TEST_F(WireDecoderTest, ReadStringArrayBigValue3) { std::string s; s.push_back('\xff'); - for (int i=0; i<255; ++i) - s.append("\x01h", 2); + for (int i = 0; i < 255; ++i) s.append("\x01h", 2); wpi::raw_mem_istream is(s.data(), s.size()); wpi::Logger logger; WireDecoder d(is, 0x0300u, logger); auto val = d.ReadValue(NT_STRING_ARRAY); - ASSERT_TRUE(bool(val)); + ASSERT_TRUE(static_cast(val)); EXPECT_EQ(*v_string_array_big, *val); ASSERT_FALSE(d.ReadValue(NT_STRING_ARRAY)); diff --git a/src/test/native/cpp/WireEncoderTest.cpp b/src/test/native/cpp/WireEncoderTest.cpp index ec6135f..5c7c90f 100644 --- a/src/test/native/cpp/WireEncoderTest.cpp +++ b/src/test/native/cpp/WireEncoderTest.cpp @@ -1,20 +1,19 @@ /*----------------------------------------------------------------------------*/ -/* Copyright (c) FIRST 2015. All Rights Reserved. */ +/* Copyright (c) FIRST 2015-2017. All Rights Reserved. */ /* Open Source Software - may be modified and shared by FRC teams. The code */ /* must be accompanied by the FIRST BSD license file in the root directory of */ /* the project. */ /*----------------------------------------------------------------------------*/ -#include "WireEncoder.h" - -#include "gtest/gtest.h" -#include "TestPrinters.h" - #include #include #include -#include "llvm/StringRef.h" +#include + +#include "TestPrinters.h" +#include "WireEncoder.h" +#include "gtest/gtest.h" #define BUFSIZE 1024 @@ -39,8 +38,7 @@ class WireEncoderTest : public ::testing::Test { v_string_array = Value::MakeStringArray(std::move(sa)); sa.clear(); - for (int i=0; i<256; ++i) - sa.push_back("h"); + for (int i = 0; i < 256; ++i) sa.push_back("h"); v_string_array_big = Value::MakeStringArray(std::move(sa)); s_normal = "hello"; @@ -77,85 +75,83 @@ TEST_F(WireEncoderTest, SetProtoRev) { } TEST_F(WireEncoderTest, Write8) { - std::size_t off = BUFSIZE-1; + size_t off = BUFSIZE - 1; WireEncoder e(0x0300u); - for(std::size_t i=0; i::infinity()); e.WriteDouble(DBL_MIN); e.WriteDouble(DBL_MAX); - ASSERT_EQ(40u, e.size()-off); + ASSERT_EQ(40u, e.size() - off); // golden values except min and max from // http://www.binaryconvert.com/result_double.html - ASSERT_EQ(llvm::StringRef( - "\x00\x00\x00\x00\x00\x00\x00\x00" - "\x41\x0c\x13\x80\x00\x00\x00\x00" - "\x7f\xf0\x00\x00\x00\x00\x00\x00" - "\x00\x10\x00\x00\x00\x00\x00\x00" - "\x7f\xef\xff\xff\xff\xff\xff\xff", - 40), + ASSERT_EQ(llvm::StringRef("\x00\x00\x00\x00\x00\x00\x00\x00" + "\x41\x0c\x13\x80\x00\x00\x00\x00" + "\x7f\xf0\x00\x00\x00\x00\x00\x00" + "\x00\x10\x00\x00\x00\x00\x00\x00" + "\x7f\xef\xff\xff\xff\xff\xff\xff", + 40), llvm::StringRef(e.data(), e.size()).substr(off)); } TEST_F(WireEncoderTest, WriteUleb128) { - std::size_t off = BUFSIZE-2; + size_t off = BUFSIZE - 2; WireEncoder e(0x0300u); - for(std::size_t i=0; i +#include "gmock/gmock.h" #include "ntcore.h" int main(int argc, char** argv) {