111 const std::string& message) :
117 memcpy(this->
buffer, static_cast<const JPrefix_t*>(
this),
sizeof(
JPrefix_t));
119 memcpy(this->
buffer +
sizeof(
JPrefix_t), message.data(), message.size());
130 static_cast<JPrefix_t&
>(*this) = message;
378 for (istringstream
is(subscription);
is >> c >> tag; ) {
438 queue.push_back(message);
452 for (std::deque<JDispatch>::iterator i =
queue.begin(); i !=
queue.end(); ) {
496 for (
iterator i = this->begin(); i != this->end(); ++i) {
507 for (
iterator i = this->begin(); i != this->end(); ++i) {
523 return out <<
"(" << message.
getTag() <<
"," << message.
size() <<
")";
579 int main(
int argc,
char* argv[])
604 catch(
const exception &error) {
605 FATAL(error.what() << endl);
609 JServerSocket server(port, backlog);
611 JClientList clientList;
614 DEBUG(
"Port " << setw(10) << port << endl);
622 select.setReaderMask(server);
624 for (JClientList::iterator
client = clientList.begin();
client != clientList.end(); ++
client) {
626 if (!
client->in.isReady()) {
627 select.setReaderMask(*
client);
630 if (
client->out.isReset()) {
632 if (!
client->queue.empty()) {
637 client->decrementRequest();
639 select.setWriterMask(*
client);
642 }
else if (
client->out.isBusy()) {
644 select.setWriterMask(*
client);
648 if (select(timeout_us) > 0) {
650 for (JClientList::iterator
client = clientList.begin();
client != clientList.end(); ) {
654 if (select.hasReaderMask(*
client)) {
659 catch(
const exception& error) {
661 ERROR(
"Remove (3) client" << *
client <<
"<" <<
client->getNickname() <<
">: " << error.what() << endl);
663 if (
client->getNickname() !=
"") {
674 DEBUG(
"Client" << *
client <<
".read" << static_cast<const JSocketInputBuffer&>(
client->in) << endl);
677 if (
client->in.isReady()) {
689 client->setSubscription(
string(
client->in.getRemainingData(),
client->in.getRemainingSize()));
693 client->setNickname(
string(
client->in.getRemainingData(),
client->in.getRemainingSize()));
699 client->incrementRequest();
707 string nick_name(
client->in.getRemainingData(),
client->in.getRemainingSize());
710 for (JClientList::iterator i = clientList.begin(); i != clientList.end(); ++i) {
711 if (i->getNickname() == nick_name) {
712 buffer +=
" " + i->getHostname();
716 JControlHost socket(*
client);
718 socket.PutFullString(
DISPTAG_WhereIs, buffer.substr(buffer.empty() ? 0 : 1));
734 for (JClientList::iterator i = clientList.begin(); i != clientList.end(); ++i) {
738 for (std::deque<JDispatch>::const_iterator message = i->queue.begin(); message != i->queue.end(); ++message) {
739 total += message->size();
742 cout <<
"client[" << i->getFileDescriptor() <<
"] " << i->getNickname() << endl;
743 cout <<
"tag - all:";
748 cout <<
"tag - any:";
753 cout <<
"queue " << i->queue.size() <<
' ' << total <<
"B" << endl;
760 istringstream
is(
string(
client->in.getRemainingData(),
client->in.getRemainingSize()));
772 clientList.add(JDispatch(
client->in.prefix,
client->in.data()));
785 if (select.hasWriterMask(*
client)) {
789 DEBUG(
"Client" << *
client <<
".write" << static_cast<const JSocketStatus&>(
client->out) << endl);
791 if (
client->out.isReady()) {
793 client->queue.pop_front();
799 catch(
const exception& error) {
801 DEBUG(
"Remove (2) client" << *
client <<
"<" <<
client->getNickname() <<
">: " << error.what() << endl);
803 if (
client->getNickname() !=
"") {
813 if (select.hasReaderMask(server)) {
817 socket.accept(server.getFileDescriptor());
822 socket.setKeepAlive (
true);
823 socket.setNonBlocking(
true);
825 DEBUG(
"New client" << socket << endl);
827 clientList.push_back(JClient(socket));
JSocketNonblockingWriter out
writer for outgoing messages
bool setSubscription(const std::string &subscription)
Set subcription.
Utility class to parse command line options.
static const JTag DISPTAG_Subscribe("_Subscri")
Special ControlHost tags.
std::set< JTag > subscriptionAll
int getSizeOfPacket(const KM3NETDAQ::JDAQAbstractPreamble &preamble)
Get size of packeet.
static const int DISPATCH_PORT
Default ControlHost port.
JDispatch & operator=(const JDispatch &message)
Assignment operator.
static const JTag DISPTAG_Died("Died")
int main(int argc, char *argv[])
Data structure of a ControlHost message.
void setSize(const long long int length)
Set size.
JSocketBuffer< const char > JSocketOutputBuffer
void setRequestAll()
Set no request.
ControlHost client manager.
std::deque< JDispatch > queue
queue for outgoing messages
void release()
Release memory.
Auxiliary class for non-blocking socket I/O.
List of ControlHost client managers.
std::set< JTag > subscriptionAny
static const JTag DISPTAG_MyId("_MyId")
void attach(const JSharedCounter &object)
Attach this counter to given shared counter object.
void setNickname(const std::string &nick_name)
Set nick name.
static const JTag DISPTAG_WhereIs("_WhereIs")
bool checkRequest() const
Check request.
bool checkSubscription(const JPrefix_t &prefix) const
Check subscription for given prefix.
JClient()
Default constructor.
const std::string & getNickname() const
Get nick name.
void decrementRequest()
Decrement request by one.
bool checkSubscriptionAll(const JPrefix_t &prefix) const
Check subscription for given prefix.
static long long int MEMORY_LIMIT
Limit size of data [Bytes].
int getSize() const
Get size.
JClientList()
Default constructor.
static void release(T *p)
Release memory.
bool checkSubscriptionAny(const JPrefix_t &prefix) const
Check subscription for given prefix.
int getFileDescriptor() const
Get file descriptor.
JSocketInputChannel_t in
reader for incoming messages
int getCounter() const
Get number of I/O attempts.
std::ostream & operator<<(std::ostream &out, const JDispatch &message)
Print message.
Non-blocking socket writer.
const std::set< JTag > & getSubscriptionAll() const
Get subscription.
then echo Test string reversed by client(hit< return > to continue)." $DIR/JProcess -c "$DIR/JEcho-r" -C fi if (( 1 ))
void incrementRequest()
Increment request by one.
#define make_field(A,...)
macro to convert parameter to JParserTemplateElement object
bool isReady() const
Check ready status.
void add(const JDispatch &message)
Add message to client queues depending on subscription of each client.
Memory management class for create/release policy based on malloc()/free().
Exception for failure of memory allocation.
static const size_t buffer_size
JDispatch()
Default constructor.
void drop()
Drop all messages for which the client has not the 'all' subscription.
JDispatch(const JPrefix_t &prefix, const char *data)
Constructor.
JDispatch(const JDispatch &message)
Copy constructor.
void create()
Allocate memory.
void drop()
Drop all messages from client queues for which the client has not the 'all' subscription.
Exception for ControlHost.
JClient(const JSocket &socket)
Constructor.
const std::set< JTag > & getSubscriptionAny() const
Get subscription.
const JTag & getTag() const
Get tag.
static bool maybe_special(const JTag &tag)
Check special ControlHost tags.
General purpose messaging.
void initialise()
Initialise counter.
static const JTag DISPTAG_Born("Born")
static long long int MEMORY_TOTAL
Total size of data [Bytes].
JMalloc< char > JMemory_t
static unsigned int QUEUE_LIMIT
Maximum number of messages in queue.
static const long long int GIGABYTE
Number of bytes in a mega-byte.
const char * data() const
Get data.
Utility class to parse command line options.
void add(const JDispatch &message)
Add message to client queues depending on subscription of each client.
unsigned long long int getRAM()
Get RAM of this CPU.
static const JTag DISPTAG_Gime("_Gime")
then usage $script< input_file >< detector_file > fi set_variable OUTPUT_DIR set_variable SELECTOR JDAQTimesliceL1 set_variable DEBUG case set_variable DEBUG
int getSize() const
Get size of pending data.
JSocketInputChannel< JPrefix_t > JSocketInputChannel_t
void setSizeOfPacket(const int size, JPrefix_t &prefix)
Set total size of internet packet.
static const JTag DISPTAG_Debug("_Debug")
static const JTag DISPTAG_Always("_Always")
Base class for memory management.
Auxiliary class for non-blocking socket I/O.
static T * create()
Create object in memory.
bool isBusy() const
Check busy status.
int size() const
Get size.
static const JTag DISPTAG_ShowStat("_ShowSta")
JDispatch(const JTag &tag, const std::string &message)
Constructor.