solarpowerlog trunk
/home/tobi/workspace/solarpowerlog/src/Connections/interfaces/IConnect.cpp
Go to the documentation of this file.
00001 /* ----------------------------------------------------------------------------
00002  solarpowerlog
00003  Copyright (C) 2009  Tobias Frost
00004 
00005  This file is part of solarpowerlog.
00006 
00007  Solarpowerlog is free software; However, it is dual-licenced
00008  as described in the file "COPYING".
00009 
00010  For this file (IConnect.cpp), the license terms are:
00011 
00012  You can redistribute it and/or modify it under the terms of the GNU
00013  General Public License as published by the Free Software Foundation; either
00014  version 3 of the License, or (at your option) any later version.
00015 
00016  This program is distributed in the hope that it will be useful, but
00017  WITHOUT ANY WARRANTY; without even the implied warranty of
00018  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00019  Lesser General Public License for more details.
00020 
00021  You should have received a copy of the GNU Library General Public
00022  License along with this proramm; if not, see
00023  <http://www.gnu.org/licenses/>.
00024  ----------------------------------------------------------------------------
00025  */
00026 
00033 #ifdef HAVE_CONFIG_H
00034 #include "config.h"
00035 #endif
00036 
00037 #include <string>
00038 
00039 #include "IConnect.h"
00040 
00041 using namespace std;
00042 
00043 IConnect::IConnect(const string& configurationname)
00044 {
00045      ConfigurationPath = configurationname;
00046      _thread_is_running = false;
00047      _thread_term_request = false;
00048 
00049 }
00050 
00051 void IConnect::SetupLogger(const string &parentlogger, const string & spec)
00052 {
00053      logger.Setup(parentlogger, spec);
00054 }
00055 
00056 IConnect::~IConnect()
00057 {
00058      mutex.lock();
00059      if (_thread_is_running) {
00060           _thread_term_request = true;
00061           workerthread.interrupt();
00062           mutex.unlock();
00063           workerthread.join();
00064      } else {
00065           mutex.unlock();
00066      }
00067 }
00068 
00069 void IConnect::StartWorkerThread(void)
00070 {
00071      mutex.lock();
00072      if (!_thread_is_running) {
00073           workerthread = boost::thread(boost::bind(&IConnect::_main, this));
00074           _thread_is_running = true;
00075      }
00076      mutex.unlock();
00077 }
00078 
00079 bool IConnect::IsTermRequested(void)
00080 {
00081      mutex.lock();
00082      bool ret = _thread_term_request;
00083      mutex.unlock();
00084      return ret;
00085 }
00086 
00087 bool IConnect::IsThreadRunning(void)
00088 {
00089      mutex.lock();
00090      bool ret = _thread_is_running;
00091      mutex.unlock();
00092      return ret;
00093 }