36 CAmDltWrapper* CAmDltWrapper::mpDLTWrapper = NULL;
37 pthread_mutex_t CAmDltWrapper::mMutex = PTHREAD_MUTEX_INITIALIZER;
39 const std::vector<const char*> CAmDltWrapper::mStr_error =
56 const std::vector<const char*> CAmDltWrapper::mStr_sourceState =
65 const std::vector<const char*> CAmDltWrapper::mStr_MuteState =
73 const std::vector<const char*> CAmDltWrapper::mStr_DomainState =
77 "DS_INDEPENDENT_STARTUP",
78 "DS_INDEPENDENT_RUNDOWN",
82 const std::vector<const char*> CAmDltWrapper::mStr_ConnectionState =
93 const std::vector<const char*> CAmDltWrapper::mStr_Availability =
101 const std::vector<const char*> CAmDltWrapper::mStr_Interrupt =
109 const std::vector<const char*> CAmDltWrapper::mStr_Handle =
117 "H_SETSINKSOUNDPROPERTY",
118 "H_SETSOURCESOUNDPROPERTY",
119 "H_SETSINKSOUNDPROPERTIES",
120 "H_SETSOURCESOUNDPROPERTIES",
123 "H_SETSINKNOTIFICATION",
124 "H_SETSOURCENOTIFICATION",
128 const std::vector<const char*> CAmDltWrapper::mStr_NotificationStatus =
141 std::string CAmDltWrapper::now()
143 std::time_t t(std::chrono::system_clock::to_time_t(std::chrono::system_clock::now()));
144 struct tm * timeinfo(localtime(&t));
146 std::strftime(buffer,80,
"%D %T ",timeinfo);
147 return (std::string(buffer));
154 mpDLTWrapper =
new CAmDltWrapper(appid,description,debugEnabled,logDest,Filename,onlyError);
156 return (mpDLTWrapper);
164 std::ostringstream description;
165 description <<
"PID=" << getpid() <<
" _=" << getenv(
"_");
166 mpDLTWrapper =
new CAmDltWrapper(
"AMDL", description.str().c_str());
167 std::cerr <<
"Application doesn't call CAmDltWrapper::instanciateOnce!!!" << std::endl;
168 std::cerr <<
"-> CAmDltWrapper::instance registers DLT application [ AMDL | " << description.str() <<
" ]" << std::endl;
175 return (mDebugEnabled);
180 if (mlogDestination==logDestination::COMMAND_LINE)
189 mNoDltContextData.
buffer <<
"\033[0;31m"<<
"[DEF] [Erro] \033[0m";
195 mNoDltContextData.
buffer <<
"\033[0;33m"<<
"[DEF] [Warn] \033[0m";
203 mNoDltContextData.
buffer <<
"\033[0;36m"<<
"[DEF] [Info] \033[0m";
211 mNoDltContextData.
buffer <<
"\033[0;32m"<<
"[DEF] [Defa] \033[0m";
219 std::string con(mMapContext.at(context));
225 mNoDltContextData.
buffer <<
"\033[0;31m["<<con<<
"] [Erro] \033[0m";
231 mNoDltContextData.
buffer <<
"\033[0;33m["<<con<<
"] [Warn] \033[0m";
239 mNoDltContextData.
buffer <<
"\033[0;36m["<<con<<
"] [Info] \033[0m";
248 mNoDltContextData.
buffer <<
"\033[0;32m["<<con<<
"] [Defa] \033[0m";
265 mNoDltContextData.
buffer <<
"[DEF] [Erro] ";
271 mNoDltContextData.
buffer <<
"[DEF] [Warn] ";
279 mNoDltContextData.
buffer <<
"[DEF] [Info] ";
287 mNoDltContextData.
buffer <<
"[DEF] [Defa] ";
296 std::string con(mMapContext.at(context));
302 mNoDltContextData.
buffer <<
"["<<con<<
"] [Erro] ";
308 mNoDltContextData.
buffer <<
"["<<con<<
"] [Warn] ";
316 mNoDltContextData.
buffer <<
"["<<con<<
"] [Info] ";
325 mNoDltContextData.
buffer <<
"["<<con<<
"] [Defa] ";
337 CAmDltWrapper::CAmDltWrapper(
const char *appid,
const char * description,
const bool debugEnabled,
const logDestination logDest,
const std::string Filename,
bool onlyError) :
338 mDebugEnabled(debugEnabled),
339 mlogDestination(logDest),
341 mOnlyError(onlyError),
344 if (mDebugEnabled && mlogDestination==logDestination::DAEMON)
346 dlt_register_app(appid, description);
348 dlt_register_context(&mDltContext,
"DEF",
"Default Context registered by DLTWrapper Class");
350 else if (mDebugEnabled)
352 if (mlogDestination==logDestination::COMMAND_LINE)
353 std::cout <<
"\033[0;36m[DLT] Registering AppID " << appid <<
" , " << description <<
"\033[0m"<< std::endl;
356 mFilename.open(Filename, std::ofstream::out | std::ofstream::trunc);
357 if (!mFilename.is_open())
359 throw std::runtime_error(
"Cannot open file for logging");
361 mFilename << now() <<
"[DLT] Registering AppID " << appid <<
" , " << description << std::endl;
368 if (mpDLTWrapper && mDebugEnabled && mlogDestination==logDestination::DAEMON)
373 else if (mpDLTWrapper && mDebugEnabled && mlogDestination==logDestination::COMMAND_LINE)
381 if (mDebugEnabled && mlogDestination==logDestination::DAEMON)
383 dlt_unregister_context(&handle);
397 if (mDebugEnabled && mlogDestination==logDestination::DAEMON)
399 dlt_register_context(&handle, contextid, description);
401 else if (mDebugEnabled)
403 mMapContext.emplace(&handle,std::string(contextid));
405 if (mlogDestination==logDestination::COMMAND_LINE)
406 std::cout <<
"\033[0;36m[DLT] Registering Context " << contextid <<
" , " << description <<
"\033[0m"<< std::endl;
408 mFilename << now() <<
"[DLT] Registering Context " << contextid <<
" , " << description << std::endl;
414 if (mDebugEnabled && mlogDestination==logDestination::DAEMON)
416 dlt_register_context_ll_ts(&handle, contextid, description, level, status);
418 else if (mDebugEnabled)
420 mMapContext.emplace(&handle,std::string(contextid));
422 if (mlogDestination==logDestination::COMMAND_LINE)
423 std::cout <<
"\033[0;36m[DLT] Registering Context " << contextid <<
" , " << description <<
"\033[0m"<< std::endl;
425 mFilename << now() <<
" [DLT] Registering Context " << contextid <<
" , " << description << std::endl;
431 pthread_mutex_lock(&mMutex);
432 if (mlogDestination==logDestination::DAEMON)
435 context = &mDltContext;
437 if(dlt_user_log_write_start(context, &mDltContextData, loglevel) <= 0)
439 pthread_mutex_unlock(&mMutex);
445 initNoDlt(loglevel,context);
452 if (mlogDestination==logDestination::DAEMON)
454 dlt_user_log_write_finish(&mDltContextData);
458 if (mlogDestination==logDestination::COMMAND_LINE && mLogOn)
459 std::cout << mNoDltContextData.
buffer.str().c_str() << std::endl;
461 mFilename << now() << mNoDltContextData.
buffer.str().c_str() << std::endl;
463 mNoDltContextData.
buffer.str(
"");
464 mNoDltContextData.
buffer.clear();
466 pthread_mutex_unlock(&mMutex);
471 if (mlogDestination==logDestination::DAEMON)
472 dlt_user_log_write_int8(&mDltContextData, value);
479 if (mlogDestination==logDestination::DAEMON)
480 dlt_user_log_write_uint8(&mDltContextData, value);
487 if (mlogDestination==logDestination::DAEMON)
488 dlt_user_log_write_int16(&mDltContextData, value);
495 if (mlogDestination==logDestination::DAEMON)
496 dlt_user_log_write_uint16(&mDltContextData, value);
503 if (mlogDestination==logDestination::DAEMON)
504 dlt_user_log_write_int32(&mDltContextData, value);
511 if (mlogDestination==logDestination::DAEMON)
512 dlt_user_log_write_uint32(&mDltContextData, value);
524 if (mlogDestination==logDestination::DAEMON)
525 dlt_user_log_write_bool(&mDltContextData, static_cast<uint8_t>(value));
532 if (mlogDestination==logDestination::DAEMON)
533 dlt_user_log_write_int64(&mDltContextData, value);
540 if (mlogDestination==logDestination::DAEMON)
541 dlt_user_log_write_uint64(&mDltContextData, value);
548 if (mlogDestination==logDestination::DAEMON)
549 dlt_user_log_write_raw(&mDltContextData,(
void*)data.data(),data.size());
551 mNoDltContextData.
buffer << data.data();
555 #else //------------------------------------------------------------------------------------------------- no DLT ! 557 CAmDltWrapper::CAmDltWrapper(
const char *appid,
const char * description,
const bool debugEnabled,
const logDestination logDest,
const std::string Filename,
bool onlyError) :
558 mDebugEnabled(debugEnabled),
559 mlogDestination(logDest),
561 mOnlyError(onlyError),
564 if (logDest==logDestination::DAEMON)
566 std::cout <<
"\033[0;31m[DLT] Cannot Use Daemon Logging, active in CMAKE! Using CommandLine\033[0m"<< std::endl;
567 mlogDestination=logDestination::COMMAND_LINE;
571 if (mlogDestination==logDestination::COMMAND_LINE)
572 std::cout <<
"\033[0;36m[DLT] Registering AppID " << appid <<
" , " << description <<
"\033[0m"<< std::endl;
575 mFilename.open(Filename, std::ofstream::out | std::ofstream::trunc);
576 if (!mFilename.is_open())
578 throw std::runtime_error(
"Cannot open file for logging");
580 mFilename << now() <<
"[DLT] Registering AppID " << appid <<
" , " << description << std::endl;
587 if (mpDLTWrapper && mDebugEnabled && mlogDestination==logDestination::COMMAND_LINE)
603 mMapContext.emplace(&handle,std::string(contextid));
605 if (mlogDestination==logDestination::COMMAND_LINE)
606 std::cout <<
"\033[0;36m[DLT] Registering Context " << contextid <<
" , " << description <<
"\033[0m"<< std::endl;
608 mFilename << now() <<
"[DLT] Registering Context " << contextid <<
" , " << description << std::endl;
616 mMapContext.emplace(&handle,std::string(contextid));
618 if (mlogDestination==logDestination::COMMAND_LINE)
619 std::cout <<
"\033[0;36m[DLT] Registering Context " << contextid <<
" , " << description <<
"\033[0m"<< std::endl;
621 mFilename << now() <<
" [DLT] Registering Context " << contextid <<
" , " << description << std::endl;
627 pthread_mutex_lock(&mMutex);
628 initNoDlt(loglevel,context);
633 if (mlogDestination==logDestination::COMMAND_LINE && mLogOn)
634 std::cout << mNoDltContextData.
buffer.str().c_str() << std::endl;
636 mFilename << now() << mNoDltContextData.
buffer.str().c_str() << std::endl;
638 mNoDltContextData.
buffer.str(
"");
639 mNoDltContextData.
buffer.clear();
640 pthread_mutex_unlock(&mMutex);
695 mNoDltContextData.
buffer << data.data();
A Common-API wrapper class, which loads the common-api runtime and instantiates all necessary objects...
std::stringstream buffer
buffer for building log message
static CAmDltWrapper * instanctiateOnce(const char *appid, const char *description, const bool debugEnabled=true, const logDestination logDest=logDestination::DAEMON, const std::string Filename="", bool onlyError=false)
Instanciate the Dlt Wrapper.
SPDX license identifier: MPL-2.0.
bool init(DltLogLevelType loglevel, DltContext *context=NULL)
static CAmDltWrapper * instance()
get the Wrapper Instance
void registerContext(DltContext &handle, const char *contextid, const char *description)
register a context
This structure is used for every context used in an application.
void appendNoDLT(T value)
error with impact to correct functionality
DltTraceStatusType
Definition of DLT trace status.
void unregisterContext(DltContext &handle)
warning, correct behaviour could not be ensured
DltLogLevelType
Definitions of DLT log level.