botsense/bsProxy/bsProxyMod.c
BsProxyModIF_T *ModLoad(const char *sModUri)
{
  BsProxyModIF_T *pModIF      = NULL;
  void           *dllHandle   = NULL;
  int             rc;

  // lock global mutex
  ModLock();

  //
  // Check if module is already loaded.
  //
  if( (pModIF = ModHashGetIF(sModUri)) != NULL )
  {
    rc = BS_OK;
    pModIF->m_uRefCnt++;
    LOGDIAG1("Interface Module \"%s\" attached (refcnt=%u).",
          pModIF->m_sModUri, pModIF->m_uRefCnt);
  }

  //
  // Load the dynamic library.
  //
  else if( (dllHandle = ModDllOpen(sModUri)) == NULL )
  {
    rc = -BS_ECODE_NO_MOD;
    BSPROXY_MOD_LOG_ERROR(sModUri, rc, "Failed to open.");
  }

  //
  // Allocate new interface control blcok and attach module's exported
  // interface.
  //
  else if( (pModIF = ModDllNewIF(sModUri, dllHandle)) == NULL )
  {
    rc = -BS_ECODE_BAD_MOD;
    BSPROXY_MOD_LOG_ERROR(sModUri, rc, "Failed to get interface.");
  }

  //
  // Call the newly loaded module's exported initialization function to
  // initialize any module specific data and resources.
  //
  else if( (rc = pModIF->m_fnModInit(sModUri, &BsModProxyCallbacks)) < 0 )
  {
    rc = -BS_ECODE_BAD_MOD;
    BSPROXY_MOD_LOG_ERROR(sModUri, rc, "Failed to initialize.");
  }

  //
  // Add the module to the hash table (failure auto-deletes node data).
  //
  else if( (rc = ModHashAdd(sModUri, pModIF)) < 0 )
  {
    rc = -BS_ECODE_NO_RSRC;
    BSPROXY_MOD_LOG_ERROR(sModUri, rc, "Failed to add module to hash table.");
  }

  //
  // Successfully loaded new module.
  //
  else
  {
    rc = BS_OK;
    LOGDIAG1("Interface Module \"%s\" loaded (refcnt=%u).",
          pModIF->m_sModUri, pModIF->m_uRefCnt);
  }

  ModUnlock();

  //
  // Error clean up.
  //
  if( rc < 0 )
  {
    if( dllHandle != NULL )
    {
      dlclose(dllHandle);
      dllHandle = NULL;
    }

    if( pModIF != NULL )
    {
      ModDllDeleteIF(pModIF);
      pModIF = NULL;
    }
  }

  return pModIF;
}
/*!
 * \brief Load the interface module.
 *
 * The module's expanded, canonical name is determined, the dynamic library is
 * loaded, the module's exported interface is attached, and the module's 
 * initialization routine is called.
 *
 * The the same module is loaded again, the reference count is bumped and the
 * already attached interface is returned.
 *
 * Multi-Thread safe.
 *
 * \param sModUri   Interface module expanded, canonical name.
 *
 * \return
 * On success, returns a pointer to the module's exported interface.\n
 * On failure, returns NULL.
 */
\brief Load the interface module.
The module's expanded, canonical name is determined, the dynamic library is
loaded, the module's exported interface is attached, and the module's
initialization routine is called.

The the same module is loaded again, the reference count is bumped and the
already attached interface is returned.

Multi-Thread safe.

\param sModUri   Interface module expanded, canonical name.

\return
On success, returns a pointer to the module's exported interface.\n
On failure, returns NULL.
\ brief Load the interface module . The module ' s expanded canonical name is determined the dynamic library is loaded the module ' s exported interface is attached and the module ' s initialization routine is called . The the same module is loaded again the reference count is bumped and the already attached interface is returned . Multi - Thread safe . \ param sModUri Interface module expanded canonical name . \ return On success returns a pointer to the module ' s exported interface . \ n On failure returns NULL .
BsProxyModIF_T *ModLoad(const char *sModUri)
{
  BsProxyModIF_T *pModIF      = NULL;
  void           *dllHandle   = NULL;
  int             rc;
  ModLock();
   Check if module is already loaded.
  if( (pModIF = ModHashGetIF(sModUri)) != NULL )
  {
    rc = BS_OK;
    pModIF->m_uRefCnt++;
    LOGDIAG1("Interface Module \"%s\" attached (refcnt=%u).",
          pModIF->m_sModUri, pModIF->m_uRefCnt);
  }
   Load the dynamic library.
  else if( (dllHandle = ModDllOpen(sModUri)) == NULL )
  {
    rc = -BS_ECODE_NO_MOD;
    BSPROXY_MOD_LOG_ERROR(sModUri, rc, "Failed to open.");
  }
   Allocate new interface control blcok and attach module's exported
   interface.
  else if( (pModIF = ModDllNewIF(sModUri, dllHandle)) == NULL )
  {
    rc = -BS_ECODE_BAD_MOD;
    BSPROXY_MOD_LOG_ERROR(sModUri, rc, "Failed to get interface.");
  }
   Call the newly loaded module's exported initialization function to
   initialize any module specific data and resources.
  else if( (rc = pModIF->m_fnModInit(sModUri, &BsModProxyCallbacks)) < 0 )
  {
    rc = -BS_ECODE_BAD_MOD;
    BSPROXY_MOD_LOG_ERROR(sModUri, rc, "Failed to initialize.");
  }
   Add the module to the hash table (failure auto-deletes node data).
  else if( (rc = ModHashAdd(sModUri, pModIF)) < 0 )
  {
    rc = -BS_ECODE_NO_RSRC;
    BSPROXY_MOD_LOG_ERROR(sModUri, rc, "Failed to add module to hash table.");
  }
   Successfully loaded new module.
  else
  {
    rc = BS_OK;
    LOGDIAG1("Interface Module \"%s\" loaded (refcnt=%u).",
          pModIF->m_sModUri, pModIF->m_uRefCnt);
  }
  ModUnlock();
   Error clean up.
  if( rc < 0 )
  {
    if( dllHandle != NULL )
    {
      dlclose(dllHandle);
      dllHandle = NULL;
    }
    if( pModIF != NULL )
    {
      ModDllDeleteIF(pModIF);
      pModIF = NULL;
    }
  }
  return pModIF;
}
BsProxyModIF_T * ModLoad ( const char * sModUri ) { BsProxyModIF_T * pModIF = NULL ; void * dllHandle = NULL ; int rc ; ModLock ( ) ; if ( ( pModIF = ModHashGetIF ( sModUri ) ) != NULL ) { rc = BS_OK ; pModIF -> m_uRefCnt ++ ; LOGDIAG1 ( " \" \" " , pModIF -> m_sModUri , pModIF -> m_uRefCnt ) ; } else if ( ( dllHandle = ModDllOpen ( sModUri ) ) == NULL ) { rc = - BS_ECODE_NO_MOD ; BSPROXY_MOD_LOG_ERROR ( sModUri , rc , " " ) ; } else if ( ( pModIF = ModDllNewIF ( sModUri , dllHandle ) ) == NULL ) { rc = - BS_ECODE_BAD_MOD ; BSPROXY_MOD_LOG_ERROR ( sModUri , rc , " " ) ; } else if ( ( rc = pModIF -> m_fnModInit ( sModUri , & BsModProxyCallbacks ) ) < 0 ) { rc = - BS_ECODE_BAD_MOD ; BSPROXY_MOD_LOG_ERROR ( sModUri , rc , " " ) ; } else if ( ( rc = ModHashAdd ( sModUri , pModIF ) ) < 0 ) { rc = - BS_ECODE_NO_RSRC ; BSPROXY_MOD_LOG_ERROR ( sModUri , rc , " " ) ; } else { rc = BS_OK ; LOGDIAG1 ( " \" \" " , pModIF -> m_sModUri , pModIF -> m_uRefCnt ) ; } ModUnlock ( ) ; if ( rc < 0 ) { if ( dllHandle != NULL ) { dlclose ( dllHandle ) ; dllHandle = NULL ; } if ( pModIF != NULL ) { ModDllDeleteIF ( pModIF ) ; pModIF = NULL ; } } return pModIF ; }
\brief Load the interface module.
\ brief Load the interface module .
// lock global mutex // // Check if module is already loaded. // // // Load the dynamic library. // // // Allocate new interface control blcok and attach module's exported // interface. // // // Call the newly loaded module's exported initialization function to // initialize any module specific data and resources. // // // Add the module to the hash table (failure auto-deletes node data). // // // Successfully loaded new module. // // // Error clean up. //