|
From: <tho...@us...> - 2012-07-02 20:42:10
|
Revision: 903
http://openautomation.svn.sourceforge.net/openautomation/?rev=903&view=rev
Author: thomas_s
Date: 2012-07-02 20:42:04 +0000 (Mon, 02 Jul 2012)
Log Message:
-----------
removed more global variables
Modified Paths:
--------------
xPLHAL/branches/thomas_s_dev/src/globals.h
xPLHAL/branches/thomas_s_dev/src/main.cpp
xPLHAL/branches/thomas_s_dev/src/xplcache.cpp
xPLHAL/branches/thomas_s_dev/src/xplcache.h
Modified: xPLHAL/branches/thomas_s_dev/src/globals.h
===================================================================
--- xPLHAL/branches/thomas_s_dev/src/globals.h 2012-07-02 20:41:43 UTC (rev 902)
+++ xPLHAL/branches/thomas_s_dev/src/globals.h 2012-07-02 20:42:04 UTC (rev 903)
@@ -17,8 +17,6 @@
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
-#include "boost/filesystem.hpp"
-
/**
* Define all global variables:
*/
@@ -28,11 +26,4 @@
class xPLCacheClass;
extern xPLCacheClass *xPLCache;
-class xPLHandler;
-extern xPLHandler *xPL;
-/** The working directories */
-extern boost::filesystem::path xPLHalRootFolder;
-extern boost::filesystem::path DataFileFolder;
-extern boost::filesystem::path ScriptEngineFolder;
-extern boost::filesystem::path rulesFolder;
Modified: xPLHAL/branches/thomas_s_dev/src/main.cpp
===================================================================
--- xPLHAL/branches/thomas_s_dev/src/main.cpp 2012-07-02 20:41:43 UTC (rev 902)
+++ xPLHAL/branches/thomas_s_dev/src/main.cpp 2012-07-02 20:42:04 UTC (rev 903)
@@ -41,15 +41,15 @@
using std::endl;
using namespace std::placeholders;
-path xPLHalRootFolder;
-path DataFileFolder;
-path ScriptEngineFolder;
-path rulesFolder;
xPLCacheClass *xPLCache;
-xPLHandler *xPL;
-static boost::asio::io_service* g_ioservice = nullptr;
+struct filefolders {
+ path dataFileFolder;
+ path xPLHalRootFolder;
+ path scriptEngineFolder;
+ path rulesFolder;
+};
/**
* \brief Main application
@@ -57,8 +57,8 @@
class XplHalApplication
{
public:
- XplHalApplication()
- :mXplCache(new xPLCacheClass)
+ XplHalApplication(struct filefolders& folders)
+ :mXplCache(new xPLCacheClass(folders.dataFileFolder))
,mDeviceManager(mXplCache)
,mXHCPServer(new XHCPServer(m_ioservice, &mDeviceManager))
,mXpl(new xPLHandler(m_ioservice, boost::asio::ip::host_name() ))
@@ -74,7 +74,7 @@
/* set global variables */
xPLCache = mXplCache;
- xPL = mXpl;
+ //xPL = mXpl;
writeLog( "initialized", logLevel::all );
}
@@ -164,11 +164,12 @@
*/
int main(int UNUSED argc, char** UNUSED argv)
{
+ struct filefolders folders;
/** Make sure the necessary infrastructure exists: */
- xPLHalRootFolder = initial_path();
- DataFileFolder = xPLHalRootFolder / "data";
- ScriptEngineFolder = DataFileFolder / "scripts";
- rulesFolder = DataFileFolder / "determinator";
+ folders.xPLHalRootFolder = current_path();
+ folders.dataFileFolder = folders.xPLHalRootFolder / "data";
+ folders.scriptEngineFolder = folders.dataFileFolder / "scripts";
+ folders.rulesFolder = folders.dataFileFolder / "determinator";
//vendorFileFolder = DataFileFolder / "vendors";
//ConfigFileFolder = DataFileFolder / "configs";
@@ -192,35 +193,35 @@
// FIXME : add exception handling for directory operations!!!
if(false) {
//FIXME if( !QDir::setCurrent( xPLHalRootFolder.path() ) )
- writeLog( "Error changing to working directory \"" + xPLHalRootFolder.string() + "\"!", logLevel::error );
+ writeLog( "Error changing to working directory \"" + folders.xPLHalRootFolder.string() + "\"!", logLevel::error );
return -1;
}
- if( !exists( DataFileFolder ) ) {
- writeLog( "Directory \"" + DataFileFolder.string() + "\" for DataFileFolder doesn't exist. Creating it...", logLevel::debug );
- if( !create_directory( DataFileFolder ) ) {
- writeLog( "Error creating data directory \"" + DataFileFolder.string() + "\"!", logLevel::error );
+ if( !exists( folders.dataFileFolder ) ) {
+ writeLog( "Directory \"" + folders.dataFileFolder.string() + "\" for DataFileFolder doesn't exist. Creating it...", logLevel::debug );
+ if( !create_directory( folders.dataFileFolder ) ) {
+ writeLog( "Error creating data directory \"" + folders.dataFileFolder.string() + "\"!", logLevel::error );
return -1;
}
}
- if( !exists( ScriptEngineFolder ) ) {
- writeLog( "Directory \"" + ScriptEngineFolder.string() + "\" for ScriptEngineFolder doesn't exist. Creating it...", logLevel::debug );
- if( !create_directory( ScriptEngineFolder ) ) {
- writeLog( "Error creating script directory \"" + ScriptEngineFolder.string() + "\"!", logLevel::error );
+ if( !exists( folders.scriptEngineFolder ) ) {
+ writeLog( "Directory \"" + folders.scriptEngineFolder.string() + "\" for ScriptEngineFolder doesn't exist. Creating it...", logLevel::debug );
+ if( !create_directory( folders.scriptEngineFolder ) ) {
+ writeLog( "Error creating script directory \"" + folders.scriptEngineFolder.string() + "\"!", logLevel::error );
return -1;
}
}
- if( !exists( rulesFolder ) ) {
- writeLog( "Directory \"" + rulesFolder.string() + "\" for rulesFolder doesn't exist. Creating it...", logLevel::debug );
- if( !create_directory( rulesFolder ) ) {
- writeLog( "Error creating determinator directory \"" + rulesFolder.string() + "\"!", logLevel::error );
+ if( !exists( folders.rulesFolder ) ) {
+ writeLog( "Directory \"" + folders.rulesFolder.string() + "\" for rulesFolder doesn't exist. Creating it...", logLevel::debug );
+ if( !create_directory( folders.rulesFolder ) ) {
+ writeLog( "Error creating determinator directory \"" + folders.rulesFolder.string() + "\"!", logLevel::error );
return -1;
}
}
- XplHalApplication app;
+ XplHalApplication app(folders);
return app.exec();
}
Modified: xPLHAL/branches/thomas_s_dev/src/xplcache.cpp
===================================================================
--- xPLHAL/branches/thomas_s_dev/src/xplcache.cpp 2012-07-02 20:41:43 UTC (rev 902)
+++ xPLHAL/branches/thomas_s_dev/src/xplcache.cpp 2012-07-02 20:42:04 UTC (rev 903)
@@ -57,7 +57,8 @@
mfSchemClass = list[5];
}
-xPLCacheClass::xPLCacheClass()
+xPLCacheClass::xPLCacheClass(const boost::filesystem::path& dataFileFolder)
+:mDataFileFolder(dataFileFolder)
{
loadCache();
}
@@ -156,7 +157,7 @@
{
mCache.clear(); // erase all entries
- BFS::path objectCacheFile( DataFileFolder / "object_mCache.xml" );
+ BFS::path objectCacheFile( mDataFileFolder / "object_mCache.xml" );
writeLog( "loadCache: ["+objectCacheFile.string()+"]", logLevel::debug );
if( BFS::exists( objectCacheFile ) ) {
writeLog( "Loading cached xPL object from file: "+objectCacheFile.string(), logLevel::debug );
Modified: xPLHAL/branches/thomas_s_dev/src/xplcache.h
===================================================================
--- xPLHAL/branches/thomas_s_dev/src/xplcache.h 2012-07-02 20:41:43 UTC (rev 902)
+++ xPLHAL/branches/thomas_s_dev/src/xplcache.h 2012-07-02 20:42:04 UTC (rev 903)
@@ -24,6 +24,7 @@
#include <mutex>
#include <boost/regex.hpp>
+#include <boost/filesystem.hpp>
#include "i_xplcache.h"
@@ -70,6 +71,7 @@
* the CacheEntry with fast lookup. */
typedef std::map< std::string, CacheEntry > cachemap_t;
cachemap_t mCache; /**< \brief The cache itself. */
+ const boost::filesystem::path& mDataFileFolder;
/** \brief variable to lock write operations on the cache for safe
* multithreading operation. */
@@ -100,7 +102,7 @@
};
public:
- xPLCacheClass();
+ xPLCacheClass(const boost::filesystem::path& dataFileFolder);
/** \returns true if the element name exists. */
bool exists( const std::string& name ) const {
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|