WPILibC++  2018.4.1-20180823210227-1173-gde212a9
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Modules Pages
NotifyCallbackHelpers.h
1 /*----------------------------------------------------------------------------*/
2 /* Copyright (c) 2017-2018 FIRST. All Rights Reserved. */
3 /* Open Source Software - may be modified and shared by FRC teams. The code */
4 /* must be accompanied by the FIRST BSD license file in the root directory of */
5 /* the project. */
6 /*----------------------------------------------------------------------------*/
7 
8 #pragma once
9 
10 #ifndef __FRC_ROBORIO__
11 
12 #include <memory>
13 
14 #include "mockdata/NotifyListenerVector.h"
15 
16 template <typename VectorType, typename CallbackType>
17 std::shared_ptr<VectorType> RegisterCallbackImpl(
18  std::shared_ptr<VectorType> currentVector, const char* name,
19  CallbackType callback, void* param, int32_t* newUid) {
20  std::shared_ptr<VectorType> newCallbacks;
21  if (currentVector == nullptr) {
22  newCallbacks = std::make_shared<VectorType>(
23  param, callback, reinterpret_cast<unsigned int*>(newUid));
24  } else {
25  newCallbacks = currentVector->emplace_back(
26  param, callback, reinterpret_cast<unsigned int*>(newUid));
27  }
28  return newCallbacks;
29 }
30 
31 template <typename VectorType, typename CallbackType>
32 std::shared_ptr<VectorType> CancelCallbackImpl(
33  std::shared_ptr<VectorType> currentVector, int32_t uid) {
34  // Create a copy of the callbacks to erase from
35  auto newCallbacks = currentVector->erase(uid);
36  return newCallbacks;
37 }
38 
39 std::shared_ptr<hal::NotifyListenerVector> RegisterCallback(
40  std::shared_ptr<hal::NotifyListenerVector> currentVector, const char* name,
41  HAL_NotifyCallback callback, void* param, int32_t* newUid);
42 
43 std::shared_ptr<hal::NotifyListenerVector> CancelCallback(
44  std::shared_ptr<hal::NotifyListenerVector> currentVector, int32_t uid);
45 
46 void InvokeCallback(std::shared_ptr<hal::NotifyListenerVector> currentVector,
47  const char* name, const HAL_Value* value);
48 
49 std::shared_ptr<hal::BufferListenerVector> RegisterCallback(
50  std::shared_ptr<hal::BufferListenerVector> currentVector, const char* name,
51  HAL_BufferCallback callback, void* param, int32_t* newUid);
52 
53 std::shared_ptr<hal::BufferListenerVector> CancelCallback(
54  std::shared_ptr<hal::BufferListenerVector> currentVector, int32_t uid);
55 
56 void InvokeCallback(std::shared_ptr<hal::BufferListenerVector> currentVector,
57  const char* name, uint8_t* buffer, int32_t count);
58 
59 std::shared_ptr<hal::ConstBufferListenerVector> RegisterCallback(
60  std::shared_ptr<hal::ConstBufferListenerVector> currentVector,
61  const char* name, HAL_ConstBufferCallback callback, void* param,
62  int32_t* newUid);
63 
64 std::shared_ptr<hal::ConstBufferListenerVector> CancelCallback(
65  std::shared_ptr<hal::ConstBufferListenerVector> currentVector, int32_t uid);
66 
67 void InvokeCallback(
68  std::shared_ptr<hal::ConstBufferListenerVector> currentVector,
69  const char* name, const uint8_t* buffer, int32_t count);
70 
71 #endif
HAL Entry Value.
Definition: HAL_Value.h:25