Skip to content
Snippets Groups Projects
Commit d1d8fe05 authored by Roman Tolchenov's avatar Roman Tolchenov
Browse files

re #151

New classes added: SignalChannel to Mantid and MantidLog to QtiPlot. 

FrameworkManager's initialization is moved to the constructor.
parent 6159957a
No related merge requests found
Showing
with 171 additions and 44 deletions
...@@ -56,7 +56,7 @@ namespace Mantid ...@@ -56,7 +56,7 @@ namespace Mantid
{ {
public: public:
/// Creates all of the required services /// Creates all of the required services
void initialize(); //void initialize();
/// Clears all memory associated with the AlgorithmManager /// Clears all memory associated with the AlgorithmManager
void clear(); void clear();
......
...@@ -24,8 +24,13 @@ namespace API ...@@ -24,8 +24,13 @@ namespace API
/// Default constructor /// Default constructor
FrameworkManagerImpl::FrameworkManagerImpl() : g_log(Kernel::Logger::get("FrameworkManager")) FrameworkManagerImpl::FrameworkManagerImpl() : g_log(Kernel::Logger::get("FrameworkManager"))
{ {
std::cerr << "Framework Manager created." << std::endl; std::string pluginDir = Kernel::ConfigService::Instance().getString("plugins.directory");
g_log.debug() << "FrameworkManager created." << std::endl; if (pluginDir.length() > 0)
{
Mantid::Kernel::LibraryManager::Instance().OpenAllLibraries(pluginDir, false);
}
std::cerr << "Framework Manager created." << std::endl;
g_log.debug() << "FrameworkManager created." << std::endl;
} }
/// Destructor /// Destructor
...@@ -35,17 +40,6 @@ FrameworkManagerImpl::~FrameworkManagerImpl() ...@@ -35,17 +40,6 @@ FrameworkManagerImpl::~FrameworkManagerImpl()
// g_log.debug() << "FrameworkManager destroyed." << std::endl; // g_log.debug() << "FrameworkManager destroyed." << std::endl;
} }
/// Creates all of the required services
void FrameworkManagerImpl::initialize()
{
std::string pluginDir = Kernel::ConfigService::Instance().getString("plugins.directory");
if (pluginDir.length() > 0)
{
Mantid::Kernel::LibraryManager::Instance().OpenAllLibraries(pluginDir, false);
}
return;
}
/** At the moment clears all memory associated with AlgorithmManager. /** At the moment clears all memory associated with AlgorithmManager.
* May do more in the future * May do more in the future
*/ */
......
...@@ -35,11 +35,11 @@ class FrameworkManagerTest : public CxxTest::TestSuite ...@@ -35,11 +35,11 @@ class FrameworkManagerTest : public CxxTest::TestSuite
{ {
public: public:
void testInitialize() //void testInitialize()
{ //{
// Not really much to test // // Not really much to test
TS_ASSERT_THROWS_NOTHING( FrameworkManager::Instance().initialize() ) // TS_ASSERT_THROWS_NOTHING( FrameworkManager::Instance().initialize() )
} //}
void testcreateAlgorithm() void testcreateAlgorithm()
{ {
......
...@@ -28,7 +28,7 @@ public: ...@@ -28,7 +28,7 @@ public:
LoadInstrumentFromRawTest() LoadInstrumentFromRawTest()
{ {
//initialise framework manager to allow logging //initialise framework manager to allow logging
Mantid::API::FrameworkManager::Instance().initialize(); //Mantid::API::FrameworkManager::Instance().initialize();
} }
void testInit() void testInit()
{ {
......
...@@ -28,7 +28,7 @@ public: ...@@ -28,7 +28,7 @@ public:
LoadInstrumentTest() LoadInstrumentTest()
{ {
//initialise framework manager to allow logging //initialise framework manager to allow logging
Mantid::API::FrameworkManager::Instance().initialize(); //Mantid::API::FrameworkManager::Instance().initialize();
} }
void testInit() void testInit()
{ {
......
...@@ -28,7 +28,7 @@ public: ...@@ -28,7 +28,7 @@ public:
LoadLogTest() LoadLogTest()
{ {
//initialise framework manager to allow logging //initialise framework manager to allow logging
Mantid::API::FrameworkManager::Instance().initialize(); //Mantid::API::FrameworkManager::Instance().initialize();
} }
void testInit() void testInit()
{ {
......
...@@ -24,7 +24,7 @@ public: ...@@ -24,7 +24,7 @@ public:
LoadRawTest() LoadRawTest()
{ {
//initialise framework manager to allow logging //initialise framework manager to allow logging
Mantid::API::FrameworkManager::Instance().initialize(); //Mantid::API::FrameworkManager::Instance().initialize();
// Path to test input file assumes Test directory checked out from SVN // Path to test input file assumes Test directory checked out from SVN
inputFile = "../../../../Test/Data/HET15869.RAW"; inputFile = "../../../../Test/Data/HET15869.RAW";
} }
......
...@@ -23,7 +23,7 @@ class MarkDeadDetectorsTest : public CxxTest::TestSuite ...@@ -23,7 +23,7 @@ class MarkDeadDetectorsTest : public CxxTest::TestSuite
public: public:
MarkDeadDetectorsTest() MarkDeadDetectorsTest()
{ {
FrameworkManager::Instance().initialize(); //FrameworkManager::Instance().initialize();
// Set up a small workspace for testing // Set up a small workspace for testing
Workspace_sptr space = WorkspaceFactory::Instance().create("Workspace2D",5,6,5); Workspace_sptr space = WorkspaceFactory::Instance().create("Workspace2D",5,6,5);
......
...@@ -126,7 +126,7 @@ ...@@ -126,7 +126,7 @@
/> />
<Tool <Tool
Name="VCLinkerTool" Name="VCLinkerTool"
AdditionalDependencies="PocoFoundation.lib PocoUtil.lib" AdditionalDependencies="PocoFoundation.lib PocoUtil.lib libboost_signals-vc80-mt-1_34_1.lib"
OutputFile="$(OutDir)\$(SolutionName)$(ProjectName).dll" OutputFile="$(OutDir)\$(SolutionName)$(ProjectName).dll"
AdditionalLibraryDirectories="../../Third_Party/lib/win32" AdditionalLibraryDirectories="../../Third_Party/lib/win32"
/> />
...@@ -208,6 +208,10 @@ ...@@ -208,6 +208,10 @@
RelativePath=".\src\PropertyWithValue.cpp" RelativePath=".\src\PropertyWithValue.cpp"
> >
</File> </File>
<File
RelativePath=".\src\SignalChannel.cpp"
>
</File>
<File <File
RelativePath=".\src\SingletonHolder.cpp" RelativePath=".\src\SingletonHolder.cpp"
> >
...@@ -374,6 +378,14 @@ ...@@ -374,6 +378,14 @@
RelativePath=".\test\PropertyWithValueTest.h" RelativePath=".\test\PropertyWithValueTest.h"
> >
</File> </File>
<File
RelativePath=".\inc\MantidKernel\Signal.h"
>
</File>
<File
RelativePath=".\inc\MantidKernel\SignalChannel.h"
>
</File>
<File <File
RelativePath=".\inc\MantidKernel\SingletonHolder.h" RelativePath=".\inc\MantidKernel\SingletonHolder.h"
> >
......
//
// SignalChannel.h
//
//
// Definition of the SignalChannel class. A small extension to the POCO logging.
//
// Copyright &copy; 2007 STFC Rutherford Appleton Laboratories
//
// This file is part of Mantid.
//
// Mantid is free software; you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation; either version 3 of the License, or
// (at your option) any later version.
//
// Mantid is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program. If not, see <http://www.gnu.org/licenses/>.
//
//File change history is stored at: <https://svn.mantidproject.org/mantid/trunk/Code/Mantid>
//
#ifndef Foundation_SignalChannel_INCLUDED
#define Foundation_SignalChannel_INCLUDED
#include "MantidKernel/System.h"
#include "Poco/Foundation.h"
#include "Poco/Channel.h"
//#include "Poco/Mutex.h"
#include "boost/signal.hpp"
#include <vector>
namespace Poco {
/**
class SignalChannel passes log messages to slots, connected to it.
**/
class DLLExport SignalChannel: public Channel
/// This channel sends a message through boost::signal.
{
public:
typedef boost::signal<void (const Message& msg)> signal_t;
/// Creates the SignalChannel.
SignalChannel();
/// Connects a slot to the channel.
void connect(void(const Message& msg));
/// Sends the given Message.
void log(const Message& msg);
signal_t& sig(){return _sig;}
private:
//mutable FastMutex _mutex;
signal_t _sig;
};
} // namespace Poco
#endif // Foundation_SignalChannel_INCLUDED
...@@ -5,6 +5,7 @@ ...@@ -5,6 +5,7 @@
#include "MantidKernel/Support.h" #include "MantidKernel/Support.h"
#include "MantidKernel/Logger.h" #include "MantidKernel/Logger.h"
#include "MantidKernel/FilterChannel.h" #include "MantidKernel/FilterChannel.h"
#include "MantidKernel/SignalChannel.h"
#include "Poco/Util/LoggingConfigurator.h" #include "Poco/Util/LoggingConfigurator.h"
#include "Poco/Util/SystemConfiguration.h" #include "Poco/Util/SystemConfiguration.h"
#include "Poco/Util/PropertyFileConfiguration.h" #include "Poco/Util/PropertyFileConfiguration.h"
...@@ -24,11 +25,14 @@ namespace Kernel ...@@ -24,11 +25,14 @@ namespace Kernel
//getting at system details //getting at system details
m_pSysConfig = new WrappedObject<Poco::Util::SystemConfiguration>; m_pSysConfig = new WrappedObject<Poco::Util::SystemConfiguration>;
m_pConf = 0; m_pConf = 0;
//Register the FilterChannel with the Poco logging factory
Poco::LoggingFactory::defaultFactory().registerChannelClass("FilterChannel",new Poco::Instantiator<Poco::FilterChannel, Poco::Channel>);
//Register the FilterChannel with the Poco logging factory //Register the SignalChannel with the Poco logging factory
Poco::LoggingFactory::defaultFactory().registerChannelClass("FilterChannel",new Poco::Instantiator<Poco::FilterChannel, Poco::Channel>); Poco::LoggingFactory::defaultFactory().registerChannelClass("SignalChannel",new Poco::Instantiator<Poco::SignalChannel, Poco::Channel>);
//attempt to load the default properties filename //attempt to load the default properties filename
loadConfig("Mantid.properties"); loadConfig("Mantid.properties");
g_log.debug() << "ConfigService created." << std::endl; g_log.debug() << "ConfigService created." << std::endl;
} }
......
#include "MantidKernel/SignalChannel.h"
#include "Poco/LoggingRegistry.h"
#include "Poco/Message.h"
//#include "boost/bind.hpp"
#include <iostream>
namespace Poco {
/// Connects a function (slot) to a SignalChannel with name chName.
/// chName must be defined in Mantid.properies file. A slot is a
/// function of the type: void slot(const Message& msg).
/// Returns true if the connection was successful.
bool DLLExport connectSignal(const std::string& chName, void(*slt)(const Message& msg))
{
try
{
SignalChannel *pChannel = dynamic_cast<SignalChannel*>(Poco::LoggingRegistry::defaultRegistry().channelForName(chName));
if (!pChannel) return false;
pChannel->connect(slt);
}
catch(...)
{
return false;
}
return true;
}
SignalChannel::SignalChannel():Channel()
{
}
void SignalChannel::log(const Message& msg)
{
_sig(msg);
}
/// Connects a slot to the channel.
void SignalChannel::connect(void(*slt)(const Message& msg))
{
_sig.connect(slt);
}
} // namespace Poco
...@@ -123,7 +123,7 @@ ...@@ -123,7 +123,7 @@
/> />
<Tool <Tool
Name="VCLinkerTool" Name="VCLinkerTool"
AdditionalDependencies="$(SolutionName)API.lib $(SolutionName)Kernel.lib $(SolutionName)Geometry.lib $(SolutionName)DataObjects.lib" AdditionalDependencies="$(SolutionName)API.lib $(SolutionName)Kernel.lib $(SolutionName)Geometry.lib $(SolutionName)DataObjects.lib $(SolutionName)UserAlgorithms.lib"
OutputFile="$(OutDir)\$(SolutionName)$(ProjectName).exe" OutputFile="$(OutDir)\$(SolutionName)$(ProjectName).exe"
AdditionalLibraryDirectories="..\Release;..\..\Third_Party\lib\win32" AdditionalLibraryDirectories="..\Release;..\..\Third_Party\lib\win32"
/> />
......
...@@ -51,8 +51,6 @@ public: ...@@ -51,8 +51,6 @@ public:
PythonInterface(); PythonInterface();
~PythonInterface(); ~PythonInterface();
void InitialiseFrameworkManager();
//Algorithms //Algorithms
API::IAlgorithm* CreateAlgorithm(const std::string&); API::IAlgorithm* CreateAlgorithm(const std::string&);
std::vector<std::string> GetAlgorithmNames(); std::vector<std::string> GetAlgorithmNames();
......
...@@ -23,6 +23,7 @@ namespace PythonAPI ...@@ -23,6 +23,7 @@ namespace PythonAPI
///Constructor ///Constructor
PythonInterface::PythonInterface() PythonInterface::PythonInterface()
{ {
FrameworkManager::Instance();
} }
///Destructor ///Destructor
...@@ -30,12 +31,6 @@ PythonInterface::~PythonInterface() ...@@ -30,12 +31,6 @@ PythonInterface::~PythonInterface()
{ {
} }
///Initialises the FrameworkManager.
void PythonInterface::InitialiseFrameworkManager()
{
FrameworkManager::Instance().initialize();
}
/** /**
* Creates a specified algorithm. * Creates a specified algorithm.
* \param algName :: The name of the algorithm to execute. * \param algName :: The name of the algorithm to execute.
......
...@@ -128,7 +128,7 @@ BOOST_PYTHON_MODULE(libMantidPythonAPI) ...@@ -128,7 +128,7 @@ BOOST_PYTHON_MODULE(libMantidPythonAPI)
//Mantid stuff //Mantid stuff
class_< Mantid::PythonAPI::PythonInterface >("PythonInterface", init< >()) class_< Mantid::PythonAPI::PythonInterface >("PythonInterface", init< >())
.def(init< const Mantid::PythonAPI::PythonInterface& >()) .def(init< const Mantid::PythonAPI::PythonInterface& >())
.def("InitialiseFrameworkManager", &Mantid::PythonAPI::PythonInterface::InitialiseFrameworkManager) // .def("InitialiseFrameworkManager", &Mantid::PythonAPI::PythonInterface::InitialiseFrameworkManager)
.def("CreateAlgorithm", &Mantid::PythonAPI::PythonInterface::CreateAlgorithm, return_value_policy< manage_new_object>()) .def("CreateAlgorithm", &Mantid::PythonAPI::PythonInterface::CreateAlgorithm, return_value_policy< manage_new_object>())
.def("GetAlgorithmNames", &Mantid::PythonAPI::PythonInterface::GetAlgorithmNames) .def("GetAlgorithmNames", &Mantid::PythonAPI::PythonInterface::GetAlgorithmNames)
.def("LoadIsisRawFile", &Mantid::PythonAPI::PythonInterface::LoadIsisRawFile) .def("LoadIsisRawFile", &Mantid::PythonAPI::PythonInterface::LoadIsisRawFile)
......
...@@ -23,10 +23,10 @@ public: ...@@ -23,10 +23,10 @@ public:
inter = new PythonInterface(); inter = new PythonInterface();
} }
void testFrameworkInitialise() //void testFrameworkInitialise()
{ //{
TS_ASSERT_THROWS_NOTHING(inter->InitialiseFrameworkManager()); // TS_ASSERT_THROWS_NOTHING(inter->InitialiseFrameworkManager());
} //}
void testCreateAlgorithm() void testCreateAlgorithm()
{ {
......
...@@ -7,7 +7,8 @@ namespace Mantid ...@@ -7,7 +7,8 @@ namespace Mantid
namespace Algorithms namespace Algorithms
{ {
DECLARE_ALGORITHM(PropertyAlgorithm); //DECLARE_ALGORITHM(PropertyAlgorithm);
DECLARE_NAMESPACED_ALGORITHM(Mantid::Algorithms,PropertyAlgorithm)
using namespace Kernel; using namespace Kernel;
......
...@@ -113,7 +113,7 @@ ...@@ -113,7 +113,7 @@
Optimization="3" Optimization="3"
AdditionalIncludeDirectories="inc;../API/inc;../Geometry/inc;../Kernel/inc;../DataObjects/inc;../../Third_Party/include" AdditionalIncludeDirectories="inc;../API/inc;../Geometry/inc;../Kernel/inc;../DataObjects/inc;../../Third_Party/include"
PreprocessorDefinitions="WIN32;_WINDOWS;POCO_DLL;WINVER=0x0500;IN_MANTID_ALGORITHMS=1;_CRT_SECURE_NO_DEPRECATE;_CRT_NONSTDC_NO_DEPRECATE;_SCL_SECURE_NO_DEPRECATE" PreprocessorDefinitions="WIN32;_WINDOWS;POCO_DLL;WINVER=0x0500;IN_MANTID_ALGORITHMS=1;_CRT_SECURE_NO_DEPRECATE;_CRT_NONSTDC_NO_DEPRECATE;_SCL_SECURE_NO_DEPRECATE"
RuntimeLibrary="3" RuntimeLibrary="2"
DisableSpecificWarnings="4996" DisableSpecificWarnings="4996"
/> />
<Tool <Tool
......
...@@ -15,3 +15,6 @@ logging.channels.fileChannel.formatter.pattern = %Y-%m-%d %H:%M:%S,%i [%I] %p %s ...@@ -15,3 +15,6 @@ logging.channels.fileChannel.formatter.pattern = %Y-%m-%d %H:%M:%S,%i [%I] %p %s
logging.formatters.f1.class = PatternFormatter logging.formatters.f1.class = PatternFormatter
logging.formatters.f1.pattern = %s-[%p] %t logging.formatters.f1.pattern = %s-[%p] %t
logging.formatters.f1.times = UTC; logging.formatters.f1.times = UTC;
logging.loggers.root.channel.channel3 = signalChannel
logging.channels.signalChannel.class = SignalChannel
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment