|
solarpowerlog trunk
|
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.h), the license terms are: 00011 00012 You can redistribute it and/or modify it under the terms of the GNU Lesser 00013 General Public License (LGPL) as published by the Free Software Foundation; 00014 either 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 #ifndef ICONNECT_H_ 00034 #define ICONNECT_H_ 00035 00036 #ifdef HAVE_CONFIG_H 00037 #include "config.h" 00038 #endif 00039 00040 #include <string> 00041 00042 #include "configuration/ILogger.h" 00043 #include <boost/thread.hpp> 00044 #include "patterns/ICommand.h" 00045 #include <errno.h> 00046 00047 using namespace std; 00048 00049 // USED ICOMMAND TOKENS 00052 #define ICONN_TOKEN_RECEIVE_STRING "ICON_RECEIVE_STRING" 00053 00056 #define ICONN_TOKEN_SEND_STRING "ICON_SEND_STRING" 00057 00064 #define ICONN_TOKEN_TIMEOUT "ICON_TIMEOUT" 00065 00072 #define ICONN_TOKEN_INTERBYTETIMEOUT "ICON_INTERBYTE_TIMEOUT" 00073 00074 #warning docs outdated! 00075 00118 class IConnect 00119 { 00120 public: 00126 IConnect(const string &configurationname); 00127 00129 virtual void SetupLogger(const string& parentlogger, const string &spec = 00130 "Comms"); 00131 00133 virtual ~IConnect(); 00134 00137 00157 virtual bool Connect(ICommand *callback = NULL) = 0; 00158 00182 virtual bool Disconnect(ICommand *callback = NULL) = 0; 00183 00184 #warning depreciate synchronous interface 00185 // private: 00193 virtual bool Send(const char *tosend, unsigned int len, ICommand *callback = 00194 NULL) = 0; 00195 00202 virtual bool Send(const string& tosend, ICommand *callback = NULL) 00203 { 00204 return Send(tosend.c_str(), tosend.length(), callback); 00205 } 00206 00240 // virtual bool Receive( string &wheretoplace, ICommand *cmd = NULL ) = 0; 00241 00242 virtual bool Receive(ICommand *cmd) = 0; 00243 00244 public: 00245 00248 virtual bool CheckConfig(void) = 0; 00249 00254 virtual bool IsConnected(void) 00255 { 00256 return true; 00257 } 00258 00259 protected: 00261 string ConfigurationPath; 00262 00266 ILogger logger; 00267 00269 00271 boost::thread workerthread; 00272 00274 boost::recursive_mutex mutex; 00275 00279 virtual void _main(void) 00280 { 00281 mutex.lock(); 00282 _thread_is_running = false; 00283 mutex.unlock(); 00284 } 00285 00287 virtual void StartWorkerThread(void); 00288 00290 virtual bool IsTermRequested(void); 00291 00296 virtual bool IsThreadRunning(void); 00297 00298 private: 00300 bool _thread_is_running; 00301 00303 bool _thread_term_request; 00304 00305 }; 00306 00307 #endif /* ICONNECT_H_ */