home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / tolkit45.zip / os2tk45 / som / include / somtempl.app < prev    next >
Text File  |  1999-02-22  |  70KB  |  2,348 lines

  1. :somapp_sccsid
  2. @(#) 1.3 src/somc/somapp/somtempl.app, somtempl, som2.1 12/19/95 10:51:42 [7/30/96 15:26:41]
  3.  
  4. :symtest
  5.         SOM_CLASS_NAME            "__SOM_CLASS_NAME__"
  6.         SOM_META_FILES            "__SOM_META_FILES__"
  7.         SOM_META_NAMES            "__SOM_META_NAMES__"
  8.         SOM_PARENT_FILES          "__SOM_PARENT_FILES__"
  9.         SOM_PARENT_NAMES          "__SOM_PARENT_NAMES__"
  10.         SOM_STEM                  "__SOM_STEM__"
  11.         SOM_OBJS                  "__SOM_OBJS__"
  12.         SOM_OBJS_RESPONSE         "__SOM_OBJS_RESPONSE__"
  13.         SOM_OBJS_C_DEPS           "__SOM_OBJS_C_DEPS__"
  14.         SOM_OBJS_CPP_DEPS         "__SOM_OBJS_CPP_DEPS__"
  15.         SOM_INITBODY              "__SOM_INITBODY__"
  16.         SOM_C_HEADER_FILES        "__SOM_C_HEADER_FILES__"
  17.         SOM_C_HEADER_DELETE_FILES "__SOM_C_HEADER_DELETE_FILES__"
  18.         SOM_CPP_HEADER_FILES        "__SOM_CPP_HEADER_FILES__"
  19.         SOM_CPP_HEADER_DELETE_FILES "__SOM_CPP_HEADER_DELETE_FILES__"
  20.         SOM_EXPORT_C_NAMES        "__SOM_EXPORT_C_NAMES__"
  21.         SOM_EXPORT_PASCAL_NAMES   "__SOM_EXPORT_PASCAL_NAMES__"
  22.         SOM_META_CLASS_NAME       "__SOM_META_CLASS_NAME__"
  23.         SOM_PARENT_CLASS_NAME     "__SOM_PARENT_CLASS_NAME__"
  24.         SOM_DLLSTEM               "__SOM_DLLSTEM__"
  25. :idl_dll_Makefile
  26. # AIX xlc Makefile for __SOM_STEM__
  27. # Author: SOMobjects Template Builder
  28.  
  29. TARGET     = __SOM_STEM__.dll
  30. TARGETS    = $(TARGET) lib__SOM_STEM__.a
  31. OBJS       = __SOM_OBJS__ __SOM_STEM__init.o
  32.  
  33. AR         = ar
  34. CC         = cc
  35. CDEBUG     = -g
  36. LDEBUG     =
  37. CFLAGS     = $(CDEBUG)
  38. LDFLAGS    = -bM:SRE -T512 -H512
  39. LIBLIST    = -lsomtk
  40. LINKER     = ld
  41. SC         = sc
  42. SCFLAGS    = -mnoaddstar -p -u
  43. EMITH      = -sh
  44. EMITIH     = -sh:ih
  45. EMITC      = -sc
  46. DELETE     = rm -f
  47.  
  48. .SUFFIXES: .idl .ih .h .sh .c
  49.  
  50. .c.o:
  51.     $(CC) -I. -I$(SOMBASE)/include $(CFLAGS) -c $<
  52.  
  53. .idl.ih:
  54.     $(SC) $(SCFLAGS) $(EMITIH) $<
  55.  
  56. .idl.h:
  57.     $(SC) $(SCFLAGS) $(EMITH) $<
  58.  
  59. .idl.c:
  60.     $(SC) $(SCFLAGS) $(EMITC) $<
  61.  
  62. .sh:
  63.     cp $? $@; chmod 0755 $@
  64.  
  65. all: $(TARGETS)
  66.  
  67. __SOM_OBJS_C_DEPS__
  68. __SOM_STEM__init.o: __SOM_STEM__.h __SOM_STEM__init.c
  69.  
  70. __SOM_STEM__.dll: $(OBJS) __SOM_STEM__.exp
  71.     $(LINKER) -o $@ -e SOMInitModule $(OBJS) -bE:__SOM_STEM__.exp -lc $(LDFLAGS) -L$(SOMBASE)/lib $(LIBLIST)
  72.  
  73. lib__SOM_STEM__.a: __SOM_STEM__.dll __SOM_STEM__.exp
  74.     $(AR) ruv $@ __SOM_STEM__.exp
  75.  
  76. clean:
  77.     $(DELETE) som.ir *.ih *.o $(TARGETS)
  78. __SOM_C_HEADER_DELETE_FILES__
  79. :idl_dll_makefile.32
  80. # OS/2 C Set Makefile for __SOM_STEM__
  81. # Author: SOMobjects Template Builder
  82.  
  83. TARGET     = __SOM_STEM__.dll
  84. TARGETS    = $(TARGET) __SOM_STEM__.lib
  85. OBJS       = __SOM_OBJS__ __SOM_STEM__init.o
  86.  
  87. CC         = icc
  88. CDEBUG     = -Ti+
  89. LDEBUG     = /debug
  90. CFLAGS     = -W3 -c $(CDEBUG) -Q+ -Ss+ -Gd- -Gm+ -Gs+ -Sm
  91. LDFLAGS    = /exepack /packd /packc /align:4 /stack:100000 /pm:vio /noe /noi /nol $(LDEBUG)
  92. LIBLIST    = somtk.lib
  93. LINKER     = link386
  94. SC         = sc
  95. SCFLAGS    = -mnoaddstar -p -u
  96. EMITH      = -sh
  97. EMITIH     = -sh;ih
  98. EMITC      = -sc
  99. DELETE     = del
  100.  
  101. .SUFFIXES: .idl .ih .h .c
  102.  
  103. .c.o:
  104.     $(CC) -fo$*.o -I. -I$(SOMBASE)\include $(CFLAGS) -Ge- $<
  105.  
  106. .idl.ih:
  107.         $(SC) $(SCFLAGS) $(EMITIH) $<
  108.  
  109. .idl.h:
  110.         $(SC) $(SCFLAGS) $(EMITH) $<
  111.  
  112. .idl.c:
  113.         $(SC) $(SCFLAGS) $(EMITC) $<
  114.  
  115. all: $(TARGETS)
  116.  
  117. __SOM_OBJS_C_DEPS__
  118. __SOM_STEM__init.o: __SOM_STEM__.h __SOM_STEM__init.c
  119.  
  120. __SOM_STEM__.dll: $(OBJS) __SOM_STEM__.def
  121.     $(LINKER) $(LDFLAGS) @<<
  122. $(OBJS: = +^
  123. )
  124. $@
  125. nul
  126. $(LIBLIST)
  127. __SOM_STEM__.def
  128. \<<
  129.  
  130. __SOM_STEM__.lib: __SOM_STEM__.dll __SOM_STEM__.def
  131.     implib __SOM_STEM__.lib __SOM_STEM__.def
  132.  
  133. clean:
  134.     -$(DELETE) som.ir
  135.     -$(DELETE) $(TARGET)
  136.     -$(DELETE) __SOM_STEM__.lib
  137.     -$(DELETE) *.ih
  138.     -$(DELETE) *.o
  139. __SOM_C_HEADER_DELETE_FILES__
  140. :idl_dll_makefile.w16
  141. # Windows Visual C++ Makefile for __SOM_STEM__
  142. # Author: SOMobjects Template Builder
  143.  
  144. TARGET     = __SOM_STEM__.dll
  145. TARGETS    = $(TARGET) __SOM_STEM__.lib
  146. OBJS       = __SOM_OBJS__ __SOM_STEM__init.o
  147.  
  148. CC         = cl
  149. CDEBUG     = -Zi
  150. LDEBUG     = /CO
  151. CFLAGS     = -nologo -Zp1 -Oi $(CDEBUG)
  152. LDFLAGS    = /nologo /ONERROR:NOEXE /nod $(LDEBUG)
  153. LIBLIST    = llibcew libw $(SOMBASE)\lib\somtk
  154. LIBLISTD   = ldllcew libw $(SOMBASE)\lib\somtk
  155. LINKER     = link
  156. SC         = somc
  157. SCFLAGS    = -mnoaddstar -p -u
  158. EMITH      = -sh
  159. EMITIH     = -sh;ih
  160. EMITC      = -sc
  161. DELETE     = del
  162.  
  163. .SUFFIXES: .idl .ih .h .c
  164.  
  165. .c.o:
  166.     $(CC) -c -Fo$*.o -I. -I$(SOMBASE)\include $(CFLAGS) -ALw $<
  167.  
  168. .idl.ih:
  169.         $(SC) $(SCFLAGS) $(EMITIH) $<
  170.  
  171. .idl.h:
  172.         $(SC) $(SCFLAGS) $(EMITH) $<
  173.  
  174. .idl.c:
  175.         $(SC) $(SCFLAGS) $(EMITC) $<
  176.  
  177. all: $(TARGETS)
  178.  
  179. som__SOM_STEM__.o: som__SOM_STEM__.c __SOM_STEM__.h
  180.     $(CC) -Fo$@ -I. -I$(SOMBASE)\include $(CFLAGS) -c -AL som__SOM_STEM__.c
  181.  
  182. __SOM_OBJS_C_DEPS__
  183. __SOM_STEM__init.o: __SOM_STEM__.h __SOM_STEM__init.c
  184.  
  185. __SOM_STEM__.dll: $(OBJS) __SOM_STEM__w16.def
  186.     $(LINKER) $(LDFLAGS) @<<
  187. $(OBJS: = +^
  188. )
  189. __SOM_STEM__.dll
  190. nul
  191. $(LIBLISTD)
  192. __SOM_STEM__w16.def
  193. \<<
  194.  
  195. __SOM_STEM__.lib: __SOM_STEM__.dll __SOM_STEM__w16.def
  196.     implib /nologo __SOM_STEM__.lib __SOM_STEM__w16.def
  197.  
  198. clean:
  199.     -$(DELETE) som.ir
  200.     -$(DELETE) $(TARGET)
  201.     -$(DELETE) __SOM_STEM__.lib
  202.     -$(DELETE) __SOM_STEM__.dll
  203.     -$(DELETE) *.ih
  204.     -$(DELETE) *.o
  205. __SOM_C_HEADER_DELETE_FILES__
  206. :idl_dll___SOM_STEM__.def
  207. LIBRARY __SOM_STEM__ INITINSTANCE
  208. DESCRIPTION '__SOM_CLASS_NAME__ Class Library'
  209. PROTMODE
  210. DATA MULTIPLE NONSHARED LOADONCALL
  211. EXPORTS
  212. SOMInitModule
  213. __SOM_EXPORT_PASCAL_NAMES__
  214. :idl_dll___SOM_STEM__.exp
  215. #! __SOM_STEM__.dll
  216. SOMInitModule
  217. __SOM_EXPORT_PASCAL_NAMES__
  218. :idl_dll___SOM_STEM__.idl
  219. #ifndef __SOM_STEM___idl
  220. #define __SOM_STEM___idl
  221.  
  222. __SOM_PARENT_FILES__
  223. __SOM_META_FILES__
  224.  
  225. interface __SOM_CLASS_NAME__ : __SOM_PARENT_NAMES__
  226. {
  227.   // Attributes filled in here:
  228.  
  229.   // Operations filled in here:
  230.  
  231. #ifdef __SOMIDL__
  232.   implementation {
  233.     releaseorder:;
  234.  
  235.     // Class Modifiers:
  236.     align     = 4;
  237.     dllname   = "__SOM_DLLSTEM__.dll";
  238.     __SOM_META_NAMES__
  239.  
  240.     // Attribute Modifiers:
  241.  
  242.     // Overrides:
  243.     somDefaultInit: override, init;     // Default object initializer
  244.     somDestruct: override;              // Default object uninitializer
  245.   };
  246. #endif /* __SOMIDL__ */
  247. };
  248. #endif  /* __SOM_STEM___idl */
  249. :idl_dll___SOM_STEM__init.c
  250. /*
  251.  * Module name: __SOM_STEM__init.c
  252.  *
  253.  * Description: This source file contains functions used during the loading
  254.  *              and initialization of the __SOM_DLLSTEM__.dll class library.
  255.  *
  256.  *
  257.  */
  258. #ifdef __IBMC__
  259. #pragma linkage(SOMInitModule, system)
  260. #endif
  261.  
  262. __SOM_C_HEADER_FILES__
  263.  
  264. void SOMLINK SOMInitModule(integer4 majorVersion, integer4 minorVersion, string ignore)
  265. {
  266. __SOM_INITBODY__
  267. }
  268.  
  269. #ifdef _WIN16
  270. #include <windows.h>
  271. int CALLBACK LibMain (HINSTANCE inst, WORD ds, WORD heapSize, LPSTR cmdLine)
  272. {
  273.     SOM_IgnoreWarning (inst);
  274.     SOM_IgnoreWarning (ds);
  275.     SOM_IgnoreWarning (heapSize);
  276.     SOM_IgnoreWarning (cmdLine);
  277.  
  278.     SOM_ClassLibrary ("__SOM_STEM__.dll");
  279.     return 1;
  280. }
  281. #endif
  282. /*
  283.  * 10H9767, 25H7912 (C) COPYRIGHT International Business Machines Corp. 1992,1996 
  284.  * All Rights Reserved
  285.  * Licensed Materials - Property of IBM
  286.  *
  287.  * DISCLAIMER OF WARRANTIES.
  288.  * The following [enclosed] code is sample code created by IBM
  289.  * Corporation. This sample code is not part of any standard or IBM
  290.  * product and is provided to you solely for the purpose of assisting
  291.  * you in the development of your applications.  The code is provided
  292.  * "AS IS".
  293.  *
  294.  * DISTRIBUTION.
  295.  * This sample code can be freely distributed, copied, altered, and
  296.  * incorporated into other software, provided that it bears the above
  297.  * Copyright notice and DISCLAIMER intact.
  298.  */
  299. :idl_dll___SOM_STEM__w16.def
  300. LIBRARY         __SOM_STEM__
  301. DESCRIPTION     '__SOM_CLASS_NAME__ Class Library'
  302. EXETYPE         WINDOWS
  303. PROTMODE
  304. STUB            'WINSTUB.EXE'
  305. DATA            MOVEABLE SINGLE SHARED LOADONCALL
  306. CODE            MOVEABLE DISCARDABLE LOADONCALL
  307. HEAPSIZE        4096
  308.  
  309. EXPORTS
  310. __SOM_EXPORT_C_NAMES__
  311. :dsom_README
  312. This directory contains a simple template DSOM application composed of the
  313. following files. See main.c for a description of the application.
  314.  
  315. Makefile      - Makefile for AIX
  316. makefile.32   - Makefile for OS/2 (IBM C Set)
  317. makefile.w16  - Makefile ofr DOS/Win (MSVC)
  318.  
  319. chk__SOM_STEM__.bat   - DOS/Win exec to check environment variables
  320. chk__SOM_STEM__.cmd   - OS/2    "    "  "     "           "
  321. chk__SOM_STEM__.sh    - AIX     "    "  "     "           "
  322.  
  323. local.bat     - DOS/Win exec to set up for objects local to the client process.
  324. local.cmd     - OS/2    "    "  "   "  "   "       "     "  "   "      "
  325. local.sh      - AIX     "    "  "   "  "   "       "     "  "   "      "
  326.  
  327. remote.bat    - DOS/Win exec to set up for remote DSOM objects.
  328. remote.cmd    - OS/2    "    "  "   "  "   "      "    "
  329. remote.sh     - AIX     "    "  "   "  "   "      "    "
  330.  
  331. som__SOM_STEM__.c     - Source of utility functions to aid local/remote transparency.
  332. som__SOM_STEM__.h     - Header for utility functions.
  333. main.c        - Main client program.
  334. __SOM_STEM__cli.def   - DOS/Win module definition file for client program.
  335.  
  336. __SOM_STEM__.idl      - The class definition of the __SOM_CLASS_NAME__ class.
  337. __SOM_STEM__.c        - The implementation of the __SOM_CLASS_NAME__ class.
  338. __SOM_STEM__init.c    - Class library initialization module.
  339. __SOM_STEM__.exp      - Class library export list for AIX.
  340. __SOM_STEM__.def      - Class library export list for OS/2.
  341. __SOM_STEM__w16.def   - Class library export list for DOS/Win.
  342.  
  343. To build this application, run make or nmake on the make file appropriate
  344. for your system.
  345.  
  346.    On AIX:    make
  347.    On OS/2:   nmake -f makefile.32
  348.    On Win:    nmake -f makefile.w16
  349.  
  350. The make file will also run the chk__SOM_STEM__ command to check your environment
  351. and report potential setup problems.
  352.  
  353. The make files produce two executables: __SOM_STEM__.dll and __SOM_STEM__cli[.exe] The dll
  354. file is the class library.  __SOM_STEM__cli is the client program.  Following the
  355. building of the executables and prior to running the client program, the
  356. "local" or "remote" command should be run to set up the application to use
  357. either local SOM objects or remote DSOM objects.  The application is written
  358. such that the location is transparent to it.  The remote command registers
  359. the object implementation in the Implementation Repository.  The remote
  360. command takes one arguement, the remote host name.  If no argument is given,
  361. the local system is assumed to be the system on which the DSOM server will
  362. run.  The DSOM server is the process that contains the remote objects.  You
  363. must ensure that the DSOM deamon somdd is running on the server system and
  364. that the class library __SOM_STEM__.dll can be located via the LIBPATH (or PATH on
  365. DOS/Win).
  366.  
  367. The local command reverses the operation done by the remote command by
  368. removing the object implementation from the Implementation Repository.  The
  369. remote command can not be run again without first running the local command.
  370.  
  371. To clean up the directory of everything but source files, run make and
  372. specify the "clean" target:
  373.  
  374.    On AIX:    make clean
  375.    On OS/2:   nmake -f makefile.32 clean
  376.    On Win:    nmake -f makefile.w16 clean
  377. :dsom_Makefile
  378. # AIX xlc Makefile for DSOM __SOM_STEM__
  379. # Author: SOMobjects Template Builder
  380.  
  381. TARGET     = __SOM_STEM__cli
  382. TARGETS    = chk__SOM_STEM__ $(TARGET) __SOM_STEM__.dll lib__SOM_STEM__.a local remote
  383. OBJS       = __SOM_OBJS__ __SOM_STEM__init.o
  384.  
  385. AR         = ar
  386. CC         = cc
  387. CDEBUG     = -g
  388. LDEBUG     =
  389. CFLAGS     = $(CDEBUG)
  390. LDFLAGS    = -bM:SRE -T512 -H512
  391. LIBLIST    = -lsomtk
  392. LINKER     = ld
  393. RUNSHELL   = ./chk__SOM_STEM__
  394. SC         = sc
  395. SCFLAGS    = -mnoaddstar -p -u
  396. EMITH      = -sh
  397. EMITIH     = -sh:ih
  398. EMITC      = -sc
  399. DELETE     = rm -f
  400.  
  401. .SUFFIXES: .idl .ih .h .sh .c
  402.  
  403. .c.o:
  404.     $(CC) -I. -I$(SOMBASE)/include $(CFLAGS) -c $<
  405.  
  406. .idl.ih:
  407.     $(SC) $(SCFLAGS) $(EMITIH) $<
  408.  
  409. .idl.h:
  410.     $(SC) $(SCFLAGS) $(EMITH) $<
  411.  
  412. .idl.c:
  413.     $(SC) $(SCFLAGS) $(EMITC) $<
  414.  
  415. .sh:
  416.     cp $? $@; chmod 0755 $@
  417.  
  418. all: $(TARGETS) sregimpl
  419.  
  420. chk__SOM_STEM__: chk__SOM_STEM__.sh
  421.     cp $? $@; chmod 0755 $@
  422.     $(RUNSHELL)
  423.  
  424. sregimpl:
  425.     @echo Run the 'remote' command to make use of non-local DSOM objects.
  426.     @echo Or, run the 'local' command to make use of local SOM objects.
  427.     @touch $@
  428.  
  429. $(TARGET): lib__SOM_STEM__.a main.o som__SOM_STEM__.o
  430.     $(CC) $(LDFLAGS) -o $@ main.o som__SOM_STEM__.o -L$(SOMBASE)/lib lib__SOM_STEM__.a $(LIBLIST)
  431.     @echo Run $(TARGET) to execute the client program.
  432.  
  433. main.o: main.c __SOM_STEM__.h
  434.  
  435. som__SOM_STEM__.o: som__SOM_STEM__.c som__SOM_STEM__.h __SOM_STEM__.h
  436.  
  437. __SOM_OBJS_C_DEPS__
  438. __SOM_STEM__init.o: __SOM_STEM__.h __SOM_STEM__init.c
  439.  
  440. __SOM_STEM__.dll: $(OBJS) __SOM_STEM__.exp
  441.     $(LINKER) -o $@ -e SOMInitModule $(OBJS) -bE:__SOM_STEM__.exp -lc $(LDFLAGS) -L$(SOMBASE)/lib $(LIBLIST)
  442.  
  443. lib__SOM_STEM__.a: __SOM_STEM__.dll __SOM_STEM__.exp
  444.     $(AR) ruv $@ __SOM_STEM__.exp
  445.  
  446. clean: local.sh
  447.     -local
  448.     $(DELETE) *.ih *.o $(TARGETS)
  449.     $(DELETE) sregimpl core
  450. __SOM_C_HEADER_DELETE_FILES__
  451. :dsom_makefile.32
  452. # OS/2 C Set Makefile for DSOM __SOM_STEM__
  453. # Author: SOMobjects Template Builder
  454.  
  455. TARGET     = __SOM_STEM__cli.exe
  456. TARGETS    = $(TARGET) __SOM_STEM__.dll __SOM_STEM__.lib
  457. OBJS       = __SOM_OBJS__ __SOM_STEM__init.o
  458.  
  459. CC         = icc
  460. CDEBUG     = -Ti+
  461. LDEBUG     = /debug
  462. CFLAGS     = -W3 -c $(CDEBUG) -Q+ -Ss+ -Gd- -Gm+ -Gs+ -Sm
  463. LDFLAGS    = /exepack /packd /packc /align:4 /stack:100000 /pm:vio /noe /noi /nol $(LDEBUG)
  464. LIBLIST    = somtk.lib
  465. LINKER     = link386
  466. SC         = sc
  467. SCFLAGS    = -mnoaddstar -p -u
  468. EMITH      = -sh
  469. EMITIH     = -sh;ih
  470. EMITC      = -sc
  471. DELETE     = del
  472.  
  473. .SUFFIXES: .idl .ih .h .c
  474.  
  475. .c.o:
  476.         $(CC) -fo$*.o -I. -I$(SOMBASE)\include $(CFLAGS) -Ge- $<
  477.  
  478. .idl.ih:
  479.         $(SC) $(SCFLAGS) $(EMITIH) $<
  480.  
  481. .idl.h:
  482.         $(SC) $(SCFLAGS) $(EMITH) $<
  483.  
  484. .idl.c:
  485.         $(SC) $(SCFLAGS) $(EMITC) $<
  486.  
  487. all: runchk $(TARGETS) sregimpl
  488.  
  489. runchk: chk__SOM_STEM__.cmd
  490.         chk__SOM_STEM__
  491.  
  492. sregimpl:
  493.         @echo Run the 'remote' command to make use of non-local DSOM objects.
  494.         @echo Or, run the 'local' command to make use of local SOM objects.
  495.         echo $@ > $@
  496.  
  497. $(TARGET): __SOM_STEM__.lib main.o som__SOM_STEM__.o
  498.         $(LINKER) $(LDFLAGS) main.o som__SOM_STEM__.o,$@,NUL,$(LIBLIST)+__SOM_STEM__;
  499.         @echo Run $(TARGET) to execute the client program.
  500.  
  501. main.o: main.c __SOM_STEM__.h
  502.         $(CC) -fo$@  $(CFLAGS) -Ge+ main.c
  503.  
  504. som__SOM_STEM__.o: som__SOM_STEM__.c __SOM_STEM__.h
  505.         $(CC) -fo$@  $(CFLAGS) -Ge+ som__SOM_STEM__.c
  506.  
  507. __SOM_OBJS_C_DEPS__
  508. __SOM_STEM__init.o: __SOM_STEM__.h __SOM_STEM__init.c
  509.  
  510. __SOM_STEM__.dll: $(OBJS) __SOM_STEM__.def
  511.         $(LINKER) $(LDFLAGS) @<<
  512. $(OBJS: = +^
  513. )
  514. $@
  515. nul
  516. $(LIBLIST)
  517. __SOM_STEM__.def
  518. \<<
  519.  
  520. __SOM_STEM__.lib: __SOM_STEM__.dll __SOM_STEM__.def
  521.         implib /nologo __SOM_STEM__.lib __SOM_STEM__.def
  522.  
  523. clean:
  524.         -local
  525.         -$(DELETE) sregimpl
  526.         -$(DELETE) $(TARGET)
  527.         -$(DELETE) __SOM_STEM__.lib
  528.         -$(DELETE) __SOM_STEM__.dll
  529.         -$(DELETE) *.ih
  530.         -$(DELETE) *.o
  531.         __SOM_C_HEADER_DELETE_FILES__
  532. :dsom_local.bat
  533. @ECHO OFF
  534. regimpl -D -i __SOM_STEM__Server
  535. echo Ignore any "alias name not found" errors.
  536. echo __SOM_CLASS_NAME__ objects are now local to the client process.
  537. :dsom_local.cmd
  538. @ECHO OFF
  539. regimpl -D -i __SOM_STEM__Server
  540. echo Ignore any "alias name not found" errors.
  541. echo __SOM_CLASS_NAME__ objects are now local to the client process.
  542. :dsom_local.sh
  543. #!/bin/sh -f
  544. regimpl -D -i __SOM_STEM__Server
  545. echo Ignore any \"alias name not found\" errors.
  546. echo __SOM_CLASS_NAME__ objects are now local to the client process.
  547. :dsom_main.c
  548. /*
  549.  * Module name: main.c
  550.  *
  551.  * Description: This is a simple program that encompasses the major elements
  552.  *              of a SOM/DSOM program. The program is written using a set
  553.  *              of general purpose functions (in som__SOM_STEM__.c) such that the
  554.  *              main program below can be run using either a local SOM object
  555.  *              or a remote (DSOM) object.
  556.  *
  557.  *              In order to provide local/remote object transparency, objects
  558.  *              used in the program are always created via a class object.
  559.  *              The class object is either a local object or a proxy for a
  560.  *              class object in the remote server process.
  561.  *
  562.  *              Because an object's creation (for DSOM) results in the creation
  563.  *              of an object in another process, a DSOM program should not
  564.  *              terminate without dealing with any non-local objects.
  565.  *              This program tracks all application objects created and
  566.  *              destroys them in the remote process prior to termination.
  567.  *              (Note: this behavior would be inappropriate if the program
  568.  *              was sharing its remote objects with other DSOM programs.)
  569.  *
  570.  */
  571.  
  572. #include <somd.h>
  573. #include "__SOM_STEM__.h"
  574. #include "som__SOM_STEM__.h"
  575.  
  576. #ifndef _WIN16
  577. int main (int argc, char *argv[])
  578. {
  579.     SOMClass cls;
  580.     __SOM_CLASS_NAME__ obj;
  581.     string name;
  582.     Environment *ev;
  583.     int i, status = 0, max = (argc == 1) ? 1 : atoi(argv[1]);
  584.     char buf[MAX_STRING_SIZE];
  585.  
  586.     somEnvironmentNew();
  587.     ev = SOM_CreateLocalEnvironment();
  588.     cls = __SOM_CLASS_NAME__Initialize(ev);
  589.  
  590.     if (EV_OK(ev)) {
  591.        for (i = 0; i < max; i++) {
  592.           obj = createObject(cls, ev);
  593.           if (EV_OK(ev) && obj) {
  594.              somPrintf("%s\n", name = __get_name(obj, ev));
  595.              freeReturnedMem(name);
  596.              sprintf(buf, "[%d] Hello", i);
  597.              __set_name(obj, ev, buf);
  598.              somPrintf("%s\n", name = __get_name(obj, ev));
  599.              freeReturnedMem(name);
  600.              _append(obj, ev, " World!");
  601.              somPrintf("%s\n", name = __get_name(obj, ev));
  602.              freeReturnedMem(name);
  603.              freeObject(obj, ev);
  604.           }
  605.        }
  606.     }
  607.     else {
  608.        somPrintf("Error creating __SOM_CLASS_NAME__ object.\n");
  609.        status = -1;
  610.     }
  611.  
  612.     SOM_DestroyLocalEnvironment(ev);
  613.     __SOM_STEM__Shutdown();
  614.     return (status);
  615. }
  616. #else
  617. #include <windows.h>
  618. #include <bccstruc.h>
  619.  
  620. long WINAPI WndProc(HWND hwnd, UINT message, UINT wParam, LONG lParam)
  621. {
  622.     static __SOM_CLASS_NAME__ obj;
  623.     static SOMClass cls;
  624.     static Environment *ev;
  625.     char *app_s = "__SOM_CLASS_NAME__ Application", *name;
  626.     char *err_s = "Error creating __SOM_CLASS_NAME__ object.";
  627.  
  628.     if (message == WM_CREATE) {
  629.         ev = SOM_CreateLocalEnvironment();
  630.         cls = __SOM_CLASS_NAME__Initialize(ev);
  631.         if (EV_OK(ev)) {
  632.            obj = createObject(cls, ev);
  633.            if (EV_OK(ev) && obj) {
  634.               __set_name(obj, ev, "Hello");
  635.               MessageBox(hwnd, name = __get_name(obj, ev), app_s, MB_OK);
  636.               freeReturnedMem(name);
  637.               _append(obj, ev, " World!");
  638.               MessageBox(hwnd, name = __get_name(obj, ev), app_s, MB_OK);
  639.               freeReturnedMem(name);
  640.               MessageBox(hwnd, "Press ok to exit", app_s, MB_OK);
  641.               freeObject(obj, ev);
  642.            }
  643.         }
  644.         else {
  645.            MessageBox(hwnd, err_s, app_s, MB_ICONEXCLAMATION);
  646.         }
  647.  
  648.         SOM_DestroyLocalEnvironment(ev);
  649.         __SOM_STEM__Shutdown();
  650.         PostQuitMessage(0);
  651.         return (0);
  652.     }
  653.     else
  654.         return (DefWindowProc(hwnd, message, wParam, lParam));
  655. }
  656.  
  657. int PASCAL WinMain(HANDLE hInstance, HANDLE hPrevInstance, LPSTR lpszCmdParam, int nCmdShow)
  658. {
  659.     static char szAppName[] = "__SOM_CLASS_NAME__";
  660.     HWND hwnd;
  661.     MSG msg;
  662.     WNDCLASS wndclass;
  663.  
  664.     SOM_MainProgram();
  665.     if (!hPrevInstance) {
  666.         wndclass.style = CS_HREDRAW | CS_VREDRAW;
  667.         wndclass.lpfnWndProc = WndProc;
  668.         wndclass.cbClsExtra = 0;
  669.         wndclass.cbWndExtra = 0;
  670.         wndclass.hInstance = hInstance;
  671.         wndclass.hIcon = LoadIcon((HINSTANCE) NULL, IDI_APPLICATION);
  672.         wndclass.hCursor = LoadCursor((HINSTANCE) NULL, IDC_ARROW);
  673.         wndclass.hbrBackground = GetStockObject(LTGRAY_BRUSH);
  674.         wndclass.lpszMenuName = NULL;
  675.         wndclass.lpszClassName = szAppName;
  676.  
  677.         RegisterClass(&wndclass);
  678.     }
  679.  
  680.     hwnd = CreateWindow(szAppName,           //window class name
  681.                         "__SOM_CLASS_NAME__ Program",   //window caption
  682.                         WS_OVERLAPPEDWINDOW, //window style
  683.                         CW_USEDEFAULT,       //initial x position
  684.                         CW_USEDEFAULT,       //initial y position
  685.                         CW_USEDEFAULT,       //initial x size
  686.                         CW_USEDEFAULT,       //initial y size
  687.                         (HWND) NULL,         //parent window handle
  688.                         (HMENU) NULL,        //window menu handle
  689.                         hInstance,           //program instance handle
  690.                         NULL);
  691.     ShowWindow(hwnd, SW_SHOWMINIMIZED);
  692.  
  693.     while (GetMessage(&msg, (HWND) NULL, 0, 0)) {
  694.         TranslateMessage(&msg);
  695.         DispatchMessage(&msg);
  696.     }
  697.     return (msg.wParam);
  698. }
  699. #endif
  700. /*
  701.  * 10H9767, 10H9769 (C) COPYRIGHT International Business Machines Corp. 1992,1994
  702.  * All Rights Reserved
  703.  * Licensed Materials - Property of IBM
  704.  *
  705.  * DISCLAIMER OF WARRANTIES.
  706.  * The following [enclosed] code is sample code created by IBM
  707.  * Corporation. This sample code is not part of any standard or IBM
  708.  * product and is provided to you solely for the purpose of assisting
  709.  * you in the development of your applications.  The code is provided
  710.  * "AS IS".
  711.  *
  712.  * DISTRIBUTION.
  713.  * This sample code can be freely distributed, copied, altered, and
  714.  * incorporated into other software, provided that it bears the above
  715.  * Copyright notice and DISCLAIMER intact.
  716.  */
  717. :dsom_makefile.w16
  718. # Windows Visual C++ Makefile for DSOM __SOM_STEM__
  719. # Author: SOMobjects Template Builder
  720.  
  721. TARGET     = __SOM_STEM__cli.exe
  722. TARGETS    = $(TARGET) __SOM_STEM__.dll __SOM_STEM__.lib
  723. OBJS       = __SOM_OBJS__ __SOM_STEM__init.o
  724.  
  725. CC         = cl
  726. CDEBUG     = -Zi
  727. LDEBUG     = /CO
  728. CFLAGS     = -nologo -Zp1 -Oi $(CDEBUG)
  729. LDFLAGS    = /nologo /ONERROR:NOEXE /nod $(LDEBUG)
  730. LIBLIST    = llibcew libw $(SOMBASE)\lib\somtk
  731. LIBLISTD   = ldllcew libw $(SOMBASE)\lib\somtk
  732. LINKER     = link
  733. SC         = somc
  734. SCFLAGS    = -mnoaddstar -p -u
  735. EMITH      = -sh
  736. EMITIH     = -sh;ih
  737. EMITC      = -sc
  738. DELETE     = del
  739.  
  740. .SUFFIXES: .idl .ih .h .c
  741.  
  742. .c.o:
  743.         $(CC) -c -Fo$*.o -I. -I$(SOMBASE)\include $(CFLAGS) -ALw $<
  744.  
  745. .idl.ih:
  746.         $(SC) $(SCFLAGS) $(EMITIH) $<
  747.  
  748. .idl.h:
  749.         $(SC) $(SCFLAGS) $(EMITH) $<
  750.  
  751. .idl.c:
  752.         $(SC) $(SCFLAGS) $(EMITC) $<
  753.  
  754. all: runchk $(TARGETS) sregimpl
  755.         @echo Now go to windows to run $(TARGET) ...
  756.  
  757. runchk: chk__SOM_STEM__.bat
  758.         chk__SOM_STEM__
  759.  
  760. sregimpl:
  761.         @echo Run the 'remote' command to make use of non-local DSOM objects.
  762.         @echo Or, run the 'local' command to make use of local SOM objects.
  763.         echo $@ > $@
  764.  
  765. $(TARGET): __SOM_STEM__.lib main.o som__SOM_STEM__.o __SOM_STEM__cli.def
  766.         $(LINKER) $(LDFLAGS) @<<
  767. main.o som__SOM_STEM__.o
  768. $@
  769. NUL
  770. $(LIBLIST) __SOM_STEM__.lib
  771. __SOM_STEM__cli.def
  772. \<<
  773.  
  774. main.o: main.c __SOM_STEM__.h
  775.         $(CC) -Fo$@ -I. -I$(SOMBASE)\include $(CFLAGS) -c -AL main.c
  776.  
  777. som__SOM_STEM__.o: som__SOM_STEM__.c __SOM_STEM__.h
  778.         $(CC) -Fo$@ -I. -I$(SOMBASE)\include $(CFLAGS) -c -AL som__SOM_STEM__.c
  779.  
  780. __SOM_OBJS_C_DEPS__
  781. __SOM_STEM__init.o: __SOM_STEM__.h __SOM_STEM__init.c
  782.  
  783. __SOM_STEM__.dll: $(OBJS) __SOM_STEM__w16.def
  784.         $(LINKER) $(LDFLAGS) @<<
  785. $(OBJS: = +^
  786. )
  787. $@
  788. nul
  789. $(LIBLISTD)
  790. __SOM_STEM__w16.def
  791. \<<
  792.  
  793. __SOM_STEM__.lib: __SOM_STEM__.dll __SOM_STEM__w16.def
  794.         implib /nologo __SOM_STEM__.lib __SOM_STEM__w16.def
  795.  
  796. clean:
  797.         -$(DELETE) sregimpl
  798.         -$(DELETE) $(TARGET)
  799.         -$(DELETE) __SOM_STEM__.lib
  800.         -$(DELETE) __SOM_STEM__.dll
  801.         -$(DELETE) *.ih
  802.         -$(DELETE) *.o
  803.         __SOM_C_HEADER_DELETE_FILES__
  804. :dsom___SOM_STEM__.c
  805. /*
  806.  * Module name: __SOM_STEM__.c
  807.  *
  808.  * Description: This source file contains the implementation of the
  809.  *              __SOM_CLASS_NAME__ class.
  810.  *
  811.  *
  812.  */
  813.  
  814. #ifndef SOM_Module___SOM_STEM___Source
  815. #define SOM_Module___SOM_STEM___Source
  816. #endif
  817. #define __SOM_CLASS_NAME___Class_Source
  818.  
  819. #include <somd.h>
  820. #include "__SOM_STEM__.ih"
  821.  
  822.  
  823. /*
  824.  *Method from the IDL attribute statement:
  825.  *"attribute string name"
  826.  */
  827.  
  828. SOM_Scope void  SOMLINK __SOM_STEM____set_name(__SOM_CLASS_NAME__ somSelf,
  829.                                         Environment *ev, string name)
  830. {
  831.     __SOM_CLASS_NAME__Data *somThis = __SOM_CLASS_NAME__GetData(somSelf);
  832.     __SOM_CLASS_NAME__MethodDebug("__SOM_CLASS_NAME__","__SOM_STEM____set_name");
  833.  
  834.     if (_name)
  835.        SOMFree(_name);
  836.     if (!name)
  837.        name = "";
  838.     _name = strcpy((string)SOMMalloc(strlen(name)+1), name);
  839. }
  840.  
  841. /*
  842.  *Method from the IDL attribute statement:
  843.  *"attribute string name"
  844.  */
  845.  
  846. SOM_Scope string  SOMLINK __SOM_STEM____get_name(__SOM_CLASS_NAME__ somSelf,
  847.                                           Environment *ev)
  848. {
  849.     string name;
  850.     __SOM_CLASS_NAME__Data *somThis = __SOM_CLASS_NAME__GetData(somSelf);
  851.     __SOM_CLASS_NAME__MethodDebug("__SOM_CLASS_NAME__","__SOM_STEM____get_name");
  852.  
  853.     if (!_name)
  854.        _name = "";
  855.     name = strcpy((string)SOMMalloc(strlen(_name)+1), _name);
  856.     return(name); /* caller frees storage */
  857. }
  858.  
  859. /*
  860.  * The append method concatenates the given <name> with this object's
  861.  * name attribute.
  862.  */
  863.  
  864. SOM_Scope void  SOMLINK __SOM_STEM___append(__SOM_CLASS_NAME__ somSelf,
  865.                                      Environment *ev, string name)
  866. {
  867.     char buf[MAX_STRING_SIZE];
  868.     string name1;
  869.     __SOM_CLASS_NAME__Data *somThis = __SOM_CLASS_NAME__GetData(somSelf);
  870.     __SOM_CLASS_NAME__MethodDebug("__SOM_CLASS_NAME__","__SOM_STEM___append");
  871.  
  872.     if (!name)
  873.        name = "";
  874.     if (!(name1 = __get_name(somSelf, ev)))
  875.        name1 = "";
  876.  
  877.     strcpy(buf, name1);
  878.     strcat(buf, name);
  879.     __set_name(somSelf, ev, buf);
  880. }
  881.  
  882.  
  883. /*
  884.  * Default object initializer
  885.  */
  886.  
  887. SOM_Scope void SOMLINK __SOM_STEM___somDefaultInit(__SOM_CLASS_NAME__ somSelf,
  888.                                            somInitCtrl* ctrl)
  889. {
  890.     __SOM_CLASS_NAME__Data *somThis; /* set in BeginInitializer */
  891.     somInitCtrl globalCtrl;
  892.     somBooleanVector myMask;
  893.     __SOM_CLASS_NAME__MethodDebug("__SOM_CLASS_NAME__","somDefaultInit");
  894.     __SOM_CLASS_NAME___BeginInitializer_somDefaultInit;
  895.  
  896.     __SOM_CLASS_NAME___Init___SOM_PARENT_CLASS_NAME___somDefaultInit(somSelf, ctrl);
  897.  
  898.     /*
  899.      * local __SOM_CLASS_NAME__ initialization code added by programmer
  900.      */
  901.     _name = (string)NULL;
  902. }
  903.  
  904.  
  905.  
  906. /*
  907.  * Default object uninitializer
  908.  */
  909.  
  910. SOM_Scope void SOMLINK __SOM_STEM___somDestruct(__SOM_CLASS_NAME__ somSelf,
  911.                                         octet doFree, somDestructCtrl* ctrl)
  912. {
  913.     __SOM_CLASS_NAME__Data *somThis; /* set in BeginDestructor */
  914.     somDestructCtrl globalCtrl;
  915.     somBooleanVector myMask;
  916.     __SOM_CLASS_NAME__MethodDebug("__SOM_CLASS_NAME__","__SOM_STEM___somDestruct");
  917.     __SOM_CLASS_NAME___BeginDestructor;
  918.  
  919.     /*
  920.      * local __SOM_CLASS_NAME__ deinitialization code added by programmer
  921.      */
  922.     if (_name)
  923.        SOMFree(_name);
  924.  
  925.     __SOM_CLASS_NAME___EndDestructor;
  926. }
  927. /*
  928.  * 10H9767, 10H9769 (C) COPYRIGHT International Business Machines Corp. 1992,1994
  929.  * All Rights Reserved
  930.  * Licensed Materials - Property of IBM
  931.  *
  932.  * DISCLAIMER OF WARRANTIES.
  933.  * The following [enclosed] code is sample code created by IBM
  934.  * Corporation. This sample code is not part of any standard or IBM
  935.  * product and is provided to you solely for the purpose of assisting
  936.  * you in the development of your applications.  The code is provided
  937.  * "AS IS".
  938.  *
  939.  * DISTRIBUTION.
  940.  * This sample code can be freely distributed, copied, altered, and
  941.  * incorporated into other software, provided that it bears the above
  942.  * Copyright notice and DISCLAIMER intact.
  943.  */
  944. :dsom___SOM_STEM__.def
  945. LIBRARY __SOM_STEM__ INITINSTANCE
  946. DESCRIPTION '__SOM_CLASS_NAME__ Class Library'
  947. PROTMODE
  948. DATA MULTIPLE NONSHARED LOADONCALL
  949. EXPORTS
  950. SOMInitModule
  951. __SOM_EXPORT_PASCAL_NAMES__
  952. :dsom___SOM_STEM__.exp
  953. #! __SOM_STEM__.dll
  954. SOMInitModule
  955. __SOM_EXPORT_PASCAL_NAMES__
  956. :dsom___SOM_STEM__.idl
  957. #ifndef __SOM_STEM___idl
  958. #define __SOM_STEM___idl
  959.  
  960. //
  961. //  Interface : __SOM_CLASS_NAME__
  962. //
  963. //  Description : Simple distributed SOM object class definition.
  964. //
  965.  
  966. __SOM_PARENT_FILES__
  967. __SOM_META_FILES__
  968.  
  969. interface __SOM_CLASS_NAME__ : __SOM_PARENT_NAMES__
  970. {
  971.   const long MAX_STRING_SIZE = 1024;
  972.   attribute string name;
  973.  
  974.   void append(in string name);
  975.   // The append method concatenates the given <name> with this object's
  976.   // name attribute.
  977.  
  978. #ifdef __SOMIDL__
  979.   implementation {
  980.     releaseorder: _get_name, _set_name, append;
  981.  
  982.     // Class Modifiers:
  983.     align     = 4;               // instance data aligned on 4 byte boundary
  984.     memory_management = corba;   // caller owns all returned memory
  985.     dllname   = "__SOM_DLLSTEM__.dll";      // loadable library of this class
  986.     functionprefix = __SOM_STEM___;      // unique method procedure names
  987.     __SOM_META_NAMES__
  988.  
  989.     // Attribute Modifiers:
  990.     name: noget,
  991.           noset; // string attribute methods must be written by user
  992.                  // for "corba" memory_management policy.
  993.  
  994.     // Overrides:
  995.     somDefaultInit: override, init;     // Default object initializer
  996.     somDestruct: override;              // Default object uninitializer
  997.  
  998.   };
  999. #endif /* __SOMIDL__ */
  1000. };
  1001.  
  1002. #endif  /* __SOM_STEM___idl */
  1003. :dsom___SOM_STEM__cli.def
  1004. NAME           __SOM_CLASS_NAME__CLI
  1005. DESCRIPTION    '__SOM_CLASS_NAME__ Client Program'
  1006. EXETYPE        WINDOWS
  1007. STUB           'WINSTUB.EXE'
  1008. CODE           PRELOAD MOVEABLE DISCARDABLE
  1009. DATA           PRELOAD MOVEABLE MULTIPLE
  1010. HEAPSIZE       5000
  1011. STACKSIZE      20000
  1012. :dsom___SOM_STEM__init.c
  1013. /*
  1014.  * Module name: __SOM_STEM__init.c
  1015.  *
  1016.  * Description: This source file contains functions used during the loading
  1017.  *              and initialization of the __SOM_STEM__.dll class library.
  1018.  *
  1019.  *
  1020.  */
  1021. #ifdef __IBMC__
  1022. #pragma linkage(SOMInitModule, system)
  1023. #endif
  1024.  
  1025. __SOM_C_HEADER_FILES__
  1026.  
  1027. void SOMLINK SOMInitModule(integer4 majorVersion, integer4 minorVersion, string ignore)
  1028. {
  1029. __SOM_INITBODY__
  1030. }
  1031.  
  1032. #ifdef _WIN16
  1033. #include <windows.h>
  1034. int CALLBACK LibMain (HINSTANCE inst, WORD ds, WORD heapSize, LPSTR cmdLine)
  1035. {
  1036.     SOM_IgnoreWarning (inst);
  1037.     SOM_IgnoreWarning (ds);
  1038.     SOM_IgnoreWarning (heapSize);
  1039.     SOM_IgnoreWarning (cmdLine);
  1040.  
  1041.     SOM_ClassLibrary ("__SOM_STEM__.dll");
  1042.     return 1;
  1043. }
  1044. #endif
  1045. /*
  1046.  * 10H9767, 10H9769 (C) COPYRIGHT International Business Machines Corp. 1992,1994
  1047.  * All Rights Reserved
  1048.  * Licensed Materials - Property of IBM
  1049.  *
  1050.  * DISCLAIMER OF WARRANTIES.
  1051.  * The following [enclosed] code is sample code created by IBM
  1052.  * Corporation. This sample code is not part of any standard or IBM
  1053.  * product and is provided to you solely for the purpose of assisting
  1054.  * you in the development of your applications.  The code is provided
  1055.  * "AS IS".
  1056.  *
  1057.  * DISTRIBUTION.
  1058.  * This sample code can be freely distributed, copied, altered, and
  1059.  * incorporated into other software, provided that it bears the above
  1060.  * Copyright notice and DISCLAIMER intact.
  1061.  */
  1062. :dsom___SOM_STEM__w16.def
  1063. LIBRARY         __SOM_STEM__
  1064. DESCRIPTION     '__SOM_CLASS_NAME__ Class Library'
  1065. EXETYPE         WINDOWS
  1066. PROTMODE
  1067. STUB            'WINSTUB.EXE'
  1068. DATA            MOVEABLE SINGLE SHARED LOADONCALL
  1069. CODE            MOVEABLE DISCARDABLE LOADONCALL
  1070. HEAPSIZE        4096
  1071.  
  1072. EXPORTS
  1073. __SOM_EXPORT_C_NAMES__
  1074. :dsom_remote.bat
  1075. @ECHO OFF
  1076. REM This program takes one argument, the name of the remote system of the
  1077. REM server process. The system defaults to the local host.
  1078. if "%1" == "" goto default
  1079. REM ------------- Non local system setup ----------------------------------
  1080. regimpl -A -h %1 -i __SOM_STEM__Server
  1081. if errorlevel 1 goto failed
  1082. echo Implementation registered for the %1 system.
  1083. echo Please verify that somdd is running on the %1 system.
  1084. goto continue
  1085. REM ------------- local system setup --------------------------------------
  1086. \:default
  1087. regimpl -A -i __SOM_STEM__Server
  1088. if errorlevel 1 goto failed
  1089. echo Implementation registered for this system.
  1090. echo Please verify that somdd is running on this system.
  1091. \:continue
  1092. regimpl -a -i __SOM_STEM__Server -c __SOM_CLASS_NAME__
  1093. regimpl -L -i __SOM_STEM__Server
  1094. regimpl -l -i __SOM_STEM__Server
  1095. goto done
  1096. \:failed
  1097. echo The object implementation registration failed.
  1098. \:done
  1099. :dsom_remote.cmd
  1100. @ECHO OFF
  1101. REM This program takes one argument, the name of the remote system of the
  1102. REM server process. The system defaults to the local host.
  1103. if "%1" == "" goto default
  1104. REM ------------- Non local system setup ----------------------------------
  1105. regimpl -A -h %1 -i __SOM_STEM__Server
  1106. if errorlevel 1 goto failed
  1107. echo Implementation registered for the %1 system.
  1108. echo Please verify that somdd is running on the %1 system.
  1109. goto continue
  1110. REM ------------- local system setup --------------------------------------
  1111. \:default
  1112. regimpl -A -i __SOM_STEM__Server
  1113. if errorlevel 1 goto failed
  1114. echo Implementation registered for this system.
  1115. echo Please verify that somdd is running on this system.
  1116. \:continue
  1117. regimpl -a -i __SOM_STEM__Server -c __SOM_CLASS_NAME__
  1118. regimpl -L -i __SOM_STEM__Server
  1119. regimpl -l -i __SOM_STEM__Server
  1120. goto done
  1121. \:failed
  1122. echo The object implementation registration failed.
  1123. \:done
  1124. :dsom_remote.sh
  1125. #!/bin/sh -f
  1126. # This program takes one argument, the name of the remote system of the
  1127. # server process. The system defaults to the local host.
  1128. sys=${1:-`hostname`}
  1129. if regimpl -A -h $sys -i __SOM_STEM__Server
  1130. then
  1131.     regimpl -a -i __SOM_STEM__Server -c __SOM_CLASS_NAME__
  1132.     echo Implementation registered for the $sys system.
  1133.     echo Please verify that somdd is running on the $sys system.
  1134.     regimpl -L -i __SOM_STEM__Server
  1135.     regimpl -l -i __SOM_STEM__Server
  1136. fi
  1137. :dsom_chk__SOM_STEM__.bat
  1138. @ECHO OFF
  1139. REM Quick check of a few important variables...
  1140. IF "%SOMBASE%" == "" echo SOMBASE must be set to SOM install directory. Usually c:\som.
  1141. IF "%SMINCLUDE%" == "" echo SMINCLUDE must be set to include %sombase%\include.
  1142. IF "%INCLUDE%" == "" echo INCLUDE must be set to include %sombase%\include.
  1143. IF "%LIB%" == "" echo LIB must be set to include %sombase%\lib.
  1144. IF "%SOMIR%" == "" echo SOMIR must be set for DSOM. Typically %sombase%\etc\som.ir;som.ir
  1145. IF "%SOMSOCKETS%" == "" echo SOMSOCKETS must be set for remote DSOM. Example: TCPIPSockets
  1146. IF "%USER%" == "" echo USER must be set for DSOM.
  1147. IF "%HOSTNAME%" == "" echo HOSTNAME must be set for DSOM.
  1148. IF "%SOMDDIR%" == "" echo SOMDDIR should be set for DSOM. Defaults to %sombase%\etc\dsom.
  1149. :dsom_chk__SOM_STEM__.cmd
  1150. @ECHO OFF
  1151. REM Quick check of a few important variables...
  1152. IF "%SOMBASE%" == "" echo SOMBASE must be set to SOM install directory. Usually c:\som. & goto pgmchk
  1153. IF "%SMINCLUDE%" == "" echo SMINCLUDE must be set to include %sombase%\include. & set chk__SOM_STEM__=1
  1154. IF "%INCLUDE%" == "" echo INCLUDE must be set to include %sombase%\include. & set chk__SOM_STEM__=1
  1155. IF "%LIB%" == "" echo LIB must be set to include %sombase%\lib. & set chk__SOM_STEM__=1
  1156. IF "%SOMIR%" == "" echo SOMIR must be set for DSOM. Typically %sombase%\etc\som.ir;som.ir & set chk__SOM_STEM__=1
  1157. IF "%SOMSOCKETS%" == "" echo SOMSOCKETS must be set for remote DSOM. Example: TCPIPSockets & set chk__SOM_STEM__=1
  1158. IF "%USER%" == "" echo USER must be set for DSOM. & set chk__SOM_STEM__=1
  1159. IF "%HOSTNAME%" == "" echo HOSTNAME must be set for DSOM. & set chk__SOM_STEM__=1
  1160. IF "%SOMDDIR%" == "" echo SOMDDIR should be set for DSOM. Defaults to %sombase%\etc\dsom. & set chk__SOM_STEM__=1
  1161. IF NOT "%CHK__SOM_STEM__%" == "1" goto done
  1162. \:pgmchk
  1163. echo You may want to run the SOMDCHK program to check your environment further.
  1164. \:done
  1165. SET CHK__SOM_STEM__=
  1166. :dsom_chk__SOM_STEM__.sh
  1167. #!/bin/sh -f
  1168. # Quick check of a few important variables...
  1169. chk__SOM_STEM__=0
  1170. if [ -z "$SOMBASE" ]
  1171. then
  1172.     echo SOMBASE must be set to SOM install directory. Usually /usr/lpp/som.
  1173.     chk__SOM_STEM__=1
  1174. else
  1175.     [ -z "$SMINCLUDE" ]  && echo SMINCLUDE must be set to include $SOMBASE/include. && chk__SOM_STEM__=1
  1176.     [ -z "$INCLUDE" ]    && echo INCLUDE must be set to include $SOMBASE/include. && chk__SOM_STEM__=1
  1177.     [ -z "$LIB" ]        && echo LIB must be set to include $SOMBASE/lib. && chk__SOM_STEM__=1
  1178.     [ -z "$SOMIR" ]      && echo SOMIR must be set for DSOM. Typically $SOMBASE'/etc/som.ir:som.ir' && chk__SOM_STEM__=1
  1179.     [ -z "$SOMSOCKETS" ] && echo SOMSOCKETS must be set for remote DSOM. Example: TCPIPSockets && chk__SOM_STEM__=1
  1180.     [ -z "$USER" ]       && echo USER must be set for DSOM. && chk__SOM_STEM__=1
  1181.     [ -z "$HOSTNAME" ]   && echo HOSTNAME must be set for DSOM. && chk__SOM_STEM__=1
  1182.     [ -z "$SOMDDIR" ]    && echo SOMDDIR should be set for DSOM. Defaults to $SOMBASE/etc/dsom. && chk__SOM_STEM__=1
  1183. fi
  1184. if [ $chk__SOM_STEM__ -eq 1 ]
  1185. then
  1186.    echo You may want to run the SOMDCHK program to check your environment further.
  1187. fi
  1188. :dsom_som__SOM_STEM__.h
  1189. #include <som.h>
  1190.  
  1191. /* Types */
  1192.  
  1193. /* For building a list of objects */
  1194. typedef
  1195.    struct objectList {
  1196.              SOMObject obj;
  1197.              struct objectList *next;
  1198.           } *objectList;
  1199.  
  1200. /* Globals */
  1201. SOMEXTERN boolean __SOM_STEM__isdsom;     /* == TRUE when process using DSOM */
  1202. SOMEXTERN boolean __SOM_STEM__inShutdown; /* == TRUE when process in shutdown */
  1203. SOMEXTERN objectList __SOM_STEM__Objs;   /* list head */
  1204. SOMEXTERN objectList __SOM_STEM__ObjsTl; /* list tail */
  1205.  
  1206. /* Functions */
  1207. void printDSOMEv(Environment *ev, boolean fatal);
  1208. SOMClass __SOM_CLASS_NAME__Initialize(Environment *ev);
  1209. void freeReturnedMem(void *p);
  1210. SOMObject createObject(SOMClass cls, Environment *ev);
  1211. void freeObject(SOMObject obj, Environment *ev);
  1212. void addObjectToShutdownList(SOMObject obj);
  1213. void removeObjectFromShutdownList(SOMObject obj);
  1214. void __SOM_STEM__SigHandler(int sig);
  1215. void __SOM_STEM__Init(Environment *ev);
  1216. void __SOM_STEM__Shutdown(void);
  1217.  
  1218. /* Macros */
  1219. #define SHUTDOWN (__SOM_STEM__inShutdown == TRUE)
  1220. #define USING_DSOM (__SOM_STEM__isdsom == TRUE)
  1221. #define FATAL ((boolean)1)
  1222. #define NOT_FATAL ((boolean)0)
  1223. #define EV_OK(ev) ((ev)->_major == NO_EXCEPTION)
  1224. #define EV_NOT_OK(ev) ((ev)->_major != NO_EXCEPTION)
  1225. /*
  1226.  * 10H9767, 10H9769 (C) COPYRIGHT International Business Machines Corp. 1992,1994
  1227.  * All Rights Reserved
  1228.  * Licensed Materials - Property of IBM
  1229.  *
  1230.  * DISCLAIMER OF WARRANTIES.
  1231.  * The following [enclosed] code is sample code created by IBM
  1232.  * Corporation. This sample code is not part of any standard or IBM
  1233.  * product and is provided to you solely for the purpose of assisting
  1234.  * you in the development of your applications.  The code is provided
  1235.  * "AS IS".
  1236.  *
  1237.  * DISTRIBUTION.
  1238.  * This sample code can be freely distributed, copied, altered, and
  1239.  * incorporated into other software, provided that it bears the above
  1240.  * Copyright notice and DISCLAIMER intact.
  1241.  */
  1242. :dsom_som__SOM_STEM__.c
  1243. /*
  1244.  * Module name: som__SOM_STEM__.c
  1245.  *
  1246.  * Description: This source file contains serveral general purpose functions
  1247.  *              that can be used to program SOM objects without regard to
  1248.  *              whether they are local or remote.
  1249.  *
  1250.  *              Functions included are:
  1251.  *
  1252.  *              __SOM_CLASS_NAME__Initialize - init and return class
  1253.  *              printDSOMEv - prints a SOM or DSOM exception
  1254.  *              createObject - creates an object from a given class
  1255.  *              freeObject - frees an object (local and remote)
  1256.  *              freeReturnedMem - frees memory returned from a method call
  1257.  *              addObjectToShutdownList - adds to set of objects to shutdown
  1258.  *              removeObjectFromShutdownList - removes from set of " " "
  1259.  *              __SOM_STEM__Init - initialize application
  1260.  *              __SOM_STEM__Shutdown - shutdown the application, free app objects
  1261.  *              __SOM_STEM__SigHandler - handle termination signals.
  1262.  *
  1263.  */
  1264.  
  1265. #include <somd.h>
  1266. #include "__SOM_STEM__.h"
  1267. #include "som__SOM_STEM__.h"
  1268. #include <signal.h>
  1269.  
  1270. /* Globals */
  1271. SOMEXTERN boolean __SOM_STEM__isdsom = FALSE;
  1272. SOMEXTERN boolean __SOM_STEM__inShutdown = FALSE;
  1273. SOMEXTERN objectList __SOM_STEM__ShutdownList = (objectList)NULL;   /* list head */
  1274. SOMEXTERN objectList __SOM_STEM__ShutdownListTl = (objectList)NULL; /* list tail */
  1275.  
  1276. /*
  1277.  * __SOM_STEM__SigHandler handles signals for the application.
  1278.  *
  1279.  */
  1280. void __SOM_STEM__SigHandler(int sig)
  1281. {
  1282.     char buf[16];
  1283.     Environment ev;
  1284.     SOM_InitEnvironment(&ev);
  1285.     __SOM_STEM__Shutdown();
  1286.     exit(sig);
  1287. }
  1288.  
  1289. /*
  1290.  * __SOM_STEM__Init prepares the process to start running. It may be called
  1291.  * multiple times without side effects.
  1292.  *
  1293.  */
  1294. static boolean initDone = FALSE;
  1295. void __SOM_STEM__Init(Environment *ev)
  1296. {
  1297.     if (!initDone) {
  1298.        initDone = TRUE;
  1299.        atexit(__SOM_STEM__Shutdown);
  1300.  
  1301. #ifndef _WIN16
  1302.        #ifdef SIGABRT
  1303.        signal(SIGABRT,  __SOM_STEM__SigHandler);  /* abnormal termination */
  1304.        #endif
  1305.  
  1306.        #ifdef SIGBREAK
  1307.        signal(SIGBREAK, __SOM_STEM__SigHandler);  /* Ctrl-break */
  1308.        #endif
  1309.  
  1310.        #ifdef SIGINT
  1311.        signal(SIGINT,   __SOM_STEM__SigHandler);  /* Ctrl-c */
  1312.        #endif
  1313.  
  1314.        #ifdef SIGQUIT
  1315.        signal(SIGQUIT,  __SOM_STEM__SigHandler);  /* Quit */
  1316.        #endif
  1317.  
  1318.        #ifdef SIGIOT
  1319.        signal(SIGIOT,   __SOM_STEM__SigHandler);  /* End process */
  1320.        #endif
  1321. #endif
  1322.     }
  1323. }
  1324.  
  1325. /*
  1326.  * printDSOMEv prints the contents of a SOM/DSOM exception and then frees
  1327.  * the contents of the exeception. If this is indicated to be a fatal
  1328.  * exception, the process is shutdown and then terminated.
  1329.  *
  1330.  */
  1331. void printDSOMEv(Environment *ev, boolean fatal)
  1332. {
  1333.     string exId;           /* exception ID string */
  1334.     StExcep *params;       /* standard exception structure */
  1335.  
  1336.     exId = exception_id(ev);
  1337.     params = exception_value(ev);
  1338.  
  1339.     somPrintf("Exception Occurred\n");
  1340.     somPrintf("    exception ID : %s\n", exId);
  1341.     somPrintf("minor error code : %u\n", params->minor);
  1342.     somPrintf(" completion code : %s\n", (params->completed == YES ? "YES" :
  1343.                                       params->completed == NO ? "NO": "MAYBE"));
  1344.  
  1345.     somdExceptionFree(ev); /* Frees SOM or DSOM exception */
  1346.  
  1347.     if (fatal) {
  1348.        __SOM_STEM__Shutdown();
  1349.        exit((int)params->minor);
  1350.     }
  1351. }
  1352.  
  1353.  
  1354. /*
  1355.  * __SOM_CLASS_NAME__Initialize returns a __SOM_CLASS_NAME__ class object.
  1356.  * The class object returned can be used to transparently create instances of
  1357.  * __SOM_CLASS_NAME__. The class object returned may be either a local
  1358.  * class object or a proxy for a non-local class object, depending on
  1359.  * whether SOMD_Init successfully initializes DSOM.
  1360.  *
  1361.  * Note: In general, this function should be customized such that the
  1362.  * class object returned is always a local object or always a proxy.
  1363.  * That is, if this function must return a proxy class, any exception
  1364.  * encountered should be considered fatal.
  1365.  *
  1366.  */
  1367. SOMClass __SOM_CLASS_NAME__Initialize(Environment *ev)
  1368. {
  1369.     SOMDServer svr;              /* DSOM server object */
  1370.     SOMClass cls;                /* class object to return */
  1371.     SOMClass rcls;               /* class object to return */
  1372.  
  1373.     __SOM_STEM__Init(ev);
  1374.  
  1375.     /* Create the __SOM_CLASS_NAME__ class object, if it doesn't
  1376.        already exist.  Use this if a remote class object can't be returned.
  1377.      */
  1378.     cls = __SOM_CLASS_NAME__NewClass(__SOM_CLASS_NAME___MajorVersion,
  1379.                                      __SOM_CLASS_NAME___MinorVersion);
  1380.  
  1381.     /* Initialize DSOM framework */
  1382.     SOMD_Init(ev);
  1383.  
  1384.     /* If no exception was encountered during DSOM initialization,
  1385.        find a DSOM server that can be used to create a remote
  1386.        object instance and then get a class object proxy from
  1387.        that server. The class object proxy will be used to
  1388.        create remote object instances.
  1389.  
  1390.        If exceptions are encountered, during init or while finding
  1391.        the server, just use the local class object.
  1392.      */
  1393.     if (EV_OK(ev)) {
  1394. #ifdef FIND_BY_CLASSNAME
  1395.        svr = _somdFindAnyServerByClass(SOMD_ObjectMgr, ev, "__SOM_CLASS_NAME__");
  1396. #else
  1397.        svr = _somdFindServerByName(SOMD_ObjectMgr, ev, "__SOM_STEM__Server");
  1398. #endif
  1399.        if (svr && EV_OK(ev)) {
  1400.           rcls = _somdGetClassObj(svr, ev, "__SOM_CLASS_NAME__");
  1401.           if (rcls && EV_OK(ev)) {
  1402.              __SOM_STEM__isdsom = TRUE;
  1403.              cls = rcls;
  1404.           }
  1405.        }
  1406.     }
  1407.  
  1408.     if (EV_NOT_OK(ev)) {
  1409.        printDSOMEv(ev, NOT_FATAL); /* report any problems, but continue */
  1410.     }
  1411.  
  1412.     return (cls);
  1413. }
  1414.  
  1415.  
  1416. /*
  1417.  * __SOM_STEM__Shutdown prepares the process for termination.
  1418.  * All application objects are freed and DSOM is uninitialized.
  1419.  *
  1420.  */
  1421. void __SOM_STEM__Shutdown()
  1422. {
  1423.     Environment ev;
  1424.     objectList p;
  1425.  
  1426.     SOM_InitEnvironment(&ev);
  1427.     __SOM_STEM__inShutdown = TRUE;
  1428.     for (p=__SOM_STEM__ShutdownList; p; p=p->next)
  1429.        freeObject(p->obj, &ev);
  1430.     SOMD_Uninit(&ev);
  1431.     somEnvironmentEnd();
  1432. }
  1433.  
  1434. /*
  1435.  * freeReturnedMem frees the given block of memory using a procedure determined
  1436.  * by whether the process is using DSOM.
  1437.  *
  1438.  */
  1439. void freeReturnedMem(void *p)
  1440. {
  1441.     if (p)
  1442.        if (USING_DSOM)
  1443.            ORBfree(p);
  1444.        else
  1445.            SOMFree(p);
  1446. }
  1447.  
  1448.  
  1449. /*
  1450.  * Create an instance of the given SOM class. Add the
  1451.  * instance to a global list of all application objects.
  1452.  *
  1453.  * Note: when the class object is a proxy for remote
  1454.  *       class object, the instance is created in the remote
  1455.  *       process.
  1456.  *
  1457.  */
  1458. SOMObject createObject(SOMClass cls, Environment *ev)
  1459. {
  1460.     SOMObject obj;
  1461.  
  1462.     obj = _somNew(cls);
  1463.     if (obj)
  1464.        /* add the object to the list of objects to be cleaned up
  1465.           at shutdown.          */
  1466.        addObjectToShutdownList(obj);
  1467.     return(obj);
  1468. }
  1469.  
  1470.  
  1471. /*
  1472.  * Delete an instance of a SOM object and remove the object
  1473.  * from the global list of all application objects.
  1474.  * This function can delete local as well as remote instances.
  1475.  *
  1476.  */
  1477. void freeObject(SOMObject obj, Environment *ev)
  1478. {
  1479.     somId methId;
  1480.  
  1481.     if (obj) {
  1482.        methId = SOM_IdFromString("somdTargetFree");
  1483.        if (USING_DSOM && _somRespondsTo(obj, methId)) {
  1484.           _somdTargetFree(obj, ev); /* free at server */
  1485.           _somdProxyFree(obj, ev); /* free local proxy */
  1486.        } else {
  1487.           _somFree(obj);
  1488.        }
  1489.        SOMFree(methId);
  1490.        removeObjectFromShutdownList(obj);
  1491.     }
  1492. }
  1493.  
  1494. /* Add an object to the tail end of the global list of
  1495.  * all application objects.
  1496.  */
  1497. void addObjectToShutdownList(SOMObject obj)
  1498. {
  1499.     if (__SOM_STEM__ShutdownList) {
  1500.        __SOM_STEM__ShutdownListTl->next =
  1501.                           (objectList)SOMMalloc(sizeof(struct objectList));
  1502.        __SOM_STEM__ShutdownListTl = __SOM_STEM__ShutdownListTl->next;
  1503.     } else
  1504.        __SOM_STEM__ShutdownList = __SOM_STEM__ShutdownListTl =
  1505.                           (objectList)SOMMalloc(sizeof(struct objectList));
  1506.     __SOM_STEM__ShutdownListTl->next = (objectList)NULL;
  1507.     __SOM_STEM__ShutdownListTl->obj = obj;
  1508. }
  1509.  
  1510. /* Remove object from global list of all application objects and
  1511.  * fixup the list.
  1512.  */
  1513. void removeObjectFromShutdownList(SOMObject obj)
  1514. {
  1515.     objectList p, t;
  1516.  
  1517.     if (!SHUTDOWN) { /* only remove entries if we are not shutting down */
  1518.        for (p=__SOM_STEM__ShutdownList, t=NULL; p && (p->obj!=obj); t=p, p=p->next);
  1519.        if (p==__SOM_STEM__ShutdownListTl) __SOM_STEM__ShutdownListTl = t;
  1520.        if (p && !t) { /* object found in first node of list */
  1521.           __SOM_STEM__ShutdownList = p->next;
  1522.           SOMFree(p);
  1523.        } else if (p && t) { /* object found in some other node of list */
  1524.           t->next = p->next;
  1525.           SOMFree(p);
  1526.        }
  1527.     }
  1528. }
  1529. /*
  1530.  * 10H9767, 10H9769 (C) COPYRIGHT International Business Machines Corp. 1992,1994
  1531.  * All Rights Reserved
  1532.  * Licensed Materials - Property of IBM
  1533.  *
  1534.  * DISCLAIMER OF WARRANTIES.
  1535.  * The following [enclosed] code is sample code created by IBM
  1536.  * Corporation. This sample code is not part of any standard or IBM
  1537.  * product and is provided to you solely for the purpose of assisting
  1538.  * you in the development of your applications.  The code is provided
  1539.  * "AS IS".
  1540.  *
  1541.  * DISTRIBUTION.
  1542.  * This sample code can be freely distributed, copied, altered, and
  1543.  * incorporated into other software, provided that it bears the above
  1544.  * Copyright notice and DISCLAIMER intact.
  1545.  */
  1546. :gidl
  1547. #ifndef __SOM_STEM___idl
  1548. #define __SOM_STEM___idl
  1549.  
  1550. __SOM_PARENT_FILES__
  1551. __SOM_META_FILES__
  1552.  
  1553. interface __SOM_CLASS_NAME__ : __SOM_PARENT_NAMES__
  1554. {
  1555.   // Attributes filled in here:
  1556.  
  1557.   // Operations filled in here:
  1558.  
  1559. #ifdef __SOMIDL__
  1560.   implementation {
  1561.     releaseorder:;
  1562.  
  1563.     // Class Modifiers:
  1564.     align     = 4;
  1565.     dllname   = "__SOM_DLLSTEM__.dll";
  1566.     __SOM_META_NAMES__
  1567.  
  1568.     // Attribute Modifiers:
  1569.  
  1570.     // Overrides:
  1571.     somDefaultInit: override, init;     // Default object initializer
  1572.     somDestruct: override;              // Default object uninitializer
  1573.   };
  1574. #endif /* __SOMIDL__ */
  1575. };
  1576. #endif  /* __SOM_STEM___idl */
  1577. :gidl_meta
  1578. #ifndef __SOM_STEM___idl
  1579. #define __SOM_STEM___idl
  1580.  
  1581. #include <somcls.idl>
  1582.  
  1583. interface __SOM_CLASS_NAME__ : SOMClass
  1584. {
  1585.   //# Attributes filled in here:
  1586.  
  1587.   //# Operations filled in here:
  1588.  
  1589. #ifdef __SOMIDL__
  1590.   implementation {
  1591.     releaseorder:;
  1592.  
  1593.     //# Class Modifiers:
  1594.     align     = 4;
  1595.     dllname   = "__SOM_DLLSTEM__.dll";
  1596.  
  1597.     //# Attribute Modifiers:
  1598.  
  1599.     //# Overrides:
  1600.   };
  1601. #endif /* __SOMIDL__ */
  1602. };
  1603. #endif  /* __SOM_STEM___idl */
  1604. :gidl_parent
  1605. #ifndef __SOM_STEM___idl
  1606. #define __SOM_STEM___idl
  1607.  
  1608. #include <somobj.idl>
  1609.  
  1610. interface __SOM_CLASS_NAME__ : SOMObject
  1611. {
  1612.   // Attributes filled in here:
  1613.  
  1614.   // Operations filled in here:
  1615.  
  1616. #ifdef __SOMIDL__
  1617.   implementation {
  1618.     releaseorder:;
  1619.  
  1620.     // Class Modifiers:
  1621.     align     = 4;
  1622.     dllname   = "__SOM_DLLSTEM__.dll";
  1623.  
  1624.     // Attribute Modifiers:
  1625.  
  1626.     // Overrides:
  1627.   };
  1628. #endif /* __SOMIDL__ */
  1629. };
  1630. #endif  /* __SOM_STEM___idl */
  1631. :dsomsvr_Makefile
  1632. # AIX xlc Makefile for DSOM server __SOM_STEM__svr
  1633. # Author: SOMObjects Application Builder
  1634.  
  1635. TARGET     = __SOM_STEM__svr
  1636. TARGETS    = $(TARGET)
  1637. OBJS       = __SOM_STEM__svr.o
  1638.  
  1639. AR         = ar
  1640. CC         = cc
  1641. CDEBUG     = -g
  1642. LDEBUG     =
  1643. CFLAGS     = $(CDEBUG)
  1644. LDFLAGS    = -bM:SRE -T512 -H512
  1645. LIBLIST    = -lsomtk
  1646. LINKER     = ld
  1647. RUNSHELL   = ./chk__SOM_STEM__
  1648. SC         = sc
  1649. SCFLAGS    = -mnoaddstar -p -u
  1650. EMITH      = -sh
  1651. EMITIH     = -sh:ih
  1652. EMITC      = -sc
  1653. DELETE     = rm -f
  1654.  
  1655. .SUFFIXES: .idl .ih .h .sh .c
  1656.  
  1657. .c.o:
  1658.     $(CC) -I. -I$(SOMBASE)/include $(CFLAGS) -c $<
  1659.  
  1660. .idl.ih:
  1661.     $(SC) $(SCFLAGS) $(EMITIH) $<
  1662.  
  1663. .idl.h:
  1664.     $(SC) $(SCFLAGS) $(EMITH) $<
  1665.  
  1666. .idl.c:
  1667.     $(SC) $(SCFLAGS) $(EMITC) $<
  1668.  
  1669. .sh:
  1670.     cp $? $@; chmod 0755 $@
  1671.  
  1672. all: chk__SOM_STEM__ $(TARGETS)
  1673.  
  1674. chk__SOM_STEM__: chk__SOM_STEM__.sh
  1675.     cp $? $@; chmod 0755 $@
  1676.     $(RUNSHELL)
  1677.  
  1678. $(TARGET): $(OBJS)
  1679.     $(CC) $(LDFLAGS) -o $@ $(OBJS) -L$(SOMBASE)/lib $(LIBLIST)
  1680.     @echo DSOM server $(TARGET) built.
  1681.  
  1682. __SOM_STEM__svr.o: __SOM_STEM__svr.c
  1683.  
  1684. clean:
  1685.     -$(DELETE) *.o $(TARGETS) chk__SOM_STEM__
  1686.  
  1687. :dsomsvr_makefile.32
  1688. # OS/2 C Set Makefile for DSOM server __SOM_STEM__svr
  1689. # Author: SOMObjects Template Builder
  1690.  
  1691. TARGET     = __SOM_STEM__svr.exe
  1692. TARGETS    = $(TARGET)
  1693. OBJS       = __SOM_STEM__svr.o
  1694.  
  1695. CC         = icc
  1696. CDEBUG     = -Ti+
  1697. LDEBUG     = /debug
  1698. CFLAGS     = -W3 -c $(CDEBUG) -Q+ -Ss+ -Gd- -Gm+ -Gs+ -Sm
  1699. LDFLAGS    = /exepack /packd /packc /align:4 /stack:100000 /pm:vio /noe /noi /nol $(LDEBUG)
  1700. LIBLIST    = somtk.lib
  1701. LINKER     = link386
  1702. RUNSHELL   = set__SOM_STEM__
  1703. SC         = sc
  1704. SCFLAGS    = -mnoaddstar -p -u
  1705. EMITH      = -sh
  1706. EMITIH     = -sh;ih
  1707. EMITC      = -sc
  1708. DELETE     = del
  1709.  
  1710. .SUFFIXES: .idl .ih .h .c
  1711.  
  1712. .c.o:
  1713.         $(CC) -fo$*.o -I. -I$(SOMBASE)\include $(CFLAGS) -Ge+ $<
  1714.  
  1715. .idl.ih:
  1716.         $(SC) $(SCFLAGS) $(EMITIH) $<
  1717.  
  1718. .idl.h:
  1719.         $(SC) $(SCFLAGS) $(EMITH) $<
  1720.  
  1721. .idl.c:
  1722.         $(SC) $(SCFLAGS) $(EMITC) $<
  1723.  
  1724. all: runchk $(TARGETS)
  1725.  
  1726. runchk: chk__SOM_STEM__.cmd
  1727.         chk__SOM_STEM__
  1728.  
  1729. $(TARGET): $(OBJS)
  1730.         $(LINKER) $(LDFLAGS) $(OBJS),$@,NUL,$(LIBLIST);
  1731.         @echo DSOM server $(TARGET) built.
  1732.  
  1733. __SOM_STEM__svr.o: __SOM_STEM__svr.c
  1734.  
  1735. clean:
  1736.         -$(DELETE) $(TARGET)
  1737.         -$(DELETE) *.o
  1738.  
  1739. :dsomsvr_makefile.w16
  1740. # Windows Visual C++ Makefile for DSOM server __SOM_STEM__svr
  1741. # Author: SOMobjects Template Builder
  1742.  
  1743. TARGET     = __SOM_STEM__svr.exe
  1744. TARGETS    = $(TARGET)
  1745. OBJS       = __SOM_STEM__svr.o
  1746.  
  1747. CC         = cl
  1748. CDEBUG     = -Zi
  1749. LDEBUG     = /CO
  1750. CFLAGS     = -nologo -Zp1 -Oi $(CDEBUG)
  1751. LDFLAGS    = /nologo /ONERROR:NOEXE /nod $(LDEBUG)
  1752. LIBLIST    = llibcew libw $(SOMBASE)\lib\somtk
  1753. LIBLISTD   = ldllcew libw $(SOMBASE)\lib\somtk
  1754. LINKER     = link
  1755. SC         = somc
  1756. SCFLAGS    = -mnoaddstar -p -u
  1757. EMITH      = -sh
  1758. EMITIH     = -sh;ih
  1759. EMITC      = -sc
  1760. DELETE     = del
  1761.  
  1762. .SUFFIXES: .idl .ih .h .c
  1763.  
  1764. .c.o:
  1765.         $(CC) -c -D_WIN16 -Fo$*.o -I. -I$(SOMBASE)\include $(CFLAGS) -AL $<
  1766.  
  1767. .idl.ih:
  1768.         $(SC) $(SCFLAGS) $(EMITIH) $<
  1769.  
  1770. .idl.h:
  1771.         $(SC) $(SCFLAGS) $(EMITH) $<
  1772.  
  1773. .idl.c:
  1774.         $(SC) $(SCFLAGS) $(EMITC) $<
  1775.  
  1776. all: runchk $(TARGETS)
  1777.         @echo Now go to windows to run $(TARGET) ...
  1778.  
  1779. runchk: chk__SOM_STEM__.bat
  1780.         chk__SOM_STEM__
  1781.  
  1782. $(TARGET): $(OBJS) __SOM_STEM__svr.def
  1783.         $(LINKER) $(LDFLAGS) @<<
  1784. $(OBJS)
  1785. $@
  1786. NUL
  1787. $(LIBLIST)
  1788. __SOM_STEM__svr.def
  1789. \<<
  1790.         @echo DSOM server $(TARGET) built.
  1791.  
  1792. __SOM_STEM__svr.o: __SOM_STEM__svr.c
  1793.  
  1794. clean:
  1795.         -$(DELETE) $(TARGET)
  1796.         -$(DELETE) *.o
  1797.  
  1798. :dsomsvr___SOM_STEM__svr.def
  1799. NAME           __SOM_STEM__svr
  1800. DESCRIPTION    'DSOM Server Program'
  1801. EXETYPE        WINDOWS
  1802. STUB           'WINSTUB.EXE'
  1803. CODE           PRELOAD MOVEABLE DISCARDABLE
  1804. DATA           PRELOAD MOVEABLE MULTIPLE
  1805. HEAPSIZE       16384
  1806. STACKSIZE      32768
  1807. :dsomsvr___SOM_STEM__svr.c
  1808. /*
  1809.  *  This is a generic DSOM server which can use the shared server or persistent
  1810.  *  server activation policy.
  1811.  *
  1812.  *  Syntax:  __SOM_STEM__svr <implid> | -a <alias>
  1813.  *
  1814.  *  The implid or alias must be defined in the current Implementation
  1815.  *  Repository.
  1816.  *
  1817.  */
  1818.  
  1819. #ifdef __OS2__
  1820.   #define INCL_DOSPROCESS
  1821.   #include <os2.h>
  1822. #endif
  1823. #if !defined(_WIN16) && !defined(__WINDOWS__) && !defined(__OS2__)
  1824.   #ifndef _ALL_SOURCE
  1825.   #define _ALL_SOURCE
  1826.   #endif
  1827. #endif
  1828. #ifdef _WIN16
  1829.   #include <windows.h>
  1830.   #define LOADDS __loadds
  1831.   #define FAR    _far
  1832.   typedef void (__cdecl * atexitFunction )(void);
  1833. #elif !defined(__OS2__)
  1834.   typedef void *HWND; /* dummy for AIX */
  1835. #endif
  1836.  
  1837. #include <stdlib.h>
  1838. #include <string.h>
  1839. #include <signal.h>
  1840. #include <somd.h>
  1841. #include <somoa.h>
  1842. #include <implrep.h>
  1843.  
  1844. /*
  1845.  *  Function Prototypes
  1846.  */
  1847. int serverMain(int argc, char **argv);
  1848. void printDSOMEv(Environment *ev, boolean fatal);
  1849. void shutDownServer();
  1850. void initializeServer(Environment **ev);
  1851. int defineExitHandler();
  1852. #ifdef __OS2__
  1853.   void APIENTRY serverExitHandler(ULONG termCode);
  1854. #elif defined(_WIN16)
  1855.   void serverExitHandler();
  1856.   int makeArgs(LPSTR lpszCmdLine, int *argc, char **argv, int argSize);
  1857.   long FAR PASCAL _export WndProc (HWND, UINT, UINT, LONG);
  1858. #else
  1859.   void serverExitHandler(int Signal);
  1860. #endif
  1861. void decodeArgs(Environment *ev, int argc, char **argv);
  1862. ORBStatus processRequests(Environment *ev);
  1863. void showMessage(HWND hwnd, char *sztext);
  1864.  
  1865. /*
  1866.  *  Globals
  1867.  */
  1868. boolean svrImplIsReady = FALSE; /* set true after ready for requests */
  1869. boolean shuttingDown   = FALSE;
  1870. Environment *gev;               /* the global SOM environment */
  1871. HWND hwndSvr = (HWND)NULL;      /* Windows server window handle */
  1872.  
  1873. /*
  1874.  *  Macro definitions
  1875.  */
  1876. #define FATAL ((boolean)1)
  1877. #define NOT_FATAL ((boolean)0)
  1878. #define EV_OK(ev) ((ev)->_major == NO_EXCEPTION)
  1879. #define EV_NOT_OK(ev) ((ev)->_major != NO_EXCEPTION)
  1880.  
  1881. #ifdef _WIN16
  1882. /*
  1883.  * Win globals
  1884.  */
  1885. char *gSzAppName = "xxxxsvr";
  1886. HANDLE gHInstance = NULL;
  1887. /* For handling command line arguments the same */
  1888. char **argv=NULL;
  1889. int argc=1;
  1890. #define MAX_ARGS 25
  1891. #define ARG_LENGTH 80
  1892. #define WM_SOMDSVR  (WM_USER+0)
  1893.  
  1894. int PASCAL WinMain(HANDLE hInstance, HANDLE hPrevInstance,
  1895.                     LPSTR lpszCmdLine, int nCmdShow)
  1896. {
  1897.     HWND hwnd;
  1898.     MSG nlsmsg;
  1899.     WNDCLASS wndclass;
  1900.     long i;
  1901.  
  1902.     gHInstance = hInstance;
  1903.  
  1904.     if (!hPrevInstance) {
  1905.         wndclass.style         = CS_HREDRAW | CS_VREDRAW;
  1906.         wndclass.lpfnWndProc   = WndProc;
  1907.         wndclass.cbClsExtra    = 0;
  1908.         wndclass.cbWndExtra    = 0;
  1909.         wndclass.hInstance     = hInstance;
  1910.         wndclass.hIcon         = LoadIcon(NULL, IDI_APPLICATION);
  1911.         wndclass.hCursor       = LoadCursor(NULL, IDC_ARROW);
  1912.         wndclass.hbrBackground = GetStockObject(WHITE_BRUSH);
  1913.         wndclass.lpszMenuName  = NULL;
  1914.         wndclass.lpszClassName = gSzAppName;
  1915.         RegisterClass(&wndclass);
  1916.     }
  1917.  
  1918.     hwnd = CreateWindow(gSzAppName, gSzAppName,
  1919.                         WS_OVERLAPPEDWINDOW | WS_MINIMIZE,
  1920.                         CW_USEDEFAULT, CW_USEDEFAULT,
  1921.                         CW_USEDEFAULT, CW_USEDEFAULT,
  1922.                         NULL, NULL, hInstance, NULL);
  1923.     ShowWindow(hwnd, SW_SHOW);
  1924.  
  1925.     argv = (char **) malloc (sizeof (char *)*MAX_ARGS);
  1926.     for (i=0; i<MAX_ARGS; ++i)
  1927.        argv[i] = (char *)calloc (ARG_LENGTH, sizeof(char *));
  1928.  
  1929.     makeArgs(lpszCmdLine, &argc, argv, MAX_ARGS);
  1930.  
  1931.     /* Start the server with Windows user message */
  1932.     SendMessage(hwnd, WM_SOMDSVR, 0, 0);
  1933.  
  1934.     /* Windows message loop */
  1935.     while (GetMessage(&nlsmsg, NULL, 0, 0)) {
  1936.         TranslateMessage(&nlsmsg);
  1937.         DispatchMessage(&nlsmsg);
  1938.     }
  1939.  
  1940.     return nlsmsg.wParam;
  1941.  
  1942.     return (0);
  1943. }                                      /* end main */
  1944.  
  1945. long FAR PASCAL _export WndProc(HWND hwnd, UINT message, UINT wParam,
  1946.                                  LONG lParam)
  1947. {
  1948.     switch (message) {
  1949.             case WM_SOMDSVR:
  1950.                 hwndSvr = hwnd; /* set server main window */
  1951.                 serverMain (argc, argv);
  1952.                 return 0 ;
  1953.  
  1954.             case WM_DESTROY:
  1955.                  PostQuitMessage (0);
  1956.                  return 0;
  1957.     }
  1958.     return DefWindowProc (hwnd, message, wParam, lParam);
  1959. }
  1960.  
  1961. int makeArgs(LPSTR lpszCmdLine, int *argc, char **argv, int argSize)
  1962. {
  1963.     char *c;
  1964.     int i;
  1965.  
  1966.     *argc = 1; /* lpszCmdLine does not have argv[0] */
  1967.     /* lpszCmdLine has command line arguments delimited by blanks */
  1968.     c = strtok ((char *)lpszCmdLine, " ");
  1969.  
  1970.     for (i=0; i<argSize; ++i) {
  1971.        if (c == NULL) break;
  1972.        strcpy ((char *)argv[*argc], (char *)c);
  1973.        c = strtok (NULL, " ");
  1974.        *argc += 1;
  1975.     }
  1976.     return *argc;
  1977. }
  1978.  
  1979. #else /* OS/2 and AIX */
  1980.  
  1981. int main(int argc, char **argv)
  1982. {
  1983.     ORBStatus rc;
  1984.  
  1985.     rc = serverMain(argc, argv);
  1986.     shutDownServer();
  1987.     exit(0);
  1988. }
  1989. #endif /* _WIN16 */
  1990.  
  1991. int serverMain(int argc, char **argv) /* generic server main program */
  1992. {
  1993.     Environment *ev;
  1994.     ORBStatus rc;
  1995.  
  1996. #ifndef __OS2__
  1997.     /*
  1998.      * Register an exit handler to handle termination.
  1999.      *
  2000.      * Note: this server registers an exit handler after the call
  2001.      * to impl_is_ready on OS/2. Moving the point of the registration is a
  2002.      * work-around to avoid a problem encountered on the OS/2 version
  2003.      * of DSOM when Ctrl-c is entered to kill this server process.
  2004.      */
  2005.     defineExitHandler();
  2006. #endif
  2007.  
  2008.     /*
  2009.      * Initialize local SOM environment and DSOM.
  2010.      * Terminates if initialization fails.
  2011.      */
  2012.     initializeServer(&ev);
  2013.  
  2014.     /*
  2015.      * Parse command line arguments to locate server ID or alias to start.
  2016.      * Terminates if command line incorrect.
  2017.      */
  2018.     decodeArgs(ev, argc, argv);
  2019.  
  2020.     /*
  2021.      * At this point, the implementation definition has been determined.
  2022.      * Inform DSOM deamon we're noew ready to accept requests.
  2023.      */
  2024.     _impl_is_ready(SOMD_SOMOAObject, ev, SOMD_ImplDefObject);
  2025.     if (EV_NOT_OK(ev)) {
  2026.        showMessage(hwndSvr, "impl_is_ready failed.");
  2027.        printDSOMEv(ev, FATAL);        /* print error and terminate   */
  2028.     } else {
  2029.        svrImplIsReady = TRUE;
  2030.     }
  2031. #ifdef __OS2__
  2032.     defineExitHandler();
  2033. #endif
  2034.  
  2035.     /*
  2036.      * Process requests until an exception is encountered.
  2037.      */
  2038.     rc = processRequests(ev);
  2039.  
  2040.     if (EV_NOT_OK(ev)) {
  2041.       showMessage(hwndSvr, "execute_request_loop failed.");
  2042.       printDSOMEv(ev, FATAL);       /* print error and terminate     */
  2043.     }
  2044. }
  2045.  
  2046. /*
  2047.  *  Process incoming requests.
  2048.  *
  2049.  *  This function does not return until termination.
  2050.  */
  2051. ORBStatus processRequests(Environment *ev)
  2052. {
  2053.     ORBStatus rc = 0;
  2054.  
  2055.     /*
  2056.      * Processing incoming requests and then wait for more.
  2057.      * This call continues to process requests and only returns
  2058.      * if an error is encountered. It is a blocking call.
  2059.      */
  2060.     rc = _execute_request_loop(SOMD_SOMOAObject, ev, SOMD_WAIT);
  2061.     return(rc);
  2062. }
  2063.  
  2064. /*
  2065.  *  Prepares the server for termination.
  2066.  *  Frees local and global DSOM objects and informs DSOM
  2067.  *  deamon the server is terminating.
  2068.  */
  2069. void shutDownServer()
  2070. {
  2071.     Environment *globalEv;
  2072.     globalEv = somGetGlobalEnvironment();
  2073.  
  2074.     if (!shuttingDown) {
  2075.        shuttingDown = TRUE;
  2076. #ifdef _WIN16
  2077.        if (globalEv->_somdAnchor != NULL) {
  2078.           if (svrImplIsReady) {
  2079.              _deactivate_impl(SOMD_SOMOAObject, globalEv, SOMD_ImplDefObject);
  2080.           }
  2081.           if (SOMD_ImplDefObject != NULL) {
  2082.              _somFree(SOMD_ImplDefObject);
  2083.              SOMD_ImplDefObject = NULL;
  2084.           }
  2085.           if (SOMD_SOMOAObject != NULL) {
  2086.              _somFree(SOMD_SOMOAObject);
  2087.              SOMD_SOMOAObject = NULL;
  2088.           }
  2089.           SOMD_Uninit(globalEv);
  2090. #else
  2091.        if (svrImplIsReady) {
  2092.           _deactivate_impl(SOMD_SOMOAObject, globalEv, SOMD_ImplDefObject);
  2093.        }
  2094.        if (SOMD_ImplDefObject != NULL) {
  2095.           _somFree(SOMD_ImplDefObject);
  2096.           SOMD_ImplDefObject = NULL;
  2097.        }
  2098.        if (SOMD_SOMOAObject != NULL) {
  2099.           _somFree(SOMD_SOMOAObject);
  2100.           SOMD_SOMOAObject = NULL;
  2101.        }
  2102.        SOMD_Uninit(globalEv);
  2103. #endif
  2104. #ifdef _WIN16
  2105.        }
  2106. #endif
  2107.        somEnvironmentEnd();
  2108.     } /* endif shuttingDown */
  2109. }
  2110.  
  2111. /*
  2112.  * serverExitHandler - Deactivate the impl, shutdown server and exit.
  2113.  *
  2114.  * This function is called when a server process is terminated.
  2115.  */
  2116. #ifdef __OS2__
  2117. void APIENTRY serverExitHandler(ULONG termCode)
  2118. {
  2119.     (void) termCode;    /* not currently used */
  2120.     shutDownServer();
  2121.     DosExitList(EXLST_EXIT, 0);
  2122. }
  2123. #elif defined(_WIN16)
  2124. void serverExitHandler()
  2125. {
  2126.     shutDownServer();
  2127. }
  2128. #else
  2129. void serverExitHandler(int Signal)
  2130. {
  2131.     sigset_t sigset;
  2132.  
  2133.     (void) Signal;   /* not used, reference to avoid warnings */
  2134.  
  2135.     /* Process is about to terminate, so disable further signals */
  2136.     sigfillset(&sigset);
  2137.     sigprocmask(SIG_BLOCK, &sigset, NULL);
  2138.  
  2139.     shutDownServer();
  2140.     exit(-1);
  2141. }
  2142.  
  2143. #endif
  2144.  
  2145. /*
  2146.  * defineExitHandler - Defines handler function for abnormal termination.
  2147.  *
  2148.  */
  2149. #ifdef __OS2__
  2150. int defineExitHandler()
  2151. {
  2152.      int rc;
  2153.      rc = DosExitList(EXLST_ADD | 0x0100, (PFNEXITLIST) serverExitHandler);
  2154.      return(rc);
  2155. }
  2156. #elif defined(_WIN16)
  2157. int defineExitHandler()
  2158. {
  2159.     SOM_MainProgramWithUserExit(((atexitFunction)serverExitHandler));
  2160.     return (0);
  2161. }
  2162. #else
  2163. /*
  2164.  *  Sets up the signal handler.
  2165.  */
  2166. int defineExitHandler()
  2167. {
  2168.     struct sigaction action;
  2169.  
  2170.     action.sa_handler = (void *) serverExitHandler;
  2171.     action.sa_flags = 0;
  2172.     sigfillset(&action.sa_mask);
  2173.  
  2174.     /*
  2175.      * Specify which signals to catch.
  2176.      */
  2177.     sigaction(SIGHUP, &action, NULL);
  2178.     sigaction(SIGINT, &action, NULL);
  2179.     sigaction(SIGQUIT, &action, NULL);
  2180.     sigaction(SIGILL, &action, NULL);
  2181.     sigaction(SIGTRAP, &action, NULL);
  2182.     sigaction(SIGIOT, &action, NULL);
  2183.     sigaction(SIGEMT, &action, NULL);
  2184.     sigaction(SIGFPE, &action, NULL);
  2185.     sigaction(SIGBUS, &action, NULL);
  2186.     sigaction(SIGSEGV, &action, NULL);
  2187.     sigaction(SIGSYS, &action, NULL);
  2188.     sigaction(SIGTERM, &action, NULL);
  2189.     sigaction(SIGPWR, &action, NULL);
  2190.     sigaction(SIGDANGER, &action, NULL);
  2191.     return (0);
  2192. }
  2193. #endif
  2194.  
  2195.  
  2196. /*
  2197.  * printDSOMEv prints the contents of a SOM/DSOM exception and then frees
  2198.  * the contents of the exeception. If this is indicated to be a fatal
  2199.  * exception, the process is shutdown and then terminated.
  2200.  *
  2201.  */
  2202. void printDSOMEv(Environment *ev, boolean fatal)
  2203. {
  2204.     string exId;           /* exception ID string */
  2205.     StExcep *params;       /* standard exception structure */
  2206.     char msgBuf[128];
  2207.  
  2208.  
  2209.     exId = exception_id(ev);
  2210.     params = exception_value(ev);
  2211.  
  2212. #ifdef _WIN16
  2213.     sprintf(msgBuf, "Exception occurred: %s", exId);
  2214.     MessageBox(hwndSvr, msgBuf, gSzAppName, MB_ICONSTOP|MB_OK);
  2215. #else
  2216.     somPrintf("Exception Occurred\n");
  2217.     somPrintf("    exception ID : %s\n", exId);
  2218.     somPrintf("minor error code : %u\n", params->minor);
  2219.     somPrintf(" completion code : %s\n", (params->completed == YES ? "YES" :
  2220.                                       params->completed == NO ? "NO": "MAYBE"));
  2221. #endif
  2222.  
  2223.     somdExceptionFree(ev); /* Frees SOM or DSOM exception */
  2224.  
  2225.     if (fatal) {
  2226.        shutDownServer();
  2227.        exit((int)params->minor);
  2228.     }
  2229. }
  2230.  
  2231. /*
  2232.  *  Initialize the server process. If an error is encountered,
  2233.  *  the exception is printed and the process is terminated.
  2234.  *  On successful completion, a pointer to the global Environment
  2235.  *  structure (per-thread) is returned.
  2236.  */
  2237. void initializeServer(Environment **ev)
  2238. {
  2239.     somEnvironmentNew();
  2240.     gev = *ev = somGetGlobalEnvironment();
  2241.     SOMD_Init(*ev);
  2242.     if (EV_NOT_OK(*ev)) {
  2243.        printDSOMEv(*ev, FATAL);      /* print error and terminate     */
  2244.     } else {
  2245.        SOMD_SOMOAObject = SOMOANew();
  2246.     } /* endif */
  2247. }
  2248.  
  2249. /*
  2250.  *  This function processes the command line arguments.
  2251.  *  The command line should contain either a implementation ID
  2252.  *  or an implementation alias. If neither is specified, an
  2253.  *  error is displayed and the process is terminated.
  2254.  *
  2255.  *  The Implementation Repository is queried with the given ID or
  2256.  *  alias in order to set up the global ImplementationDef object
  2257.  *  for the server process.
  2258.  */
  2259. void decodeArgs(Environment *ev, int argc, char **argv)
  2260. {
  2261.     char msgBuf[80];
  2262.  
  2263.     switch (argc) {
  2264.     /*
  2265.      * Implementation ID passed
  2266.      */
  2267.     case 2:
  2268.         /*
  2269.          * Get the ImplementationDef object from the Implementation Repository
  2270.          * based on the given ID. The impldef object is stored in the process
  2271.          * global variable SOMD_ImplDefObject.
  2272.          */
  2273.         SOMD_ImplDefObject = _find_impldef(SOMD_ImplRepObject, ev, argv[1]);
  2274.         if (EV_NOT_OK(ev)) {
  2275.            showMessage(hwndSvr, "find_impldef failed.");
  2276.            printDSOMEv(ev, FATAL);  /* print error and terminate     */
  2277.         }
  2278.         break;
  2279.  
  2280.     /*
  2281.      * Alias passed
  2282.      */
  2283.     case 3:
  2284.         /*
  2285.          * Get the ImplementationDef object from the Implementation Repository
  2286.          * based on the given alias. The impldef object is stored in the process
  2287.          * global variable SOMD_ImplDefObject.
  2288.          *
  2289.          * The alias option can be given as either:
  2290.          *
  2291.          *  -a alias_name
  2292.          *     or
  2293.          *  -A alias_name
  2294.          *
  2295.          */
  2296.         if ((argv[1][0] == '-') &&
  2297.             ((argv[1][1] == 'a') || (argv[1][1] == 'A'))) {
  2298.            SOMD_ImplDefObject = _find_impldef_by_alias(SOMD_ImplRepObject, ev, argv[2]);
  2299.            if (EV_NOT_OK(ev)) {
  2300.               showMessage(hwndSvr, "find_impldef_by_alias failed.");
  2301.               printDSOMEv(ev, FATAL); /* print error and terminate   */
  2302.            }
  2303.         } else {
  2304.           sprintf(msgBuf, "Usage: %s -a <alias>", argv[0]);
  2305.           showMessage(hwndSvr, msgBuf);
  2306.           shutDownServer();
  2307.           exit(1);
  2308.         }
  2309.         break;
  2310.  
  2311.     /*
  2312.      * Invalid number of arguments.
  2313.      */
  2314.     default:
  2315.         sprintf(msgBuf, "Usage: %s <implid> | -a <alias>", argv[0]);
  2316.         showMessage(hwndSvr, msgBuf);
  2317.         shutDownServer();
  2318.         exit(1);
  2319.         break;
  2320.     }
  2321. }
  2322.  
  2323. void showMessage(HWND hwnd, char *sztext)
  2324. {
  2325. #ifdef _WIN16
  2326.     MessageBox(hwnd, sztext, gSzAppName, MB_ICONINFORMATION|MB_OK);
  2327. #else
  2328.     somPrintf("%s\n", sztext);
  2329. #endif
  2330. }
  2331. /*
  2332.  * 10H9767, 10H9769 (C) COPYRIGHT International Business Machines Corp. 1992,1994
  2333.  * All Rights Reserved
  2334.  * Licensed Materials - Property of IBM
  2335.  *
  2336.  * DISCLAIMER OF WARRANTIES.
  2337.  * The following [enclosed] code is sample code created by IBM
  2338.  * Corporation. This sample code is not part of any standard or IBM
  2339.  * product and is provided to you solely for the purpose of assisting
  2340.  * you in the development of your applications.  The code is provided
  2341.  * "AS IS".
  2342.  *
  2343.  * DISTRIBUTION.
  2344.  * This sample code can be freely distributed, copied, altered, and
  2345.  * incorporated into other software, provided that it bears the above
  2346.  * Copyright notice and DISCLAIMER intact.
  2347.  */
  2348.