IBR-DTNSuite  0.8
daemon/src/storage/SQLiteConfigure.cpp
Go to the documentation of this file.
00001 /*
00002  * SQLiteConfigure.cpp
00003  *
00004  *  Created on: 30.03.2010
00005  *      Author: Myrtus
00006  */
00007 #include "storage/SQLiteConfigure.h"
00008 #include <sqlite3.h>
00009 #include <iostream>
00010 #include <ibrcommon/thread/MutexLock.h>
00011 #include <ibrcommon/Logger.h>
00012 
00013 namespace dtn
00014 {
00015         namespace storage
00016         {
00017                 ibrcommon::Mutex SQLiteConfigure::_mutex;
00018                 bool SQLiteConfigure::_isSet = false;
00019 
00020                 void SQLiteConfigure::configure()
00021                 {
00022                         //Configure SQLite Library
00023                         ibrcommon::MutexLock lock = ibrcommon::MutexLock(_mutex);
00024 
00025                         if (!_isSet)
00026                         {
00027                                 int err = sqlite3_config(SQLITE_CONFIG_SERIALIZED);
00028 
00029                                 if (err != SQLITE_OK)
00030                                 {
00031                                         IBRCOMMON_LOGGER(error) << "SQLite configure failed: " << err << IBRCOMMON_LOGGER_ENDL;
00032                                         throw ibrcommon::Exception("unable to set serialized sqlite configuration");
00033                                 }
00034 
00035                                 _isSet = true;
00036 
00037                                 // initialize sqlite
00038                                 sqlite3_initialize();
00039                         }
00040                 }
00041 
00042                 void SQLiteConfigure::shutdown()
00043                 {
00044                         sqlite3_shutdown();
00045                 }
00046         }
00047 }