Instrument Neutral Distributed Interface INDI 2.2.5
DvrInfo.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 "MsgQueue.hpp"
22#include "lilxml.h"
23
24#include <list>
25#include <set>
26#include <string>
27
28class Msg;
29class Property;
30
31/* info for each connected driver */
32class DvrInfo: public MsgQueue
33{
34 /* add dev/name to this device's snooping list.
35 * init with blob mode set to B_NEVER.
36 */
37 void addSDevice(const std::string &dev, const std::string &name);
38
39 public:
40 /* return Property if dp is this driver is snooping dev/name, else NULL.
41 */
42 Property *findSDevice(const std::string &dev, const std::string &name) const;
43
44 protected:
45 /* send message to each interested client
46 */
47 void onMessage(XMLEle *root, std::list<int> &sharedBuffers) override;
48
49 /* override to kill driver that are not reachable anymore */
50 void closeWritePart() override;
51
52
53 /* Construct an instance that will start the same driver */
54 DvrInfo(const DvrInfo &model);
55
56 public:
57 std::string name; /* persistent name */
58
59 std::set<std::string> dev; /* device served by this driver */
60 std::list<Property*>sprops; /* props we snoop */
61 int restarts; /* times process has been restarted */
62 bool restart = true; /* Restart on shutdown */
63
65 virtual ~DvrInfo();
66
67 bool isHandlingDevice(const std::string &dev) const;
68
69 /* start the INDI driver process or connection.
70 * exit if trouble.
71 */
72 virtual void start() = 0;
73
74 /* close down the given driver and restart if set*/
75 void close() override;
76
77 /* Allocate an instance that will start the same driver */
78 virtual DvrInfo * clone() const = 0;
79
80 void log(const std::string &log) const override;
81
82 virtual const std::string remoteServerUid() const = 0;
83
84 /* put Msg mp on queue of each driver responsible for dev, or all drivers
85 * if dev empty.
86 */
87 static void q2RDrivers(const std::string &dev, Msg *mp, XMLEle *root);
88
89 /* put Msg mp on queue of each driver snooping dev/name.
90 * if BLOB always honor current mode.
91 */
92 static void q2SDrivers(DvrInfo *me, int isblob, const std::string &dev, const std::string &name, Msg *mp, XMLEle *root);
93
94 /* Reference to all active drivers */
96
97 // decoding of attached blobs from driver is not supported ATM. Be conservative here
98 bool acceptSharedBuffers() const override
99 {
100 return false;
101 }
102};
bool restart
Definition DvrInfo.hpp:62
std::set< std::string > dev
Definition DvrInfo.hpp:59
static void q2RDrivers(const std::string &dev, Msg *mp, XMLEle *root)
Definition DvrInfo.cpp:181
void closeWritePart() override
Definition DvrInfo.cpp:116
bool isHandlingDevice(const std::string &dev) const
Definition DvrInfo.cpp:315
static void q2SDrivers(DvrInfo *me, int isblob, const std::string &dev, const std::string &name, Msg *mp, XMLEle *root)
Definition DvrInfo.cpp:230
virtual const std::string remoteServerUid() const =0
virtual void start()=0
virtual DvrInfo * clone() const =0
static ConcurrentSet< DvrInfo > drivers
Definition DvrInfo.hpp:95
void onMessage(XMLEle *root, std::list< int > &sharedBuffers) override
Definition DvrInfo.cpp:30
void log(const std::string &log) const override
Definition DvrInfo.cpp:320
Property * findSDevice(const std::string &dev, const std::string &name) const
Definition DvrInfo.cpp:281
virtual ~DvrInfo()
Definition DvrInfo.cpp:306
bool acceptSharedBuffers() const override
Definition DvrInfo.hpp:98
std::string name
Definition DvrInfo.hpp:57
void close() override
Definition DvrInfo.cpp:124
std::list< Property * > sprops
Definition DvrInfo.hpp:60
int restarts
Definition DvrInfo.hpp:61
bool useSharedBuffer
Definition MsgQueue.hpp:66
Definition Msg.hpp:33
char * me
Definition indidriver.c:50
A little DOM-style library to handle parsing and processing an XML file.