Commit Graph

66 Commits

Author SHA1 Message Date
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
Peter Johnson
a73166a665 Make many more utility classes/headers public. (#76)
Moving these headers from src to include enables other libraries to use the
functionality provided.

* tcpsockets
* atomic_static
* raw_istream
* timestamp
* SafeThread
* Base64
* LEB128
* ConcurrentQueue

The classes have been moved into the wpi namespace as they're generic.
2016-07-27 00:39:38 -07: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
3c77faaf61 Fix UTF8 conversion in Java. (#70)
Java doesn't use standard UTF8, so surrogate pairs were being converted
incorrectly and incompatibly with C++.

Fixes #69 (artf3973).
2016-06-10 22:24:42 -04: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
d9efcbc7a9 C++ NetworkTable: Add array and raw getters and setters.
For consistency with Java NetworkTable; also makes these data types easier
to use (although they are less efficient as they require a memory allocation
and data copy).
2016-01-04 09:37:29 -08: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
Peter Johnson
bc6da8effa Add noexcept shim for MSVC. 2015-12-09 01:22:21 -08:00
Peter Johnson
5d26b13553 NetworkTable: Add override declarations for all functions.
clang generates errors for using override on only some functions.
2015-12-09 01:18:14 -08:00
Peter Johnson
0d7106450b Make TableKeyNotDefinedException::what() const noexcept. 2015-12-09 01:18:00 -08:00
Peter Johnson
76ee093e92 Add exception-generating C++ functions, but mark as deprecated.
These are good to have for backwards compatibility, but discouraged for new
development (default-taking functions should be used instead).  The reason
is that the exceptions must be explicitly handled and may initially work but
then fail at an inopportune moment.

Mark the similar Java functions as deprecated as well for the same reason.

Update all the docs for consistency.

Mark overridden functions as such in both C++ and Java.

Make IsPersistent and GetFlags const in C++.
2015-12-06 22:39:38 -08:00
Thad House
2e050b0540 Makes SetTeam use Mdns 2015-11-19 23:02:39 -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
4c83259acb C++ NetworkTable: Provide AddSubTableListener().
This matches the implementation provided by Java NetworkTable, with the
exception that the subtable is not provided (because it's not a value).
The listener still can get access to the subtable by calling
source->getSubTable(key).
2015-09-19 12:25:21 -07:00
Peter Johnson
90ce262bb3 C++ NetworkTable: Provide SetPort() method.
This was previously only available in Java.
2015-09-19 11:44:14 -07:00
Peter Johnson
23448c8277 NetworkTable interface: Provide method to set persistent filename. 2015-09-19 11:40:31 -07:00
Peter Johnson
c5d456f3a6 Add ITable/NetworkTable GetKeys and GetSubTables accessors. 2015-09-16 00:51:05 -07:00
Peter Johnson
6cbc219427 Add ITable/NetworkTable accessors for new features. 2015-09-15 23:43:42 -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
302cc064c6 ConnectionListener: Use bool instead of int for connected parameter. 2015-08-27 23:48:40 -07:00
Peter Johnson
6e4d7ca933 NetworkTable: Protect listeners with mutex. 2015-08-27 23:39:52 -07:00
Peter Johnson
86445b6670 Import llvm::SmallPtrSet. 2015-08-27 22:16:56 -07:00
Peter Johnson
a8836b7665 Value: Use variant of enable_if to fix MakeString/MakeRaw in GCC.
Tested on GCC 4.8, GCC 4.9, and clang 3.6.
2015-08-22 14:01:33 -07:00
Peter Johnson
c41341c7e3 Clean up trailing whitespace. 2015-08-19 20:41:59 -07:00
Peter Johnson
8d7cdeabbf Implement remote procedure calls. 2015-08-13 21:32:16 -07:00
Peter Johnson
0cbcfbc3f0 Import llvm::DenseMap.
Bring in (most of) MathExtras.h as well, as it's shared by SmallVector and
DenseMap.
2015-08-12 17:08:45 -07:00
Peter Johnson
00feb67064 Only use enable_if template on Windows.
This isn't required and doesn't compile on older GCC versions.
2015-08-04 19:59:45 -07:00
Peter Johnson
4146db6fc8 Visual Studio 2013 compilation fixes.
- Missing header file callouts in some cases (library deltas)
- Lack of support for auto parameters in lambdas
- Defining of ERROR by windows.h
- Dispatcher::Connection needs a move constructor (default not generated)
- Need explicit enable_if on std::string move template in Value to avoid trying to move const char[] (string literal)
- Compile flags
2015-08-03 01:27:02 -07:00
Peter Johnson
06e8d835dd Provide ostream output for StringRef. 2015-07-31 23:20:59 -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
ae070aca70 Value: Add type check functions. 2015-07-24 22:11:57 -07:00
Peter Johnson
3f24b86875 ITable: Add Persist function to make a key persistent. 2015-07-23 21:53:33 -07:00
Peter Johnson
196fcf791b ITable: Const'ify getter functions. 2015-07-23 21:46:30 -07:00
Peter Johnson
6bccf528d7 ITableListener.h: Forward declare ITable. 2015-07-23 21:41:30 -07:00
Peter Johnson
1fc03803cd ITableListener::ValueChanged: Don't make key const. 2015-07-23 21:40:24 -07:00
Peter Johnson
8fa0e6c914 Add shims for old NetworkTable interface.
This provides classes for virtual subtables using path delimiters within
the global NetworkTable namespace.
2015-07-23 01:23:09 -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