The 'SOMMTraced' Metaclass

SOMMTraced is a metaclass that facilitates tracing of method invocations. If class "Collie" is an instance of SOMMTraced (if SOMMTraced is the metaclass of "Collie"), any method invoked on an instance of "Collie" is traced. That is, before the method begins execution, a message prints (to standard output) giving the actual parameters. Then, after the method completes execution, a second message prints giving the returned value. This behavior is attained merely by being an instance of the SOMMTraced metaclass.

If the class being traced is contained in the Interface Repository, actual parameters are printed as part of the trace. If the class is not contained in the Interface Repository, an ellipsis is printed.

To be more concrete, suppose that the class "Collie" is a child of "Dog" and is an instance of SOMMTraced. Because SOMMTraced is the metaclass of "Collie," any method invoked on "Lassie" (an instance of "Collie") is traced.

It is easy to use SOMMTraced: Just make a class an instance of SOMMTraced in order to get tracing.

There is one more step for using SOMMTraced: Nothing prints unless the environment variable SOMM_TRACED is set. If it is set to the empty string, all traced classes print. If SOMM_TRACED is not the empty string, it should be set to the list of names of classes that should be traced. For example, the following command turns on printing of the trace for "Collie", but not for any other traced class:

export  SOMM_TRACED=Collie      (on AIX)
SET     SOMM_TRACED=Collie      (on OS/2 or Windows)

The example below shows the IDL needed to create a traced dog class: Just run the appropriate emitter to get an implementation binding.

SOM IDL for 'TracedDog' class

#include "dog.idl"
#include <somtrcls.idl>
interface TracedDog : Dog
{
#ifdef __SOMIDL__
implementation
{
  //# Class Modifiers
  filestem = trdog;
  metaclass = SOMMTraced;
};
#endif /* __SOMIDL__ */
};


[Back: The 'SOMMSingleInstance' Metaclass]
[Next: Error Codes]