home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: InfoMgt / InfoMgt.zip / shr93.zip / README.TXT < prev    next >
Text File  |  1993-07-12  |  15KB  |  364 lines

  1. OS/2 Work Place Shell Sample Program - Address Book
  2.  
  3. Copyright (C) 1993 IBM Corporation
  4.  
  5.   DISCLAIMER OF WARRANTIES.  The following [enclosed] code is
  6.   sample code created by IBM Corporation.  This sample code is
  7.   not part of any standard or IBM product and is provided to you
  8.   solely for the purpose of assisting you in the development of
  9.   your applications.  The code is provided "AS IS".  ALL
  10.   WARRANTIES ARE EXPRESSLY DISCLAIMED, INCLUDING THE IMPLIED
  11.   WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
  12.   PURPOSE.  IBM shall not be liable for any damages arising out
  13.   of your use of the sample code, even if IBM has been advised of
  14.   the possibility of such damages.
  15.  
  16. Acknowledgements
  17.  
  18.   Specials thanks to Diana Mack for the careful review of the
  19.   code and dokumentation <g>.
  20.  
  21. Warning!
  22.  
  23.   Multiple WPS subclasses in the same DLL would sometimes be
  24.   spontaneously unloaded by WPS on OS/2 2.0 GA causing
  25.   a trap.  This has been fixed in OS/2 2.1, therefore you should
  26.   only run this example on 2.1 or greater versions of OS/2.
  27.  
  28. Introduction
  29.  
  30.   This example implements a simple address book.  An address book 
  31.   contains "people" who have names, addresses, phone numbers, etc.  
  32.  
  33.   The address book is implemented as a subclass of the WPS folder 
  34.   class, WPFolder.  Subclassing WPFolder has the advantage of 
  35.   inheriting standard folder behavior, especially the Icon, 
  36.   Settings, and Details view.  The address book adds an additional
  37.   view, "Indexed View", which is an alphabetically-tabbed view of
  38.   the persons within the address book.
  39.  
  40.   The person object contained within the address book is 
  41.   implemented as a subclass of WPAbstract.  Subclassing WPAbstract 
  42.   has the advantage of inheriting base WPS object behavior like 
  43.   drag/drop, pop-up menu, and the Settings view.  The person 
  44.   class adds an additional "Info" page to the Settings view where
  45.   the user can change an address, phone number, etc.
  46.  
  47.   Alternatively, the person class could have been a subclass of 
  48.   WPDataFile.  This allows the person object to be copied to a 
  49.   diskette (WPAbstract's cannot be copied to diskette because 
  50.   their instance data is stored in the OS2.INI file).  However, 
  51.   WPAbstract instances are more quickly created for objects whose 
  52.   data storage requirements are small.  Indeed, FAT file system 
  53.   drives waste considerable space for small files because they 
  54.   allocate an entire sector (usually about 2-4K) for each data 
  55.   file.  
  56.  
  57.   This example also has other "support" classes.  The ShrList 
  58.   class is a simple ordered list.  And the ShrNotifier is a 
  59.   mechanism used by the ShrAddressBook and ShrPerson classes to 
  60.   simplify the synchronization of the display of their instance 
  61.   data with the views seen by the user.  
  62.  
  63. Installation of the Address Book
  64.  
  65.   Copy SHARE.DLL to one of your fixed disks, then execute 
  66.   SHRINST.EXE.  It will prompt you for the path where you copied 
  67.   SHARE.DLL, select Install.  SHRINST.EXE will register all the 
  68.   classes needed by this example, namely, ShrFolder, 
  69.   ShrAddressBook, ShrPerson, ShrList, and ShrNotifier.  
  70.  
  71.   An "Address Book" object will be created on your desktop.
  72.   Open it and select "Create person".
  73.  
  74.   Note: Some users reported having to reboot after the installation
  75.   to get the correct icon for the address book.  If the address
  76.   book icon looks like a folder after installing, try rebooting.
  77.  
  78. Known Problems
  79.  
  80.   All known problems are documented in detail in WPS-PGM.TXT.
  81.  
  82.   This example was tested on OS/2 2.0 GA and several problems with 
  83.   person's not showing in the Icon view of the address book were 
  84.   found; these problems did not occur in later testing on the 
  85.   March beta of OS/2 2.1.  
  86.  
  87.   There was also a rather serious problem with the SHARE.DLL
  88.   being wrongly unloaded by the WPS (see "Problem 16" in WPS-PGM.TXT).
  89.   This can be avoided by keeping an address book "Indexed View" open
  90.   and minimized.
  91.  
  92. Source Files
  93.  
  94.   The SOM compiler generates a number of files based on the 
  95.   contents of the class definition file (*.CSC):
  96.  
  97.     *.IH - implementation header.
  98.     *.PH - private header.
  99.     *.SC - compiled SOM class definition
  100.     *.PSC - private portion of compiled SOM class definition.
  101.     *.H - SOM method macro definition (eg, ADDRBK.H).
  102.  
  103.   Do not create an include file (*.H) with the same name as your
  104.   class definition file (*.CSC).  It will be overwritten by the 
  105.   *.H file generated by the SOM compiler.  You can include 
  106.   constants, macros, typedefs, etc, in the "passthru" section of 
  107.   your class definition file, or if you prefer, create an include 
  108.   file but use a different suffix, eg, *.PTH.  
  109.  
  110.   Common files:
  111.  
  112.     SHARE.C - common functions, DLL initialization, etc.
  113.     SHARE.H - MRI constants, macros, typedef's, etc.
  114.     SHARE.DEF - exports for SHARE.DLL
  115.     SHARE.MAK - make file for SHARE.DLL and SHRINST.EXE.
  116.  
  117.   ShrFolder's files:
  118.  
  119.     SHRFOLDR.H - header file.
  120.     SHRFOLDR.SC - compiled CSC file.
  121.     SHRFOLDR.OBJ - object code file.
  122.     SHRFOLDR.CSC is NOT included in this package.
  123.     SHRFOLDR.C is NOT included in this package.
  124.  
  125.     NOTE: ShrFolder is a subclass of WPFolder created to add the 
  126.     methods shrAddedToContent and shrRemovedFromContent.  The 
  127.     source code for this module IS NOT INCLUDED because it uses 
  128.     undocumented methods.  This problem has been reported to Boca.  
  129.     See WPS-PGM.TXT for other known problems and workarounds.  
  130.  
  131.   ShrAddressBook's files:
  132.  
  133.     ADDRBK.CSC - class definition.
  134.     ADDRBK.C - model code.
  135.     ADDRBKV.C - view code.
  136.     ADDRBK.ICO - address book icon.
  137.  
  138.     ShrAddressBook is a subclass of ShrFolder that adds an 
  139.     additional view, the "Indexed View", which looks similar to a 
  140.     tabbed address book.  ShrAddressBook's Indexed View displays 
  141.     instances of ShrPerson in separate pages, eg, page "A - C" 
  142.     might hold an instance of ShrPerson titled "Adams, John".  
  143.  
  144.   ShrPerson's files:
  145.  
  146.     PERSON.CSC - class definition.
  147.     PERSON.C - model code.
  148.     PERSONV.C - view code.
  149.     PERSON.ICO - person icon.
  150.  
  151.     ShrPerson is a subclass of WPAbstract that hold information 
  152.     about a person, eg, name, address, etc.  ShrPerson adds an 
  153.     "Info" page to the Settings notebook to allow the user to 
  154.     change the person data.  
  155.  
  156.   ShrNotifier's files:
  157.  
  158.     NOTIFY.CSC - class definition.
  159.     NOTIFY.C - model code.
  160.  
  161.     ShrNotifier is a subclass of SOMObject that provides a simple 
  162.     notification mechanism used to keep models (like 
  163.     ShrAddressBook and ShrPerson, in ADDRBK.C and PERSON.C, 
  164.     respectively) synchronized with their views (ADDRBKV.C and 
  165.     PERSONV.C).
  166.  
  167.   ShrList's files:
  168.  
  169.     SOMLIST.CSC - class definition.
  170.     SOMLIST.C - model code.
  171.     LIST.C - basic list functions.
  172.     LIST.H - basic list functions header.
  173.  
  174.     ShrList is a subclass of SOMOBJECT that implements an ordered
  175.     list.  It is used by ShrNotifier to keep track of the 
  176.     models interested views (windows).
  177.  
  178.   MRI files:
  179.  
  180.     SHARE.RC - menus, strings, pointers.
  181.     SHARE.DLG - dialogs.
  182.  
  183.   Installation files:
  184.  
  185.     SHRINST.C - source code.
  186.     SHRINST.DLG - dialog.
  187.     SHRINST.H - MRI constants.
  188.  
  189. ADDRESS BOOK EXAMPLE - HINTS AND TIPS
  190.  
  191.   This section contains information that may be of interest to the
  192.   SOM/WPS programmer.  Much of it is gleaned from the comments 
  193.   within the source code.
  194.  
  195. What is SOM?
  196.  
  197.   Let's break the question down a bit first...
  198.  
  199. What is an Object?
  200.  
  201.   The short answer -- an object is data and behavior.  Objects 
  202.   communicate using a messaging technique.  These messages can be 
  203.   used to query an object's data or ask it to perform some
  204.   behavior.  
  205.  
  206. What is an Object Model?
  207.  
  208.   A representation of an object.  In rough terms, the object model 
  209.   of C++ is a structure with a list of associated functions that 
  210.   act on that structure.  In Smalltalk, the object model is either 
  211.   byte data or pointers to other objects with a collection of 
  212.   methods that act on the byte data or object pointers.  
  213.  
  214. So, What is a System Object Model?
  215.  
  216.   A common representation of an object.  The goal is to allow for 
  217.   communication between objects and sharing of object class 
  218.   implementations independent of the underlying implementation 
  219.   language.  
  220.  
  221.   SOM provides a basic class definition compiler that generates 
  222.   bindings that are acceptable to the various compilers (C Set/2 
  223.   and C++).  
  224.  
  225. How are SOM and WPS Related?
  226.  
  227.   The Workplace Shell uses SOM as the basis for its object model. 
  228.   All the objects created by WPS are subclasses of the root
  229.   class provided by SOM, SOMObject.
  230.  
  231.   SOM can be used independently of the WPS.  For example, the 
  232.   ShrList and ShrNotifier classes are implemented as a subclass of
  233.   SOMObject.  The converse is not possible, that is, if you write 
  234.   to the WPS, you must use a SOM-based solution (eg, C Set/2 and 
  235.   SOM/WPS macros, or C++ and SOM/WPS C++ bindings).
  236.  
  237.   WPS uses C Set/2 and the SOM C Set/2 bindings.  There exists
  238.   SOM/WPS bindings for C++, but they have not been as throughly
  239.   tested as the SOM C Set/2 bindings for WPS.
  240.  
  241. Serial Access to Object Instance Data
  242.  
  243.   If you're going to access instance data YOUR subclass has 
  244.   defined from a second thread, use wpRequestObjectMutexSem and 
  245.   wpReleaseObjectMutexSem.  
  246.  
  247.   The wpRequestObjectMutexSem method will prevent other threads 
  248.   from modifying your object's instance data (of course, this 
  249.   assumes new methods you add that query/set instance data use 
  250.   wpRequestObjectMutexSem and wpReleaseObjectMutexSem, too).  
  251.                                                               
  252.   WPS is extremely multithreaded.  The wpRequestObjectMutexSem and 
  253.   wpReleaseObjectMutexSem methods are very important.  It is wise 
  254.   to request/release the object mutex semaphore in each new 
  255.   instance method your define that queries/sets object instance 
  256.   data (eg, shrSetAddress, shrQueryAddress).  In addition, the 
  257.   method should include exception protection should the method 
  258.   trap to make certain it releases the object's semaphore.  
  259.  
  260.   See ShrSetObjectString and ShrQueryObjectString in SHARE.C for 
  261.   examples.
  262.  
  263. Exception Handling
  264.  
  265.   Handling exception conditions (eg, referencing an invalid 
  266.   pointer) is very easy under OS/2 2.0.  ShrExceptionHandler in 
  267.   SHARE.C along with two macros, ShrStartTryBlock and 
  268.   ShrEndTryBlock, make it very easy to code.  See examples in 
  269.   ADDRBKV.C and SHARE.C.  BTW, the OS/2 2.1 toolkit example WPCAR
  270.   shows how to use the "#pragma handler" rather than the macros
  271.   this example uses.
  272.  
  273.   NOTE!  It is very important that exception handlers be coded in 
  274.   routines that request mutex semaphores!  The exception condition 
  275.   should relinquish the semaphore if it was successfully 
  276.   requested.  Otherwise, later requestors of the semaphore could 
  277.   wait indefinitely, typically resulting in a hang of one of the 
  278.   WPS threads or the entire WPS.  
  279.  
  280. Registering New WPS Views
  281.  
  282.   When a view is registered with wpRegisterView, it is subclassed 
  283.   by the WPS and its window procedure pointer saved in a reserved 
  284.   window words.  The WPS subclass window procedure handles all the 
  285.   WM_CONTROL (CN_) notification messages for WPS object container 
  286.   records inserted into a container, along with the system menu 
  287.   code to display the context menu, and a few WM_COMMAND 
  288.   messages (delete, copy, move, etc).
  289.  
  290.   It is often desireable to re-subclass after calling 
  291.   wpRegisterView so your frame window procedure gets called before 
  292.   the WPS version.  This is necessary because the WPS version does 
  293.   not forward any WM_CONTROL messages to its superclass, and your 
  294.   frame window procedure may need these notifications.  
  295.  
  296.   See ShrOpenAddressBook in ADDRBKV.C for an example.
  297.  
  298. Determining an Object's Protocol (Type)
  299.  
  300.   One advantage SOM has over C++ is the choice of method 
  301.   resolution.  You can use one similar to C++ (offset into a 
  302.   v-table), or dynamic lookup at runtime using the "name lookup" 
  303.   on the method declaration.  
  304.                                                                      
  305.   This allows the definition of more polymorphic classes.  For 
  306.   example, 
  307.                                                                      
  308.                       Things                                         
  309.                                                                      
  310.       LivingThings                   UndeadThings                    
  311.                                                                      
  312.    Mammals  Reptiles   Birds    Ghouls   Ghosts  Goblins             
  313.                                                                      
  314.   Assume LivingThings and UndeadThings respond to 
  315.   "areYouFriendly", but Things do not.  Using SOM and given a 
  316.   pointer to a LivingThing or UndeadThing, I could ask 
  317.   "areYouFriendly".  In C++, LivingThings and UndeadThings would 
  318.   have to have a common ancestor that responded to that message.  
  319.   In SOM, LivingThings and UndeadThings would not have to have a 
  320.   common ancestor if the "areYouFriendly" method was defined as 
  321.   "name lookup", ie, it uses SOM's dynamic message resolution, not 
  322.   offset method resolution technique.  SOM also provides 
  323.   somRespondsTo to help figure out cases where your are really not 
  324.   certain the type of the receiver.  
  325.  
  326.   Despite this flexibility, many SOM programmers use _somIsA to
  327.   determine an objects type, instead of _somRespondsTo.
  328.  
  329.   One drawback to _somIsA is its dependency on the class hierarchy 
  330.   to infer an object's protocol.  For example, a new-and-improved
  331.   version of LivingThings that is not a direct descendant of 
  332.   Things would not be recognized as a "LivingThings" if client 
  333.   classes used _somIsA, while they would if client classes had 
  334.   used _somRespondsTo.  
  335.  
  336.   But note there is a problem to be considered -- a class often 
  337.   has methods that are not "name lookup" methods, ie, they use 
  338.   SOM's offset message resolution much like that used by C++, so 
  339.   creating a new class that is not a subclass of the class's 
  340.   superclass would require considerable care since it would have 
  341.   to be certain to have its version of this class has its methods 
  342.   in the same order as the method table of this class.  
  343.  
  344.   The ShrPerson class implements the "shrUnderstandsProtocol" 
  345.   method.  Ideally this method would exist in the root class, so 
  346.   OO programmers could determine the object's protocol and avoid 
  347.   type checking, which leads to more flexibility and reuse.
  348.  
  349.   See ADDRBK.C for an example.
  350.  
  351. Restriction Containment
  352.  
  353.   ShrAddressBook is an example of "restrictive containment".  It 
  354.   will hold objects, but only those of a specific type.  There are 
  355.   other examples of restrictive containment in the OS/2 WPS.  The 
  356.   Printer object only allows print jobs within it; the Minimized 
  357.   Window Viewer only allows minimized windows within it.  
  358.   
  359.   Restrictive containment can effectively be used to guide the 
  360.   user to the purpose of a container.  But be certain that such 
  361.   restriction is considered reasonable to the user.  It is often 
  362.   tempting to use restrictions to solve programming problems and 
  363.   not user interface problems.  
  364.