Instrument Neutral Distributed Interface INDI 2.2.5
device_manager.h
Go to the documentation of this file.
1/*******************************************************************************
2 Copyright(c) 2025 Jasem Mutlaq. All rights reserved.
3
4 INDI Alpaca Device Manager
5
6 This program is free software; you can redistribute it and/or modify it
7 under the terms of the GNU General Public License as published by the Free
8 Software Foundation; either version 2 of the License, or (at your option)
9 any later version.
10
11 This program is distributed in the hope that it will be useful, but WITHOUT
12 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
14 more details.
15
16 You should have received a copy of the GNU Library General Public License
17 along with this library; see the file COPYING.LIB. If not, write to
18 the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
19 Boston, MA 02110-1301, USA.
20
21 The full GNU General Public License is included in this distribution in the
22 file called LICENSE.
23*******************************************************************************/
24
25#pragma once
26
27#include "basedevice.h"
28#include "indiproperty.h"
29#include <memory>
30#include <map>
31#include <string>
32#include <vector>
33#include <mutex>
34#include <httplib.h>
35
36class IDeviceBridge;
37
38// Alpaca device information structure
40{
42 std::string deviceName;
43 std::string deviceType;
44 std::string uniqueID;
45};
46
47class AlpacaClient;
48
50{
51 public:
52 // Singleton instance
53 static DeviceManager* getInstance();
54
56
57 private:
58 // Private constructor for singleton
60
61 public:
62
63 // Set the AlpacaClient
64 void setAlpacaClient(const std::shared_ptr<AlpacaClient> &client);
65
66 // Device management
70
71 // Alpaca API request handling
73
74 // Alpaca Setup API request handling
76
77 // Get device information
78 std::vector<AlpacaDeviceInfo> getDeviceList();
79
80 // Send commands to INDI server
81 void sendNewNumber(const INDI::PropertyNumber &numberProperty);
82 void sendNewSwitch(const INDI::PropertySwitch &switchProperty);
83
84 public:
85 // Helper method to extract transaction IDs from request
86 bool extractTransactionIDs(const httplib::Request &req, httplib::Response &res, int &clientTransactionID,
87 int &serverTransactionID);
88
89 // Helper method to parse form-urlencoded data from request body
90 static void parseFormUrlEncodedBody(const std::string &body, std::map<std::string, std::string> &params);
91
92 private:
93 // Alpaca device type ("telescope", "camera") for an INDI driver interface, empty if unsupported
94 static std::string getAlpacaDeviceType(uint32_t interface);
95
96 // Create a bridge for the device if it has no bridge yet and its interface is known and supported
97 void createBridgeIfReady(INDI::BaseDevice device);
98
99 // Create appropriate bridge for device type
100 std::unique_ptr<IDeviceBridge> createBridge(INDI::BaseDevice device, int deviceNumber);
101
102 // Route request to appropriate device
103 void routeRequest(int deviceNumber, const std::string &deviceType,
104 const std::string &method,
105 const httplib::Request &req, httplib::Response &res,
106 int clientTransactionID, int serverTransactionID);
107
108 // Handle management API requests
109 void handleManagementRequest(const std::string &endpoint,
110 const httplib::Request &req,
112 int clientTransactionID, int serverTransactionID);
113
114 // Alpaca devices are addressed by device type and number, numbers start at 0 for each type
115 using BridgeKey = std::pair<std::string, int>;
116
117 // Maps to track devices and bridges
118 std::map<std::string, INDI::BaseDevice> m_Devices; // INDI device name -> device
119 std::map<BridgeKey, std::unique_ptr<IDeviceBridge>> m_Bridges; // Alpaca device type and number -> bridge
120 std::map<std::string, BridgeKey> m_DeviceNumberMap; // INDI device name -> Alpaca device type and number
121
122 // AlpacaClient reference
123 std::shared_ptr<AlpacaClient> m_Client;
124
125 // Thread safety
126 std::mutex m_Mutex;
127};
hid_device * device
void addDevice(INDI::BaseDevice device)
void handleAlpacaRequest(const httplib::Request &req, httplib::Response &res)
std::vector< AlpacaDeviceInfo > getDeviceList()
void handleSetupRequest(const httplib::Request &req, httplib::Response &res)
static void parseFormUrlEncodedBody(const std::string &body, std::map< std::string, std::string > &params)
void removeDevice(INDI::BaseDevice device)
void sendNewSwitch(const INDI::PropertySwitch &switchProperty)
bool extractTransactionIDs(const httplib::Request &req, httplib::Response &res, int &clientTransactionID, int &serverTransactionID)
static DeviceManager * getInstance()
void setAlpacaClient(const std::shared_ptr< AlpacaClient > &client)
void updateDeviceProperty(INDI::Property property)
void sendNewNumber(const INDI::PropertyNumber &numberProperty)
Class to provide basic INDI device functionality.
Definition basedevice.h:52
Provides generic container for INDI properties.
std::string deviceName
std::string uniqueID
std::string deviceType