CuteHMI - Modbus (CuteHMI.Modbus.3)
AbstractClient.hpp
1 #ifndef H_EXTENSIONS_CUTEHMI_MODBUS_3_INCLUDE_CUTEHMI_MODBUS_ABSTRACTCLIENT_HPP
2 #define H_EXTENSIONS_CUTEHMI_MODBUS_3_INCLUDE_CUTEHMI_MODBUS_ABSTRACTCLIENT_HPP
3 
4 #include "AbstractDevice.hpp"
5 
6 #include "internal/PollingIterator.hpp"
7 
8 namespace cutehmi {
9 namespace modbus {
10 
16 class CUTEHMI_MODBUS_API AbstractClient:
17  public AbstractDevice
18 {
19  Q_OBJECT
20 
21  public:
22  static constexpr int INITIAL_POLLING_INTERVAL = 250;
23 
24  static constexpr int INITIAL_POLLING_TASK_INTERVAL = 10;
25 
26  Q_PROPERTY(int pollingInterval READ pollingInterval WRITE setPollingInterval NOTIFY pollingIntervalChanged)
27 
28  Q_PROPERTY(int pollingTaskInterval READ pollingTaskInterval WRITE setPollingTaskInterval NOTIFY pollingTaskIntervalChanged)
29 
30  int pollingInterval() const;
31 
32  void setPollingInterval(int interval);
33 
34  int pollingTaskInterval() const;
35 
36  void setPollingTaskInterval(int interval);
37 
38  std::unique_ptr<ServiceStatuses> configureStarting(QState * starting) override;
39 
40  std::unique_ptr<ServiceStatuses> configureStarted(QState * active, const QState * idling, const QState * yielding) override;
41 
42  std::unique_ptr<ServiceStatuses> configureStopping(QState * stopping) override;
43 
44  std::unique_ptr<ServiceStatuses> configureBroken(QState * broken) override;
45 
46  std::unique_ptr<ServiceStatuses> configureRepairing(QState * repairing) override;
47 
48  std::unique_ptr<ServiceStatuses> configureEvacuating(QState * evacuating) override;
49 
50  std::unique_ptr<QAbstractTransition> transitionToStarted() const override;
51 
52  std::unique_ptr<QAbstractTransition> transitionToStopped() const override;
53 
54  std::unique_ptr<QAbstractTransition> transitionToBroken() const override;
55 
56  std::unique_ptr<QAbstractTransition> transitionToYielding() const override;
57 
58  std::unique_ptr<QAbstractTransition> transitionToIdling() const override;
59 
60  signals:
61  void pollingIntervalChanged();
62 
63  void pollingTaskIntervalChanged();
64 
65  protected:
66  AbstractClient(QObject * parent = nullptr);
67 
68  void handleRequest(const QJsonObject & request) override;
69 
70  void handleReply(QUuid requestId, QJsonObject reply) override;
71 
72  protected slots:
73  virtual void onStateChanged();
74 
75  void poll();
76 
77  void pollingTask();
78 
79  CUTEHMI_PROTECTED_SIGNALS:
80  void requestReceived(QJsonObject request);
81 
82  void pollingRequested();
83 
84  void pollingFinished();
85 
86  void pollingTaskRequested();
87 
88  void pollingTaskFinished();
89 
90  private:
91  struct Members {
92  internal::PollingIterator pollingIterator;
93  int pollingInterval;
94  int pollingTaskInterval;
95 
96  Members(AbstractDevice * device):
97  pollingIterator(device),
98  pollingInterval(INITIAL_POLLING_INTERVAL),
99  pollingTaskInterval(INITIAL_POLLING_TASK_INTERVAL)
100  {
101  }
102  };
103 
104  MPtr<Members> m;
105 };
106 
107 }
108 }
109 
110 #endif
111 
112 //(c)C: Copyright © 2021, Michał Policht <michal@policht.pl>. All rights reserved.
113 //(c)C: SPDX-License-Identifier: LGPL-3.0-or-later OR MIT
114 //(c)C: This file is a part of CuteHMI.
115 //(c)C: CuteHMI is free software: you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.
116 //(c)C: CuteHMI 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 Lesser General Public License for more details.
117 //(c)C: You should have received a copy of the GNU Lesser General Public License along with CuteHMI. If not, see <https://www.gnu.org/licenses/>.
118 //(c)C: Additionally, this file is licensed under terms of MIT license as expressed below.
119 //(c)C: Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
120 //(c)C: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
121 //(c)C: THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
cutehmi::modbus::internal::PollingIterator
Definition: PollingIterator.hpp:16
QState
QUuid
cutehmi::modbus::AbstractDevice
Abstract Modbus device.
Definition: AbstractDevice.hpp:33
cutehmi::MPtr< Members >
QObject
cutehmi
cutehmi::modbus::AbstractClient
Abstract client.
Definition: AbstractClient.hpp:16
QAbstractTransition
QJsonObject
std
QHash