1 #ifndef __JNET__JCONTROLHOST__
2 #define __JNET__JCONTROLHOST__
23 namespace JPP {
using namespace JNET; }
148 const_iterator p = this->find(subscription);
150 if (p != this->end() && p->getID() == subscription.
getID()) {
159 this->insert(p, subscription);
174 for (const_iterator i = this->begin(); i != this->end(); ++i)
175 buffer +=
' ' + i->toString();
222 public JThrow<JControlHost>
244 return tag[0] ==
'_';
360 int MyId(
const std::string& nick_name)
407 write((
char*) buffer, length);
413 return Throw(error, -1);
434 return Throw(error, -1);
437 return Throw(error, -2);
450 const std::string& buffer)
464 const std::string& buffer)
466 return PutFullData(tag, buffer.c_str(), buffer.size());
496 return Throw(error, -1);
544 return Throw(error, -1);
557 int CheckHead(std::string& tag,
int& length,
const int timeout_us = 0)
559 const int rvalue =
CheckHead(this->prefix, timeout_us);
562 tag = this->prefix.
getTag();
563 length = this->prefix.
getSize();
581 read((
char*) buffer, length);
586 return Throw(error, -1);
599 buffer.resize(this->prefix.
getSize());
601 return GetFullData((
char*) buffer.data(), buffer.size());
613 static int WhereIs(
const std::string& host_name,
614 const std::string& nick_name,
634 return Throw(error, -1);
658 return Throw(error, -1);
void setReuseAddress(const bool on)
Set reuse address.
static const JTag DISPTAG_Subscribe("_Subscri")
Special ControlHost tags.
JSubscription_t getSubscription() const
Get subscription type.
int Subscribe(const JSubscriptionList &subscription)
Subscribe to list of tags.
static const int DISPATCH_PORT
Default ControlHost port.
JNET::JSubscriptionList getSubscription(const JEventTable &event_table)
Convert event table to ControlHost subscription.
JSubscriptionAll(const JTag &tag)
Constructor.
int MyId(const std::string &nick_name)
Identify.
JSubscription_t
ControlHost subscription types.
int write(const char *buffer, const int length)
Write data to socket.
static const std::string CHOO_VERSION
const char * c_str() const
C-string.
void setSendBufferSize(const int size)
Set send buffer size.
int Connected()
Send version.
Auxiliary base class for controling the throwing of exceptions.
static JTimeval min()
Get minimal time value.
int PutFullString(const std::string &tag, const std::string &buffer)
Send string.
static const JTag DISPTAG_MyId("_MyId")
std::string toString() const
Convert subscription list to string.
int Subscribe(const JSubscription &subscription)
Subscribe to single tag.
int SendMeAlways()
Tell server to send messages forever.
static const JTag DISPTAG_WhereIs("_WhereIs")
Auxiliary data structure for hostname and port number.
std::string toString() const
Convert subscription to string.
int PutFullData(const std::string &tag, const void *buffer, const int length)
Send data.
int getSize() const
Get size.
int WaitHead(std::string &tag, int &length)
Wait for header.
JControlHost(const JSocket &socket)
Constructor.
static const JTag DISPTAG_Version("_Version")
Auxiliary class for time values.
int CheckHead(JPrefix &prefix, JTimeval timeout=JTimeval::min())
Check for header, without waiting.
bool in_avail(JTimeval timeout=JTimeval::min()) const
Check availability of input.
JSubscription(const JSubscription_t sub, const JTag &tag)
Constructor.
JSubscriptionList()
Default constructor.
JControlHost(const std::string &server, const int port)
Constructor.
JControlHost(const int ip_number, const int port=DISPATCH_PORT)
Constructor.
JControlHost(const JHostname &server)
Constructor.
int GetFullString(std::string &buffer)
Receive string.
int shutdown()
Shut down socket.
JControlHost ControlHost
Match name.
int SendMeNext()
Tell server to send next message.
JTag_t getID() const
Get identifier.
Auxiliary class for any subscription.
JSubscriptionList operator+(const JSubscription &first, const JSubscription &second)
Add operator.
JControlHost & operator=(const JControlHost &)
JSubscriptionList & add(const JSubscription &subscription)
Add subscription.
Exception for ControlHost.
void set(const JTag &tag, const int length)
Set prefix.
Auxiliary class for all subscription.
JSubscriptionAny(const JTag &tag)
Constructor.
static bool is_valid(const char c)
Check validity of subscription specifier.
const JTag & getTag() const
Get tag.
static bool maybe_special(const JTag &tag)
Check special ControlHost tags.
void setReceiveBufferSize(const int size)
Set receive buffer size.
int WaitHead(JPrefix &prefix)
Wait for header.
std::string toString() const
Convert tag to string.
int configure()
Configure socket (factory reset).
int CheckHead(std::string &tag, int &length, const int timeout_us=0)
Check for header, without waiting.
static const JTag DISPTAG_Gime("_Gime")
ControlHost subscription.
void connect(const int port)
Connect to port on local host.
void setNonBlocking(const bool on)
Set non-blocking of I/O.
void setKeepAlive(const bool on)
Set keep alive of socket.
static int WhereIs(const std::string &host_name, const std::string &nick_name, std::string &answer)
Locate ControlHost client(s).
void setTcpNoDelay(const bool on)
Set TCP no-delay.
int read(char *buffer, const int length)
Read data from socket.
static const JTag DISPTAG_Always("_Always")
~JControlHost()
Destructor.
JSubscription_t subscription
static void Throw(const bool option)
Enable/disable throw option.
int PutFullString(const JTag &tag, const std::string &buffer)
Send string.
int GetFullData(void *buffer, int length)
Receive data.
JControlHost()
Default constructor.
int PutFullData(const JTag &tag, const void *buffer, const int length)
Send data.