- /*=========================================================================
+/*
+# ---------------------------------------------------------------------
+#
+# Copyright (c) CREATIS (Centre de Recherche en Acquisition et Traitement de l'Image
+# pour la Santé)
+# Authors : Eduardo Davila, Frederic Cervenansky, Claire Mouton
+# Previous Authors : Laurent Guigues, Jean-Pierre Roux
+# CreaTools website : www.creatis.insa-lyon.fr/site/fr/creatools_accueil
+#
+# This software is governed by the CeCILL-B license under French law and
+# abiding by the rules of distribution of free software. You can use,
+# modify and/ or redistribute the software under the terms of the CeCILL-B
+# license as circulated by CEA, CNRS and INRIA at the following URL
+# http://www.cecill.info/licences/Licence_CeCILL-B_V1-en.html
+# or in the file LICENSE.txt.
+#
+# As a counterpart to the access to the source code and rights to copy,
+# modify and redistribute granted by the license, users are provided only
+# with a limited warranty and the software's author, the holder of the
+# economic rights, and the successive licensors have only limited
+# liability.
+#
+# The fact that you are presently reading this means that you have had
+# knowledge of the CeCILL-B license and that you accept its terms.
+# ------------------------------------------------------------------------
+*/
+
+/*=========================================================================
Program: crea
Module: $RCSfile: creaMessageManager.cxx,v $
Language: C++
- Date: $Date: 2008/09/26 14:09:55 $
- Version: $Revision: 1.1 $
-
- Copyright (c) CREATIS (Centre de Recherche et d'Applications en Traitement de
- l'Image). All rights reserved. See Doc/License.txt or
- http://www.creatis.insa-lyon.fr/Public/Gdcm/License.html for details.
+ Date: $Date: 2012/11/15 10:43:26 $
+ Version: $Revision: 1.4 $
This software is distributed WITHOUT ANY WARRANTY; without even
the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
namespace crea
{
+ //===========================================================================
MessageManager::MessageManager()
- : mMaxMessageLength(8)//, mAllLevel(0), mMaxLevel(9)
-
+ : mMaxMessageLength(8),
+ mSendToCout(true)
{
std::string key;
+
key ="all";
- mMessageLevel[key] = 0;
- mMessageHelp[key] = "Minimum level for all kind of messages";
+ mMessageMap[key] = new MessageType(0,"Minimum level for all kind of messages");
if (mMaxMessageLength<key.length()) mMaxMessageLength = key.length();
+
+ key ="max";
+ mMessageMap[key] = new MessageType(9,"Maximum level for all kind of messages");
+ if (mMaxMessageLength<key.length()) mMaxMessageLength = key.length();
+
+ key ="info";
+ mMessageMap[key] = new MessageType(1,"Information messages");
+ if (mMaxMessageLength<key.length()) mMaxMessageLength = key.length();
+
+ key ="warning";
+ mMessageMap[key] = new MessageType(1,"Warning messages");
+ if (mMaxMessageLength<key.length()) mMaxMessageLength = key.length();
+
+ /*
key ="max";
mMessageLevel[key] = 9;
mMessageHelp[key] = "Maximum level for all kind of messages";
mMessageLevel[key] = 1;
mMessageHelp[key] = "Information messages";
if (mMaxMessageLength<key.length()) mMaxMessageLength = key.length();
- /*
- key ="Kernel";
- mMessageLevel[key] = 0;
- mMessageHelp[key] = "Messages generated by the core classes of the lib";
- if (mMaxMessageLength<key.length()) mMaxMessageLength = key.length();
- key ="process";
- mMessageLevel[key] = 0;
- mMessageHelp[key] = "Messages related to box processing";
- if (mMaxMessageLength<key.length()) mMaxMessageLength = key.length();
- key = "Help";
- mMessageLevel[key] = 1;
- mMessageHelp[key] = "Help messages";
- if (mMaxMessageLength<key.length()) mMaxMessageLength = key.length();
- key = "Error";
- mMessageLevel[key] = 0;
- mMessageHelp[key] = "Error messages";
- if (mMaxMessageLength<key.length()) mMaxMessageLength = key.length();
- key = "Warning";
- mMessageLevel[key] = 1;
- mMessageHelp[key] = "Warning messages";
- if (mMaxMessageLength<key.length()) mMaxMessageLength = key.length();
- key = "Output";
- mMessageLevel[key] = 1;
- mMessageHelp[key] = "Output messages";
- if (mMaxMessageLength<key.length()) mMaxMessageLength = key.length();
- key = "debug";
- mMessageLevel[key] = 0;
- mMessageHelp[key] = "Debug messages";
- if (mMaxMessageLength<key.length()) mMaxMessageLength = key.length();
- key = "Config";
- mMessageLevel[key] = 0;
- mMessageHelp[key] = "Configuration related messages";
- if (mMaxMessageLength<key.length()) mMaxMessageLength = key.length();
- key = "data";
- mMessageLevel[key] = 0;
- mMessageHelp[key] = "Data related messages";
- if (mMaxMessageLength<key.length()) mMaxMessageLength = key.length();
- key = "wx";
- mMessageLevel[key] = 0;
- mMessageHelp[key] = "Widgets related messages";
- if (mMaxMessageLength<key.length()) mMaxMessageLength = key.length();
- key = "gui";
- mMessageLevel[key] = 0;
- mMessageHelp[key] = "Graphical user interface related messages";
- if (mMaxMessageLength<key.length()) mMaxMessageLength = key.length();
- key = "object";
- mMessageLevel[key] = 0;
- mMessageHelp[key] = "object memory related messages";
- if (mMaxMessageLength<key.length()) mMaxMessageLength = key.length();
- key = "package";
- mMessageLevel[key] = 0;
- mMessageHelp[key] = "Packages related messages";
- if (mMaxMessageLength<key.length()) mMaxMessageLength = key.length();
- key = "connection";
- mMessageLevel[key] = 0;
- mMessageHelp[key] = "Connections related messages";
- if (mMaxMessageLength<key.length()) mMaxMessageLength = key.length();
- key = "modified";
- mMessageLevel[key] = 0;
- mMessageHelp[key] = "Modified related messages";
- if (mMaxMessageLength<key.length()) mMaxMessageLength = key.length();
*/
- }
+ }
+ //===========================================================================
+ //===========================================================================
MessageManager::~MessageManager()
{
// std::cout << "~MessageManager"<<std::endl;
+ MessageMapType::iterator i;
+ for (i=mMessageMap.begin(); i!=mMessageMap.end(); ++i)
+ {
+ delete i->second;
+ }
}
-
+ //===========================================================================
+ //===========================================================================
MessageManager* MessageManager::GetInstance()
{
static MessageManager* m = 0;
if (!m) m = new MessageManager();
return m;
}
+ //===========================================================================
- void MessageManager::RegisterMessageType(std::string key,
- std::string help,
- unsigned char default_level)
+ //===========================================================================
+ void MessageManager::RegisterMessageType(const std::string& key,
+ const std::string& help,
+ unsigned char default_level)
{
- GetInstance()->mMessageLevel[key] = default_level;
- GetInstance()->mMessageHelp[key] = help;
+ GetInstance()->mMessageMap[key] = new MessageType(default_level,help);
+
if (GetInstance()->mMaxMessageLength<key.length())
GetInstance()->mMaxMessageLength = key.length();
}
+ //===========================================================================
-
-
- void MessageManager::SetMessageLevel(std::string key,
- unsigned char level)
+ //===========================================================================
+ void MessageManager::SetMessageLevel(const std::string& key,
+ unsigned char level)
{
- std::map<std::string,int>::iterator i;
- i = GetInstance()->mMessageLevel.find(key);
- if (i!=GetInstance()->mMessageLevel.end())
+ MessageMapType::iterator i;
+ i = GetInstance()->mMessageMap.find(key);
+ if (i!=GetInstance()->mMessageMap.end())
{
- (*i).second = level;
+ (*i).second->Level = level;
}
else
{
}
}
+ //===========================================================================
-
-
- int MessageManager::GetMessageLevel(std::string key)
+ //===========================================================================
+ int MessageManager::GetMessageLevel(const std::string& key)
{
- int l = GetInstance()->mMessageLevel["all"];
- std::map<std::string,int>::iterator i =
- GetInstance()->mMessageLevel.find(key);
- if (i!=GetInstance()->mMessageLevel.end()) {
- if ( (*i).second > l ) l = (*i).second;
+ int l = GetInstance()->mMessageMap["all"]->Level;
+ MessageMapType::iterator i = GetInstance()->mMessageMap.find(key);
+ if (i!=GetInstance()->mMessageMap.end()) {
+ if ( (*i).second->Level > l ) l = (*i).second->Level;
}
- int m = GetInstance()->mMessageLevel["max"];
+ int m = GetInstance()->mMessageMap["max"]->Level;
if (l>m) l=m;
return l;
}
+ //===========================================================================
+ //===========================================================================
+ void MessageManager::SendMessagesToCout(bool v)
+ {
+ GetInstance()->mSendToCout = v;
+ }
+ //===========================================================================
+ //===========================================================================
+ void MessageManager::SendMessage(const std::string& key, const std::string& mess)
+ {
+ if (GetInstance()->mSendToCout)
+ {
+ std::cout << mess;
+ }
+ GetInstance()->mMessageMap[key]->Signal(mess);
+ }
+ //===========================================================================
+ //===========================================================================
+ void MessageManager::AddMessageObserver( const std::string& key, MessageCallbackType callback )
+ {
+ GetInstance()->mMessageMap[key]->Signal.connect(callback);
+ }
+ //===========================================================================
+
+ //===========================================================================
void MessageManager::PrintInfo()
{
creaMessage("info",1,"================ Messages ================="
creaMessageCont("info",1," ");
}
creaMessageCont("info",1,"Level Nature" << creaendl);
- std::map<std::string,int>::iterator i;
- std::map<std::string,std::string>::iterator j;
- for (i=GetInstance()->mMessageLevel.begin(),
- j=GetInstance()->mMessageHelp.begin();
- i!=GetInstance()->mMessageLevel.end();++i,++j) {
- creaMessage("info",1, (*i).first);
- for (int k=0;
- k<(int)(GetInstance()->mMaxMessageLength+2-(*i).first.length());
- k++) {
- creaMessageCont("info",1," ");
- }
- creaMessageCont("info",1, (*i).second << "\t"
- << (*j).second << creaendl);
+ MessageMapType::iterator i;
+ for (i=GetInstance()->mMessageMap.begin();
+ i!=GetInstance()->mMessageMap.end();
+ ++i)
+ {
+ creaMessage("info",1, (*i).first);
+ for (int k=0;
+ k<(int)(GetInstance()->mMaxMessageLength+2-(*i).first.length());
+ k++) {
+ creaMessageCont("info",1," ");
+ }
+ creaMessageCont("info",1, (*i).second->Level << "\t"
+ << (*i).second->Help << creaendl);
}
creaMessage("info",1,"==========================================="
<< creaendl);
}
-
+ //===========================================================================
}