Instrument Neutral Distributed Interface INDI  2.0.2
parentdevice.cpp
Go to the documentation of this file.
1 #include "parentdevice.h"
2 #include "parentdevice_p.h"
3 
4 #include "basedevice.h"
5 #include "basedevice_p.h"
6 
7 #include <atomic>
8 
9 namespace INDI
10 {
11 
12 static std::shared_ptr<ParentDevicePrivate> create(bool valid)
13 {
14  class InvalidParentDevicePrivate: public ParentDevicePrivate
15  {
16  public:
17  InvalidParentDevicePrivate()
18  {
19  this->valid = false;
20  }
21  };
22 
23  if (valid == false)
24  {
25  static InvalidParentDevicePrivate invalidDevice;
26  return make_shared_weak(&invalidDevice);
27  }
28  else
29  {
30  std::shared_ptr<ParentDevicePrivate> validDevice(new ParentDevicePrivate);
31  return validDevice;
32  }
33 }
34 
35 
36 ParentDevice::ParentDevice(ParentDevice::Type type)
37  : BaseDevice(std::shared_ptr<BaseDevicePrivate>(create(type == Valid)))
38 {
39  D_PTR(ParentDevice);
40  ++d->ref;
41 }
42 
43 ParentDevice::ParentDevice(const std::shared_ptr<ParentDevicePrivate> &dd)
44  : BaseDevice(std::shared_ptr<BaseDevicePrivate>(dd))
45 {
46  D_PTR(ParentDevice);
47  ++d->ref;
48 }
49 
51 {
52  D_PTR(ParentDevice);
53  if (--d->ref == 0)
54  {
55  // prevent circular reference
56  d->pAll.clear();
57  }
58 }
59 
60 }
Class to provide basic INDI device functionality.
Definition: basedevice.h:52
The class is used to create device instances. Class copying is not allowed. When an object is destroy...
Definition: parentdevice.h:18
Namespace to encapsulate INDI client, drivers, and mediator classes.
Definition: json.h:4973
__le16 type
Definition: pwc-ioctl.h:0