| 
									
										
										
										
											2020-09-20 01:06:34 +02:00
										 |  |  | ///////////////////////////////////////////////////////////////////////////////////
 | 
					
						
							| 
									
										
										
										
											2023-11-19 06:43:20 +01:00
										 |  |  | // Copyright (C) 2012 maintech GmbH, Otto-Hahn-Str. 15, 97204 Hoechberg, Germany //
 | 
					
						
							|  |  |  | // written by Christian Daniel                                                   //
 | 
					
						
							|  |  |  | // Copyright (C) 2015-2020, 2022 Edouard Griffiths, F4EXB <f4exb06@gmail.com>    //
 | 
					
						
							|  |  |  | // Copyright (C) 2021 Jon Beniston, M7RCE <jon@beniston.com>                     //
 | 
					
						
							| 
									
										
										
										
											2020-09-20 01:06:34 +02:00
										 |  |  | //                                                                               //
 | 
					
						
							|  |  |  | // API for features                                                              //
 | 
					
						
							|  |  |  | //                                                                               //
 | 
					
						
							|  |  |  | // This program is free software; you can redistribute it and/or modify          //
 | 
					
						
							|  |  |  | // it under the terms of the GNU General Public License as published by          //
 | 
					
						
							|  |  |  | // the Free Software Foundation as version 3 of the License, or                  //
 | 
					
						
							|  |  |  | // (at your option) any later version.                                           //
 | 
					
						
							|  |  |  | //                                                                               //
 | 
					
						
							|  |  |  | // This program is distributed in the hope that it will be useful,               //
 | 
					
						
							|  |  |  | // but WITHOUT ANY WARRANTY; without even the implied warranty of                //
 | 
					
						
							|  |  |  | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the                  //
 | 
					
						
							|  |  |  | // GNU General Public License V3 for more details.                               //
 | 
					
						
							|  |  |  | //                                                                               //
 | 
					
						
							|  |  |  | // You should have received a copy of the GNU General Public License             //
 | 
					
						
							|  |  |  | // along with this program. If not, see <http://www.gnu.org/licenses/>.          //
 | 
					
						
							|  |  |  | ///////////////////////////////////////////////////////////////////////////////////
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | #ifndef SDRBASE_FETURE_FEATUREAPI_H_
 | 
					
						
							|  |  |  | #define SDRBASE_FETURE_FEATUREAPI_H_
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | #include <QObject>
 | 
					
						
							|  |  |  | #include <QString>
 | 
					
						
							|  |  |  | #include <QByteArray>
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | #include "export.h"
 | 
					
						
							|  |  |  | #include "util/messagequeue.h"
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | class WebAPIAdapterInterface; | 
					
						
							| 
									
										
										
										
											2020-10-22 08:38:43 +02:00
										 |  |  | class ChannelAPI; | 
					
						
							| 
									
										
										
										
											2020-12-13 13:04:36 +01:00
										 |  |  | class Message; | 
					
						
							| 
									
										
										
										
											2020-09-20 01:06:34 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-09-21 03:13:36 +02:00
										 |  |  | namespace SWGSDRangel | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |     class SWGFeatureSettings; | 
					
						
							|  |  |  |     class SWGFeatureReport; | 
					
						
							|  |  |  |     class SWGFeatureActions; | 
					
						
							|  |  |  |     class SWGDeviceState; | 
					
						
							| 
									
										
										
										
											2020-10-22 08:38:43 +02:00
										 |  |  |     class SWGChannelSettings; | 
					
						
							| 
									
										
										
										
											2020-09-21 03:13:36 +02:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-03-29 23:03:54 +02:00
										 |  |  | class SDRBASE_API Feature : public QObject { | 
					
						
							| 
									
										
										
										
											2020-09-20 01:06:34 +02:00
										 |  |  |     Q_OBJECT | 
					
						
							|  |  |  | public: | 
					
						
							|  |  |  |     enum FeatureState { | 
					
						
							|  |  |  | 		StNotStarted,  //!< feature is before initialization
 | 
					
						
							|  |  |  | 		StIdle,        //!< feature is idle
 | 
					
						
							|  |  |  | 		StRunning,     //!< feature is running
 | 
					
						
							|  |  |  | 		StError        //!< feature is in error
 | 
					
						
							|  |  |  | 	}; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     Feature(const QString& name, WebAPIAdapterInterface *webAPIAdapterInterface); | 
					
						
							|  |  |  |     virtual ~Feature() {} | 
					
						
							|  |  |  |     virtual void destroy() = 0; | 
					
						
							|  |  |  | 	virtual bool handleMessage(const Message& cmd) = 0; //!< Processing of a message. Returns true if message has actually been processed
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-11-22 19:29:27 +01:00
										 |  |  |     const QString& getURI() const { return m_uri; } | 
					
						
							| 
									
										
										
										
											2020-09-21 03:13:36 +02:00
										 |  |  |     virtual void getIdentifier(QString& id) const = 0; | 
					
						
							| 
									
										
										
										
											2022-03-26 12:25:35 +01:00
										 |  |  |     virtual QString getIdentifier() const = 0; | 
					
						
							| 
									
										
										
										
											2020-09-21 03:13:36 +02:00
										 |  |  |     virtual void getTitle(QString& title) const = 0; | 
					
						
							| 
									
										
										
										
											2020-09-20 01:06:34 +02:00
										 |  |  |     virtual void setName(const QString& name) { m_name = name; } | 
					
						
							|  |  |  |     virtual const QString& getName() const { return m_name; } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     virtual QByteArray serialize() const = 0; | 
					
						
							|  |  |  |     virtual bool deserialize(const QByteArray& data) = 0; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-09-21 03:13:36 +02:00
										 |  |  |     /**
 | 
					
						
							|  |  |  |      * API adapter for the feature run GET requests | 
					
						
							|  |  |  |      */ | 
					
						
							|  |  |  |     virtual int webapiRunGet( | 
					
						
							|  |  |  |             SWGSDRangel::SWGDeviceState& response, | 
					
						
							|  |  |  |             QString& errorMessage) const; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     /**
 | 
					
						
							|  |  |  |      * API adapter for the feature run POST and DELETE requests | 
					
						
							|  |  |  |      */ | 
					
						
							|  |  |  |     virtual int webapiRun(bool run, | 
					
						
							|  |  |  |             SWGSDRangel::SWGDeviceState& response, | 
					
						
							|  |  |  |             QString& errorMessage) | 
					
						
							|  |  |  |     { | 
					
						
							|  |  |  |         (void) run; | 
					
						
							|  |  |  |         (void) response; | 
					
						
							|  |  |  |         errorMessage = "Not implemented"; | 
					
						
							|  |  |  |         return 501; | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     /**
 | 
					
						
							|  |  |  |      * API adapter for the feature settings GET requests | 
					
						
							|  |  |  |      */ | 
					
						
							|  |  |  |     virtual int webapiSettingsGet( | 
					
						
							|  |  |  |             SWGSDRangel::SWGFeatureSettings& response, | 
					
						
							|  |  |  |             QString& errorMessage) | 
					
						
							|  |  |  |     { | 
					
						
							|  |  |  |         (void) response; | 
					
						
							|  |  |  |         errorMessage = "Not implemented"; return 501; | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     /**
 | 
					
						
							|  |  |  |      * API adapter for the feature settings PUT and PATCH requests | 
					
						
							|  |  |  |      */ | 
					
						
							|  |  |  |     virtual int webapiSettingsPutPatch( | 
					
						
							|  |  |  |             bool force, | 
					
						
							|  |  |  |             const QStringList& featureSettingsKeys, | 
					
						
							|  |  |  |             SWGSDRangel::SWGFeatureSettings& response, | 
					
						
							|  |  |  |             QString& errorMessage) | 
					
						
							|  |  |  |     { | 
					
						
							|  |  |  |         (void) force; | 
					
						
							|  |  |  |         (void) featureSettingsKeys; | 
					
						
							|  |  |  |         (void) response; | 
					
						
							|  |  |  |         errorMessage = "Not implemented"; return 501; | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     /**
 | 
					
						
							|  |  |  |      * API adapter for the feature report GET requests | 
					
						
							|  |  |  |      */ | 
					
						
							|  |  |  |     virtual int webapiReportGet( | 
					
						
							|  |  |  |             SWGSDRangel::SWGFeatureReport& response, | 
					
						
							|  |  |  |             QString& errorMessage) | 
					
						
							|  |  |  |     { | 
					
						
							|  |  |  |         (void) response; | 
					
						
							|  |  |  |         errorMessage = "Not implemented"; return 501; | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     /**
 | 
					
						
							|  |  |  |      * API adapter for the feature actions POST requests | 
					
						
							|  |  |  |      */ | 
					
						
							|  |  |  |     virtual int webapiActionsPost( | 
					
						
							|  |  |  |             const QStringList& featureActionsKeys, | 
					
						
							|  |  |  |             SWGSDRangel::SWGFeatureActions& query, | 
					
						
							|  |  |  |             QString& errorMessage) | 
					
						
							|  |  |  |     { | 
					
						
							|  |  |  |         (void) query; | 
					
						
							|  |  |  |         (void) featureActionsKeys; | 
					
						
							|  |  |  |         errorMessage = "Not implemented"; return 501; | 
					
						
							|  |  |  |     } | 
					
						
							| 
									
										
										
										
											2020-09-20 01:06:34 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-10-16 08:35:06 +02:00
										 |  |  |     int getIndexInFeatureSet() const { return m_indexInFeatureSet; } | 
					
						
							| 
									
										
										
										
											2022-03-23 05:53:12 +01:00
										 |  |  | 
 | 
					
						
							|  |  |  |     void setIndexInFeatureSet(int indexInFeatureSet) | 
					
						
							|  |  |  |     { | 
					
						
							|  |  |  |         m_indexInFeatureSet = indexInFeatureSet; | 
					
						
							|  |  |  |         emit indexInFeatureSetChanged(m_indexInFeatureSet); | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-09-20 01:06:34 +02:00
										 |  |  |     uint64_t getUID() const { return m_uid; } | 
					
						
							|  |  |  |     FeatureState getState() const { return m_state; } | 
					
						
							|  |  |  |     const QString& getErrorMessage() const { return m_errorMessage; } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	MessageQueue *getInputMessageQueue() { return &m_inputMessageQueue; } //!< Get the queue for asynchronous inbound communication
 | 
					
						
							|  |  |  |     void setMessageQueueToGUI(MessageQueue *queue) { m_guiMessageQueue = queue; } | 
					
						
							|  |  |  |     MessageQueue *getMessageQueueToGUI() { return m_guiMessageQueue; } | 
					
						
							| 
									
										
										
										
											2022-05-13 22:24:48 +02:00
										 |  |  |     void setWorkspaceIndex(int index) { m_workspaceIndex = index; } | 
					
						
							|  |  |  |     int getWorkspaceIndex() const { return m_workspaceIndex; } | 
					
						
							| 
									
										
										
										
											2022-09-21 06:01:45 +02:00
										 |  |  |     WebAPIAdapterInterface *getWebAPIAdapterInterface() { return m_webAPIAdapterInterface; } | 
					
						
							| 
									
										
										
										
											2020-09-20 01:06:34 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  | protected: | 
					
						
							|  |  |  |     MessageQueue m_inputMessageQueue; | 
					
						
							|  |  |  |     MessageQueue *m_guiMessageQueue;  //!< Input message queue to the GUI
 | 
					
						
							|  |  |  |     FeatureState m_state; | 
					
						
							|  |  |  |     QString m_errorMessage; | 
					
						
							|  |  |  |     WebAPIAdapterInterface *m_webAPIAdapterInterface; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-09-21 03:13:36 +02:00
										 |  |  |     void getFeatureStateStr(QString& stateStr) const; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-09-20 01:06:34 +02:00
										 |  |  | protected slots: | 
					
						
							|  |  |  | 	void handleInputMessages(); | 
					
						
							| 
									
										
										
										
											2021-01-13 17:07:38 +00:00
										 |  |  |     void handlePipeMessageQueue(MessageQueue* messageQueue); | 
					
						
							| 
									
										
										
										
											2020-09-20 01:06:34 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  | private: | 
					
						
							| 
									
										
										
										
											2020-11-22 19:29:27 +01:00
										 |  |  |     QString m_name; //!< Unique identifier in a device set used for sorting may change depending on relative position in device set
 | 
					
						
							|  |  |  |     QString m_uri;  //!< Unique non modifiable identifier attached to channel type
 | 
					
						
							| 
									
										
										
										
											2020-09-20 01:06:34 +02:00
										 |  |  |     uint64_t m_uid; | 
					
						
							| 
									
										
										
										
											2020-10-16 08:35:06 +02:00
										 |  |  |     int m_indexInFeatureSet; | 
					
						
							| 
									
										
										
										
											2022-05-13 22:24:48 +02:00
										 |  |  |     int m_workspaceIndex; | 
					
						
							| 
									
										
										
										
											2022-03-23 05:53:12 +01:00
										 |  |  | 
 | 
					
						
							|  |  |  | signals: | 
					
						
							|  |  |  |     void indexInFeatureSetChanged(int index); | 
					
						
							| 
									
										
										
										
											2020-09-20 01:06:34 +02:00
										 |  |  | }; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-09-21 03:13:36 +02:00
										 |  |  | #endif // SDRBASE_FETURE_FEATUREAPI_H_
 |