C12Adapter Opensource C++ Interface
|
Implements the channel interface for an UDP datagram socket. More...
Public Types | |
enum | { MaximumUdpDatagramSize = 1500 } |
![]() | |
enum | { CANCEL_COMMUNICATION_CHECK_OPTIMUM_INTERVAL = 1000 } |
Public Member Functions | |
MChannelSocketUdp () | |
Construct the socket channel. | |
virtual | ~MChannelSocketUdp () |
Destructor. | |
virtual void | Connect () |
Establishes connection to the meter using a socket. More... | |
virtual void | WaitForNextIncomingConnection (bool reinitialize=true) |
When GetAutoAnswer true, wait for the incoming connection without disconnecting the channel. More... | |
void | WriteDatagramBuffer (const char *buff, unsigned size) |
Send the whole datagram given as data pointer and size into the UDP socket. More... | |
void | WriteDatagram (const MByteString &bytes) |
Send the whole datagram to the UDP socket. More... | |
unsigned | ReadDatagramBuffer (char *buff, unsigned size) |
Receive the datagram given as data pointer and size. More... | |
MByteString | ReadDatagram () |
Receive the datagram. More... | |
const MStreamSocketUdp & | GetSocketConst () const |
Get the constant socket object that is used by this channel. | |
MStreamSocketUdp & | GetSocket () |
virtual void | SetSocket (MStreamSocketBase &other) |
![]() | |
virtual | ~MChannelSocketBase () |
Destructor. | |
virtual bool | IsConnected () const |
Returns the current state of the socket channel. | |
virtual void | Disconnect () |
Partly implemented disconnect method, overridden by children. More... | |
const MStreamSocketBase & | GetSocketConst () const |
Get the constant socket object that is used by this channel. | |
MStdString | GetActualLocalAddress () const |
Get the actual address of the local socket as it is known by Sockets. More... | |
unsigned | GetActualLocalPort () const |
Get the actual port number of the local socket as it is known by Sockets. More... | |
MStdString | GetActualPeerAddress () const |
Get the actual address of the peer socket as it is known by Sockets. More... | |
unsigned | GetActualPeerPort () const |
Get the actual port number of the peer socket as it is known by Sockets. More... | |
virtual void | FlushOutputBuffer (unsigned numberOfCharsInBuffer=UINT_MAX) |
Ensure that the characters from the output buffer are sent. More... | |
virtual MStdString | GetMediaIdentification () const |
Return a string that identifies the media through which this channel is talking. More... | |
unsigned | GetAutoAnswerPort () const |
void | SetAutoAnswerPort (unsigned port) |
const MStdString & | GetAutoAnswerAddress () const |
void | SetAutoAnswerAddress (const MStdString &addr) |
MStreamSocketBase & | GetSocket () |
const MStdString & | GetPeerAddress () const |
void | SetPeerAddress (const MStdString &addr) |
unsigned | GetPeerPort () const |
void | SetPeerPort (unsigned port) |
![]() | |
virtual MChannel * | CreateClone () const |
Virtual copy constructor, creates the channel, which is a clone of current. More... | |
virtual | ~MChannel () |
The destructor is public, and virtual. More... | |
void | WriteBytes (const MByteString &buffer) |
Writes the data to the channel, and returns when the last byte has been sent by the software. More... | |
void | WriteByte (Muint8 b) |
Writes a byte to the channel, and returns when it has been sent. More... | |
void | WriteBuffer (const char *buf, unsigned len) |
Writes the data buffer to the channel, and returns when the last character has been sent by the software (but hardware might still need to do some work). More... | |
Muint8 | ReadByte () |
Read a single byte from the channel. More... | |
void | ReadBuffer (char *buf, unsigned numberToRead) |
Read an exact number of characters from the channel. More... | |
void | Unread (const MVariant &byteOrBytes) |
Return the given byte or bytes to the stream buffer so they get read at the next read operation. More... | |
void | UnreadBuffer (const char *buff, unsigned size) |
Return the given bytes to the stream buffer so they get read at the next read operation. More... | |
MByteString | ReadBytes (unsigned numberToRead) |
Read bytes directly from the communication channel. More... | |
MByteString | ReadBytesUntil (const MByteString &terminatingString) |
Read bytes from the channel until a specified sequence is read. More... | |
MByteString | ReadBytesUntilAnyByte (const char *finisher, unsigned finisherSize, unsigned headerSize, unsigned footerSize) |
Read bytes from the channel until a specified sequence is read. More... | |
MByteString | ReadAllBytes () |
Read an arbitrary number of characters from the channel, as much as available. More... | |
void | ClearInputBuffer () |
Immediately discards all the pending characters from the channel. More... | |
void | ClearInputUntilSilence (unsigned milliseconds) |
Keep reading and ignoring input until there is silence. More... | |
virtual void | CheckIfConnected () |
Throw an appropriate exception if the channel is not connected. More... | |
void | CheckIfConnectedConst () const |
Throw an appropriate exception if the channel is not connected, constant version. More... | |
unsigned | GetCountBytesSent () const |
Number of bytes sent through the channel since its creation or since the last ResetCounts(). More... | |
unsigned | GetCountBytesReceived () const |
The number of bytes received through the channel since creation or since the last ResetCounts(). More... | |
void | ResetCounts () |
Reset channel statistical data, so the counters become zeros. More... | |
virtual void | WriteToMonitor (const MStdString &message) |
Synchronously write a message to the monitor, if it is connected. More... | |
virtual void | CancelCommunication (bool callDisconnect=false) |
Request canceling of the communication. More... | |
void | EnterUninterruptibleCommunication (bool notify=true) |
Enter a communication sequence that shall not be be interrupted with CancelCommunication call. More... | |
void | LeaveUninterruptibleCommunication (bool notify=true) |
Leave a communication sequence that shall not be be interrupted with CancelCommunication call. More... | |
void | CheckIfOperationIsCancelled () |
Check if the user has requested the termination of the communication, and whether the cancel operation lock is zero. More... | |
void | Sleep (unsigned milliseconds) |
Channel version of Sleep, a delay function that is aware of cancel communication event. More... | |
unsigned | ReadWithTimeout (char *buf, unsigned size, unsigned timeout) |
Read up to size bytes into buffer using the given timeout. More... | |
bool | GetAutoAnswer () const |
void | SetAutoAnswer (bool isAutoAnswer) |
unsigned | GetAutoAnswerTimeout () const |
void | SetAutoAnswerTimeout (unsigned timeout) |
void | SetMonitor (MMonitor::Pointer monitor) |
MMonitor::Pointer | GetMonitor () const |
SHOW_INTERNAL bool | GetEcho () const |
void | SetEcho (bool echo) |
bool | GetSendEchoBytesToMonitor () const |
void | SetSendEchoBytesToMonitor (bool doSend) |
unsigned | GetIntercharacterTimeout () const |
void | SetIntercharacterTimeout (unsigned timeout) |
unsigned | GetReadTimeout () const |
void | SetReadTimeout (unsigned timeout) |
unsigned | GetWriteTimeout () const |
void | SetWriteTimeout (unsigned timeout) |
![]() | |
virtual | ~MCOMObject () |
Object destructor. | |
virtual MStdStringVector | GetAllPropertyNames () const |
Return the list of publicly available properties in MCOM syntax. More... | |
virtual MStdStringVector | GetAllPersistentPropertyNames () const |
Return the list of publicly available persistent properties in MCOM syntax. More... | |
MStdString | GetPersistentPropertyValues (bool onlyNondefaults=false, bool excludeSecurityRelated=false) const |
Get the string with the list of persistent property names and their values. More... | |
void | SetPersistentPropertyValues (const MStdString &values) |
Set the persistent properties for the object using the string with the following format: More... | |
void | SetPropertyValues (const MDictionary &values) |
Set the properties for the object using the property list object. More... | |
void | WritePropertiesToMonitor () |
Write all non-default values of protocol properties into monitor. More... | |
MStdString | DoGetPersistentPropertyValues0 () const |
Get the string with the whole list of persistent property names and their values. More... | |
MStdString | DoGetPersistentPropertyValues1 (bool onlyNondefaults) const |
Get the string with the list of persistent property names and their values. More... | |
![]() | |
virtual | ~MObject () |
Object destructor. | |
virtual const MClass * | GetClass () const =0 |
Get the final class of the object. More... | |
virtual unsigned | GetEmbeddedSizeof () const |
For embedded object types, return the size of the class. More... | |
bool | IsEmbeddedObject () const |
Tell if the object is of embedded kind. More... | |
SHOW_INTERNAL MVariant | Call (const MStdString &name, const MVariant ¶ms) |
Call the object service with parameters, given as variant. More... | |
MVariant | Call0 (const MStdString &name) |
Call the object service with no parameters. More... | |
MVariant | Call1 (const MStdString &name, const MVariant &p1) |
Call the object service with one parameter. More... | |
MVariant | Call2 (const MStdString &name, const MVariant &p1, const MVariant &p2) |
Call the object service with two parameter. More... | |
MVariant | Call3 (const MStdString &name, const MVariant &p1, const MVariant &p2, const MVariant &p3) |
Call the object service with three parameter. More... | |
MVariant | Call4 (const MStdString &name, const MVariant &p1, const MVariant &p2, const MVariant &p3, const MVariant &p4) |
Call the object service with four parameter. More... | |
MVariant | Call5 (const MStdString &name, const MVariant &p1, const MVariant &p2, const MVariant &p3, const MVariant &p4, const MVariant &p5) |
Call the object service with five parameter. More... | |
MVariant | Call6 (const MStdString &name, const MVariant &p1, const MVariant &p2, const MVariant &p3, const MVariant &p4, const MVariant &p5, const MVariant &p6) |
Call the object service with six parameter. More... | |
virtual MVariant | CallV (const MStdString &name, const MVariant::VariantVector ¶ms) |
Call the object service with parameters, given as variant vector. More... | |
virtual bool | IsPropertyPresent (const MStdString &name) const |
Tell if the property with the given name exists. | |
virtual bool | IsServicePresent (const MStdString &name) const |
Tell if the service with the given name exists. | |
virtual MVariant | GetProperty (const MStdString &name) const |
Get the property value using name of the property. More... | |
virtual void | SetProperty (const MStdString &name, const MVariant &value) |
Set the property using name of the property, and value. More... | |
virtual void | SetPersistentPropertiesToDefault () |
Set the persistent properties of the object to their default values. More... | |
virtual MVariant | GetPersistentPropertyDefaultValue (const MStdString &name) const |
Get the default value of persistent property with the name given. More... | |
virtual void | SetPersistentPropertyToDefault (const MStdString &name) |
Set the persistent property with the name given to default value. More... | |
virtual const char * | GetType () const |
Get the name of the type for the object (could be the same as class name). | |
virtual void | SetType (const MStdString &) |
Intentionally, it will set the name of the type for the object, but the service will not allow setting the name to anything other than the current name. More... | |
virtual void | Validate () |
Validate internal structures of the object. More... | |
Additional Inherited Members | |
![]() | |
static const MClass * | GetStaticClass () |
Get the declared class of this particular object. More... | |
static bool | IsClassPresent (const MStdString &name) |
Tells if the given class name is available. More... | |
![]() | |
static const MClass | s_class |
Class of MObject. | |
![]() | |
MChannelSocketBase () | |
Construct the abstract socket channel. | |
![]() | |
MChannel () | |
Construct the channel object from parent class. More... | |
![]() | |
MCOMObject () | |
Object constructor, protected as the class is abstract. | |
![]() | |
MObject () | |
Object constructor, protected as the class is abstract. | |
void | DoSetPersistentPropertiesToDefault (const MClass *staticClass) |
Set the persistent properties to their default values for one object provided the class for that object. More... | |
Implements the channel interface for an UDP datagram socket.
anonymous enum |
Enumerator | |
---|---|
MaximumUdpDatagramSize |
Maximum practical size of UDP datagram. The theoretical UDP datagram size is 65,535 according to https://en.wikipedia.org/wiki/User_Datagram_Protocol. However, such size is not practical as UDP size is typically selected to be smaller than MTU (Maximum Transmission Unit of the media). According to http://stackoverflow.com/questions/1098897/what-is-the-largest-safe-udp-packet-size-on-the-internet the value 1500 is a good practical maximum, while in reality the size is even smaller to make sure the packet is never reassembled. |
|
virtual |
Establishes connection to the meter using a socket.
Implements MChannelSocketBase.
|
inline |
Socket object that is used by this channel.
Setting UDP socket object has a feature: what actually happens, this channel's socket is swapped with the given UDP socket. MChannelSocketUdp accepts only MStreamSocketUdp object as input.
MByteString MChannelSocketUdp::ReadDatagram | ( | ) |
Receive the datagram.
While the standard Channel data reading methods work just fine with UDP, this UDP specific method guarantees calling a single recvfrom method of socket interface. Because the method bypasses certain logic of the base channel class, unread bytes are not seen when ReceiveDatagram is called.
After receiving the buffer, the address and port from where the data were got are available as GetActualPeerAddress and GetActualPeerPort.
If the datagram was not received for the duration of GetReadTimeout, an exception is thrown. Any other socket related exception is also possible. Just as any channel sending call, the operation is cancellable, in which case MEOperationCancelled is thrown.
unsigned MChannelSocketUdp::ReadDatagramBuffer | ( | char * | buff, |
unsigned | size | ||
) |
Receive the datagram given as data pointer and size.
While the standard Channel data reading methods work just fine with UDP, this UDP specific method guarantees calling a single recvfrom method of socket interface. Because the method bypasses certain logic of the base channel class, unread bytes are not seen when ReceiveDatagram is called.
After receiving the buffer, the address and port from where the data were got are available as GetActualPeerAddress and GetActualPeerPort.
If the datagram was not received for the duration of GetReadTimeout, an exception is thrown. Any other socket related exception is also possible. Just as any channel sending call, the operation is cancellable, in which case MEOperationCancelled is thrown.
buff | Write only buffer pointer of the datagram. |
size | Size of the buffer. |
|
virtual |
Socket object that is used by this channel.
Setting UDP socket object has a feature: what actually happens, this channel's socket is swapped with the given UDP socket. MChannelSocketUdp accepts only MStreamSocketUdp object as input.
Implements MChannelSocketBase.
|
virtual |
When GetAutoAnswer true, wait for the incoming connection without disconnecting the channel.
A typical server application sequence that uses this call:
reinitialize | When true, the channel is reinitialized at each new incoming connection. |
Reimplemented from MChannel.
void MChannelSocketUdp::WriteDatagram | ( | const MByteString & | bytes | ) |
Send the whole datagram to the UDP socket.
While the standard Channel data writing methods work just fine with UDP, this UDP specific method guarantees calling a single sendto method of socket interface.
The address and port where the data will be sent is determined by GetPeerAddress and GetPeerPort.
If the datagram was not sent for the duration of GetWriteTimeout, an exception is thrown. Any other socket related exception is also possible. Just as any channel sending call, the operation is cancellable, in which case MEOperationCancelled is thrown.
bytes | Datagram buffer |
void MChannelSocketUdp::WriteDatagramBuffer | ( | const char * | buff, |
unsigned | size | ||
) |
Send the whole datagram given as data pointer and size into the UDP socket.
While the standard Channel data writing methods work just fine with UDP, this UDP specific method guarantees calling a single sendto method of socket interface.
The address and port where the data will be sent is determined by GetPeerAddress and GetPeerPort.
If the datagram was not sent for the duration of GetWriteTimeout, an exception is thrown. Any other socket related exception is also possible. Just as any channel sending call, the operation is cancellable, in which case MEOperationCancelled is thrown.
buff | Constant buffer pointer of the datagram. |
size | Size of the buffer. |