//
#include <string>
#include "DSC_interface.hxx"
+#include <sys/time.h>
+#include <fstream>
+#include <sys/stat.h>
+#include <sstream>
+#include <stdlib.h>
//#define MYDEBUG
rtn_properties = Ports::PortProperties::_duplicate(my_ports[port_name]->port_prop);
return rtn_properties;
}
+
+//Trace functions for DSC operations: a local function (initTrace) and a class method (Engines_DSC_interface::writeEvent)
+static int traceType=-1; // 0=stderr;1=file;
+static int traceLevel=-1; // 0=no trace;1=normal trace;2=detailed trace
+static std::ofstream traceFile;
+static std::ostream *out;
+
+//! Initialize the trace file
+/*!
+ * The trace file depends on an environment variable (DSC_TRACE). If this variable
+ * is equal to 1, the trace file is a file with the name : <TMPDIR>/<container name>.tce.
+ * In all other cases, the trace file is stderr
+ * The environment variable DSC_TRACELEVEL can be used to suppress the trace (value 0)
+ *
+ * \param containerName the name of the container where the trace is built
+ */
+static void initTrace(const std::string& containerName)
+{
+ // if initialization has already been done do nothing
+ if(traceLevel >= 0)return;
+
+ std::string typeenv="0";
+ std::string levelenv="1";
+ char* valenv=0;
+ valenv=getenv("DSC_TRACE");
+ if(valenv)typeenv=valenv;
+ valenv=getenv("DSC_TRACELEVEL");
+ if(valenv)levelenv=valenv;
+
+ if(levelenv=="0")
+ traceLevel=0; // no trace
+ else if(levelenv=="2")
+ traceLevel=2; //detailed trace
+ else
+ traceLevel=1; // normal trace (default)
+
+ if(traceLevel==0)
+ return;
+
+ if(typeenv=="1")
+ {
+ //trace in file
+ traceType=1;
+#ifdef WNT
+ std::string logFilename=getenv("TEMP");
+ logFilename += "\\";
+#else
+ std::string logFilename="/tmp";
+ char* val = getenv("SALOME_TMP_DIR");
+ if(val)
+ {
+ struct stat file_info;
+ stat(val, &file_info);
+ bool is_dir = S_ISDIR(file_info.st_mode);
+ if (is_dir)logFilename=val;
+ }
+ logFilename += "/";
+#endif
+
+ logFilename=logFilename+containerName+".tce";
+ traceFile.open(logFilename.c_str(), std::ios::out | std::ios::app);
+ out=&traceFile;
+ }
+ else
+ {
+ //trace to stderr (default)
+ traceType=0;
+ out=&std::cerr;
+ }
+ //trace heading
+ out->width(17);
+ *out << "Elapsed time" ;
+ *out << " | " ;
+ out->width(16);
+ *out << "Request" ;
+ *out << " | " ;
+ out->width(16);
+ *out << "Container" ;
+ *out << " | " ;
+ out->width(16);
+ *out << "Instance" ;
+ *out << " | " ;
+ out->width(16);
+ *out << "Port" ;
+ *out << " | " ;
+ out->width(24);
+ *out << "Error";
+ *out << " | " ;
+ *out << "Infos" ;
+ *out << std::endl;
+}
+
+
+//! Write a record in the trace file
+/*!
+ * \param request the name of the request executed
+ * \param containerName the name of the container where the request is executed
+ * \param instance_name the name of the component where the request is executed
+ * \param port_name the name of the port that is concerned
+ * \param error if an error has occured, a string that identifies the error
+ * \param message informations about error or about the request
+ */
+void Engines_DSC_interface::writeEvent(const char* request,const std::string& containerName, const char* instance_name,
+ const char* port_name, const char* error, const char* message)
+{
+ if(traceLevel < 0)
+ initTrace(containerName);
+ if(traceLevel == 0)return;
+
+ struct timeval tv;
+ gettimeofday(&tv,0);
+ long tt0=tv.tv_sec/3600; //hours
+
+ if(traceType == 2)
+ {
+ //notifier (not used: salome notifier is now obsolete)
+ std::ostringstream msg;
+ msg.width(7);
+ msg << tt0 ;
+ msg << ":" ;
+ long tt1=(tv.tv_sec-3600*tt0)/60;//minutes
+ msg.width(2);
+ msg << tt1 ;
+ msg << ":" ;
+ long tt2=tv.tv_sec - 3600*tt0-60*tt1; //seconds
+ msg.width(2);
+ msg << tt2 ;
+ msg << ":" ;
+ long tt3=tv.tv_usec/1000; //milliseconds
+ msg.width(3);
+ msg << tt3 ;
+ msg << " | " ;
+ msg.width(24);
+ msg << error;
+ msg << " | " ;
+ msg << message ;
+ //send event to notifier (containerName.c_str(),instance_name, request, msg.str().c_str())
+ }
+ else
+ {
+ //cerr or file
+ out->width(7);
+ *out << tt0 ;
+ *out << ":" ;
+ long tt1=(tv.tv_sec-3600*tt0)/60;//minutes
+ out->width(2);
+ *out << tt1 ;
+ *out << ":" ;
+ long tt2=tv.tv_sec - 3600*tt0-60*tt1; //seconds
+ out->width(2);
+ *out << tt2 ;
+ *out << ":" ;
+ long tt3=tv.tv_usec/1000; //milliseconds
+ out->width(3);
+ *out << tt3 ;
+ *out << " | " ;
+ out->width(16);
+ *out << request ;
+ *out << " | " ;
+ out->width(16);
+ *out << containerName ;
+ *out << " | " ;
+ out->width(16);
+ *out << instance_name ;
+ *out << " | " ;
+ out->width(16);
+ *out << port_name ;
+ *out << " | " ;
+ out->width(24);
+ *out << error;
+ *out << " | " ;
+ *out << message ;
+ *out << std::endl;
+ }
+}
+
static const bool value = true;
};
+extern const char * CPMESSAGE[];
+
//#define MYDEBUG
#include <boost/type_traits/remove_all_extents.hpp>
namespace CalciumInterface {
- /********************* LOGGING INTERFACE *****************/
-
- void initTrace(const std::string&);
- void writeEvent(const char*, const std::string&, const char*, const char*, int, const char*);
-
/********************* CONNECTION INTERFACE *****************/
static inline void
CORBA::String_var componentName=component.instanceName();
std::string containerName=component.getContainerName();
if (instanceName.empty()) instanceName=componentName;
- writeEvent("CP_CD",containerName,componentName,"",0,"");
+ Engines_DSC_interface::writeEvent("CP_CD",containerName,componentName,"","","");
}
static void
{
CORBA::String_var componentName=component.instanceName();
std::string containerName=component.getContainerName();
- writeEvent("CP_FIN",containerName,componentName,"",0,"");
+ Engines_DSC_interface::writeEvent("CP_FIN",containerName,componentName,"","","");
std::vector<std::string> usesPortNames;
std::vector<std::string>::const_iterator it;
}
catch ( const Superv_Component_i::BadCast & ex)
{
- writeEvent("CP_FIN",containerName,componentName,"",CalciumTypes::CPTPVR,ex.what());
+ Engines_DSC_interface::writeEvent("CP_FIN",containerName,componentName,"",CPMESSAGE[CalciumTypes::CPTPVR],ex.what());
throw (CalciumException(CalciumTypes::CPTPVR,ex));
}
catch ( const DSC_Exception & ex)
{
- writeEvent("CP_FIN",containerName,componentName,"",CalciumTypes::CPOK,ex.what());
+ Engines_DSC_interface::writeEvent("CP_FIN",containerName,componentName,"",CPMESSAGE[CalciumTypes::CPOK],ex.what());
// Exception venant de SupervComponent :
// PortNotDefined(CPNMVR), PortNotConnected(CPLIEN)
// ou du port uses : Dsc_Exception
}
catch (...)
{
- writeEvent("CP_FIN",containerName,componentName,"",CalciumTypes::CPATAL,"Unexpected exception");
+ Engines_DSC_interface::writeEvent("CP_FIN",containerName,componentName,"",CPMESSAGE[CalciumTypes::CPATAL],"Unexpected exception");
throw (CalciumException(CalciumTypes::CPATAL,"Unexpected exception"));
// En fonction du mode de gestion des erreurs throw;
}
if (nomVar.empty())
{
- writeEvent("BEGIN_READ",containerName,componentName,"",CalciumTypes::CPNMVR,"");
+ Engines_DSC_interface::writeEvent("BEGIN_READ",containerName,componentName,"",CPMESSAGE[CalciumTypes::CPNMVR],"");
throw CalciumException(CalciumTypes::CPNMVR, LOC("Empty variable name"));
}
PortType * port;
}
catch ( const Superv_Component_i::PortNotDefined & ex)
{
- writeEvent("BEGIN_READ",containerName,componentName,nomVar.c_str(),CalciumTypes::CPNMVR,ex.what());
+ Engines_DSC_interface::writeEvent("BEGIN_READ",containerName,componentName,nomVar.c_str(),CPMESSAGE[CalciumTypes::CPNMVR],ex.what());
throw (CalciumException(CalciumTypes::CPNMVR,ex));
}
catch ( const Superv_Component_i::PortNotConnected & ex)
{
- writeEvent("BEGIN_READ",containerName,componentName,nomVar.c_str(),CalciumTypes::CPLIEN,ex.what());
+ Engines_DSC_interface::writeEvent("BEGIN_READ",containerName,componentName,nomVar.c_str(),CPMESSAGE[CalciumTypes::CPLIEN],ex.what());
throw (CalciumException(CalciumTypes::CPLIEN,ex));
// VERIFIER LES CAS DES CODES : CPINARRET, CPSTOPSEQ, CPCTVR, CPLIEN
}
catch ( const Superv_Component_i::BadCast & ex)
{
- writeEvent("BEGIN_READ",containerName,componentName,nomVar.c_str(),CalciumTypes::CPTPVR,ex.what());
+ Engines_DSC_interface::writeEvent("BEGIN_READ",containerName,componentName,nomVar.c_str(),CPMESSAGE[CalciumTypes::CPTPVR],ex.what());
throw (CalciumException(CalciumTypes::CPTPVR,ex));
}
if ( portDependencyType == CalciumTypes::UNDEFINED_DEPENDENCY )
{
- writeEvent("BEGIN_READ",containerName,componentName,nomVar.c_str(),CalciumTypes::CPIT,"Dependency mode is undefined");
+ Engines_DSC_interface::writeEvent("BEGIN_READ",containerName,componentName,nomVar.c_str(),CPMESSAGE[CalciumTypes::CPIT],"Dependency mode is undefined");
throw CalciumException(CalciumTypes::CPIT, LOC(OSS()<<"Dependency mode of variable " << nomVar << " is undefined."));
}
if ( ( portDependencyType != _dependencyType ) && ( _dependencyType != CalciumTypes::SEQUENCE_DEPENDENCY ) )
{
- writeEvent("BEGIN_READ",containerName,componentName,nomVar.c_str(),CalciumTypes::CPIT,
+ Engines_DSC_interface::writeEvent("BEGIN_READ",containerName,componentName,nomVar.c_str(),CPMESSAGE[CalciumTypes::CPIT],
"Dependency mode is not the same as the required one");
throw CalciumException(CalciumTypes::CPITVR, LOC(OSS()<<"Dependency mode of variable " << nomVar << ": "
<< portDependencyType << " is not the same as the required one."));
{
double tt=ti;
msg << "ti=" << ti << ", tf=" << tf ;
- writeEvent("BEGIN_READ",containerName,componentName,nomVar.c_str(),0,msg.str().c_str());
+ Engines_DSC_interface::writeEvent("BEGIN_READ",containerName,componentName,nomVar.c_str(),"",msg.str().c_str());
corbaData = port->get(tt,tf, 0);
msgout << "read t=" << tt ;
#ifdef MYDEBUG
}
catch ( const DSC_Exception & ex)
{
- writeEvent("END_READ",containerName,componentName,nomVar.c_str(),0,ex.what());
+ Engines_DSC_interface::writeEvent("END_READ",containerName,componentName,nomVar.c_str(),"",ex.what());
throw;
}
}
try
{
msg << "i=" << i ;
- writeEvent("BEGIN_READ",containerName,componentName,nomVar.c_str(),0,msg.str().c_str());
+ Engines_DSC_interface::writeEvent("BEGIN_READ",containerName,componentName,nomVar.c_str(),"",msg.str().c_str());
corbaData = port->get(0, i);
msgout << "read i=" << i ;
#ifdef MYDEBUG
}
catch ( const DSC_Exception & ex)
{
- writeEvent("END_READ",containerName,componentName,nomVar.c_str(),0,ex.what());
+ Engines_DSC_interface::writeEvent("END_READ",containerName,componentName,nomVar.c_str(),"",ex.what());
throw;
}
}
#ifdef MYDEBUG
std::cout << "-------- CalciumInterface(ecp_lecture) MARK 7 ------------------" << std::endl;
#endif
- writeEvent("BEGIN_READ",containerName,componentName,nomVar.c_str(),0,"Sequential read");
+ Engines_DSC_interface::writeEvent("BEGIN_READ",containerName,componentName,nomVar.c_str(),"","Sequential read");
corbaData = port->next(ti,i);
msgout << "read ";
if(i==0)msgout<< "t=" <<ti;
}
catch ( const DSC_Exception & ex)
{
- writeEvent("END_READ",containerName,componentName,nomVar.c_str(),0,ex.what());
+ Engines_DSC_interface::writeEvent("END_READ",containerName,componentName,nomVar.c_str(),"",ex.what());
throw;
}
}
std::cout << "Ptr :" << data << std::endl;
std::cout << "-------- CalciumInterface(ecp_lecture) MARK 13 ------------------" << std::endl;
#endif
- writeEvent("END_READ",containerName,componentName,nomVar.c_str(),CalciumTypes::CPOK,msgout.str().c_str());
+ Engines_DSC_interface::writeEvent("END_READ",containerName,componentName,nomVar.c_str(),CPMESSAGE[CalciumTypes::CPOK],msgout.str().c_str());
return;
}
#endif
if ( nomVar.empty() )
{
- writeEvent("WRITE",containerName,componentName,"",CalciumTypes::CPNMVR,"");
+ Engines_DSC_interface::writeEvent("WRITE",containerName,componentName,"",CPMESSAGE[CalciumTypes::CPNMVR],"");
throw CalciumException(CalciumTypes::CPNMVR, LOC("Empty variable name"));
}
UsesPortType * port;
}
catch ( const Superv_Component_i::PortNotDefined & ex)
{
- writeEvent("WRITE",containerName,componentName,nomVar.c_str(),CalciumTypes::CPNMVR,ex.what());
+ Engines_DSC_interface::writeEvent("WRITE",containerName,componentName,nomVar.c_str(),CPMESSAGE[CalciumTypes::CPNMVR],ex.what());
throw (CalciumException(CalciumTypes::CPNMVR,ex));
}
catch ( const Superv_Component_i::PortNotConnected & ex)
{
- writeEvent("WRITE",containerName,componentName,nomVar.c_str(),CalciumTypes::CPLIEN,ex.what());
+ Engines_DSC_interface::writeEvent("WRITE",containerName,componentName,nomVar.c_str(),CPMESSAGE[CalciumTypes::CPLIEN],ex.what());
throw (CalciumException(CalciumTypes::CPLIEN,ex));
// VERIFIER LES CAS DES CODES : CPINARRET, CPSTOPSEQ, CPCTVR, CPLIEN
}
catch ( const Superv_Component_i::BadCast & ex)
{
- writeEvent("WRITE",containerName,componentName,nomVar.c_str(),CalciumTypes::CPTPVR,ex.what());
+ Engines_DSC_interface::writeEvent("WRITE",containerName,componentName,nomVar.c_str(),CPMESSAGE[CalciumTypes::CPTPVR],ex.what());
throw (CalciumException(CalciumTypes::CPTPVR,ex));
}
if ( _dependencyType == CalciumTypes::UNDEFINED_DEPENDENCY )
{
- writeEvent("WRITE",containerName,componentName,nomVar.c_str(),CalciumTypes::CPIT,"Dependency mode is undefined");
+ Engines_DSC_interface::writeEvent("WRITE",containerName,componentName,nomVar.c_str(),CPMESSAGE[CalciumTypes::CPIT],"Dependency mode is undefined");
throw CalciumException(CalciumTypes::CPIT, LOC(OSS()<<"Dependency mode of variable " << nomVar << " is undefined."));
}
if ( _dependencyType == CalciumTypes::SEQUENCE_DEPENDENCY )
{
- writeEvent("WRITE",containerName,componentName,nomVar.c_str(),CalciumTypes::CPIT,
+ Engines_DSC_interface::writeEvent("WRITE",containerName,componentName,nomVar.c_str(),CPMESSAGE[CalciumTypes::CPIT],
"SEQUENCE_DEPENDENCY mode is not possible when writing");
throw CalciumException(CalciumTypes::CPIT, LOC(OSS()<<"Dependency mode SEQUENCE_DEPENDENCY for variable " << nomVar
<< " is not possible when writing."));
if ( bufferLength < 1 )
{
- writeEvent("WRITE",containerName,componentName,nomVar.c_str(),CalciumTypes::CPNTNULL,"Buffer to send is empty");
+ Engines_DSC_interface::writeEvent("WRITE",containerName,componentName,nomVar.c_str(),CPMESSAGE[CalciumTypes::CPNTNULL],"Buffer to send is empty");
throw CalciumException(CalciumTypes::CPNTNULL, LOC(OSS()<<"Buffer to send is empty"));
}
port->put(*corbaData,t, -1);
std::stringstream msg;
msg << "t=" << t ;
- writeEvent("WRITE",containerName,componentName,nomVar.c_str(),CalciumTypes::CPOK,msg.str().c_str());
+ Engines_DSC_interface::writeEvent("WRITE",containerName,componentName,nomVar.c_str(),CPMESSAGE[CalciumTypes::CPOK],msg.str().c_str());
}
catch ( const DSC_Exception & ex)
{
- writeEvent("WRITE",containerName,componentName,nomVar.c_str(),CalciumTypes::CPATAL,ex.what());
+ Engines_DSC_interface::writeEvent("WRITE",containerName,componentName,nomVar.c_str(),CPMESSAGE[CalciumTypes::CPATAL],ex.what());
throw (CalciumException(CalciumTypes::CPATAL,ex.what()));
}
//Le -1 peut être traité par le cst DataIdContainer et transformé en 0
port->put(*corbaData,-1, i);
std::stringstream msg;
msg << "i=" << i ;
- writeEvent("WRITE",containerName,componentName,nomVar.c_str(),CalciumTypes::CPOK,msg.str().c_str());
+ Engines_DSC_interface::writeEvent("WRITE",containerName,componentName,nomVar.c_str(),CPMESSAGE[CalciumTypes::CPOK],msg.str().c_str());
}
catch ( const DSC_Exception & ex)
{
- writeEvent("WRITE",containerName,componentName,nomVar.c_str(),CalciumTypes::CPATAL,ex.what());
+ Engines_DSC_interface::writeEvent("WRITE",containerName,componentName,nomVar.c_str(),CPMESSAGE[CalciumTypes::CPATAL],ex.what());
throw (CalciumException(CalciumTypes::CPATAL,ex.what()));
}
#ifdef MYDEBUG