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 int length)
 Set size. More...
 
void set (const JTag &tag, const 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
 
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 63 of file JLigier.cc.

Member Typedef Documentation

Definition at line 69 of file JLigier.cc.

Constructor & Destructor Documentation

JNET::JDispatch::JDispatch ( )
inline

Default constructor.

Definition at line 77 of file JLigier.cc.

77  :
78  JPrefix_t(),
80  buffer(NULL)
81  {}
JSharedCounter()
Default constructor.
JPrefix JPrefix_t
Definition: JLigier.cc:28
char * buffer
Definition: JLigier.cc:234
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 91 of file JLigier.cc.

92  :
93  JPrefix_t(prefix),
95  {
96  create();
97 
98  memcpy(this->buffer, data, size());
99  }
JSharedCounter()
Default constructor.
JPrefix JPrefix_t
Definition: JLigier.cc:28
void create()
Allocate memory.
Definition: JLigier.cc:207
const char * data() const
Get data.
Definition: JLigier.cc:197
char * buffer
Definition: JLigier.cc:234
int size() const
Get size.
Definition: JLigier.cc:186
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 109 of file JLigier.cc.

110  :
111  JPrefix_t(tag, message.size()),
113  {
114  create();
115 
116  memcpy(this->buffer, static_cast<const JPrefix_t*>(this), sizeof(JPrefix_t));
117 
118  memcpy(this->buffer + sizeof(JPrefix_t), message.data(), message.size());
119  }
JSharedCounter()
Default constructor.
char tag[TAGSIZE]
Definition: JTag.hh:247
JPrefix JPrefix_t
Definition: JLigier.cc:28
void create()
Allocate memory.
Definition: JLigier.cc:207
char * buffer
Definition: JLigier.cc:234
JNET::JDispatch::JDispatch ( const JDispatch message)
inline

Copy constructor.

Parameters
messagemessage

Definition at line 127 of file JLigier.cc.

128  {
129  static_cast<JPrefix_t&>(*this) = message;
130 
131  buffer = message.buffer;
132 
133  attach(message);
134  }
void attach(const JSharedCounter &object)
Attach this counter to given shared counter object.
JPrefix JPrefix_t
Definition: JLigier.cc:28
char * buffer
Definition: JLigier.cc:234
JNET::JDispatch::~JDispatch ( )
inline

Destructor.

Definition at line 140 of file JLigier.cc.

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

Member Function Documentation

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

Assignment operator.

Parameters
messagemessage
Returns
this JDispatch

Definition at line 153 of file JLigier.cc.

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

Type conversion operator.

Returns
socket output buffer

Definition at line 175 of file JLigier.cc.

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

Get size.

Returns
number of bytes

Definition at line 186 of file JLigier.cc.

187  {
188  return getSizeOfPacket(static_cast<const JPrefix_t&>(*this));
189  }
int getSizeOfPacket(const KM3NETDAQ::JDAQAbstractPreamble &preamble)
Definition: JDataFilter.cc:81
const char* JNET::JDispatch::data ( ) const
inline

Get data.

Returns
pointer to data

Definition at line 197 of file JLigier.cc.

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

Allocate memory.

Definition at line 207 of file JLigier.cc.

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

Release memory.

Definition at line 227 of file JLigier.cc.

228  {
230 
231  MEMORY_TOTAL -= size();
232  }
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:71
char * buffer
Definition: JLigier.cc:234
int size() const
Get size.
Definition: JLigier.cc:186
int JNET::JPrefix::getSize ( ) const
inlineinherited

Get size.

Returns
number of bytes

Definition at line 63 of file JPrefix.hh.

64  {
65  return ntohl(size);
66  }
void JNET::JPrefix::setSize ( const int  length)
inlineinherited

Set size.

Parameters
lengthnumber of bytes

Definition at line 74 of file JPrefix.hh.

75  {
76  size = htonl(length);
77  }
void JNET::JPrefix::set ( const JTag tag,
const int  length 
)
inlineinherited

Set prefix.

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

Definition at line 87 of file JPrefix.hh.

89  {
90  setTag (tag);
91  setSize(length);
92  }
void setSize(const int length)
Set size.
Definition: JPrefix.hh:74
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 32 of file JSharedCounter.hh.

33  {
34  detach();
35 
36  counter = new int(1);
37  }
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 45 of file JSharedCounter.hh.

46  {
47  detach();
48 
49  counter = object.counter;
50 
51  if (counter != NULL) {
52  ++(*counter);
53  }
54  }
bool detach()
Detach.
bool JLANG::JSharedCounter::detach ( )
inlineinherited

Detach.

Returns
true if counter at zero; else false

Definition at line 62 of file JSharedCounter.hh.

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

Member Data Documentation

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

Total size of data [Bytes].

Total memory allocation.

Definition at line 71 of file JLigier.cc.

long long int JNET::JDispatch::MEMORY_LIMIT
static

Limit size of data [Bytes].

Limit memory allocation.

Definition at line 72 of file JLigier.cc.

char* JNET::JDispatch::buffer
protected

Definition at line 234 of file JLigier.cc.

int JNET::JPrefix::size
protectedinherited

Definition at line 95 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 82 of file JSharedCounter.hh.


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