Electroneum
Loading...
Searching...
No Matches
levin_base.h
Go to the documentation of this file.
1// Copyright (c) 2006-2013, Andrey N. Sabelnikov, www.sabelnikov.net
2// All rights reserved.
3//
4// Redistribution and use in source and binary forms, with or without
5// modification, are permitted provided that the following conditions are met:
6// * Redistributions of source code must retain the above copyright
7// notice, this list of conditions and the following disclaimer.
8// * Redistributions in binary form must reproduce the above copyright
9// notice, this list of conditions and the following disclaimer in the
10// documentation and/or other materials provided with the distribution.
11// * Neither the name of the Andrey N. Sabelnikov nor the
12// names of its contributors may be used to endorse or promote products
13// derived from this software without specific prior written permission.
14//
15// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
16// ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
17// WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
18// DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER BE LIABLE FOR ANY
19// DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
20// (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
21// LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
22// ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
23// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
24// SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
25//
26
27
28
29#ifndef _LEVIN_BASE_H_
30#define _LEVIN_BASE_H_
31
32#include "net_utils_base.h"
33
34#define LEVIN_SIGNATURE 0x0101010101012101LL //Bender's nightmare
35
36namespace epee
37{
38namespace levin
39{
40#pragma pack(push)
41#pragma pack(1)
43 {
49 uint32_t m_reservedA; //probably some flags in future
50 uint32_t m_reservedB; //probably some check sum in future
51 };
52#pragma pack(pop)
53
54
55#pragma pack(push)
56#pragma pack(1)
67#pragma pack(pop)
68
69
70#define LEVIN_DEFAULT_TIMEOUT_PRECONFIGURED 0
71#define LEVIN_DEFAULT_MAX_PACKET_SIZE 100000000 //100MB by default
72
73#define LEVIN_PACKET_REQUEST 0x00000001
74#define LEVIN_PACKET_RESPONSE 0x00000002
75
76
77#define LEVIN_PROTOCOL_VER_0 0
78#define LEVIN_PROTOCOL_VER_1 1
79
80 template<class t_connection_context = net_utils::connection_context_base>
82 {
83 virtual int invoke(int command, const epee::span<const uint8_t> in_buff, std::string& buff_out, t_connection_context& context)=0;
84 virtual int notify(int command, const epee::span<const uint8_t> in_buff, t_connection_context& context)=0;
85 virtual void callback(t_connection_context& context){};
86
87 virtual void on_connection_new(t_connection_context& context){};
88 virtual void on_connection_close(t_connection_context& context){};
89
91 };
92
93#define LEVIN_OK 0
94#define LEVIN_ERROR_CONNECTION -1
95#define LEVIN_ERROR_CONNECTION_NOT_FOUND -2
96#define LEVIN_ERROR_CONNECTION_DESTROYED -3
97#define LEVIN_ERROR_CONNECTION_TIMEDOUT -4
98#define LEVIN_ERROR_CONNECTION_NO_DUPLEX_PROTOCOL -5
99#define LEVIN_ERROR_CONNECTION_HANDLER_NOT_DEFINED -6
100#define LEVIN_ERROR_FORMAT -7
101
102#define DESCRIBE_RET_CODE(code) case code: return #code;
103 inline
120
121
122}
123}
124
125
126#endif //_LEVIN_BASE_H_
Non-owning sequence of data. Does not deep copy.
Definition span.h:57
#define DESCRIBE_RET_CODE(code)
Definition levin_base.h:102
#define LEVIN_ERROR_CONNECTION
Definition levin_base.h:94
#define LEVIN_ERROR_CONNECTION_NO_DUPLEX_PROTOCOL
Definition levin_base.h:98
#define LEVIN_OK
Definition levin_base.h:93
#define LEVIN_ERROR_CONNECTION_DESTROYED
Definition levin_base.h:96
#define LEVIN_ERROR_CONNECTION_HANDLER_NOT_DEFINED
Definition levin_base.h:99
#define LEVIN_ERROR_CONNECTION_NOT_FOUND
Definition levin_base.h:95
#define LEVIN_ERROR_FORMAT
Definition levin_base.h:100
#define LEVIN_ERROR_CONNECTION_TIMEDOUT
Definition levin_base.h:97
const char * get_err_descr(int err)
Definition levin_base.h:104
unsigned int uint32_t
Definition stdint.h:126
signed int int32_t
Definition stdint.h:123
unsigned __int64 uint64_t
Definition stdint.h:136
virtual void on_connection_new(t_connection_context &context)
Definition levin_base.h:87
virtual int notify(int command, const epee::span< const uint8_t > in_buff, t_connection_context &context)=0
virtual void on_connection_close(t_connection_context &context)
Definition levin_base.h:88
virtual void callback(t_connection_context &context)
Definition levin_base.h:85
virtual int invoke(int command, const epee::span< const uint8_t > in_buff, std::string &buff_out, t_connection_context &context)=0