C12Adapter Opensource C++ Interface
MMonitor Class Reference

Abstract monitor to watch communication. More...

Inheritance diagram for MMonitor:

Public Types

enum  MessageType {
  MessageChannelAttach = 0x20,
  MessageChannelConnect = 0x21,
  MessageChannelDisconnect = 0x22,
  MessageChannelByteRx = 0x23,
  MessageChannelByteTx = 0x24,
  MessageProtocolLinkLayerInformation = 0x35,
  MessageProtocolLinkLayerRetry = 0x37,
  MessageProtocolLinkLayerFail = 0x39,
  MessageProtocolApplicationLayerStart = 0x3B,
  MessageProtocolApplicationLayerRetry = 0x3D,
  MessageProtocolApplicationLayerSuccess = 0x3F,
  MessageProtocolApplicationLayerFail = 0x41,
  MessageProtocolSynchronize = 0x43,
  MessageUser = 0x60
}
 Enumeration that defines supported monitor messages, and whether the parameters are expected. More...
 

Public Member Functions

 MMonitor ()
 Object constructor.
 
virtual ~MMonitor ()
 Object destructor.
 
bool IsListening () const
 Whether the monitor is interested in any events.
 
virtual void Attach (const MStdString &mediaIdentification)
 Tell that the application is starting a sequence of events that it would like to monitor, attach to the monitor. More...
 
virtual void Detach ()
 Detach from the monitor, if attached previously. More...
 
virtual void Write (const MStdString &str)
 Write the user message to the monitor. More...
 
virtual void OnMessage (MessageType code, const char *message, int length)
 Send message with the specified code. More...
 
virtual void OnConnect ()
 Notify that the channel has just connected.
 
virtual void OnDisconnect ()
 Notify that the channel is disconnected.
 
virtual void OnDataLinkLayerSuccess ()
 Notifies that the data link layer operation succeeded. More...
 
virtual void OnDataLinkLayerInformation (const MStdString &msg)
 Notifies about any neutral or positive information during the data link layer operations. More...
 
virtual void OnDataLinkLayerRetry (const MStdString &reason)
 Notifies that the last data link layer operation failed and will be repeated. More...
 
virtual void OnDataLinkLayerFail (const MStdString &msg)
 Notifies that the last data link layer operation failed and no other action will be performed. More...
 
virtual void OnApplicationLayerRetry (const MStdString &reason)
 Notifies that the last application layer operation failed and will be repeated. More...
 
virtual void OnApplicationLayerFail (const MStdString &service)
 Notifies that the last application layer operation failed and no other action will be performed. More...
 
virtual void OnApplicationLayerStart (const MStdString &service)
 Notifies that the application layer operation started. More...
 
virtual void OnApplicationLayerSuccess (const MStdString &service)
 Notifies that the last application layer operation succeeded. More...
 
virtual void OnEnterUninterruptibleCommunication ()
 Notifies that the uninterruptible communication sequence is entered. More...
 
virtual void OnLeaveUninterruptibleCommunication ()
 Notifies that the uninterruptible communication sequence is left. More...
 
virtual void OnByteRX (const char *data, int length)
 
void OnBytesReceived (const MByteString &data)
 
virtual void OnByteTX (const char *data, int length)
 
void OnBytesSent (const MByteString &data)
 
MObjectGetClient () const
 
void SetClient (MObject *client)
 
- Public Member Functions inherited from MObject
virtual ~MObject ()
 Object destructor.
 
virtual const MClassGetClass () 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 &params)
 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 &params)
 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 MStdStringVector GetAllPropertyNames () const
 Return the list of publicly available properties, persistent or not. More...
 
virtual MStdStringVector GetAllPersistentPropertyNames () const
 Return the list of persistent properties. 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...
 

Public Attributes

SHOW_INTERNAL typedef SharedPointer Pointer
 Pointer type that clients should use to access to monitor.
 

Protected Member Functions

void OnMessageWithText (MessageType code, const MStdString &text)
 Send text message with the specified code. More...
 
- Protected Member Functions inherited from MObject
 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...
 

Additional Inherited Members

- Static Public Member Functions inherited from MObject
static const MClassGetStaticClass ()
 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 Public Attributes inherited from MObject
static const MClass s_class
 Class of MObject.
 

Detailed Description

Abstract monitor to watch communication.

Concrete monitors will implement their specific actions to fulfill monitoring tasks, such as dumping the contents into a file, or sending it to an interactive monitor.

Sharing of monitors among simultaneously communicating channels can produce obscure output or lead to synchronization errors, therefore, each channel should have its own monitor object. The monitor is registered with the client channel object using the service MChannel::SetMonitor.

Note that when M_NO_MCOM_MONITOR_SHARED_POINTER=0 the monitor object should be created on a heap with operator new, and handled through the pointer type MMonitor::Pointer. The deletion of such object will be done through the stared pointer. When M_NO_MCOM_MONITOR_SHARED_POINTER=1 the user will be responsible for deletion of the object, however the monitor object should outlive the channel that it monitors.

Member Enumeration Documentation

Enumeration that defines supported monitor messages, and whether the parameters are expected.

Note that the values for this enumeration have to be kept for compatibility reasons.

Enumerator
MessageChannelAttach 

Channel is attached to the monitor.

The parameter is the channel identification.

MessageChannelConnect 

Channel connected, no parameter.

MessageChannelDisconnect 

Channel disconnected, no parameter.

MessageChannelByteRx 

Channel bytes received.

Byte string is the parameter.

MessageChannelByteTx 

Channel bytes transmitted.

Byte string is the parameter.

MessageProtocolLinkLayerInformation 

Link layer information message.

Information message is specified as parameter.

MessageProtocolLinkLayerRetry 

Link layer retry error message.

Retry message is specified as parameter.

MessageProtocolLinkLayerFail 

Link layer failure error message.

Fail message is specified as parameter.

MessageProtocolApplicationLayerStart 

Application layer information message.

Application layer start message is specified as parameter.

MessageProtocolApplicationLayerRetry 

Application layer retry error message.

Application layer retry message is specified as parameter.

MessageProtocolApplicationLayerSuccess 

Application layer success error message.

Application layer success message is specified as parameter.

MessageProtocolApplicationLayerFail 

Application layer failure error message.

Application layer failure message is specified as parameter.

MessageProtocolSynchronize 

Special message that has information about absolute time of messages in session.

MessageUser 

User message sent to the monitor.

User message is specified as parameter.

Member Function Documentation

virtual void MMonitor::Attach ( const MStdString mediaIdentification)
virtual

Tell that the application is starting a sequence of events that it would like to monitor, attach to the monitor.

The action is not immediate, and some time might pass before the monitor is attached. Any number of Attach can be issued, and they are not necessarily matched with the number of Detach calls.

Media identification is a string that somehow tells about the client. Like for the channel based on COM port, this would be the com port name, and for the socket it will be the address and the port.

Other preconditions will depend on implementation in the child class.

Reimplemented in MMonitorFile, MMonitorSocket, and MMonitorSyslog.

virtual void MMonitor::Detach ( )
virtual

Detach from the monitor, if attached previously.

The action is not immediate, and some time might pass before the monitor is detached. No matter for how much the Attach was called, Detach will schedule detachment of the monitor.

Reimplemented in MMonitorFile.

MObject* MMonitor::GetClient ( ) const
inline

Client that supports monitor messages through reflection.

virtual void MMonitor::OnApplicationLayerFail ( const MStdString service)
virtual

Notifies that the last application layer operation failed and no other action will be performed.

Precondition
The errors are not reported by this service.
virtual void MMonitor::OnApplicationLayerRetry ( const MStdString reason)
virtual

Notifies that the last application layer operation failed and will be repeated.

Precondition
The errors are not reported by this service.
virtual void MMonitor::OnApplicationLayerStart ( const MStdString service)
virtual

Notifies that the application layer operation started.

Precondition
The errors are not reported by this service.
virtual void MMonitor::OnApplicationLayerSuccess ( const MStdString service)
virtual

Notifies that the last application layer operation succeeded.

Precondition
The errors are not reported by this service.
virtual void MMonitor::OnByteRX ( const char *  data,
int  length 
)
virtual

Notify that the bytes are received by the channel.

Precondition
The errors are not reported by this service.
void MMonitor::OnBytesReceived ( const MByteString data)

Notify that the bytes are received by the channel.

Precondition
The errors are not reported by this service.
void MMonitor::OnBytesSent ( const MByteString data)

Notify that the bytes are sent through the channel.

Precondition
The errors are not reported by this service.
virtual void MMonitor::OnByteTX ( const char *  data,
int  length 
)
virtual

Notify that the bytes are sent through the channel.

Precondition
The errors are not reported by this service.
virtual void MMonitor::OnDataLinkLayerFail ( const MStdString msg)
virtual

Notifies that the last data link layer operation failed and no other action will be performed.

Precondition
The errors are not reported by this service.
virtual void MMonitor::OnDataLinkLayerInformation ( const MStdString msg)
virtual

Notifies about any neutral or positive information during the data link layer operations.

Precondition
The errors are not reported by this service.
virtual void MMonitor::OnDataLinkLayerRetry ( const MStdString reason)
virtual

Notifies that the last data link layer operation failed and will be repeated.

Precondition
The errors are not reported by this service.
virtual void MMonitor::OnDataLinkLayerSuccess ( )
virtual

Notifies that the data link layer operation succeeded.

Precondition
The errors are not reported by this service.
virtual void MMonitor::OnEnterUninterruptibleCommunication ( )
virtual

Notifies that the uninterruptible communication sequence is entered.

Precondition
The errors are not reported by this service.
virtual void MMonitor::OnLeaveUninterruptibleCommunication ( )
virtual

Notifies that the uninterruptible communication sequence is left.

Precondition
The errors are not reported by this service.
virtual void MMonitor::OnMessage ( MessageType  code,
const char *  message,
int  length 
)
virtual

Send message with the specified code.

Message is a sequence of bytes, and size is length of the sequence. No UNICODE version provided.

Reimplemented in MMonitorFile, and MMonitorSyslog.

void MMonitor::OnMessageWithText ( MessageType  code,
const MStdString text 
)
protected

Send text message with the specified code.

Default implementation will fit majority of cases, which include calling OnMessage with code and message possibly translated for UNICODE.

Precondition
The message code shall have both UNICODE and plain variants. There is a debug check for that. The given text shall be a valid zero-terminated string.
void MMonitor::SetClient ( MObject client)
inline

Client that supports monitor messages through reflection.

virtual void MMonitor::Write ( const MStdString str)
virtual

Write the user message to the monitor.

Writes the message to the binary log file (if one has been specified) and the Monitor (if one is attached to the connection). No error is generated if no log file has been specified or if no Monitor is attached to the connection.

The Write method can be used to make communication transactions more readable by marking key data transactions, such as the start/end of a test. Note that the Write occurs when it is issued and it cannot be inserted into the Queue services. For the code example below, the Monitor would get the Write Message "Read ST-001", before the Queue services Start Session, Read Table, End Session. The QCommit causes the commands in the Queue to be issued, so the Write Message was issued before any of the Queue services had been issued.

protocol.QStartSession();
protocol.QTableRead(1, 0, 0); // read ST1
protocol.QEndSession();
protocol.Monitor.Write("Read ST-001");
protocol.QCommit();
Parameters
strThe message to posted to the file and/or Monitor.
See also
MProtocol::QWriteToMonitor - inserts the message into the MProtocol queue.