1 /*!
2  * \file ClientAPIForMathPluginManagement.h
3  *
4  * \author Roger James
5  * \date 13th November 2013
6  *
7  */
8 
9 #pragma once
10 
11 #include "basedevice.h"
12 #include "baseclient.h"
13 
14 #include <string>
15 #include <vector>
16 #include <pthread.h>
17 
18 namespace INDI
19 {
20 namespace AlignmentSubsystem
21 {
22 /*!
23  * \class ClientAPIForMathPluginManagement
24  * \brief This class provides the client API for driver side math plugin management. It communicates
25  * with the driver via the INDI properties interface.
26  */
27 class ClientAPIForMathPluginManagement
28 {
29   public:
30     /// \brief Virtual destructor
~ClientAPIForMathPluginManagement()31     virtual ~ClientAPIForMathPluginManagement() {}
32 
33     typedef std::vector<std::string> MathPluginsList;
34 
35     // Public methods
36 
37     /*!
38          * \brief Return a list of the names of the available math plugins.
39          * \param[out] AvailableMathPlugins Reference to a list of the names of the available math plugins.
40          * \return False on failure
41          */
42     bool EnumerateMathPlugins(MathPluginsList &AvailableMathPlugins);
43 
44     /// \brief Intialise the API
45     /// \param[in] BaseClient Pointer to the INDI:BaseClient class
46     void Initialise(INDI::BaseClient *BaseClient);
47 
48     /** \brief Process new device message from driver. This routine should be called from within
49          the newDevice handler in the client. This routine is not normally called directly but is called by
50          the ProcessNewDevice function in INDI::Alignment::AlignmentSubsystemForClients which filters out calls
51          from unwanted devices. TODO maybe hide this function.
52             \param[in] DevicePointer A pointer to the INDI::BaseDevice object.
53         */
54     void ProcessNewDevice(INDI::BaseDevice *DevicePointer);
55 
56     /** \brief Process new property message from driver. This routine should be called from within
57          the newProperty handler in the client. This routine is not normally called directly but is called by
58          the ProcessNewProperty function in INDI::Alignment::AlignmentSubsystemForClients which filters out calls
59          from unwanted devices. TODO maybe hide this function.
60             \param[in] PropertyPointer A pointer to the INDI::Property object.
61         */
62     void ProcessNewProperty(INDI::Property *PropertyPointer);
63 
64     /** \brief Process new switch message from driver. This routine should be called from within
65          the newSwitch handler in the client. This routine is not normally called directly but is called by
66          the ProcessNewSwitch function in INDI::Alignment::AlignmentSubsystemForClients which filters out calls
67          from unwanted devices. TODO maybe hide this function.
68             \param[in] SwitchVectorProperty A pointer to the INDI::ISwitchVectorProperty.
69         */
70     void ProcessNewSwitch(ISwitchVectorProperty *SwitchVectorProperty);
71 
72     /*!
73          * \brief Selects, loads and initialises the named math plugin.
74          * \param[in] MathPluginName The name of the required math plugin.
75          * \return False on failure.
76          */
77     bool SelectMathPlugin(const std::string &MathPluginName);
78 
79     /*!
80          * \brief Re-initialises the current math plugin.
81          * \return False on failure.
82          */
83     bool ReInitialiseMathPlugin();
84 
85   private:
86     // Private methods
87 
88     bool SetDriverBusy();
89     bool SignalDriverCompletion();
90     bool WaitForDriverCompletion();
91 
92     // Private properties
93 
94     INDI::BaseClient *BaseClient;
95     pthread_cond_t DriverActionCompleteCondition;
96     pthread_mutex_t DriverActionCompleteMutex;
97     bool DriverActionComplete;
98     INDI::BaseDevice *Device;
99     INDI::Property *MathPlugins;
100     INDI::Property *PluginInitialise;
101 };
102 
103 } // namespace AlignmentSubsystem
104 } // namespace INDI
105