libhomegear-base  0.7
Base library for Homegear and Homegear family modules.
BinaryRpc.h
Go to the documentation of this file.
1 /* Copyright 2013-2019 Homegear GmbH
2  *
3  * libhomegear-base is free software: you can redistribute it and/or
4  * modify it under the terms of the GNU Lesser General Public License as
5  * published by the Free Software Foundation, either version 3 of the
6  * License, or (at your option) any later version.
7  *
8  * libhomegear-base is distributed in the hope that it will be useful,
9  * but WITHOUT ANY WARRANTY; without even the implied warranty of
10  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11  * GNU Lesser General Public License for more details.
12  *
13  * You should have received a copy of the GNU Lesser General Public
14  * License along with libhomegear-base. If not, see
15  * <http://www.gnu.org/licenses/>.
16  *
17  * In addition, as a special exception, the copyright holders give
18  * permission to link the code of portions of this program with the
19  * OpenSSL library under certain conditions as described in each
20  * individual source file, and distribute linked combinations
21  * including the two.
22  * You must obey the GNU Lesser General Public License in all respects
23  * for all of the code used other than OpenSSL. If you modify
24  * file(s) with this exception, you may extend this exception to your
25  * version of the file(s), but you are not obligated to do so. If you
26  * do not wish to do so, delete this exception statement from your
27  * version. If you delete this exception statement from all source
28  * files in the program, then also delete it here.
29 */
30 
31 #ifndef BINARYRPC_H_
32 #define BINARYRPC_H_
33 
34 #include "../Variable.h"
35 #include "../Exception.h"
36 
37 namespace BaseLib {
38 
39 class SharedObjects;
40 
41 namespace Rpc {
42 
44  public:
45  explicit BinaryRpcException(const std::string &message) : BaseLib::Exception(message) {}
46 };
47 
48 class BinaryRpc {
49  public:
50  enum class Type {
51  unknown,
52  request,
53  response
54  };
55 
56  BinaryRpc();
57 
61  explicit BinaryRpc(BaseLib::SharedObjects *bl);
62  ~BinaryRpc() = default;
63 
64  size_t getMaxHeaderSize() { return _maxHeaderSize; }
65  void setMaxHeaderSize(size_t value) { _maxHeaderSize = value; }
66  size_t getMaxContentSize() { return _maxContentSize; }
67  void setMaxContentSize(size_t value) { _maxContentSize = value; }
68  Type getType() { return _type; }
69  bool hasHeader() { return _hasHeader; }
70  bool processingStarted() { return _headerProcessingStarted || _dataProcessingStarted; }
71  bool headerProcessingStarted() { return _headerProcessingStarted; }
72  bool dataProcessingStarted() { return _dataProcessingStarted; }
73  bool isFinished() { return _finished; }
74  std::vector<char> &getData() { return _data; }
75 
76  void reset();
77 
85  int32_t process(char *buffer, int32_t bufferLength);
86  private:
87  SharedObjects *_bl = nullptr;
88  size_t _maxHeaderSize = 102400;
89  size_t _maxContentSize = 104857600;
90  bool _hasHeader = false;
91  bool _headerProcessingStarted = false;
92  bool _dataProcessingStarted = false;
93  bool _finished = false;
94  Type _type = Type::unknown;
95  uint32_t _headerSize = 0;
96  uint32_t _dataSize = 0;
97  std::vector<char> _data;
98 };
99 }
100 }
101 #endif
Type getType()
Definition: BinaryRpc.h:68
BinaryRpcException(const std::string &message)
Definition: BinaryRpc.h:45
bool processingStarted()
Definition: BinaryRpc.h:70
This is the base library main class.
Definition: BaseLib.h:95
Type
Definition: BinaryRpc.h:50
size_t getMaxContentSize()
Definition: BinaryRpc.h:66
Definition: BaseLib.cpp:34
size_t getMaxHeaderSize()
Definition: BinaryRpc.h:64
bool hasHeader()
Definition: BinaryRpc.h:69
bool dataProcessingStarted()
Definition: BinaryRpc.h:72
PVariable value
Definition: UiElements.h:217
bool isFinished()
Definition: BinaryRpc.h:73
bool headerProcessingStarted()
Definition: BinaryRpc.h:71
Definition: BinaryRpc.h:48
Base class for all exceptions defined in Homegear.
Definition: Exception.h:41
void setMaxContentSize(size_t value)
Definition: BinaryRpc.h:67
void setMaxHeaderSize(size_t value)
Definition: BinaryRpc.h:65
Definition: BinaryRpc.h:43
std::vector< char > & getData()
Definition: BinaryRpc.h:74