Instrument Neutral Distributed Interface INDI 2.2.5
indiproperty_p.h
Go to the documentation of this file.
1/*******************************************************************************
2 Copyright(c) 2011 Jasem Mutlaq. All rights reserved.
3 2022 Pawel Soja <[email protected]>
4
5 This library is free software; you can redistribute it and/or
6 modify it under the terms of the GNU Library General Public
7 License version 2 as published by the Free Software Foundation.
8
9 This library is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 Library General Public License for more details.
13
14 You should have received a copy of the GNU Library General Public License
15 along with this library; see the file COPYING.LIB. If not, write to
16 the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
17 Boston, MA 02110-1301, USA.
18*******************************************************************************/
19
20#pragma once
21
22#include "indimacros.h"
23#include "indibase.h"
24#include "indiproperty.h"
25#include "basedevice.h"
26#include <memory>
27#include <functional>
28#include <typeinfo>
29#include <cstring>
30
31namespace INDI
32{
33
34template <typename T, typename U>
35static inline std::shared_ptr<T> property_private_cast(const std::shared_ptr<U> &r)
36{
37 static struct Invalid : public T
38 {
39 Invalid() : T(16) { this->type = INDI_UNKNOWN; }
40 } invalid;
41 auto result = std::dynamic_pointer_cast<T>(r);
42
43 // Drivers that are also clients load both libindidriver and libindiclient, and each carries its
44 // own copy of this code and its RTTI. Where type_info is compared by address (e.g. macOS), the
45 // dynamic_cast fails for objects created by the other library, so match the exact type by name.
46 if (result == nullptr && r != nullptr)
47 {
48 const U &object = *r;
49 if (std::strcmp(typeid(object).name(), typeid(T).name()) == 0)
50 result = std::static_pointer_cast<T>(r);
51 }
52
53 return result != nullptr ? result : make_shared_weak(&invalid);
54}
55
56class BaseDevice;
58{
59 public:
60 void *property = nullptr;
63 bool registered = false;
64 bool dynamic = false;
65
66 std::function<void()> onUpdateCallback;
67
74
75 virtual ~PropertyPrivate();
76
77#ifdef INDI_PROPERTY_BACKWARD_COMPATIBILE
78 Property self {make_shared_weak(this)};
79#endif
80};
81
82}
Class to provide basic INDI device functionality.
Definition basedevice.h:52
std::function< void()> onUpdateCallback
INDI_PROPERTY_TYPE type
Provides generic container for INDI properties.
INDI_PROPERTY_TYPE
@ INDI_UNKNOWN
Definition indidriver.c:62
Namespace to encapsulate INDI client, drivers, and mediator classes.
uint16_t type
Definition pwc-ioctl.h:0