Jpp  18.0.0
the software that should make you happy
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
Public Types | Public Member Functions | Static Public Attributes | Protected Member Functions | Protected Attributes | List of all members
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. More...
 
 JDispatch (const JPrefix_t &prefix, const char *data)
 Constructor. More...
 
 JDispatch (const JTag &tag, const std::string &message)
 Constructor. More...
 
 JDispatch (const JDispatch &message)
 Copy constructor. More...
 
 ~JDispatch ()
 Destructor. More...
 
JDispatchoperator= (const JDispatch &message)
 Assignment operator. More...
 
 operator JSocketOutputBuffer () const
 Type conversion operator. More...
 
int size () const
 Get size. More...
 
const char * data () const
 Get data. More...
 
int getSize () const
 Get size. More...
 
void setSize (const long long int length)
 Set size. More...
 
void set (const JTag &tag, const long long int length)
 Set prefix. More...
 
const JTaggetTag () const
 Get tag. More...
 
JTaggetTag ()
 Get tag. More...
 
void setTag (const JTag &tag)
 Set tag. More...
 
void setTag (const std::string &tag)
 Set tag. More...
 
void setTag (const JTag_t id)
 Set tag. More...
 
JTag_t getID () const
 Get identifier. More...
 
std::string toString () const
 Convert tag to string. More...
 
 operator std::string () const
 Type conversion operators. More...
 
const char * c_str () const
 C-string. More...
 
const char operator[] (int i) const
 Get character. More...
 
void initialise ()
 Initialise counter. More...
 
void attach (const JSharedCounter &object)
 Attach this counter to given shared counter object. More...
 
bool detach ()
 Detach. More...
 
const int getCount ()
 Get count. More...
 

Static Public Attributes

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

Protected Member Functions

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

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

Definition at line 70 of file JLigier.cc.

Constructor & Destructor Documentation

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
char * buffer
Definition: JLigier.cc:236
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  }
JSharedCounter()
Default constructor.
JPrefix JPrefix_t
Definition: JLigier.cc:29
void create()
Allocate memory.
Definition: JLigier.cc:209
const char * data() const
Get data.
Definition: JLigier.cc:199
char * buffer
Definition: JLigier.cc:236
int size() const
Get size.
Definition: JLigier.cc:188
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  }
JSharedCounter()
Default constructor.
JPrefix JPrefix_t
Definition: JLigier.cc:29
void create()
Allocate memory.
Definition: JLigier.cc:209
char * buffer
Definition: JLigier.cc:236
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.
JPrefix JPrefix_t
Definition: JLigier.cc:29
char * buffer
Definition: JLigier.cc:236
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
bool detach()
Detach.

Member Function Documentation

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  }
void release()
Release memory.
Definition: JLigier.cc:229
void attach(const JSharedCounter &object)
Attach this counter to given shared counter object.
char * buffer
Definition: JLigier.cc:236
bool detach()
Detach.
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
const char * data() const
Get data.
Definition: JLigier.cc:199
int size() const
Get size.
Definition: JLigier.cc:188
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.
Definition: JDataFilter.cc:79
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  }
char * buffer
Definition: JLigier.cc:236
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  }
void initialise()
Initialise counter.
static long long int MEMORY_TOTAL
Total size of data [Bytes].
Definition: JLigier.cc:72
char * buffer
Definition: JLigier.cc:236
static JClass_t * create()
Create object in memory.
Definition: JMemory.hh:89
int size() const
Get size.
Definition: JLigier.cc:188
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
static long long int MEMORY_TOTAL
Total size of data [Bytes].
Definition: JLigier.cc:72
char * buffer
Definition: JLigier.cc:236
int size() const
Get size.
Definition: JLigier.cc:188
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
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  }
long long int size
Definition: JPrefix.hh:92
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
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  }
ControlHost tag.
Definition: JTag.hh:38
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  }
ControlHost tag.
Definition: JTag.hh:38
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  }
JTag_t getID() const
Get identifier.
Definition: JTag.hh:160
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.
Definition: JException.hh:696
static const size_t TAGSIZE
Size of ControlHost tag.
Definition: JTag.hh:32
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
JTag_t JNET::JTag::getID ( ) const
inlineinherited

Get identifier.

Returns
identifier

Definition at line 160 of file JTag.hh.

161  {
162  return id;
163  }
JTag_t id
Definition: JTag.hh:254
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  }
static const size_t TAGSIZE
Size of ControlHost tag.
Definition: JTag.hh:32
then awk 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
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  }
JTag_t id
Definition: JTag.hh:254
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  }
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  }
bool detach()
Detach.
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  }
bool detach()
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  }
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

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.

long long int JNET::JDispatch::MEMORY_LIMIT
static

Limit size of data [Bytes].

Limit memory allocation.

Definition at line 73 of file JLigier.cc.

char* JNET::JDispatch::buffer
protected

Definition at line 236 of file JLigier.cc.

long long int JNET::JPrefix::size
protectedinherited

Definition at line 92 of file JPrefix.hh.

JTag_t JNET::JTag::id
protectedinherited

Definition at line 254 of file JTag.hh.

int* JLANG::JSharedCounter::counter
protectedinherited

Definition at line 94 of file JSharedCounter.hh.


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