COVISE Core
message.h
Go to the documentation of this file.
1/* This file is part of COVISE.
2
3 You can use it under the terms of the GNU Lesser General Public License
4 version 2.1 or later, see lgpl-2.1.txt.
5
6 * License: LGPL 2+ */
7
8#ifndef EC_MESSAGE_H
9#define EC_MESSAGE_H
10
11#include "dataHandle.h"
12
13#include <util/coExport.h>
14#include <util/byteswap.h>
15
16#include <string>
17
18#ifdef _WIN64
19#define __WORDSIZE 64
20#endif
21
22namespace covise
23{
24
25const int MSG_NOCOPY = 0;
26const int MSG_COPY = 1;
27
28class Connection;
29
30typedef long data_type;
31
32#ifdef BYTESWAP
33
34inline void swap_byte(unsigned int &byte) // only if necessary
35{
36 byteSwap(byte);
37}
38
39// only if necessary
40inline void swap_bytes(unsigned int *bytes, int no)
41{
42 byteSwap(bytes, no);
43}
44
45inline void swap_short_byte(unsigned short &byte) // only if necessary
46{
47 byteSwap(byte);
48}
49
50// only if necessary
51inline void swap_short_bytes(unsigned short *bytes, int no)
52{
53 byteSwap(bytes, no);
54}
55
56#else
57inline void swap_byte(unsigned int){}
58inline void swap_bytes(unsigned int *, int){}
59inline void swap_short_byte(unsigned short){}
60inline void swap_short_bytes(unsigned short *, int){}
61#endif
62
63class TokenBuffer;
65{
66public:
68 const Connection* conn = nullptr; // connection at which message has been received (if so)
72 virtual ~MessageBase() = default;
73 virtual void print() = 0;
74};
75class NETEXPORT Message : public MessageBase// class for messages
76{
77public:
78 // message types
79 enum Type
80 {
81 EMPTY = -1,
82 HOSTID = 81,
83 SOCKET_CLOSED = 84,
84 CLOSE_SOCKET = 31,
85 STDINOUT_EMPTY = 54,
86 UI = 6,
87 RENDER = 45,
88 };
89
91 {
93 STDINOUT = 9
94 };
95
96 int sender = -1; // sender of message (max. 3bytes)
97 int send_type = UNDEFINED; // type of sender
98 int type = EMPTY; // type of the message
99
100 // empty initialization:
101 Message();
102 explicit Message(TokenBuffer& t);
103 explicit Message(const Connection *c);
104
105 // initialization with data only (for sending):
106 explicit Message(int message_type, const std::string &str = std::string());
107
108 Message(int message_type, const DataHandle& dh);
109
110 Message(const Message &); // copy constructor
111 //copies data
112 Message &operator=(const Message &src); // assignment
113 //does not copy data
114 void copyAndReuseData(const Message& src);
115 //char *extract_data();
116 void print() override;
117
118};
119}
120#endif
#define NETEXPORT
Definition: coExport.h:373
GLsizei const GLchar *const * string
Definition: khronos-glext.h:6750
const GLubyte * c
Definition: khronos-glext.h:9864
GLenum src
Definition: khronos-glext.h:7031
GLdouble GLdouble t
Definition: khronos-glext.h:6449
GLenum type
Definition: khronos-glext.h:6279
list of all chemical elements
Definition: coConfig.h:27
@ EMPTY
Definition: udp_message_types.h:39
const int MSG_NOCOPY
Definition: message.h:25
long data_type
Definition: message.h:28
void swap_short_byte(unsigned short)
Definition: message.h:59
const int MSG_COPY
Definition: message.h:26
@ UNDEFINED
Definition: message_types.h:370
@ STDINOUT
Definition: message_types.h:379
void swap_bytes(unsigned int *, int)
Definition: message.h:58
void swap_short_bytes(unsigned short *, int)
Definition: message.h:60
void swap_byte(unsigned int)
Definition: message.h:57
std::enable_if< I==sizeof...(Tp), void >::type print(Stream &s, const std::tuple< Tp... > &t)
Definition: tokenbuffer_util.h:68
Definition: covise_connect.h:122
Definition: dataHandle.h:18
Definition: message.h:65
DataHandle data
Definition: message.h:67
virtual ~MessageBase()=default
virtual void print()=0
Definition: message.h:76
SenderType
Definition: message.h:91
Type
Definition: message.h:80
Definition: tokenbuffer.h:79