|
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 (IValue.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 00198 #ifndef INVERTERBASE_H_ 00199 #define INVERTERBASE_H_ 00200 00201 #ifdef HAVE_CONFIG_H 00202 #include "config.h" 00203 #endif 00204 00205 #include <string> 00206 #include <map> 00207 00208 #include "Connections/interfaces/IConnect.h" 00209 #include "interfaces/CCapability.h" 00210 #include "patterns/ICommandTarget.h" 00211 #include "configuration/ILogger.h" 00212 00213 class ICapaIterator; 00214 00215 using namespace std; 00216 00221 #define CONFIG_TWEAK_CONNECTION_TIMEOUT "option_connectiontimeout" 00222 #define CONFIG_TWEAK_CONNECTION_TIMEOUT_DEFAULT (15000) 00223 00225 // TODO: This class renamed, as it also fits for the "Filters" (Data source, data computing/enhancing, ...) 00226 // Inverters will be only a special interface, derived from this base class 00227 class IInverterBase: public ICommandTarget 00228 { 00229 00230 public: 00231 friend class ICapaIterator; 00232 00254 IInverterBase(const string &name, const string & configurationpath, 00255 const string & role); 00256 00257 virtual ~IInverterBase(); 00258 00260 virtual const std::string& GetName(void) const; 00261 00264 // TODO Move to c++ file 00265 virtual CCapability *GetConcreteCapability(const string &identifier); 00266 00270 virtual ICapaIterator* GetCapaNewIterator(); 00271 00274 virtual bool CheckConfig() = 0; 00275 00276 virtual const std::string& GetConfigurationPath() const 00277 { 00278 return configurationpath; 00279 } 00280 00281 virtual IConnect * getConnection(void) const { 00282 return connection; 00283 } 00284 00285 protected: 00286 00288 #warning TODO: Make this interface obsolete. 00289 virtual void AddCapability(const string &id, CCapability* capa); 00290 00291 protected: 00293 virtual void AddCapability(CCapability* capa) 00294 { 00295 AddCapability(capa->getDescription(), capa); 00296 } 00297 00299 virtual map<string, CCapability*>::iterator 00300 GetCapabilityIterator(void); 00301 00304 virtual map<string, CCapability*>::iterator GetCapabilityLastIterator(void); 00305 00307 std::string configurationpath; 00309 std::string name; 00310 00311 // Class for handling the connectivity. 00312 // Is a strategy design pattern interface. So different ways of connection can be handled by the same interface 00313 // (In other words: Our inverter does need nor want to know, if it is RS485 or TCP/IP, or even, both.) 00314 // NOTE: The Connection is to be made by a factory! 00315 // NOTE2: Beware: Connections can die any time! Make sure to handle this. 00316 IConnect *connection; 00317 00318 protected: 00319 00320 // This maps contains all the Caps by the Inverter. 00321 // Caps implements the Subject in the Observer-Pattern. 00322 // This keeps all informed! 00323 // Class for handling capabilities. 00324 // (Inverters can add capabilities at runtime, also can enhancement filters. 00325 // (A Capabilites bundles on discret feature, reading of a inverter, 00326 // like also current readings and so on... 00327 00328 map<string, CCapability*> CapabilityMap; 00329 00331 ILogger logger; 00332 }; 00333 00334 #endif /* INVERTERBASE_H_ */ 00335 00336 // debug code to keep... 00337 00338 // Dumping the map. 00339 // map<string, CCapability*>::iterator it1 = CapabilityMap.begin(); 00340 // cerr << "DUMP Capabilites: " << this->GetName() << endl; 00341 // for (int i=0; it1 != CapabilityMap.end(); it1++,i++) 00342 // { 00343 // cerr << i << " " << (*it1).first << endl; 00344 // }