source: rrlib_serialization/PublishedRegisters.cpp @ 160:a7fa406b8ffc

17.03
Last change on this file since 160:a7fa406b8ffc was 160:a7fa406b8ffc, checked in by Max Reichardt <mreichardt@…>, 2 years ago

Adds check for valid 'uid' parameter to PublishedRegisters::AddListener

File size: 3.5 KB
Line 
1//
2// You received this file as part of RRLib
3// Robotics Research Library
4//
5// Copyright (C) Finroc GbR (finroc.org)
6//
7// This program is free software; you can redistribute it and/or modify
8// it under the terms of the GNU General Public License as published by
9// the Free Software Foundation; either version 2 of the License, or
10// (at your option) any later version.
11//
12// This program is distributed in the hope that it will be useful,
13// but WITHOUT ANY WARRANTY; without even the implied warranty of
14// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15// GNU General Public License for more details.
16//
17// You should have received a copy of the GNU General Public License along
18// with this program; if not, write to the Free Software Foundation, Inc.,
19// 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
20//
21//----------------------------------------------------------------------
22/*!\file    rrlib/serialization/PublishedRegisters.cpp
23 *
24 * \author  Max Reichardt
25 *
26 * \date    2017-02-05
27 *
28 */
29//----------------------------------------------------------------------
30#include "rrlib/serialization/PublishedRegisters.h"
31
32//----------------------------------------------------------------------
33// External includes (system with <>, local with "")
34//----------------------------------------------------------------------
35#include "rrlib/logging/messages.h"
36
37//----------------------------------------------------------------------
38// Internal includes with ""
39//----------------------------------------------------------------------
40
41//----------------------------------------------------------------------
42// Debugging
43//----------------------------------------------------------------------
44#include <cassert>
45
46//----------------------------------------------------------------------
47// Namespace usage
48//----------------------------------------------------------------------
49
50//----------------------------------------------------------------------
51// Namespace declaration
52//----------------------------------------------------------------------
53namespace rrlib
54{
55namespace serialization
56{
57
58//----------------------------------------------------------------------
59// Forward declarations / typedefs / enums
60//----------------------------------------------------------------------
61
62//----------------------------------------------------------------------
63// Const values
64//----------------------------------------------------------------------
65
66//----------------------------------------------------------------------
67// Implementation
68//----------------------------------------------------------------------
69
70void PublishedRegisters::AddListener(uint uid, const std::function<void()>& callback, const void* address)
71{
72  if (RegisteredRegisters()[uid])
73  {
74    RegisteredRegisters()[uid]->AddListener(callback, address);
75  }
76  else
77  {
78    RRLIB_LOG_PRINT(WARNING, "There is no register with uid ", uid);
79  }
80}
81
82std::array<std::unique_ptr<PublishedRegisters::tPerRegisterInfo>, cMAX_PUBLISHED_REGISTERS>& PublishedRegisters::RegisteredRegisters()
83{
84  static std::array<std::unique_ptr<PublishedRegisters::tPerRegisterInfo>, cMAX_PUBLISHED_REGISTERS> instance;
85  return instance;
86}
87
88PublishedRegisters::tRemoteRegisterBase::~tRemoteRegisterBase()
89{}
90
91PublishedRegisters::tPerRegisterInfo::~tPerRegisterInfo()
92{}
93
94//----------------------------------------------------------------------
95// End of namespace declaration
96//----------------------------------------------------------------------
97}
98}
Note: See TracBrowser for help on using the repository browser.