DAQ  1.0.0
Data Acquisition System (basic demo)
client.h
Go to the documentation of this file.
1 /*! \brief This file have the interface for Client class.
2  \file client.h
3  \author Alvaro Denis <denisacostaq@gmail.com>
4  \date 6/28/2019
5 
6  \copyright
7  \attention <h1><center><strong>COPYRIGHT &copy; 2019 </strong>
8  [<strong>denisacostaq</strong>][denisacostaq-URL].
9  All rights reserved.</center></h1>
10  \attention This file is part of [<strong>DAQs</strong>][DAQs-URL].
11 
12  Redistribution and use in source and binary forms, with or without
13  modification, are permitted provided that the following conditions
14  are met:
15  - 1. Redistributions of source code must retain the above copyright
16  notice, this list of conditions and the following disclaimer.
17  - 2. Redistributions in binary form must reproduce the above copyright
18  notice, this list of conditions and the following disclaimer in the
19  documentation and/or other materials provided with the distribution.
20  - 3. Neither the name of the University nor the names of its contributors
21  may be used to endorse or promote products derived from this software
22  without specific prior written permission.
23 
24  THIS PRODUCT IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
25  AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
26  IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
27  ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER BE LIABLE FOR ANY
28  DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
29  (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
30  LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
31  ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
32  (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
33  THIS PRODUCT, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
34 
35  [denisacostaq-URL]: https://about.me/denisacostaq "Alvaro Denis Acosta"
36  [DAQs-URL]: http://github.com/denisacostaq/apirestgenerator
37  "APIRestGenerator based on golang revel and gorm"
38  */
39 #ifndef CLIENT_H
40 #define CLIENT_H
41 
42 #include <chrono>
43 
44 #include <QtCore/QObject>
45 #include <QtNetwork/QTcpSocket>
46 
47 #include <messages.pb.h>
48 
49 #include "src/database-server/data-source/idatasource.h"
50 
51 class Client : public QObject {
52  Q_OBJECT
53  public:
55 
56  void connect();
57 
58  void send_var(const Variable &var);
59  void send_var_val(const QString &var_name, double value);
60  void request_vars();
61  void request_var_values(const QString &var_name);
65 
66  ~Client() { socket_.close(); }
67 
68  signals:
69  // FIXME(denisacostaq@gmail.com): expensive copy
70  void valuesReceived(const std::vector<VarValue> &vals);
71  // FIXME(denisacostaq@gmail.com): expensive copy
72  void variablesReceived(const std::vector<Variable> &vals);
73  void responseReceived(message::MessageType *prev_msg,
74  message::ResponseStatus status, QString response);
75  void connected();
76 
77  private slots:
78  void onReadyRead();
79 
80  private:
81  bool is_connected() const;
82  void do_request(const message::GetVariables &gv);
83  void do_request(const message::GetValues &gv);
85  const QString host_;
87 #ifdef __ANDROID__
88  // TODO(denisacostaq@gmail.com): send this in the request
89  // max_values_ammount
91 #else
92  static constexpr size_t max_values_ammount{120};
93 #endif
94 };
95 
96 #endif // CLIENT_H
void send_var(const Variable &var)
Definition: client.cc:197
const QString host_
Definition: client.h:85
Definition: variable.h:44
void request_vars()
Definition: client.cc:236
void variablesReceived(const std::vector< Variable > &vals)
void do_request(const message::GetVariables &gv)
Definition: client.cc:277
QTcpSocket socket_
Definition: client.h:84
void connected()
void send_var_val(const QString &var_name, double value)
Definition: client.cc:217
void responseReceived(message::MessageType *prev_msg, message::ResponseStatus status, QString response)
void request_var_values(const QString &var_name)
Definition: client.cc:241
bool is_connected() const
Definition: client.cc:293
void do_request(const message::GetValues &gv)
Definition: client.cc:261
~Client()
Definition: client.h:66
void connect()
Definition: client.cc:195
std::uint16_t port_
Definition: client.h:86