C12Adapter Opensource C++ Interface
MMonitorFile Class Reference

Activity monitor object that dumps communication into a binary file. More...

Inheritance diagram for MMonitorFile:

Public Member Functions

 MMonitorFile (const MStdString &fileName=MVariant::s_emptyString)
 Constructor that creates a monitor with the given file name, or without file name, in which case no monitoring will be done. More...
 
virtual ~MMonitorFile ()
 Object destructor. More...
 
virtual void Attach (const MStdString &clientIdentitfication)
 Tell that the application is starting a sequence of events that it would like to monitor, attach by attempting to open the file. More...
 
virtual void Detach ()
 Detach from the monitor by attempting to close the file, if it was open previously. More...
 
void DeleteFile ()
 Delete the file, if it was previously created. More...
 
virtual void OnMessage (MessageType code, const char *message, int length)
 Send text message with the specified code. More...
 
virtual void OnPageBoundHit ()
 What to do when the new page is about to be written. More...
 
const MStdStringGetFileName () const
 
void SetFileName (const MStdString &name)
 
unsigned GetMaxFileSizeKB () const
 
void SetMaxFileSizeKB (unsigned size)
 
bool GetObfuscate () const
 
void SetObfuscate (bool yes)
 
- Public Member Functions inherited from MMonitor
 MMonitor ()
 Object constructor.
 
virtual ~MMonitor ()
 Object destructor.
 
bool IsListening () const
 Whether the monitor is interested in any events.
 
virtual void Write (const MStdString &str)
 Write the user message to the monitor. 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...
 

Protected Member Functions

void DoFileDetach ()
 This service finalizes and detaches the file, if it was set up previously. More...
 
void DoFinish ()
 This service shall be called from every destructor of the child class. More...
 
virtual unsigned DoSendBackgroundBuffer (const MByteString &backgroundThreadBuffer)
 Send the buffer to the monitor entity on the background. More...
 
void OnIdle ()
 Background worker thread callable function which implements monitor communication. More...
 
void PostSyncMessage ()
 Places the synchronization message to message queue. More...
 
- Protected Member Functions inherited from MMonitor
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

- Public Types inherited from MMonitor
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...
 
- 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...
 
- Public Attributes inherited from MMonitor
SHOW_INTERNAL typedef SharedPointer Pointer
 Pointer type that clients should use to access to monitor.
 
- Static Public Attributes inherited from MObject
static const MClass s_class
 Class of MObject.
 

Detailed Description

Activity monitor object that dumps communication into a binary file.

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.

Constructor & Destructor Documentation

MMonitorFile::MMonitorFile ( const MStdString fileName = MVariant::s_emptyString)

Constructor that creates a monitor with the given file name, or without file name, in which case no monitoring will be done.

Precondition
The object should be created on a heap with operator new, and handled with a shared pointer, otherwise the behavior is undefined. File, if given, shall be a valid directory or a file name, but the check is deferred to the attaching time.
virtual MMonitorFile::~MMonitorFile ( )
virtual

Object destructor.

The children of this class shall call DoFinish in their destructors.

Member Function Documentation

virtual void MMonitorFile::Attach ( const MStdString clientIdentitfication)
virtual

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

The action is not immediate, and some time might pass before the file is open.

Client 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. It is used to construct default file name for MMonitorFile, if the file is not specified directly.

Reimplemented from MMonitor.

Reimplemented in MMonitorSocket.

void MMonitorFile::DeleteFile ( )

Delete the file, if it was previously created.

Deletes the binary log file that stores the communication transactions. It does NOT clear the data from the Monitor if one is attached to the connection.

virtual void MMonitorFile::Detach ( )
virtual

Detach from the monitor by attempting to close the file, if it was open previously.

The action is not immediate, and some time might pass before the file is closed.

Reimplemented from MMonitor.

void MMonitorFile::DoFileDetach ( )
protected

This service finalizes and detaches the file, if it was set up previously.

Precondition
There is no error to detach if there was no file attached.
void MMonitorFile::DoFinish ( )
protected

This service shall be called from every destructor of the child class.

It does all necessary preparations to finish the background processing at the level of the most upper class of the hierarchy where all virtuals have their final meaning.

Precondition
Called from destructor, no check is done for such precondition. It is okay to call this service multiple times, like from a child destructor, and from the destructor of its parent.
virtual unsigned MMonitorFile::DoSendBackgroundBuffer ( const MByteString backgroundThreadBuffer)
protectedvirtual

Send the buffer to the monitor entity on the background.

The returned value is nonzero if the class is still interested in receiving the messages. The children classes can overload this service to provide their ways of monitoring the events. Typically they will call the parent implementation, and return nonzero unconditionally if the parent returned nonzero.

Precondition
Called from the Run procedure of the background thread. No check is done for such precondition.
const MStdString& MMonitorFile::GetFileName ( ) const
inline

The path and name of the file that will be used to store communication data.

If the file name is "", then none of the communication data is saved. The FileName must be specified before the client wants to start saving data. The communication data is saved to the file as the transaction occurs. If the specified file already exists, then no error or warning is generated and the new data is appended to the existing file.

The file will be in binary format. To view the communication transactions, load the file into the Monitor. The Monitor does NOT have to be running in order for communication data to be written to the file.

Default value:
"" (empty string)
Possible values:
  • Any valid path and file name.
unsigned MMonitorFile::GetMaxFileSizeKB ( ) const
inline

Maximum size of the binary log file in kilobytes.

Once the file reaches the maximum size, it does not get any bigger. Old data is removed from the file as new data is added. The file will always contain the latest communication data.

Default value:
0 : A zero value indicates that there is no restriction on the size of the file.
Possible values:
  • 0 .. 2,147,483,647
bool MMonitorFile::GetObfuscate ( ) const
inline

Whether or not the file shall be obfuscated.

void MMonitorFile::OnIdle ( )
protected

Background worker thread callable function which implements monitor communication.

Note it is not currently virtual.

Precondition
This shall be called by the worker polling thread, otherwise the behavior is undefined.
virtual void MMonitorFile::OnMessage ( MessageType  code,
const char *  message,
int  length 
)
virtual

Send text message with the specified code.

Precondition
Code is valid and message has a valid format.

Reimplemented from MMonitor.

virtual void MMonitorFile::OnPageBoundHit ( )
virtual

What to do when the new page is about to be written.

This can be used to write some special message that has to be present on every page. For instance, feature is used to have absolute timestamps in the log.

void MMonitorFile::PostSyncMessage ( )
protected

Places the synchronization message to message queue.

Internal service.

void MMonitorFile::SetFileName ( const MStdString name)

The path and name of the file that will be used to store communication data.

If the file name is "", then none of the communication data is saved. The FileName must be specified before the client wants to start saving data. The communication data is saved to the file as the transaction occurs. If the specified file already exists, then no error or warning is generated and the new data is appended to the existing file.

The file will be in binary format. To view the communication transactions, load the file into the Monitor. The Monitor does NOT have to be running in order for communication data to be written to the file.

Default value:
"" (empty string)
Possible values:
  • Any valid path and file name.
void MMonitorFile::SetMaxFileSizeKB ( unsigned  size)

Maximum size of the binary log file in kilobytes.

Once the file reaches the maximum size, it does not get any bigger. Old data is removed from the file as new data is added. The file will always contain the latest communication data.

Default value:
0 : A zero value indicates that there is no restriction on the size of the file.
Possible values:
  • 0 .. 2,147,483,647
void MMonitorFile::SetObfuscate ( bool  yes)

Whether or not the file shall be obfuscated.