001// Copyright (c) FIRST and other WPILib contributors. 002// Open Source Software; you can modify and/or share it under the terms of 003// the WPILib BSD license file in the root directory of this project. 004 005// THIS FILE WAS AUTO-GENERATED BY ./ntcore/generate_topics.py. DO NOT MODIFY 006 007package edu.wpi.first.networktables; 008 009import edu.wpi.first.util.RuntimeLoader; 010import edu.wpi.first.util.datalog.DataLog; 011import java.io.IOException; 012import java.nio.ByteBuffer; 013import java.util.EnumSet; 014import java.util.OptionalLong; 015import java.util.concurrent.atomic.AtomicBoolean; 016 017public final class NetworkTablesJNI { 018 static boolean libraryLoaded = false; 019 static RuntimeLoader<NetworkTablesJNI> loader = null; 020 021 public static class Helper { 022 private static AtomicBoolean extractOnStaticLoad = new AtomicBoolean(true); 023 024 public static boolean getExtractOnStaticLoad() { 025 return extractOnStaticLoad.get(); 026 } 027 028 public static void setExtractOnStaticLoad(boolean load) { 029 extractOnStaticLoad.set(load); 030 } 031 } 032 033 static { 034 if (Helper.getExtractOnStaticLoad()) { 035 try { 036 loader = 037 new RuntimeLoader<>( 038 "ntcorejni", RuntimeLoader.getDefaultExtractionRoot(), NetworkTablesJNI.class); 039 loader.loadLibrary(); 040 } catch (IOException ex) { 041 ex.printStackTrace(); 042 System.exit(1); 043 } 044 libraryLoaded = true; 045 } 046 } 047 048 /** 049 * Force load the library. 050 * 051 * @throws IOException if the library fails to load 052 */ 053 public static synchronized void forceLoad() throws IOException { 054 if (libraryLoaded) { 055 return; 056 } 057 loader = 058 new RuntimeLoader<>( 059 "ntcorejni", RuntimeLoader.getDefaultExtractionRoot(), NetworkTablesJNI.class); 060 loader.loadLibrary(); 061 libraryLoaded = true; 062 } 063 064 private static PubSubOptions buildOptions(PubSubOption... options) { 065 if (options.length == 0) { 066 return null; // optimize common case (JNI checks for null) 067 } 068 return new PubSubOptions(options); 069 } 070 071 public static native int getDefaultInstance(); 072 073 public static native int createInstance(); 074 075 public static native void destroyInstance(int inst); 076 077 public static native int getInstanceFromHandle(int handle); 078 079 private static native int getEntryImpl( 080 int topic, int type, String typeStr, PubSubOptions options); 081 082 public static native int getEntry(int inst, String key); 083 084 public static int getEntry( 085 int topic, int type, String typeStr, PubSubOptions options) { 086 return getEntryImpl(topic, type, typeStr, options); 087 } 088 089 public static int getEntry( 090 int topic, int type, String typeStr, PubSubOption... options) { 091 return getEntryImpl(topic, type, typeStr, buildOptions(options)); 092 } 093 094 public static native String getEntryName(int entry); 095 096 public static native long getEntryLastChange(int entry); 097 098 public static native int getType(int entry); 099 100 /* Topic functions */ 101 102 public static native int[] getTopics(int inst, String prefix, int types); 103 104 public static native int[] getTopicsStr(int inst, String prefix, String[] types); 105 106 public static native TopicInfo[] getTopicInfos( 107 NetworkTableInstance instObject, int inst, String prefix, int types); 108 109 public static native TopicInfo[] getTopicInfosStr( 110 NetworkTableInstance instObject, int inst, String prefix, String[] types); 111 112 public static native int getTopic(int inst, String name); 113 114 public static native String getTopicName(int topic); 115 116 public static native int getTopicType(int topic); 117 118 public static native void setTopicPersistent(int topic, boolean value); 119 120 public static native boolean getTopicPersistent(int topic); 121 122 public static native void setTopicRetained(int topic, boolean value); 123 124 public static native boolean getTopicRetained(int topic); 125 126 public static native void setTopicCached(int topic, boolean value); 127 128 public static native boolean getTopicCached(int topic); 129 130 public static native String getTopicTypeString(int topic); 131 132 public static native boolean getTopicExists(int topic); 133 134 public static native String getTopicProperty(int topic, String name); 135 136 public static native void setTopicProperty(int topic, String name, String value); 137 138 public static native void deleteTopicProperty(int topic, String name); 139 140 public static native String getTopicProperties(int topic); 141 142 public static native void setTopicProperties(int topic, String properties); 143 144 public static native int subscribe( 145 int topic, int type, String typeStr, PubSubOptions options); 146 147 public static int subscribe( 148 int topic, int type, String typeStr, PubSubOption... options) { 149 return subscribe(topic, type, typeStr, buildOptions(options)); 150 } 151 152 public static native void unsubscribe(int sub); 153 154 public static native int publish( 155 int topic, int type, String typeStr, PubSubOptions options); 156 157 public static int publish( 158 int topic, int type, String typeStr, PubSubOption... options) { 159 return publish(topic, type, typeStr, buildOptions(options)); 160 } 161 162 public static native int publishEx( 163 int topic, int type, String typeStr, String properties, PubSubOptions options); 164 165 public static int publishEx( 166 int topic, int type, String typeStr, String properties, PubSubOption... options) { 167 return publishEx(topic, type, typeStr, properties, buildOptions(options)); 168 } 169 170 public static native void unpublish(int pubentry); 171 172 public static native void releaseEntry(int entry); 173 174 public static native void release(int pubsubentry); 175 176 public static native int getTopicFromHandle(int pubsubentry); 177 178 public static native int subscribeMultiple(int inst, String[] prefixes, PubSubOptions options); 179 180 public static int subscribeMultiple(int inst, String[] prefixes, PubSubOption... options) { 181 return subscribeMultiple(inst, prefixes, buildOptions(options)); 182 } 183 184 public static native void unsubscribeMultiple(int sub); 185 186 public static native TimestampedBoolean getAtomicBoolean( 187 int subentry, boolean defaultValue); 188 189 public static native TimestampedBoolean[] readQueueBoolean(int subentry); 190 191 public static native boolean[] readQueueValuesBoolean(int subentry); 192 193 public static native boolean setBoolean(int entry, long time, boolean value); 194 195 public static native boolean getBoolean(int entry, boolean defaultValue); 196 197 public static native boolean setDefaultBoolean(int entry, long time, boolean defaultValue); 198 199 200 public static native TimestampedInteger getAtomicInteger( 201 int subentry, long defaultValue); 202 203 public static native TimestampedInteger[] readQueueInteger(int subentry); 204 205 public static native long[] readQueueValuesInteger(int subentry); 206 207 public static native boolean setInteger(int entry, long time, long value); 208 209 public static native long getInteger(int entry, long defaultValue); 210 211 public static native boolean setDefaultInteger(int entry, long time, long defaultValue); 212 213 214 public static native TimestampedFloat getAtomicFloat( 215 int subentry, float defaultValue); 216 217 public static native TimestampedFloat[] readQueueFloat(int subentry); 218 219 public static native float[] readQueueValuesFloat(int subentry); 220 221 public static native boolean setFloat(int entry, long time, float value); 222 223 public static native float getFloat(int entry, float defaultValue); 224 225 public static native boolean setDefaultFloat(int entry, long time, float defaultValue); 226 227 228 public static native TimestampedDouble getAtomicDouble( 229 int subentry, double defaultValue); 230 231 public static native TimestampedDouble[] readQueueDouble(int subentry); 232 233 public static native double[] readQueueValuesDouble(int subentry); 234 235 public static native boolean setDouble(int entry, long time, double value); 236 237 public static native double getDouble(int entry, double defaultValue); 238 239 public static native boolean setDefaultDouble(int entry, long time, double defaultValue); 240 241 242 public static native TimestampedString getAtomicString( 243 int subentry, String defaultValue); 244 245 public static native TimestampedString[] readQueueString(int subentry); 246 247 public static native String[] readQueueValuesString(int subentry); 248 249 public static native boolean setString(int entry, long time, String value); 250 251 public static native String getString(int entry, String defaultValue); 252 253 public static native boolean setDefaultString(int entry, long time, String defaultValue); 254 255 256 public static native TimestampedRaw getAtomicRaw( 257 int subentry, byte[] defaultValue); 258 259 public static native TimestampedRaw[] readQueueRaw(int subentry); 260 261 public static native byte[][] readQueueValuesRaw(int subentry); 262 263 public static boolean setRaw(int entry, long time, byte[] value) { 264 return setRaw(entry, time, value, 0, value.length); 265 } 266 267 public static native boolean setRaw(int entry, long time, byte[] value, int start, int len); 268 269 public static boolean setRaw(int entry, long time, ByteBuffer value) { 270 int pos = value.position(); 271 return setRaw(entry, time, value, pos, value.capacity() - pos); 272 } 273 274 public static boolean setRaw(int entry, long time, ByteBuffer value, int start, int len) { 275 if (value.isDirect()) { 276 if (start < 0) { 277 throw new IndexOutOfBoundsException("start must be >= 0"); 278 } 279 if (len < 0) { 280 throw new IndexOutOfBoundsException("len must be >= 0"); 281 } 282 if ((start + len) > value.capacity()) { 283 throw new IndexOutOfBoundsException("start + len must be smaller than buffer capacity"); 284 } 285 return setRawBuffer(entry, time, value, start, len); 286 } else if (value.hasArray()) { 287 return setRaw(entry, time, value.array(), value.arrayOffset() + start, len); 288 } else { 289 throw new UnsupportedOperationException("ByteBuffer must be direct or have a backing array"); 290 } 291 } 292 293 private static native boolean setRawBuffer(int entry, long time, ByteBuffer value, int start, int len); 294 295 public static native byte[] getRaw(int entry, byte[] defaultValue); 296 297 public static boolean setDefaultRaw(int entry, long time, byte[] defaultValue) { 298 return setDefaultRaw(entry, time, defaultValue, 0, defaultValue.length); 299 } 300 301 public static native boolean setDefaultRaw(int entry, long time, byte[] defaultValue, int start, int len); 302 303 public static boolean setDefaultRaw(int entry, long time, ByteBuffer defaultValue) { 304 int pos = defaultValue.position(); 305 return setDefaultRaw(entry, time, defaultValue, pos, defaultValue.limit() - pos); 306 } 307 308 public static boolean setDefaultRaw(int entry, long time, ByteBuffer defaultValue, int start, int len) { 309 if (defaultValue.isDirect()) { 310 if (start < 0) { 311 throw new IndexOutOfBoundsException("start must be >= 0"); 312 } 313 if (len < 0) { 314 throw new IndexOutOfBoundsException("len must be >= 0"); 315 } 316 if ((start + len) > defaultValue.capacity()) { 317 throw new IndexOutOfBoundsException("start + len must be smaller than buffer capacity"); 318 } 319 return setDefaultRawBuffer(entry, time, defaultValue, start, len); 320 } else if (defaultValue.hasArray()) { 321 return setDefaultRaw(entry, time, defaultValue.array(), defaultValue.arrayOffset() + start, len); 322 } else { 323 throw new UnsupportedOperationException("ByteBuffer must be direct or have a backing array"); 324 } 325 } 326 327 private static native boolean setDefaultRawBuffer(int entry, long time, ByteBuffer defaultValue, int start, int len); 328 329 330 public static native TimestampedBooleanArray getAtomicBooleanArray( 331 int subentry, boolean[] defaultValue); 332 333 public static native TimestampedBooleanArray[] readQueueBooleanArray(int subentry); 334 335 public static native boolean[][] readQueueValuesBooleanArray(int subentry); 336 337 public static native boolean setBooleanArray(int entry, long time, boolean[] value); 338 339 public static native boolean[] getBooleanArray(int entry, boolean[] defaultValue); 340 341 public static native boolean setDefaultBooleanArray(int entry, long time, boolean[] defaultValue); 342 343 344 public static native TimestampedIntegerArray getAtomicIntegerArray( 345 int subentry, long[] defaultValue); 346 347 public static native TimestampedIntegerArray[] readQueueIntegerArray(int subentry); 348 349 public static native long[][] readQueueValuesIntegerArray(int subentry); 350 351 public static native boolean setIntegerArray(int entry, long time, long[] value); 352 353 public static native long[] getIntegerArray(int entry, long[] defaultValue); 354 355 public static native boolean setDefaultIntegerArray(int entry, long time, long[] defaultValue); 356 357 358 public static native TimestampedFloatArray getAtomicFloatArray( 359 int subentry, float[] defaultValue); 360 361 public static native TimestampedFloatArray[] readQueueFloatArray(int subentry); 362 363 public static native float[][] readQueueValuesFloatArray(int subentry); 364 365 public static native boolean setFloatArray(int entry, long time, float[] value); 366 367 public static native float[] getFloatArray(int entry, float[] defaultValue); 368 369 public static native boolean setDefaultFloatArray(int entry, long time, float[] defaultValue); 370 371 372 public static native TimestampedDoubleArray getAtomicDoubleArray( 373 int subentry, double[] defaultValue); 374 375 public static native TimestampedDoubleArray[] readQueueDoubleArray(int subentry); 376 377 public static native double[][] readQueueValuesDoubleArray(int subentry); 378 379 public static native boolean setDoubleArray(int entry, long time, double[] value); 380 381 public static native double[] getDoubleArray(int entry, double[] defaultValue); 382 383 public static native boolean setDefaultDoubleArray(int entry, long time, double[] defaultValue); 384 385 386 public static native TimestampedStringArray getAtomicStringArray( 387 int subentry, String[] defaultValue); 388 389 public static native TimestampedStringArray[] readQueueStringArray(int subentry); 390 391 public static native String[][] readQueueValuesStringArray(int subentry); 392 393 public static native boolean setStringArray(int entry, long time, String[] value); 394 395 public static native String[] getStringArray(int entry, String[] defaultValue); 396 397 public static native boolean setDefaultStringArray(int entry, long time, String[] defaultValue); 398 399 400 public static native NetworkTableValue[] readQueueValue(int subentry); 401 402 public static native NetworkTableValue getValue(int entry); 403 404 public static native void setEntryFlags(int entry, int flags); 405 406 public static native int getEntryFlags(int entry); 407 408 public static native TopicInfo getTopicInfo(NetworkTableInstance inst, int topic); 409 410 public static native int createListenerPoller(int inst); 411 412 public static native void destroyListenerPoller(int poller); 413 414 private static int kindsToMask(EnumSet<NetworkTableEvent.Kind> kinds) { 415 int mask = 0; 416 for (NetworkTableEvent.Kind kind : kinds) { 417 mask |= kind.getValue(); 418 } 419 return mask; 420 } 421 422 public static int addListener(int poller, String[] prefixes, EnumSet<NetworkTableEvent.Kind> kinds) { 423 return addListener(poller, prefixes, kindsToMask(kinds)); 424 } 425 426 public static int addListener(int poller, int handle, EnumSet<NetworkTableEvent.Kind> kinds) { 427 return addListener(poller, handle, kindsToMask(kinds)); 428 } 429 430 public static native int addListener(int poller, String[] prefixes, int mask); 431 432 public static native int addListener(int poller, int handle, int mask); 433 434 public static native NetworkTableEvent[] readListenerQueue( 435 NetworkTableInstance inst, int poller); 436 437 public static native void removeListener(int listener); 438 439 public static native int getNetworkMode(int inst); 440 441 public static native void startLocal(int inst); 442 443 public static native void stopLocal(int inst); 444 445 public static native void startServer( 446 int inst, String persistFilename, String listenAddress, int port3, int port4); 447 448 public static native void stopServer(int inst); 449 450 public static native void startClient3(int inst, String identity); 451 452 public static native void startClient4(int inst, String identity); 453 454 public static native void stopClient(int inst); 455 456 public static native void setServer(int inst, String serverName, int port); 457 458 public static native void setServer(int inst, String[] serverNames, int[] ports); 459 460 public static native void setServerTeam(int inst, int team, int port); 461 462 public static native void disconnect(int inst); 463 464 public static native void startDSClient(int inst, int port); 465 466 public static native void stopDSClient(int inst); 467 468 public static native void flushLocal(int inst); 469 470 public static native void flush(int inst); 471 472 public static native ConnectionInfo[] getConnections(int inst); 473 474 public static native boolean isConnected(int inst); 475 476 public static native OptionalLong getServerTimeOffset(int inst); 477 478 public static native long now(); 479 480 private static native int startEntryDataLog(int inst, long log, String prefix, String logPrefix); 481 482 public static int startEntryDataLog(int inst, DataLog log, String prefix, String logPrefix) { 483 return startEntryDataLog(inst, log.getImpl(), prefix, logPrefix); 484 } 485 486 public static native void stopEntryDataLog(int logger); 487 488 private static native int startConnectionDataLog(int inst, long log, String name); 489 490 public static int startConnectionDataLog(int inst, DataLog log, String name) { 491 return startConnectionDataLog(inst, log.getImpl(), name); 492 } 493 494 public static native void stopConnectionDataLog(int logger); 495 496 public static native int addLogger(int poller, int minLevel, int maxLevel); 497}