Jpp
 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...
 
JTag_t getID () const
 Get identifier. More...
 
bool setID (const JTag_t id)
 Set 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...
 

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
 
union {
   char   tag [TAGSIZE]
 
   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:235
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:208
const char * data() const
Get data.
Definition: JLigier.cc:198
char * buffer
Definition: JLigier.cc:235
int size() const
Get size.
Definition: JLigier.cc:187
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.
char tag[TAGSIZE]
Definition: JTag.hh:247
JPrefix JPrefix_t
Definition: JLigier.cc:29
void create()
Allocate memory.
Definition: JLigier.cc:208
char * buffer
Definition: JLigier.cc:235
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:235
JNET::JDispatch::~JDispatch ( )
inline

Destructor.

Definition at line 141 of file JLigier.cc.

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

Member Function Documentation

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

Assignment operator.

Parameters
messagemessage
Returns
this JDispatch

Definition at line 154 of file JLigier.cc.

155  {
156  if (buffer != message.buffer) {
157 
158  if (detach()) {
159  release();
160  }
161 
162  buffer = message.buffer;
163 
164  attach(message);
165  }
166 
167  return *this;
168  }
void release()
Release memory.
Definition: JLigier.cc:228
void attach(const JSharedCounter &object)
Attach this counter to given shared counter object.
char * buffer
Definition: JLigier.cc:235
bool detach()
Detach.
JNET::JDispatch::operator JSocketOutputBuffer ( ) const
inline

Type conversion operator.

Returns
socket output buffer

Definition at line 176 of file JLigier.cc.

177  {
178  return JSocketOutputBuffer(this->data(), this->size());
179  }
JSocketBuffer< const char > JSocketOutputBuffer
const char * data() const
Get data.
Definition: JLigier.cc:198
int size() const
Get size.
Definition: JLigier.cc:187
int JNET::JDispatch::size ( ) const
inline

Get size.

Returns
number of bytes

Definition at line 187 of file JLigier.cc.

188  {
189  return getSizeOfPacket(static_cast<const JPrefix_t&>(*this));
190  }
int getSizeOfPacket(const KM3NETDAQ::JDAQAbstractPreamble &preamble)
Get size of packeet.
Definition: JDataFilter.cc:76
const char* JNET::JDispatch::data ( ) const
inline

Get data.

Returns
pointer to data

Definition at line 198 of file JLigier.cc.

199  {
200  return buffer;
201  }
char * buffer
Definition: JLigier.cc:235
void JNET::JDispatch::create ( )
inlineprotected

Allocate memory.

Definition at line 208 of file JLigier.cc.

209  {
211 
212  if (buffer != NULL) {
213 
215 
216  MEMORY_TOTAL += size();
217 
218  } else {
219 
220  throw JMallocException("Not enough space in memory.");
221  }
222  }
void initialise()
Initialise counter.
static long long int MEMORY_TOTAL
Total size of data [Bytes].
Definition: JLigier.cc:72
char * buffer
Definition: JLigier.cc:235
static JClass_t * create()
Create object in memory.
Definition: JMemory.hh:89
int size() const
Get size.
Definition: JLigier.cc:187
void JNET::JDispatch::release ( )
inlineprotected

Release memory.

Definition at line 228 of file JLigier.cc.

229  {
231 
232  MEMORY_TOTAL -= size();
233  }
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:235
int size() const
Get size.
Definition: JLigier.cc:187
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:93
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:93
void JNET::JPrefix::set ( const JTag tag,
const long long int  length 
)
inlineinherited

Set prefix.

Parameters
tagtag
lengthnumber of bytes
Returns
true if OK; else false

Definition at line 86 of file JPrefix.hh.

87  {
88  setTag (tag);
89  setSize(length);
90  }
void setSize(const long long int length)
Set size.
Definition: JPrefix.hh:73
void setTag(const JTag &tag)
Set tag.
Definition: JTag.hh:105
const JTag& JNET::JTag::getTag ( ) const
inlineinherited

Get tag.

Returns
tag

Definition at line 82 of file JTag.hh.

83  {
84  return static_cast<const JTag&>(*this);
85  }
ControlHost tag.
Definition: JTag.hh:35
JTag& JNET::JTag::getTag ( )
inlineinherited

Get tag.

Returns
tag

Definition at line 93 of file JTag.hh.

94  {
95  return static_cast<JTag&>(*this);
96  }
ControlHost tag.
Definition: JTag.hh:35
void JNET::JTag::setTag ( const JTag tag)
inlineinherited

Set tag.

Parameters
tagtag
Returns
true if OK; else false

Definition at line 105 of file JTag.hh.

106  {
107  id = tag.getID();
108  }
JTag_t getID() const
Get identifier.
Definition: JTag.hh:143
void JNET::JTag::setTag ( const std::string &  tag)
inlineinherited

Set tag.

Parameters
tagtag
Returns
true if OK; else false

Definition at line 117 of file JTag.hh.

118  {
119  if (!tag.empty() && tag.size() <= TAGSIZE) {
120 
121  size_t i = 0;
122 
123  for ( ; i < tag.size(); ++i) {
124  this->tag[i] = tag[i];
125  }
126 
127  for ( ; i < TAGSIZE; ++i) {
128  this->tag[i] = '\0';
129  }
130 
131  } else {
132 
133  return throw(JControlHostException("JTag::setTag() invalid tag length."));
134  }
135  }
char tag[TAGSIZE]
Definition: JTag.hh:247
static const size_t TAGSIZE
Definition: JTag.hh:29
JTag_t JNET::JTag::getID ( ) const
inlineinherited

Get identifier.

Returns
identifier

Definition at line 143 of file JTag.hh.

144  {
145  return id;
146  }
JTag_t id
Definition: JTag.hh:248
bool JNET::JTag::setID ( const JTag_t  id)
inlineinherited

Set identifier.

Returns
identifier

Definition at line 154 of file JTag.hh.

155  {
156  this->id = id;
157 
158  return true;
159  }
JTag_t id
Definition: JTag.hh:248
std::string JNET::JTag::toString ( ) const
inlineinherited

Convert tag to string.

Returns
tag

Definition at line 167 of file JTag.hh.

168  {
169  int pos = TAGSIZE;
170 
171  while (pos != 0 && tag[pos-1] == '\0') {
172  --pos;
173  }
174 
175  return std::string(tag, pos);
176  }
char tag[TAGSIZE]
Definition: JTag.hh:247
static const size_t TAGSIZE
Definition: JTag.hh:29
JNET::JTag::operator std::string ( ) const
inlineinherited

Type conversion operators.

Returns
tag

Definition at line 184 of file JTag.hh.

185  {
186  return toString();
187  }
std::string toString() const
Convert tag to string.
Definition: JTag.hh:167
const char* JNET::JTag::c_str ( ) const
inlineinherited

C-string.

Returns
tag

Definition at line 195 of file JTag.hh.

196  {
197  return tag;
198  }
char tag[TAGSIZE]
Definition: JTag.hh:247
const char JNET::JTag::operator[] ( int  i) const
inlineinherited

Get character.

Parameters
iindex
Returns
character at index

Definition at line 207 of file JTag.hh.

208  {
209  return tag[i];
210  }
char tag[TAGSIZE]
Definition: JTag.hh:247
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  }

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 235 of file JLigier.cc.

long long int JNET::JPrefix::size
protectedinherited

Definition at line 93 of file JPrefix.hh.

char JNET::JTag::tag[TAGSIZE]
inherited

Definition at line 247 of file JTag.hh.

JTag_t JNET::JTag::id
inherited

Definition at line 248 of file JTag.hh.

union { ... }
int* JLANG::JSharedCounter::counter
protectedinherited

Definition at line 83 of file JSharedCounter.hh.


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