Commit Graph

31 Commits

Author SHA1 Message Date
Sam Carlberg
f43675e2bd Add functionality for getting the current network mode (#202)
Use bit flags to indicate a combination of network mode and status.
2017-06-02 17:25:20 -07:00
Peter Johnson
77edf1e103 Add FRC Driver Station connection support.
The 2017 FRC Driver Station supports getting the robot IP via a TCP
connection that returns JSON.  Use this to support overriding the
server IP address used for client connections.

Default to using this approach for client connections in the NetworkTable
interfaces.

Add support for setting the server address without stopping and
restarting the client.

SetTeam now also round-robins by default.
2016-11-04 23:42:41 -07:00
Thad House
05ca76ea99 Runs clang-format on ntcore (#150)
Also updates .clang-format to match allwpilib

WPIUtil was skipped
2016-11-03 21:03:45 -07:00
Thad House
a7eca7d4bd Adds ConnectionInfo to Rpc callback (#116) 2016-10-03 10:04:30 -07:00
Thad House
e952236e1a Reverts the last 2 Rpc changes (#114)
* Revert "Fully asigns the ConnectionInfo struct (#113)"

This reverts commit 9a3100b221.

* Revert "Passes the ConnectionInfo of the Rpc client on server callback (#112)"

This reverts commit 7e9754acff.
2016-09-16 22:23:58 -07:00
Thad House
7e9754acff Passes the ConnectionInfo of the Rpc client on server callback (#112) 2016-09-16 20:20:55 -07:00
Thad House
c0ce4270f0 Adds a way to cancel a blocking rpc call (#94) 2016-08-16 23:31:45 -07:00
Thad House
0b80bd2b09 Adds timeout capabilities to blocking Rpc Calls (#86) 2016-08-15 20:24:07 -07:00
Thad House
bc99d341fb Changes remote_name to remote_ip (#87)
Was confusing, as remote_name seemed like a name but wasn't.
Also changes remote_ip in the C api to use an NT_String
2016-08-07 16:38:20 -05:00
Thad House
58092c5190 Adds SetDefault methods to NetworkTables (#54)
There was no way to atomically check for a key in the table,
and then setting if it if non existant. Back before persistent
this was not a problem, however now it is, as its possible for
values to be added before team's robot programs start. This makes
the old method of calling Put*** methods in RobotInit invalid.
This adds SetDefault methods, which do this atomically.
2016-07-13 00:31:03 -07:00
Peter Johnson
5ac68f74d4 Support client round robin to multiple server addresses.
Change-Id: If87dc64a485b1c8a340c5f6fa39ca09d40133e30
2016-04-08 22:02:52 -07:00
Peter Johnson
e6054f543a ntcore_c.h: Whitespace fixes. 2015-12-29 08:57:10 -08:00
Peter Johnson
fef8f933d9 Add SafeThread to fix thread JNI shutdown races.
During JVM shutdown, some JNI calls may not return, so it's not possible to
reliably perform a join() during static variable destruction (which occurs
as the JVM unloads the JNI module).

Also, due to static variable destruction, it's not safe to use any members
of a static class instance from a separate thread of execution.

SafeThread is a templated thread class and a related owner class that's
designed for safe operation and shutdown of threads in the presence of
callbacks that may not return.  It also passes ownership of variables from
the static instance to the thread, so the thread can safely operate until
it exits (the last operation of the thread being to destroy its instance).

Notifiers, RpcServer, and Logger now use SafeThread to ensure race-free
destruction in both C++ and Java.

All Java callback threads are now marked as Java daemon threads so they
don't keep the JVM running after main() terminates.

All Java callback threads are now named so their purpose is more easily
identified in a debugger.

Add SetRpcServerOnStart and SetRpcServerOnExit (similar to Listener).
2015-12-28 17:51:56 -08:00
Peter Johnson
32001427d4 Java: call JNI AttachCurrentThread less frequently.
Each call to AttachCurrentThread results in a new Java thread object being
created.  This is inefficient and also causes debugging issues with Eclipse
due to constant creation and removal of threads.  Now AttachCurrentThread is
only called once for (all) listeners and once for logging (if used).
2015-12-20 20:42:09 -08:00
Thad House
a142cc48d3 Adds StopNotifier and StopRpcServer functions
Workaround for #30.  Allows libraries to shut down the secondary
threads.
2015-11-11 20:50:30 -08:00
Peter Johnson
90959defd9 Provide more extensive listener features.
This enables listeners to be notified of not only value updates, but also flag
changes and deletions by using a bitmask to specify what notifications are
desired.  The old API (which only provided a new/not new) flag is still
supported.  This also subsumes the feature to listen to local changes (that's
one of the bitmask options).
2015-09-27 01:55:32 -07:00
Peter Johnson
424bf51a7b Implement local notification.
The default behavior is to only notify remote changes, but for some
applications (e.g. GUI's) it's advantageous to know about local
changes as well.

This is (slightly) optimized in that local changes only result in
additional resources being consumed if (any) local listeners have been
created.
2015-09-23 00:56:08 -07:00
Peter Johnson
51eb96903c Java: Improve robustness against JVM crashes on exit.
The JVM doesn't always do a good job of telling JNI modules that the JVM
is going away, which results in a crash in the JavaGlobal and/or
JavaWeakGlobal destructors as they try to delete the associated references
after the JVM has already gone away.

To protect against this, the Notifier now has a static variable that's set
when the Notifier instance (a singleton) is destroyed.  This is used by
JavaGlobal and JavaWeakGlobal to detect when a process exit is in process.
2015-09-14 22:00:22 -07:00
Thad House
46e0ac1258 Added documentation to the C interface
Client/Server functions.
2015-08-31 19:12:45 -07:00
Thad House
22d984a6bd Comments the interop functions in the C interface.
Properly space the comments.
2015-08-31 18:56:05 -07:00
Peter Johnson
8d6f96adb9 Add NT_FreeCharArray. 2015-08-29 08:58:53 -07:00
Peter Johnson
1f431754a9 Simplify C entry point function names.
Rename GetEntry*FromValue to GetValue*.
Rename a couple of NTStringArray to simply StringArray.
2015-08-29 08:48:36 -07:00
Peter Johnson
9b9b41f40e Reformat to match coding style. No functional changes. 2015-08-29 08:30:40 -07:00
Peter Johnson
a451fd3f04 Make string/raw getters/setters use char*+len instead of NT_String.
Also remove NT_AllocateString.

This avoids passing and returning struct NT_String by value.

Also make GetEntry*FromValue take a const NT_Value*.
2015-08-29 08:25:48 -07:00
Thad House
4b7dfc0254 Implements individual getters and setters for the C interface.
Starting to add Getters, Setters, and Allocators to the C interface

Because of the union in the NT_Value structure, some languages would
have a difficult time with the interop. This commit adds individual
getters and setters to the C interface to make interop easier.

In addition, some languages cannot allocate native memory in the same
heap that the C code would use. This adds allocation functions to make
sure that all our memory is allocated and can be freed properly from the
same heap.

The reason the getters are not individual get functions are because that
would require the calling code to first get the type, and then call the
specific getter for that type. Doing combined get functions causes
interop code to only have to cross interop boundaries once to get the
value instead of twice, for a light performance increase. However, this
could be changed without much work.

NT getters and setters round 2

Fixed some of the code based on the comments in the pull request.

Creates individual getters.

Should work better then 1 single getter.

Fixes end of file new line, and fixes function nameing

SetNTValue... made less sense then SetEntry... Matches the getter
naming.

Fixed methods to be less leaky.

Fixed Formatting, Fixed return values on Bool and Double. Added Contains Key

Changed ContainsKey to GetType. Also renamed Arr to Array

In public functions, I think I like Array better then Arr. Also, make
the getters that use value check for a null value, which should prevent
segfaults.

Fixes C++ Type functions to work properly

NTString Set functions still do not work properly though. I need some
help on there. Error message is in the pull request.

Changes Get functions to return status and have pointer to data passed in to be set.

Fixes NT_Strings

Added  new functions to ntcore.def

Fixes NT_PostRpcResponse in the def file

Was NT_PostRpcRepsonse, which was failing the build.

Removed unused parameter from setters

Since we were forcing exports in the cmake build, they were seen in
windows, but since the header didnt match the implementation they
wouldn't export on linux. So fixed that. Linux builds now work properly,
tested on a physical RIO.

Added a DisposeEntryInfoArray method.

There was no way to free the array returned from GetEntryInfo

Adds NT_DisposeEntryInfoArray to the def file.

Implement automatic persistent saves.

Also loads persistent file on server start.

Update TODO.

raw_istream and kin: a few cleanups.

anchor() doesn't seem to change compiler output in current compilers, so
remove it.  Use default where appropriate rather than empty bodies.

Clean up trailing whitespace.

Dispatcher: Move several fixed initial values to header.

Uninline constructors to reduce GetInstance() inlined code size.

Logger: Move m_min_level init to header.

Replaced time.h with std::chrono

This implementation returns the same values as the previous one on both a Linux machine and the roboRIO.

Value: Use variant of enable_if to fix MakeString/MakeRaw in GCC.

Tested on GCC 4.8, GCC 4.9, and clang 3.6.

Don't dispose in ConvertToC for NT_String and NT_Value.

Fixes #16.

Fixed Gradle build to actually export proper functions

Finishes fixes in pull request

Changes array setters to be const

To build RPC, needed a way to allocate a Char Array

Since after the callback, the C code explicitly frees, a way to make
sure to allocate the callback return string from the same heap was
needed.

Adds const to NTString setters.

Removes Const from NTString setters
2015-08-28 13:37:49 -07:00
Peter Johnson
b488cdd6ff Support immediate notify of connection listener.
Also only perform immediate notification to the callback actually
requesting the notification, not all existing callbacks.

Offset returned uids by 1 so uid=0 can be used to indicate immediate
notification.
2015-08-28 00:13:56 -07:00
Peter Johnson
8d7cdeabbf Implement remote procedure calls. 2015-08-13 21:32:16 -07:00
Peter Johnson
4356e313ec Add logging framework.
DEBUG messages are completely optimized out if NDEBUG is defined.
2015-07-31 22:41:26 -07:00
Peter Johnson
6f940bcaaf Add immediate_notify and is_new to entry listener.
On the callback function, is_new indicates the value is newly added.

On adding a callback function, immediate_notify indicates the callback
should be called once (with is_new=true) for each matching entry that
already exists.
2015-07-23 01:02:53 -07:00
Peter Johnson
3025a7e51e Finish C wrappers. 2015-07-17 08:47:25 -07:00
Peter Johnson
fcbd2751ba Provide C++ API. Move all classes to "nt" namespace.
The C API is now just simple wrappers around the C++ API.
2015-07-17 07:21:07 -07:00