Commit Graph

228 Commits

Author SHA1 Message Date
Peter Johnson
7528b6b8bf Fix NetworkTable::ContainsKey.
Previously this would always return false due to how explicit bool is
evaluated in a return context.

Also add a test for this function.

Reported by: jcreigh
2015-12-19 08:47:52 -08:00
Peter Johnson
e25d9fc96a Use correct condition variable in DispatchThreadMain(). 2015-12-11 21:13:41 -08:00
Peter Johnson
bc6da8effa Add noexcept shim for MSVC. 2015-12-09 01:22:21 -08:00
Peter Johnson
0d7106450b Make TableKeyNotDefinedException::what() const noexcept. 2015-12-09 01:18:00 -08:00
Peter Johnson
60647a2f8c Turn off Nagle algorithm to decrease latency.
This is safe because of the way writes are performed: for each transmission,
all outgoing messages are concatenated in memory and only a single write()
syscall is made.
2015-12-09 00:58:06 -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
Fredric Silberberg
9e6635ec13 Fixed log compilation on Mac
Change-Id: Ic231c56bdfd74c23d6086fb8ec485a0cec17d248
2015-12-06 16:14:26 -05:00
Peter Johnson
c2642f39ed Avoid null pointer deref on disconnect. 2015-11-30 20:02:40 -08:00
Peter Johnson
7182b9a6b5 Upgrade TCPConnector messages from DEBUG to ERROR / INFO.
This makes the client a lot more "chatty" but also a lot more informative
as to what's actually going on connection-wise.
2015-11-30 20:01:54 -08:00
Peter Johnson
ac9e42af36 TCPConnector: Select only IPv4 addresses. 2015-11-30 20:01:15 -08:00
Peter Johnson
790862db4b Provide default stderr logger for INFO/WARN/ERR levels. 2015-11-30 19:43:47 -08:00
Austin Schuh
bb9988365f Fixed const correctness in casts and unused parameters.
GCC was throwing warnings about const correctness issues and unused
parameters.  This patch gets rid of those warnings by using the
correct casts.
2015-11-28 13:12:30 -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
3469f6733c GetRpcResult: Check m_terminating after wait() returns. 2015-11-10 23:21:50 -08:00
Thad House
aefeee39aa Fixes SetEntryRaw to actually set raw. 2015-11-10 23:03:00 -08:00
Peter Johnson
27101979fa Add extern "C" to ntcore_c implementation.
This will catch any future parameter type mismatches to the header file.
2015-11-10 00:39:46 -08:00
Thad House
16e68c3480 Fixes parameter type differences for c interface. 2015-11-10 00:25:37 -08:00
Thad House
8fc2eee2b4 Makes Value::MakeStringArray properly set size
The Value::MakeStringArray methods were not setting the size of the
arr_string. This was causing the  NT_Value struct called from the C
entry listener callback to not have the array size, which would then
cause the GetValueStringArray method to fail the malloc.
2015-11-09 22:05:38 -08:00
Peter Johnson
424efca1bf NetworkConnection: bump debug levels a bit.
DEBUG4 is getting pretty verbose.
2015-11-02 22:12:20 -08:00
Peter Johnson
4d7ea37d56 Fix update message type data.
The type was being read and written as the raw enum value rather than as
the actual type definition.
2015-11-02 22:08:35 -08:00
Peter Johnson
32a1beb772 WireDecoder: Add commented-out read stream dumping. 2015-11-02 22:06:55 -08:00
Peter Johnson
9f5fe63aaa Reuse dead connection slots.
This fixes a memory leak on multiple disconnect/reconnect of the same client.
2015-11-01 22:48:11 -08:00
Peter Johnson
03ee425e5f Add additional debug messages. 2015-11-01 22:48:11 -08:00
Peter Johnson
dd0e3e4abb Implement join with timeout (and detach).
Under certain situations (notably JNI shutdown), it's possible to get
deadlock when using thread join().  To avoid this, implement a timeout.
Normally we try to simply join the thread, but if it times out, we
detach the thread instead.
2015-10-09 23:50:01 -07:00
Peter Johnson
d77b3d788e Dispatcher: Remove unused member variable. 2015-10-09 22:52:26 -07:00
Peter Johnson
dff6e89b4b Notify local listeners on preferences load.
Also notify local listeners even when disconnected.
2015-10-08 00:04:38 -07:00
Peter Johnson
734e9a4461 Fix NT_GetEntryInfo implementation signature to match header.
Fixes #25.
2015-09-27 21:08:15 -07: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
51064f5e75 Fix client initial flags setting.
Before the server has assigned the id, the client doesn't generate flags
update messages.  This behavior is correct, but the client must then send
the appropriate flags update message when the id is finally assigned by
the server.
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
Peter Johnson
6d8e796932 Disable logging on static instance destruction.
This avoids possible deadlocks on exit when a logger callback exists.
2015-09-12 21:44:51 -07:00
Peter Johnson
f7e603c7db Add DEBUG4 message for messages received during client handshake. 2015-09-11 19:19:15 -07:00
Peter Johnson
30ad381b6c Notify on entries created/modified during handshake. 2015-09-11 19:18:50 -07:00
Peter Johnson
953a2ce807 Implement keep-alives. 2015-09-08 23:17:11 -07:00
Peter Johnson
e1efb7364e Don't allow update intervals slower than 1 second. 2015-09-06 11:41:35 -07:00
Peter Johnson
123ba9c670 Use SmallVector instead of malloc buffers for WireEncoder. 2015-09-06 11:00:44 -07:00
Peter Johnson
07942bf422 Notifier: fix Stop() so it actually notifies the thread. 2015-09-05 10:55:24 -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
f3bfee149c Change NT_GetEntry*FromValue to return copies.
Previously they returned references to the strings/arrays within the passed
NT_Value, which is different from the GetEntry* functions and risks
double-frees.
2015-08-29 08:39:40 -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
Peter Johnson
7565207242 StartClient(): Make a local copy of server_name.
Previously we just held onto the const char* provided by the user.
This does not work in cases such as Java which provide a temporary
string.
2015-08-29 00:07:10 -07:00