1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179
|
/*
* FeatureProviderInterface.h - interface class for feature plugins
*
* Copyright (c) 2017-2021 Tobias Junghans <tobydox@veyon.io>
*
* This file is part of Veyon - https://veyon.io
*
* 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; either
* version 2 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 for more details.
*
* You should have received a copy of the GNU General Public
* License along with this program (see COPYING); if not, write to the
* Free Software Foundation, Inc., 59 Temple Place - Suite 330,
* Boston, MA 02111-1307, USA.
*
*/
#pragma once
#include "ComputerControlInterface.h"
#include "EnumHelper.h"
#include "FeatureMessage.h"
#include "Feature.h"
#include "MessageContext.h"
#include "PluginInterface.h"
class VeyonMasterInterface;
class VeyonServerInterface;
class VeyonWorkerInterface;
// clazy:excludeall=copyable-polymorphic
class VEYON_CORE_EXPORT FeatureProviderInterface
{
Q_GADGET
public:
enum class Operation
{
Initialize,
Start,
Stop
};
Q_ENUM(Operation)
virtual ~FeatureProviderInterface() = default;
/*!
* \brief Returns a list of features implemented by the feature class
*/
virtual const FeatureList& featureList() const = 0;
virtual bool hasFeature( Feature::Uid featureUid ) const
{
for( const auto& feature : featureList() )
{
if( feature.uid() == featureUid )
{
return true;
}
}
return false;
}
template<class T>
static QString argToString( T item )
{
return EnumHelper::toCamelCaseString( item );
}
/*!
* \brief Control feature in a generic way based on passed arguments
* \param featureUid the UID of the feature to control
* \param operation the operation to perform for the feature
* \param arguments the arguments specifying what and how to control
* \param computerControlInterfaces a list of ComputerControlInterfaces to operate on
*/
virtual bool controlFeature( Feature::Uid featureUid,
Operation operation, const QVariantMap& arguments,
const ComputerControlInterfaceList& computerControlInterfaces ) = 0;
/*!
* \brief Start a feature on master side for given computer control interfaces
* \param master a reference to a master instance implementing the VeyonMasterInterface
* \param feature the feature to start
* \param computerControlInterfaces a list of ComputerControlInterfaces to operate on
*/
virtual bool startFeature( VeyonMasterInterface& master,
const Feature& feature,
const ComputerControlInterfaceList& computerControlInterfaces )
{
Q_UNUSED(master)
return controlFeature( feature.uid(), Operation::Start, {}, computerControlInterfaces );
}
/*!
* \brief Stops a feature on master side for given computer control interfaces
* \param master a reference to a master instance implementing the VeyonMasterInterface
* \param feature the feature to stop
* \param computerControlInterfaces a list of ComputerControlInterfaces to operate on
*/
virtual bool stopFeature( VeyonMasterInterface& master,
const Feature& feature,
const ComputerControlInterfaceList& computerControlInterfaces )
{
Q_UNUSED(master)
return controlFeature( feature.uid(), Operation::Stop, {}, computerControlInterfaces );
}
/*!
* \brief Handles a received feature message received on a certain ComputerControlInterface
* \param message the message which has been received and needs to be handled
* \param computerControlInterfaces the interface over which the message has been received
*/
virtual bool handleFeatureMessage( ComputerControlInterface::Pointer computerControlInterface ,
const FeatureMessage& message )
{
Q_UNUSED(computerControlInterface)
Q_UNUSED(message)
return false;
}
/*!
* \brief Handles a received feature message inside server
* \param server a reference to a server instance implementing the VeyonServerInterface
* \param message the message which has been received and needs to be handled
*/
virtual bool handleFeatureMessage( VeyonServerInterface& server,
const MessageContext& messageContext,
const FeatureMessage& message )
{
Q_UNUSED(server)
Q_UNUSED(messageContext)
Q_UNUSED(message)
return false;
}
/*!
* \brief Handles a received feature message inside worker
* \param worker a reference to a worker instance implementing the VeyonWorkerInterface
* \param message the message which has been received and needs to be handled
*/
virtual bool handleFeatureMessage( VeyonWorkerInterface& worker, const FeatureMessage& message )
{
Q_UNUSED(worker)
Q_UNUSED(message)
return false;
}
protected:
void sendFeatureMessage( const FeatureMessage& message,
const ComputerControlInterfaceList& computerControlInterfaces,
bool wake = true )
{
for( const auto& controlInterface : computerControlInterfaces )
{
controlInterface->sendFeatureMessage( message, wake );
}
}
};
using FeatureProviderInterfaceList = QList<FeatureProviderInterface *>;
#define FeatureProviderInterface_iid "io.veyon.Veyon.FeatureProviderInterface"
Q_DECLARE_INTERFACE(FeatureProviderInterface, FeatureProviderInterface_iid)
|