In general, XWorkplace is pretty straightforward SOM/WPS code. It overrides a lot of wp* and wpcls* methods.

In order to avoid too much confusion, the methods which XWorkplace adds do not carry the usual wp* and wpcls* prefixes, but xwp* and xwpcls* instead. Only "real" XWorkplace SOM methods have this prefix; "normal" functions have other prefixes (see the previous page for a list).

As XWorkplace became more complex over time, I have delved quite deeply into SOM. While I still don't fully understand what is going on in the SOM kernel (from what I hear, I guess nobody does) and some bugs in there keep puzzling me, I've found out some interesting stuff.

Note: The following is not required to write WPS classes. This is additional information for those who have written WPS classes already and might be interested in some SOM internals.

Most of this is related to the "WPS Classes" object (xclslist.c). The SOM logic for this is in classlst.c in clsWPSClasses2Cnr, which can analyze the current SOM runtime environment (which is that of the WPS), i.e. all the classes that have been loaded and query their inheritance hierarchy at runtime.

This inserts the WPS class tree as recordcores into a given cnr control. This works with any containers in tree views, so that some XWorkplace dialogs can use this too. Check the sources, there's some interesting stuff.

Note that there are quite a number of functions in XWorkplace which take SOM (WPS) objects as a parameter, even though they are not SOM methods. See src\shared\wpsh.c for examples. The reason for this is that resolving SOM methods takes quite a bit of time, and calling regular functions will work just as well, but faster.

If you look into the .IH header files created by the SOM compiler, you see that the C bindings for method calls are really all macros #define'd in the header files which translate into more complex C code.

Here's an example: if you call _wpQueryStyle(somSelf) in xfldr.c, where this method has not been overridden, the WPObject version of this method should get called. Here's the #define in xfldr.ih for this:

#define XFolder_wpQueryStyle WPObject_wpQueryStyle

And WPObject_wpQueryStyle is #define'd in wpobject.h from the toolkit headers as follows:

#define WPObject_wpQueryStyle(somSelf) \
    (SOM_Resolve(somSelf, WPObject, wpQueryStyle) \
    (somSelf))
Actually, there are more macros related to this, but this is the important one. SOM_Resolve in turn is a macro #define'd in somcdev.h, which calls the SOM kernel function somResolve. That function finally goes through the class method tables to find the actual function address and call it.

As as result, not only does compiling of SOM code take ages (because of all the nested macros), but also calling SOM methods does, because as opposed to "static" OO languages such as C++, method resolution is occuring at run-time. IBM says in the SOM docs that calling a SOM method takes at least three times as long as calling a normal C function.

Since there is no real need to write functions as SOM methods, except when you want to design a method which can be overriden in subclasses, I have only done so in rare occasions to speed up processing.

Here are some other SOM tricks and functions which are not mentioned directly in the WPS reference (but only in the chaotic SOM docs), but these are very useful. Some of this is pretty basic, some might be new to WPS programmers, so I'll list this here: