Jpp 19.3.0-rc.3
the software that should make you happy
Loading...
Searching...
No Matches
JNET::JDispatch Class Reference

Data structure of a ControlHost message. More...

Inheritance diagram for JNET::JDispatch:
JNET::JPrefix JLANG::JSharedCounter JNET::JTag

Public Types

typedef JMalloc< char > JMemory_t
 

Public Member Functions

 JDispatch ()
 Default constructor.
 
 JDispatch (const JPrefix_t &prefix, const char *data)
 Constructor.
 
 JDispatch (const JTag &tag, const std::string &message)
 Constructor.
 
 JDispatch (const JDispatch &message)
 Copy constructor.
 
 ~JDispatch ()
 Destructor.
 
JDispatchoperator= (const JDispatch &message)
 Assignment operator.
 
 operator JSocketOutputBuffer () const
 Type conversion operator.
 
int size () const
 Get size.
 
const char * data () const
 Get data.
 
int getSize () const
 Get size.
 
void setSize (const long long int length)
 Set size.
 
void set (const JTag &tag, const long long int length)
 Set prefix.
 
const JTaggetTag () const
 Get tag.
 
JTaggetTag ()
 Get tag.
 
void setTag (const JTag &tag)
 Set tag.
 
void setTag (const std::string &tag)
 Set tag.
 
void setTag (const JTag_t id)
 Set tag.
 
JTag_t getID () const
 Get identifier.
 
std::string toString () const
 Convert tag to string.
 
 operator std::string () const
 Type conversion operators.
 
const char * c_str () const
 C-string.
 
const char operator[] (int i) const
 Get character.
 
void initialise ()
 Initialise counter.
 
void attach (const JSharedCounter &object)
 Attach this counter to given shared counter object.
 
bool detach ()
 Detach.
 
const int getCount ()
 Get count.
 

Static Public Attributes

static long long int MEMORY_TOTAL = 0
 Total size of data [Bytes].
 
static long long int MEMORY_LIMIT
 Limit size of data [Bytes].
 

Protected Member Functions

void create ()
 Allocate memory.
 
void release ()
 Release memory.
 

Protected Attributes

char * buffer
 
long long int size
 
JTag_t id
 
int * counter
 

Detailed Description

Data structure of a ControlHost message.

This data structure consists of a copy of the ControlHost prefix and an array of bytes (including the ControlHost prefix). A new array of bytes is created by the appropriate constructor. The allocated memory is released upon destruction of the last object of this class.

Definition at line 64 of file JLigier.cc.

Member Typedef Documentation

◆ JMemory_t

Definition at line 70 of file JLigier.cc.

Constructor & Destructor Documentation

◆ JDispatch() [1/4]

JNET::JDispatch::JDispatch ( )
inline

Default constructor.

Definition at line 78 of file JLigier.cc.

78 :
79 JPrefix_t(),
81 buffer(NULL)
82 {}
JSharedCounter()
Default constructor.
JPrefix JPrefix_t
Definition JLigier.cc:29

◆ JDispatch() [2/4]

JNET::JDispatch::JDispatch ( const JPrefix_t & prefix,
const char * data )
inline

Constructor.

Note that the input data should contain a copy of the prefix.

Parameters
prefixprefix
datadata

Definition at line 92 of file JLigier.cc.

93 :
94 JPrefix_t(prefix),
96 {
97 create();
98
99 memcpy(this->buffer, data, size());
100 }
int size() const
Get size.
Definition JLigier.cc:188
void create()
Allocate memory.
Definition JLigier.cc:209
const char * data() const
Get data.
Definition JLigier.cc:199

◆ JDispatch() [3/4]

JNET::JDispatch::JDispatch ( const JTag & tag,
const std::string & message )
inline

Constructor.

Note that the given message is appended to a copy of the prefix.

Parameters
tagtag
messagemessage

Definition at line 110 of file JLigier.cc.

111 :
112 JPrefix_t(tag, message.size()),
114 {
115 create();
116
117 memcpy(this->buffer, static_cast<const JPrefix_t*>(this), sizeof(JPrefix_t));
118
119 memcpy(this->buffer + sizeof(JPrefix_t), message.data(), message.size());
120 }

◆ JDispatch() [4/4]

JNET::JDispatch::JDispatch ( const JDispatch & message)
inline

Copy constructor.

Parameters
messagemessage

Definition at line 128 of file JLigier.cc.

129 {
130 static_cast<JPrefix_t&>(*this) = message;
131
132 buffer = message.buffer;
133
134 attach(message);
135 }
void attach(const JSharedCounter &object)
Attach this counter to given shared counter object.

◆ ~JDispatch()

JNET::JDispatch::~JDispatch ( )
inline

Destructor.

Definition at line 141 of file JLigier.cc.

142 {
143 if (detach()) {
144 release();
145 }
146 }
void release()
Release memory.
Definition JLigier.cc:229

Member Function Documentation

◆ operator=()

JDispatch & JNET::JDispatch::operator= ( const JDispatch & message)
inline

Assignment operator.

Parameters
messagemessage
Returns
this JDispatch

Definition at line 155 of file JLigier.cc.

156 {
157 if (buffer != message.buffer) {
158
159 if (detach()) {
160 release();
161 }
162
163 buffer = message.buffer;
164
165 attach(message);
166 }
167
168 return *this;
169 }

◆ operator JSocketOutputBuffer()

JNET::JDispatch::operator JSocketOutputBuffer ( ) const
inline

Type conversion operator.

Returns
socket output buffer

Definition at line 177 of file JLigier.cc.

178 {
179 return JSocketOutputBuffer(this->data(), this->size());
180 }
JSocketBuffer< const char > JSocketOutputBuffer

◆ size()

int JNET::JDispatch::size ( ) const
inline

Get size.

Returns
number of bytes

Definition at line 188 of file JLigier.cc.

189 {
190 return getSizeOfPacket(static_cast<const JPrefix_t&>(*this));
191 }
int getSizeOfPacket(const KM3NETDAQ::JDAQAbstractPreamble &preamble)
Get size of packeet.

◆ data()

const char * JNET::JDispatch::data ( ) const
inline

Get data.

Returns
pointer to data

Definition at line 199 of file JLigier.cc.

200 {
201 return buffer;
202 }

◆ create()

void JNET::JDispatch::create ( )
inlineprotected

Allocate memory.

Definition at line 209 of file JLigier.cc.

210 {
212
213 if (buffer != NULL) {
214
216
217 MEMORY_TOTAL += size();
218
219 } else {
220
221 throw JMallocException("Not enough space in memory.");
222 }
223 }
static JClass_t * create()
Create object in memory.
Definition JMemory.hh:89
void initialise()
Initialise counter.
static long long int MEMORY_TOTAL
Total size of data [Bytes].
Definition JLigier.cc:72

◆ release()

void JNET::JDispatch::release ( )
inlineprotected

Release memory.

Definition at line 229 of file JLigier.cc.

230 {
232
233 MEMORY_TOTAL -= size();
234 }
static void release(JClass_t *p)
Release memory.
Definition JMemory.hh:112

◆ getSize()

int JNET::JPrefix::getSize ( ) const
inlineinherited

Get size.

Returns
number of bytes

Definition at line 62 of file JPrefix.hh.

63 {
64 return ntohl(size);
65 }
long long int size
Definition JPrefix.hh:92

◆ setSize()

void JNET::JPrefix::setSize ( const long long int length)
inlineinherited

Set size.

Parameters
lengthnumber of bytes

Definition at line 73 of file JPrefix.hh.

74 {
75 size = htonl(length);
76 }

◆ set()

void JNET::JPrefix::set ( const JTag & tag,
const long long int length )
inlineinherited

Set prefix.

Parameters
tagtag
lengthnumber of bytes

Definition at line 85 of file JPrefix.hh.

86 {
87 setTag (tag);
88 setSize(length);
89 }
void setSize(const long long int length)
Set size.
Definition JPrefix.hh:73
void setTag(const JTag &tag)
Set tag.
Definition JTag.hh:108

◆ getTag() [1/2]

const JTag & JNET::JTag::getTag ( ) const
inlineinherited

Get tag.

Returns
tag

Definition at line 86 of file JTag.hh.

87 {
88 return static_cast<const JTag&>(*this);
89 }

◆ getTag() [2/2]

JTag & JNET::JTag::getTag ( )
inlineinherited

Get tag.

Returns
tag

Definition at line 97 of file JTag.hh.

98 {
99 return static_cast<JTag&>(*this);
100 }

◆ setTag() [1/3]

void JNET::JTag::setTag ( const JTag & tag)
inlineinherited

Set tag.

Parameters
tagtag

Definition at line 108 of file JTag.hh.

109 {
110 id = tag.getID();
111 }

◆ setTag() [2/3]

void JNET::JTag::setTag ( const std::string & tag)
inlineinherited

Set tag.

This method may throw an exception.

Parameters
tagtag

Definition at line 121 of file JTag.hh.

122 {
123 if (!tag.empty() && tag.size() <= TAGSIZE) {
124
125 char* __p = (char*) &(this->id);
126
127 size_t i = 0;
128
129 for ( ; i != tag.size(); ++i) {
130 __p[i] = tag[i];
131 }
132
133 for ( ; i != TAGSIZE; ++i) {
134 __p[i] = '\0';
135 }
136
137 } else {
138
139 THROW(JControlHostException, "Invalid tag length <" << tag << "> " << tag.size());
140 }
141 }
#define THROW(JException_t, A)
Marco for throwing exception with std::ostream compatible message.
static const size_t TAGSIZE
Size of ControlHost tag.
Definition JTag.hh:32

◆ setTag() [3/3]

void JNET::JTag::setTag ( const JTag_t id)
inlineinherited

Set tag.

Parameters
ididentifier

Definition at line 149 of file JTag.hh.

150 {
151 this->id = id;
152 }
JTag_t id
Definition JTag.hh:254

◆ getID()

JTag_t JNET::JTag::getID ( ) const
inlineinherited

Get identifier.

Returns
identifier

Definition at line 160 of file JTag.hh.

161 {
162 return id;
163 }

◆ toString()

std::string JNET::JTag::toString ( ) const
inlineinherited

Convert tag to string.

Returns
tag

Definition at line 171 of file JTag.hh.

172 {
173 int pos = TAGSIZE;
174
175 const char* __p = (const char*) &(this->id);
176
177 while (pos != 0 && __p[pos-1] == '\0') {
178 --pos;
179 }
180
181 return std::string(__p, pos);
182 }

◆ operator std::string()

JNET::JTag::operator std::string ( ) const
inlineinherited

Type conversion operators.

Returns
tag

Definition at line 190 of file JTag.hh.

191 {
192 return toString();
193 }
std::string toString() const
Convert tag to string.
Definition JTag.hh:171

◆ c_str()

const char * JNET::JTag::c_str ( ) const
inlineinherited

C-string.

Returns
tag

Definition at line 201 of file JTag.hh.

202 {
203 return (const char*) &(this->id);
204 }

◆ operator[]()

const char JNET::JTag::operator[] ( int i) const
inlineinherited

Get character.

Parameters
iindex
Returns
character at index

Definition at line 213 of file JTag.hh.

214 {
215 const char* __p = (const char*) &(this->id);
216
217 return __p[i];
218 }

◆ initialise()

void JLANG::JSharedCounter::initialise ( )
inlineinherited

Initialise counter.

Definition at line 33 of file JSharedCounter.hh.

34 {
35 detach();
36
37 counter = new int(1);
38 }

◆ attach()

void JLANG::JSharedCounter::attach ( const JSharedCounter & object)
inlineinherited

Attach this counter to given shared counter object.

Parameters
objectshared counter

Definition at line 46 of file JSharedCounter.hh.

47 {
48 detach();
49
50 counter = object.counter;
51
52 if (counter != NULL) {
53 ++(*counter);
54 }
55 }

◆ detach()

bool JLANG::JSharedCounter::detach ( )
inlineinherited

Detach.

Returns
true if counter at zero; else false

Definition at line 63 of file JSharedCounter.hh.

64 {
65 if (counter != NULL) {
66
67 if (--(*counter) == 0) {
68
69 delete counter;
70
71 counter = NULL;
72
73 return true;
74 }
75
76 counter = NULL;
77 }
78
79 return false;
80 }

◆ getCount()

const int JLANG::JSharedCounter::getCount ( )
inlineinherited

Get count.

Returns
count

Definition at line 88 of file JSharedCounter.hh.

89 {
90 return (counter != NULL ? *counter : 0);
91 }

Member Data Documentation

◆ MEMORY_TOTAL

long long int JNET::JDispatch::MEMORY_TOTAL = 0
static

Total size of data [Bytes].

Total memory allocation.

Definition at line 72 of file JLigier.cc.

◆ MEMORY_LIMIT

long long int JNET::JDispatch::MEMORY_LIMIT
static

Limit size of data [Bytes].

Limit memory allocation.

Definition at line 73 of file JLigier.cc.

◆ buffer

char* JNET::JDispatch::buffer
protected

Definition at line 236 of file JLigier.cc.

◆ size

long long int JNET::JPrefix::size
protectedinherited

Definition at line 92 of file JPrefix.hh.

◆ id

JTag_t JNET::JTag::id
protectedinherited

Definition at line 254 of file JTag.hh.

◆ counter

int* JLANG::JSharedCounter::counter
protectedinherited

Definition at line 94 of file JSharedCounter.hh.


The documentation for this class was generated from the following file: