JX Application Framework
Loading...
Searching...
No Matches
Public Member Functions | Protected Member Functions | List of all members
JMessageProtocol< ACE_PEER_STREAM_1 > Class Template Reference

#include <JMessageProtocol.h>

Inheritance diagram for JMessageProtocol< ACE_PEER_STREAM_1 >:
[legend]

Public Member Functions

 JMessageProtocol (const bool synchSend=false)
 
 JMessageProtocol (const ACE_HANDLE fd, const bool synchSend=false)
 
 ~JMessageProtocol () override
 
void GetProtocol (JString *separator, JString *disconnect) const
 
void SetProtocol (const JUtf8Byte *separatorStr, const JSize separatorByteCount, const JUtf8Byte *disconnectStr, const JSize disconnectByteCount)
 
void UseUNIXProtocol ()
 
void UseMacintoshProtocol ()
 
void UseDOSProtocol ()
 
bool ReceivedDisconnect () const
 
void SendDisconnect ()
 
bool HasMessages () const
 
JSize GetMessageCount () const
 
bool GetNextMessage (JString *message)
 
bool PeekNextMessage (JString *message)
 
bool PeekPartialMessage (JString *message)
 
void SendMessage (const JString &message)
 
void SendData (const JString &data)
 
bool WantsBlankMessages () const
 
void SetWantsBlankMessages (const bool wantsBlanks=true)
 
JSize GetBufferSize () const
 
void SetBufferSize (const JSize bufferSize)
 
int handle_input (ACE_HANDLE) override
 
- Public Member Functions inherited from JNetworkProtocolBase< ACE_PEER_STREAM_2 >
 JNetworkProtocolBase (const bool synch)
 
 ~JNetworkProtocolBase () override
 
bool DataPending () const
 
void Flush ()
 
bool WillSendSynch () const
 
void ShouldSendSynch (const bool synch=true)
 
int handle_output (ACE_HANDLE) override
 
- Public Member Functions inherited from JBroadcaster
 JBroadcaster ()
 
virtual ~JBroadcaster ()
 
JBroadcasteroperator= (const JBroadcaster &source)
 
bool HasSenders () const
 
JSize GetSenderCount () const
 
bool HasRecipients () const
 
JSize GetRecipientCount () const
 
virtual JString ToString () const
 
template<class T >
void ListenTo (const JBroadcaster *sender, const std::function< void(const T &)> &f)
 

Protected Member Functions

bool BytesEqual (const JString &s1, const JString &s2) const
 
- Protected Member Functions inherited from JNetworkProtocolBase< ACE_PEER_STREAM_2 >
void Send (const JString &data)
 
void Send (const JUtf8Byte *data, const JSize count)
 
void Send (const iovec data[], const JSize count)
 
- Protected Member Functions inherited from JBroadcaster
 JBroadcaster (const JBroadcaster &source)
 
void ListenTo (const JBroadcaster *sender)
 
void StopListening (const JBroadcaster *sender)
 
void ClearWhenGoingAway (const JBroadcaster *sender, void *pointerToMember)
 
void StopListening (const JBroadcaster *sender, const std::type_info &messageType)
 
template<class T >
void Send (JBroadcaster *recipient, const T &message)
 
template<class T >
void Broadcast (const T &message)
 
virtual void Receive (JBroadcaster *sender, const Message &message)
 
void SendWithFeedback (JBroadcaster *recipient, Message *message)
 
void BroadcastWithFeedback (Message *message)
 
virtual void ReceiveWithFeedback (JBroadcaster *sender, Message *message)
 
virtual void ReceiveGoingAway (JBroadcaster *sender)
 

Constructor & Destructor Documentation

◆ JMessageProtocol() [1/2]

template<ACE_PEER_STREAM_1 >
JMessageProtocol< ACE_PEER_STREAM_1 >::JMessageProtocol ( const bool  synchSend = false)

Parses incoming bytes into messages separated by itsSeparatorStr.

The data that you send can contain any byte sequence other than itsDisconnectStr. This sequence is reserved for terminating the connection. (You can set itsDisconnectStr to be empty.)

The default is the UNIX protocol which uses "\n" as separator and "\0" as terminator. Macintosh sets the separator to "\r", and DOS sets the separator to "\r\n". In general, the separator must not contain the terminator, and visa versa.

You cannot use the std::function version of ListenTo() because
the way this class broadcasts confuses the type inference.

◆ JMessageProtocol() [2/2]

template<ACE_PEER_STREAM_1 >
JMessageProtocol< ACE_PEER_STREAM_1 >::JMessageProtocol ( const ACE_HANDLE  fd,
const bool  synchSend = false 
)

◆ ~JMessageProtocol()

template<ACE_PEER_STREAM_1 >
JMessageProtocol< ACE_PEER_STREAM_1 >::~JMessageProtocol ( )
override

Client must call SendDisconnect() explicitly. This makes their code clearer. It also allows using this class on read-only connections because the client can ensure that nothing will ever be written.

Member Function Documentation

◆ BytesEqual()

template<ACE_PEER_STREAM_1 >
bool JMessageProtocol< ACE_PEER_STREAM_1 >::BytesEqual ( const JString s1,
const JString s2 
) const
protected

Compare raw bytes because control characters are often zero-length in UTF-8.

◆ GetBufferSize()

template<ACE_PEER_STREAM_1 >
JSize JMessageProtocol< ACE_PEER_STREAM_1 >::GetBufferSize ( ) const

This controls how much is read from the connection at one time.

◆ GetMessageCount()

template<ACE_PEER_STREAM_1 >
JSize JMessageProtocol< ACE_PEER_STREAM_1 >::GetMessageCount ( ) const

◆ GetNextMessage()

template<ACE_PEER_STREAM_1 >
bool JMessageProtocol< ACE_PEER_STREAM_1 >::GetNextMessage ( JString message)

Stores the next complete message in *message and removes it from the queue. Returns false if no complete messages are available.

◆ GetProtocol()

template<ACE_PEER_STREAM_1 >
void JMessageProtocol< ACE_PEER_STREAM_1 >::GetProtocol ( JString separator,
JString disconnect 
) const

◆ handle_input()

template<ACE_PEER_STREAM_1 >
int JMessageProtocol< ACE_PEER_STREAM_1 >::handle_input ( ACE_HANDLE  )
override

This is called when we receive data. It is also safe for anybody else to call it.

◆ HasMessages()

template<ACE_PEER_STREAM_1 >
bool JMessageProtocol< ACE_PEER_STREAM_1 >::HasMessages ( ) const

◆ PeekNextMessage()

template<ACE_PEER_STREAM_1 >
bool JMessageProtocol< ACE_PEER_STREAM_1 >::PeekNextMessage ( JString message)

Stores the next complete message in *message. Returns false if no complete messages are available.

◆ PeekPartialMessage()

template<ACE_PEER_STREAM_1 >
bool JMessageProtocol< ACE_PEER_STREAM_1 >::PeekPartialMessage ( JString message)

Stores the message that is being received in *message. Returns false if the message is empty.

◆ ReceivedDisconnect()

template<ACE_PEER_STREAM_1 >
bool JMessageProtocol< ACE_PEER_STREAM_1 >::ReceivedDisconnect ( ) const

◆ SendData()

template<ACE_PEER_STREAM_1 >
void JMessageProtocol< ACE_PEER_STREAM_1 >::SendData ( const JString data)

Sends the given data without a separator. The data can contain separators.

◆ SendDisconnect()

template<ACE_PEER_STREAM_1 >
void JMessageProtocol< ACE_PEER_STREAM_1 >::SendDisconnect ( )

◆ SendMessage()

template<ACE_PEER_STREAM_1 >
void JMessageProtocol< ACE_PEER_STREAM_1 >::SendMessage ( const JString message)

Sends the given data and then a separator. The data can contain separators.

◆ SetBufferSize()

template<ACE_PEER_STREAM_1 >
void JMessageProtocol< ACE_PEER_STREAM_1 >::SetBufferSize ( const JSize  bufferSize)

◆ SetProtocol()

template<ACE_PEER_STREAM_1 >
void JMessageProtocol< ACE_PEER_STREAM_1 >::SetProtocol ( const JUtf8Byte separatorStr,
const JSize  separatorByteCount,
const JUtf8Byte disconnectStr,
const JSize  disconnectByteCount 
)

◆ SetWantsBlankMessages()

template<ACE_PEER_STREAM_1 >
void JMessageProtocol< ACE_PEER_STREAM_1 >::SetWantsBlankMessages ( const bool  wantsBlanks = true)

◆ UseDOSProtocol()

template<ACE_PEER_STREAM_1 >
void JMessageProtocol< ACE_PEER_STREAM_1 >::UseDOSProtocol ( )

◆ UseMacintoshProtocol()

template<ACE_PEER_STREAM_1 >
void JMessageProtocol< ACE_PEER_STREAM_1 >::UseMacintoshProtocol ( )

◆ UseUNIXProtocol()

template<ACE_PEER_STREAM_1 >
void JMessageProtocol< ACE_PEER_STREAM_1 >::UseUNIXProtocol ( )

◆ WantsBlankMessages()

template<ACE_PEER_STREAM_1 >
bool JMessageProtocol< ACE_PEER_STREAM_1 >::WantsBlankMessages ( ) const

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