Instrument Neutral Distributed Interface INDI 2.2.5
Collectable.hpp
Go to the documentation of this file.
1/* INDI Server for protocol version 1.7.
2 * Copyright (C) 2007 Elwood C. Downey <[email protected]>
3 2013 Jasem Mutlaq <[email protected]>
4 2022 Ludovic Pollet
5 This library is free software; you can redistribute it and/or
6 modify it under the terms of the GNU Lesser General Public
7 License as published by the Free Software Foundation; either
8 version 2.1 of the License, or (at your option) any later version.
9
10 This library is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 Lesser General Public License for more details.
14
15 You should have received a copy of the GNU Lesser General Public
16 License along with this library; if not, write to the Free Software
17 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
18*/
19#pragma once
20
21#include "ConcurrentSet.hpp"
22/* An object that can be put in a ConcurrentSet, and provide a heartbeat
23 * to detect removal from ConcurrentSet
24 */
26{
27 template<class P> friend class ConcurrentSet;
28 unsigned long id = 0;
29 const ConcurrentSet<void> * current;
30
31 /* Keep the id */
32 class HeartBeat
33 {
34 friend class Collectable;
35 unsigned long id;
36 const ConcurrentSet<void> * current;
37 HeartBeat(unsigned long id, const ConcurrentSet<void> * current)
38 : id(id), current(current) {}
39 public:
40 bool alive() const
41 {
42 return id != 0 && (*current)[id] != nullptr;
43 }
44 };
45
46 protected:
47 /* heartbeat.alive will return true as long as this item has not changed collection.
48 * Also detect deletion of the Collectable */
49 HeartBeat heartBeat() const
50 {
51 return HeartBeat(id, current);
52 }
53};
HeartBeat heartBeat() const