:copyrightS
/* @(#) 1.15 src/somc/fwemit/imod/imod.efw, somemit.fmwk.imod, som3.0 10/16/96 17:22:16 [12/22/96 21:31:18]
 *
 *   COMPONENT_NAME: somemit.fmwk.imod
 *
 *   ORIGINS: 27
 *
 *
 *   10H9767, 25H7912  (C) COPYRIGHT International Business Machines Corp. 1995, 1996
 *   All Rights Reserved
 *   Licensed Materials - Property of IBM
 *   US Government Users Restricted Rights - Use, duplication or
 *   disclosure restricted by GSA ADP Schedule Contract with IBM Corp.
 */
:prologS
/*
 * The functions contained within this source file are used to
 * initialize/uninitialize the SOMObjects 3.0 style class library named
 * <dllFileName>.
 *
 * The functions contained are:
 *
 * - createClasses               Calls NewClass procedures for all classes
 * - somInitTermDependents       For initializing dependent classes
 * - <dllNameStem>SOMInitTerm    Main init/term function
 * - SOMInitModule               Entry used by SOM runtime after library loading
 *
 * The following functions in this source file may be customized:
 *
 * - somInitTermDependents
 * - <dllNameStem>SOMInitTerm
 *
 * Search for lines containing !!! for the the places where these functions
 * may be customized.
 *
 * This source file may be conditionally compiled for OS/2, AIX and Windows.
 *
 *    OS/2 C Set ++ users:  Compile with flag -DDYNA_LINK_C if you are
 *                          dynamically linking the C runtimes.
 *
 *    Windows users:        Compile with flag -D_WIN16
 *
 *    AIX users:            Be sure to customize somInitTermDependents
 *                          appropriately.
 *
 * Note: This file was generated based on the contents of the file
 *       imod.efw in the toolkit include directory.
 *
 */
#if defined __OS2__
  #define INCL_DOSMODULEMGR
  #include \<os2.h>
#elif defined(_WIN32)
  #define WIN32_LEAN_AND_MEAN
  #include \<windows.h>
#else
  #ifdef _WIN16
  #include \<windows.h>
  #endif
#endif
#include \<som.h>
#define SOM_LIBRARY_INITIALIZE 0L
#define SOM_LIBRARY_TERMINATE  1L
#ifdef SOM_STRICT_IDL
  typedef SOMClass imodSOMClass;
#else
  typedef SOMClass *imodSOMClass;
#endif
#if defined(__IBMC__) &&  defined(__OS2__)
#pragma linkage(SOMInitModule, system)
#pragma linkage(<dllNameStem>SOMInitTerm, system)
#pragma linkage(somTP_NewClassFn, system)
#pragma linkage(createClasses, system)
#endif
typedef imodSOMClass SOMLINK somTP_NewClassFn(integer4 majv, integer4 minv);
typedef somTP_NewClassFn *SOMNewClassFnPtr;

:classS
/* \<NewClassProcExterns> follow this line. Do not remove this line. */
<NewClassProcExterns>/* \<NewClassProcExterns> inserted above this line. Do not remove this line. */

/* Do not change the name of the following array. The imod emitter  */
/* depends on the name of the array to locate and add               */
/* secondary NewClass calls.                                        */
static SOMNewClassFnPtr somInitModArray[] = {
<classNameNewClassCalls>}; /* Do not remove this line. */

static long numSOMClasses = sizeof(somInitModArray)/sizeof(SOMNewClassFnPtr);

/* This function is called to create the SOM class objects for this
 * class library. The class objects are destroyed at termination time.
 */
static void SOMLINK createClasses(void)
{
   SOMNewClassFnPtr *ncp;
   int i;
   for (i = 0, ncp = (SOMNewClassFnPtr *)somInitModArray;
        i \< numSOMClasses ; ncp++, i++)
      (*ncp)(0,0);
}

#if defined(__OS2__)||defined(_WIN32)
  #define SOM_SYS_DEPENDENT_INITTERM(flag) 0
  /*
   * Init/term processing for load time links is handled by the OS.
   */
#else
  /*
   * The somInitTermDependents function is provided for systems that must
   * perform init/term processing for references to other SOM class
   * library externals that this class library is dependent upon and
   * that are resolved at load time (as opposed to references resolved by run
   * time dynamic linking).
   *
   * On AIX, for example: if this class library, a.dll, has explicit
   * references to externals in the class library b.dll that are resolved
   * at link time, then somInitTermDependents should call that class library's
   * \<dllstem>SOMInitTerm function explicitly:
   *
   *        rc = bSOMInitTerm(flag);
   *
   */
  #define SOM_SYS_DEPENDENT_INITTERM(flag) somInitTermDependents(flag)
  static long somInitTermDependents(unsigned long flag)
  {
     long rc = 0L; /* success */

     /*
      *  !!! Place user customization here !!!
      *  for example:  rc = bSOMInitTerm(flag);
      */
     return(rc);
  }
#endif

/*
 * This function provides an initialization and termination function for a
 * SOM class library.
 *
 * The function returns zero to indicate success.
 *
 * System notes:
 *
 *    AIX: This function must be exported by the class library.
 *
 *    OS2: This function may be exported by the class library but it is not
 *         required.
 *
 */
SOMEXTERN long SOMLINK <dllNameStem>SOMInitTerm (unsigned long flag)
{
   long rc = 0L; /* success */

   switch (flag) {
      case SOM_LIBRARY_INITIALIZE:
         if (SOM_SYS_DEPENDENT_INITTERM(flag) == 0) {
            somRegisterClassLibrary("<dllFileName>",
                                    (somMethodProc*)createClasses);
            /*
             *  !!! Place user customization here !!!
             */
         }
         break;

      case SOM_LIBRARY_TERMINATE:
         somUnregisterClassLibrary("<dllFileName>");
         rc = SOM_SYS_DEPENDENT_INITTERM(flag);
         /*
          *  !!! Place user customization here !!!
          */
         break;

       default:
         rc = 1L; /* Failure */
   }
   return(rc);
}

/*
 * This function is called by the SOM run time in response to
 * a call to somFindClass, following the loading of a class library.
 */
SOMEXTERN void SOMLINK SOMInitModule( long majorVersion,
                                      long minorVersion,
                                      string className )
{
   <dllNameStem>SOMInitTerm(SOM_LIBRARY_INITIALIZE);
}

#if defined(__OS2__) || defined(_WIN32)
#define INITTERM_SUCCESS 1
#define INITTERM_FAILURE 0

#if defined(__IBMC__)||defined(__IBMCPP__) /* IBM C Set ++ */
  #ifdef __cplusplus
  extern "C" {
  #endif
  int _CRT_init (void);
  void _CRT_term (void);
  void __ctordtorInit(void);
  void __ctordtorTerm(void);
#ifdef _WIN32
  #define DLL_INITTERM \\
   unsigned long _System _DLL_InitTerm (HMODULE hMod , \\
                                        DWORD fdwReason, LPVOID lpvReserved)
#else
  #define DLL_INITTERM \\
   unsigned long _System _DLL_InitTerm (unsigned long hModule, \\
                                        unsigned long flag)
#endif
  #ifdef __cplusplus
  }
  #endif
  /*
   * Note: define DYNA_LINK_C if you are dynamically linking to the
   *       C runtime library.
   */
  #ifndef DYNA_LINK_C /* C Set runtime is not dynamically linked (default) */
     #define CRUNTIME_INIT if (_CRT_init() == -1) \\
                              return(INITTERM_FAILURE)
  #else
     #define CRUNTIME_INIT
  #endif
  #ifndef DYNA_LINK_C /* C Set runtime is not dynamically linked (default) */
     #define CRUNTIME_TERM _CRT_term()
  #else
     #define CRUNTIME_TERM
  #endif
  #define CPPRUNTIME_INIT __ctordtorInit()
  #define CPPRUNTIME_TERM __ctordtorTerm()

#elif defined(__BCPLUSPLUS__)||defined(__BORLANDC__)||defined(_MSC_VER)
  #define DLL_INITTERM \\
     BOOL WINAPI DllMain(HMODULE hMod , \\
                                        DWORD fdwReason, LPVOID lpvReserved)
     #define CRUNTIME_INIT
     #define CRUNTIME_TERM
     #define CPPRUNTIME_INIT 
     #define CPPRUNTIME_TERM 

#elif defined(__WATCOMC__)
  #define DLL_INITTERM \\
   unsigned long _DLL_InitTerm (unsigned long hModule, \\
                                unsigned long flag); \\
   static unsigned long modHandle() \\
   {HMODULE hModule; DosQueryModuleHandle("<dllNameStem>", &hModule); \\
    return((unsigned long)hModule);}\\
   int __dll_initialize() \\
   {return((int)_DLL_InitTerm(modHandle(), SOM_LIBRARY_INITIALIZE));}\\
   int __dll_terminate() \\
   {return((int)_DLL_InitTerm(modHandle(), SOM_LIBRARY_TERMINATE));}\\
   unsigned long _DLL_InitTerm (unsigned long hModule, \\
                                unsigned long flag)
  #define CRUNTIME_INIT
  #define CRUNTIME_TERM
  #define CPPRUNTIME_INIT
  #define CPPRUNTIME_TERM

#elif defined(__HIGHC__)
  #define DLL_INITTERM \\
   unsigned long _DLL_InitTerm (unsigned long hModule, \\
                                unsigned long flag)
  #define CRUNTIME_INIT
  #define CRUNTIME_TERM
  #define CPPRUNTIME_INIT
  #define CPPRUNTIME_TERM

#else  /* default */
  #define DLL_INITTERM \\
   unsigned long _System _DLL_InitTerm (unsigned long hModule, \\
                                        unsigned long flag)
  #define CRUNTIME_INIT
  #define CRUNTIME_TERM
  #define CPPRUNTIME_INIT
  #define CPPRUNTIME_TERM
#endif

#ifdef _WIN32
/* \<_WIN32_EXIT_HANDLER>: DO NOT REMOVE THIS and the FOLLOWING LINE */
<exitHandlerDecl>

#ifdef _WIN32_EXIT_HANDLER
SOMEXTERN void SOMLINK SOM_TERMINATION_HANDLER(void);
#endif

DLL_INITTERM
{
unsigned long rc = INITTERM_SUCCESS;

  switch (fdwReason) {

    case DLL_PROCESS_ATTACH:
         CRUNTIME_INIT ; 
         CPPRUNTIME_INIT;
         rc = (<dllNameStem>SOMInitTerm(SOM_LIBRARY_INITIALIZE))?
		INITTERM_FAILURE :INITTERM_SUCCESS;
    break;

    case DLL_PROCESS_DETACH:
#ifdef _WIN32_EXIT_HANDLER
	SOM_TERMINATION_HANDLER();
#endif
         <dllNameStem>SOMInitTerm(SOM_LIBRARY_TERMINATE);
         CPPRUNTIME_TERM; /* Zeynal, defect 26191:calling order swaped. */
         CRUNTIME_TERM;
    break;

    case DLL_THREAD_ATTACH:
    break;

    case DLL_THREAD_DETACH:
    break;

    default:
         return 0UL;
  }

  return rc;
}
#else /* _WIN32 */
DLL_INITTERM
{
   unsigned long rc = INITTERM_SUCCESS;

   switch (flag) {
      case SOM_LIBRARY_INITIALIZE:
         CRUNTIME_INIT;
         CPPRUNTIME_INIT;
         rc = (<dllNameStem>SOMInitTerm(flag))?INITTERM_FAILURE
                                              :INITTERM_SUCCESS;
         break;

      case SOM_LIBRARY_TERMINATE:
         <dllNameStem>SOMInitTerm(flag);
         CPPRUNTIME_TERM;
         CRUNTIME_TERM;
         break;

       default:
         rc = INITTERM_FAILURE;
   }
   return(rc);
}
#endif /* _WIN32 */
#else /* __OS2__ || _WIN32 */
  #ifdef _WIN16
  int CALLBACK LibMain (HINSTANCE inst, WORD ds, WORD heapSize, LPSTR cmdLine)
  {
      SOM_IgnoreWarning (inst);
      SOM_IgnoreWarning (ds);
      SOM_IgnoreWarning (heapSize);
      SOM_IgnoreWarning (cmdLine);

      <dllNameStem>SOMInitTerm(SOM_LIBRARY_INITIALIZE);
      return 1;
  }
  #endif
#endif /* __OS2__ || _WIN32*/

