"Fossies" - the Fresh Open Source Software Archive

Member "netxms-3.8.166/src/server/core/modules.cpp" (23 Feb 2021, 4863 Bytes) of package /linux/misc/netxms-3.8.166.tar.gz:


As a special service "Fossies" has tried to format the requested source page into HTML format using (guessed) C and C++ source code syntax highlighting (style: standard) with prefixed line numbers and code folding option. Alternatively you can here view or download the uninterpreted source code file. For more information about "modules.cpp" see the Fossies "Dox" file reference documentation.

    1 /* 
    2 ** NetXMS - Network Management System
    3 ** Copyright (C) 2003-2020 Victor Kirhenshtein
    4 **
    5 ** This program is free software; you can redistribute it and/or modify
    6 ** it under the terms of the GNU General Public License as published by
    7 ** the Free Software Foundation; either version 2 of the License, or
    8 ** (at your option) any later version.
    9 **
   10 ** This program is distributed in the hope that it will be useful,
   11 ** but WITHOUT ANY WARRANTY; without even the implied warranty of
   12 ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
   13 ** GNU General Public License for more details.
   14 **
   15 ** You should have received a copy of the GNU General Public License
   16 ** along with this program; if not, write to the Free Software
   17 ** Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
   18 **
   19 ** File: modules.cpp
   20 **
   21 **/
   22 
   23 #include "nxcore.h"
   24 
   25 /**
   26  * Server config
   27  */
   28 extern Config g_serverConfig;
   29 
   30 /**
   31  * List of loaded modules
   32  */
   33 StringList g_moduleLoadList;
   34 StructArray<NXMODULE> g_moduleList(0, 8);
   35 
   36 /**
   37  * Load module
   38  */
   39 static bool LoadNetXMSModule(const TCHAR *name)
   40 {
   41     bool success = false;
   42    TCHAR errorText[256];
   43 
   44 #ifdef _WIN32
   45    HMODULE hModule = DLOpen(name, errorText);
   46 #else
   47    TCHAR fullName[MAX_PATH];
   48 
   49    if (_tcschr(name, _T('/')) == nullptr)
   50    {
   51       // Assume that module name without path given
   52       // Try to load it from pkglibdir
   53       TCHAR libdir[MAX_PATH];
   54       GetNetXMSDirectory(nxDirLib, libdir);
   55       _sntprintf(fullName, MAX_PATH, _T("%s/%s"), libdir, name);
   56    }
   57    else
   58    {
   59       _tcslcpy(fullName, name, MAX_PATH);
   60    }
   61    HMODULE hModule = DLOpen(fullName, errorText);
   62 #endif
   63 
   64    if (hModule != nullptr)
   65    {
   66       bool (*RegisterModule)(NXMODULE *) = (bool (*)(NXMODULE *))DLGetSymbolAddr(hModule, "NXM_Register", errorText);
   67       if (RegisterModule != nullptr)
   68       {
   69          NXMODULE module;
   70          memset(&module, 0, sizeof(NXMODULE));
   71          if (RegisterModule(&module))
   72          {
   73             if (module.dwSize == sizeof(NXMODULE))
   74             {
   75                if ((module.pfInitialize == nullptr) || module.pfInitialize(&g_serverConfig))
   76                {
   77                   // Add module to module's list
   78                   module.hModule = hModule;
   79                   module.metadata = (NXMODULE_METADATA*)DLGetSymbolAddr(hModule, "NXM_metadata", errorText);
   80                   g_moduleList.add(module);
   81                   nxlog_write(NXLOG_INFO, _T("Server module %s loaded successfully"), module.szName);
   82                   success = true;
   83                }
   84                else
   85                {
   86                   nxlog_write(NXLOG_ERROR, _T("Initialization of server module \"%s\" failed"), name);
   87                   DLClose(hModule);
   88                }
   89             }
   90             else
   91             {
   92                nxlog_write(NXLOG_ERROR, _T("Module \"%s\" has invalid magic number - probably it was compiled for different NetXMS server version"), name);
   93                DLClose(hModule);
   94             }
   95          }
   96          else
   97          {
   98             nxlog_write(NXLOG_ERROR, _T("Registartion of server module \"%s\" failed"), name);
   99             DLClose(hModule);
  100          }
  101       }
  102       else
  103       {
  104          nxlog_write(NXLOG_ERROR, _T("Unable to find entry point in server module \"%s\""), name);
  105          DLClose(hModule);
  106       }
  107    }
  108    else
  109    {
  110       nxlog_write(NXLOG_ERROR, _T("Unable to load module \"%s\" (%s)"), name, errorText);
  111    }
  112    return success;
  113 }
  114 
  115 /**
  116  * Load all registered modules
  117  */
  118 bool LoadNetXMSModules()
  119 {
  120    bool success = true;
  121     for(int i = 0; i < g_moduleLoadList.size(); i++)
  122    {
  123        TCHAR *curr = MemCopyString(g_moduleLoadList.get(i));
  124         StrStrip(curr);
  125         if (*curr == 0)
  126         {
  127            MemFree(curr);
  128             continue;
  129         }
  130 
  131         bool mandatory = false;
  132 
  133         // Check for "mandatory" option
  134         TCHAR *options = _tcschr(curr, _T(','));
  135         if (options != nullptr)
  136         {
  137             *options = 0;
  138             options++;
  139             StrStrip(curr);
  140             StrStrip(options);
  141             mandatory = (*options == _T('1')) || (*options == _T('Y')) || (*options == _T('y'));
  142         }
  143 
  144       if (!LoadNetXMSModule(curr))
  145       {
  146             if (mandatory)
  147             {
  148             MemFree(curr);
  149                 success = false;
  150                 break;
  151             }
  152       }
  153       MemFree(curr);
  154    }
  155     return success;
  156 }
  157 
  158 /**
  159  * Module object data constructor
  160  */
  161 ModuleData::ModuleData()
  162 {
  163 }
  164 
  165 /**
  166  * Module object data destructor
  167  */
  168 ModuleData::~ModuleData()
  169 {
  170 }
  171 
  172 /**
  173  * Fill NXCP message with module data
  174  */
  175 void ModuleData::fillMessage(NXCPMessage *msg, UINT32 baseId)
  176 {
  177 }
  178 
  179 /**
  180  * Save module data to database.
  181  */
  182 bool ModuleData::saveToDatabase(DB_HANDLE hdb, UINT32 objectId)
  183 {
  184    return true;
  185 }
  186 
  187 /**
  188  * Save runtime data to database (called only on server shutdown).
  189  */
  190 bool ModuleData::saveRuntimeData(DB_HANDLE hdb, UINT32 objectId)
  191 {
  192    return true;
  193 }
  194 
  195 /**
  196  * Delete module data from database.
  197  */
  198 bool ModuleData::deleteFromDatabase(DB_HANDLE hdb, UINT32 objectId)
  199 {
  200    return true;
  201 }