dllmain.cpp

Go to the documentation of this file.
00001 /***************************************************************************
00002   file : $URL: https://frepple.svn.sourceforge.net/svnroot/frepple/tags/0.8.0/src/dllmain.cpp $
00003   version : $LastChangedRevision: 1108 $  $LastChangedBy: jdetaeye $
00004   date : $LastChangedDate: 2009-12-06 18:54:18 +0100 (Sun, 06 Dec 2009) $
00005  ***************************************************************************/
00006 
00007 /***************************************************************************
00008  *                                                                         *
00009  * Copyright (C) 2007 by Johan De Taeye                                    *
00010  *                                                                         *
00011  * This library is free software; you can redistribute it and/or modify it *
00012  * under the terms of the GNU Lesser General Public License as published   *
00013  * by the Free Software Foundation; either version 2.1 of the License, or  *
00014  * (at your option) any later version.                                     *
00015  *                                                                         *
00016  * This library is distributed in the hope that it will be useful,         *
00017  * but WITHOUT ANY WARRANTY; without even the implied warranty of          *
00018  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser *
00019  * General Public License for more details.                                *
00020  *                                                                         *
00021  * You should have received a copy of the GNU Lesser General Public        *
00022  * License along with this library; if not, write to the Free Software     *
00023  * Foundation Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 *
00024  * USA                                                                     *
00025  *                                                                         *
00026  ***************************************************************************/
00027 
00028 #define FREPPLE_CORE
00029 #include "frepple.h"
00030 #include "freppleinterface.h"
00031 using namespace frepple;
00032 #include <sys/stat.h>
00033 
00034 
00035 DECLARE_EXPORT(const char*) FreppleVersion()
00036 {
00037   return PACKAGE_VERSION;
00038 }
00039 
00040 
00041 DECLARE_EXPORT(void) FreppleInitialize()
00042 {
00043   // Initialize only once
00044   static bool initialized = false;
00045   if (initialized) return;
00046   initialized = true;
00047 
00048   // Initialize the libraries
00049   LibraryModel::initialize(); // also initializes the utils library
00050   LibrarySolver::initialize();
00051 
00052   // Search for the initialization PY file
00053   string init = Environment::searchFile("init.py");
00054   if (!init.empty())
00055   {
00056     // Execute the commands in the file
00057     try
00058     {
00059       CommandPython cmd;
00060       cmd.setFileName(init);
00061       cmd.execute();
00062     }
00063     catch (...)
00064     {
00065       logger << "Exception caught during execution of 'init.py'" << endl;
00066       throw;
00067     }
00068   }
00069 
00070   // Search for the initialization XML file
00071   init = Environment::searchFile("init.xml");
00072   if (!init.empty())
00073   {
00074     // Execute the commands in the file
00075     try {CommandReadXMLFile(init).execute();}
00076     catch (...)
00077     {
00078       logger << "Exception caught during execution of 'init.xml'" << endl;
00079       throw;
00080     }
00081   }
00082 }
00083 
00084 
00085 DECLARE_EXPORT(void) FreppleReadXMLData (const char* x, bool validate, bool validateonly)
00086 {
00087   if (x) CommandReadXMLString(string(x), validate, validateonly).execute();
00088 }
00089 
00090 
00091 DECLARE_EXPORT(void) FreppleReadXMLFile (const char* x, bool validate, bool validateonly)
00092 {
00093   CommandReadXMLFile(x, validate, validateonly).execute();
00094 }
00095 
00096 
00097 DECLARE_EXPORT(void) FreppleSaveFile(const char* x)
00098 {
00099   CommandSave(x).execute();
00100 }
00101 
00102 
00103 /** Closing any resources still used by frePPle.<br>
00104   * Allocated memory is not freed up with this call - for performance
00105   * reasons it is easier to "leak" the memory. The memory is freed when
00106   * the process exits.
00107   */
00108 DECLARE_EXPORT(void) FreppleExit()
00109 {
00110   // Close the log file
00111   Environment::setLogFile("");
00112 }
00113 
00114 
00115 DECLARE_EXPORT(void) FreppleLog(const string& msg)
00116 {
00117   logger << msg << endl;
00118 }
00119 
00120 
00121 extern "C" DECLARE_EXPORT(void) FreppleLog(const char* msg)
00122 {
00123   logger << msg << endl;
00124 }
00125 
00126 
00127 extern "C" DECLARE_EXPORT(int) FreppleWrapperInitialize()
00128 {
00129   try {FreppleInitialize();}
00130   catch (...) {return EXIT_FAILURE;}
00131   return EXIT_SUCCESS;
00132 }
00133 
00134 
00135 extern "C" DECLARE_EXPORT(int) FreppleWrapperReadXMLData(char* d, bool v, bool c)
00136 {
00137   try {FreppleReadXMLData(d, v, c);}
00138   catch (...) {return EXIT_FAILURE;}
00139   return EXIT_SUCCESS;
00140 }
00141 
00142 
00143 extern "C" DECLARE_EXPORT(int) FreppleWrapperReadXMLFile(const char* f, bool v, bool c)
00144 {
00145   try {FreppleReadXMLFile(f, v, c);}
00146   catch (...) {return EXIT_FAILURE;}
00147   return EXIT_SUCCESS;
00148 }
00149 
00150 
00151 extern "C" DECLARE_EXPORT(int) FreppleWrapperSaveFile(char* f)
00152 {
00153   try {FreppleSaveFile(f);}
00154   catch (...) {return EXIT_FAILURE;}
00155   return EXIT_SUCCESS;
00156 }
00157 
00158 
00159 extern "C" DECLARE_EXPORT(int) FreppleWrapperExit()
00160 {
00161   try {FreppleExit();}
00162   catch (...) {return EXIT_FAILURE;}
00163   return EXIT_SUCCESS;
00164 }
00165