Newer
Older
/*
* Copyright 2012, 2017 INFN
*
* Licensed under the EUPL, Version 1.2 or – as soon they
* will be approved by the European Commission - subsequent
* versions of the EUPL (the "Licence");
* You may not use this work except in compliance with the
* Licence.
* You may obtain a copy of the Licence at:
* https://joinup.ec.europa.eu/software/page/eupl
* Unless required by applicable law or agreed to in
* writing, software distributed under the Licence is
* distributed on an "AS IS" basis,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
* express or implied.
* See the Licence for the specific language governing
* permissions and limitations under the Licence.
#ifndef ChaosFramework_ChaosCommon_h
#define ChaosFramework_ChaosCommon_h

Claudio Bisegni
committed
#include <chaos/common/global.h>
#include <chaos/common/log/LogManager.h>

Claudio Bisegni
committed
#include <chaos/common/chaos_constants.h>

Claudio Bisegni
committed
#include <chaos/common/utility/Singleton.h>
#include <chaos/common/utility/TimingUtil.h>
#include <chaos/common/utility/InetUtility.h>

Andrea Michelotti
committed

Claudio Bisegni
committed
#include <chaos/common/plugin/PluginManager.h>
#include <chaos/common/action/DeclareAction.h>
#include <chaos/common/utility/StartableService.h>
#include <chaos/common/async_central/AsyncCentralManager.h>
#include <chaos/common/configuration/GlobalConfiguration.h>

Claudio Bisegni
committed
#include <boost/version.hpp>
#include <boost/interprocess/sync/file_lock.hpp>
#include <boost/interprocess/sync/scoped_lock.hpp>

Claudio Bisegni
committed
//! Default chaos namespace used to group all common api

Claudio Bisegni
committed
namespace chaos {
struct __file_remover__ {
const char*name;
__file_remover__(const char*_name):name(_name){}
~__file_remover__(){std::remove(name);}
};
//! Chaos common engine class

Claudio Bisegni
committed
/*!
This is the base class for the other toolkit, it thake care to initialize all common
resource used for the base chaos function
*/
public common::utility::StartableService,
public DeclareAction {

Claudio Bisegni
committed
protected:
bool initialized,deinitialized;
//!ingore unregistered program option
bool ingore_unreg_po;
//!return build infromation via rpc

Andrea Michelotti
committed
chaos::common::data::CDWUniquePtr _registrationAck(chaos::common::data::CDWUniquePtr data);
//! Constructor Method

Claudio Bisegni
committed
/*!
This method call the \ref GlobalConfiguration::preParseStartupParameters method, starting the

Claudio Bisegni
committed
allocation of the startup framework parameter
*/
//! Destructor method

Claudio Bisegni
committed
/*!
A more elaborate description of the destructor.
*/

Claudio Bisegni
committed
/*!
parse a config file before initializzation
*/
void preparseConfigFile(std::istream &config_file_stream);

Claudio Bisegni
committed
/*!
parse a config file before initializzation
*/
void preparseCommandOption(int argc, const char* argv[]);
//! C and C++ attribute parser

Claudio Bisegni
committed
/*!
Specialized option for startup c and cpp program main options parameter
*/
void init(int argc, const char* argv[]);
//!stream parser

Claudio Bisegni
committed
/*
specialized option for string stream buffer with boost semantics
*/
//! Initialization methdo

Claudio Bisegni
committed
/*!
This virtual method can be extended by toolkit subclass for specialized initializaion
in themain toolkit subclass of ChaosCommon
*/
void init(void *init_data);
void deinit();
/**
* Return a JSON document with the version of the libraries
*/

Andrea Michelotti
committed
chaos::common::data::CDWUniquePtr getBuildInfo(chaos::common::data::CDWUniquePtr data);
chaos::common::data::CDWUniquePtr getProcessInfo(chaos::common::data::CDWUniquePtr data);

Claudio Bisegni
committed
virtual chaos::common::data::CDWUniquePtr nodeShutDown(chaos::common::data::CDWUniquePtr data);
virtual chaos::common::data::CDWUniquePtr clearAlarm(chaos::common::data::CDWUniquePtr data);
virtual void logError(const std::string&uid, const std::string&msg,const std::string&org=__PRETTY_FUNCTION__,int lvl=2);
GlobalConfiguration* getGlobalConfigurationInstance();
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
};
//templated class to force singleton on master
template<class T>
class ChaosCommon:
public common::utility::Singleton<T>,
public ChaosAbstractCommon {
protected:
//! Constructor Method
/*!
This method call the \ref GlobalConfiguration::preParseStartupParameters method, starting the
allocation of the startup framework parameter
*/
ChaosCommon():
ChaosAbstractCommon(){}
//! Destructor method
/*!
A more elaborate description of the destructor.
*/
virtual ~ChaosCommon(){}
public:
using ChaosAbstractCommon::init;
using ChaosAbstractCommon::deinit;
using ChaosAbstractCommon::start;
using ChaosAbstractCommon::stop;
using ChaosAbstractCommon::getGlobalConfigurationInstance;

Claudio Bisegni
committed
};
}