Add name to HAL Notifier

This commit is contained in:
Peter Johnson
2019-11-09 11:41:58 -08:00
parent 2da64d15f6
commit 3e049e02f0
10 changed files with 74 additions and 2 deletions

View File

@@ -139,6 +139,9 @@ HAL_NotifierHandle HAL_InitializeNotifier(int32_t* status) {
return handle;
}
void HAL_SetNotifierName(HAL_NotifierHandle notifierHandle, const char* name,
int32_t* status) {}
void HAL_StopNotifier(HAL_NotifierHandle notifierHandle, int32_t* status) {
auto notifier = notifierHandles->Get(notifierHandle);
if (!notifier) return;

View File

@@ -10,6 +10,8 @@
#include <cassert>
#include <cstdio>
#include <wpi/jni_util.h>
#include "HALUtil.h"
#include "edu_wpi_first_hal_NotifierJNI.h"
#include "hal/Notifier.h"
@@ -37,6 +39,21 @@ Java_edu_wpi_first_hal_NotifierJNI_initializeNotifier
return (jint)notifierHandle;
}
/*
* Class: edu_wpi_first_hal_NotifierJNI
* Method: setNotifierName
* Signature: (ILjava/lang/String;)V
*/
JNIEXPORT void JNICALL
Java_edu_wpi_first_hal_NotifierJNI_setNotifierName
(JNIEnv* env, jclass cls, jint notifierHandle, jstring name)
{
int32_t status = 0;
HAL_SetNotifierName((HAL_NotifierHandle)notifierHandle,
wpi::java::JStringRef{env, name}.c_str(), &status);
CheckStatus(env, status);
}
/*
* Class: edu_wpi_first_hal_NotifierJNI
* Method: stopNotifier

View File

@@ -1,5 +1,5 @@
/*----------------------------------------------------------------------------*/
/* Copyright (c) 2016-2018 FIRST. All Rights Reserved. */
/* Copyright (c) 2016-2019 FIRST. 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. */
@@ -31,6 +31,15 @@ extern "C" {
*/
HAL_NotifierHandle HAL_InitializeNotifier(int32_t* status);
/**
* Sets the name of a notifier.
*
* @param notifierHandle the notifier handle
* @param name name
*/
void HAL_SetNotifierName(HAL_NotifierHandle notifierHandle, const char* name,
int32_t* status);
/**
* Stops a notifier from running.
*

View File

@@ -8,6 +8,7 @@
#include "hal/Notifier.h"
#include <chrono>
#include <string>
#include <wpi/condition_variable.h>
#include <wpi/mutex.h>
@@ -20,6 +21,7 @@
namespace {
struct Notifier {
std::string name;
uint64_t waitTime;
bool updatedAlarm = false;
bool active = true;
@@ -71,6 +73,14 @@ HAL_NotifierHandle HAL_InitializeNotifier(int32_t* status) {
return handle;
}
void HAL_SetNotifierName(HAL_NotifierHandle notifierHandle, const char* name,
int32_t* status) {
auto notifier = notifierHandles->Get(notifierHandle);
if (!notifier) return;
std::scoped_lock lock(notifier->mutex);
notifier->name = name;
}
void HAL_StopNotifier(HAL_NotifierHandle notifierHandle, int32_t* status) {
auto notifier = notifierHandles->Get(notifierHandle);
if (!notifier) return;