source: flair-src/trunk/lib/FlairCore/src/Object.cpp@ 67

Last change on this file since 67 was 15, checked in by Bayard Gildas, 6 years ago

sources reformatted with flair-format-dir script

File size: 3.5 KB
RevLine 
[2]1// %flair:license{
[15]2// This file is part of the Flair framework distributed under the
3// CECILL-C License, Version 1.0.
[2]4// %flair:license}
5// created: 2012/05/07
6// filename: Object.cpp
7//
8// author: Guillaume Sanahuja
9// Copyright Heudiasyc UMR UTC/CNRS 7253
10//
11// version: $Id: $
12//
13// purpose: Base class for all Framework's classes
14//
15//
16/*********************************************************************/
17
18#include <stdio.h>
19
20#include "Object.h"
21#include "Object_impl.h"
22#include "FrameworkManager.h"
23
24#ifdef __XENO__
25#include <native/task.h>
26#include <native/timer.h>
27#include "rtdk.h"
28#else
29#include <sys/time.h>
30#endif
31
32using std::string;
33using std::vector;
34
[15]35namespace flair {
36namespace core {
[2]37
[15]38Time GetTime(void) {
[2]39#ifdef __XENO__
[15]40 return rt_timer_read();
[2]41#else
[15]42 struct timeval t;
43 gettimeofday(&t, NULL);
44 return (Time)((Time)(t.tv_sec) * 1000000 + (Time)(t.tv_usec)) * 1000;
[2]45
46#endif
47}
48
[15]49void Printf(const char *format, ...) {
50 va_list args;
51 va_start(args, format);
[2]52#ifdef __XENO__
[15]53 if (rt_task_self() != NULL) {
54 rt_vfprintf(stderr, format, args);
55 } else
[2]56#endif
[15]57 {
58 vfprintf(stderr, format, args);
59 }
[2]60
[15]61 va_end(args);
[2]62}
63
[15]64Object::Object(const Object *parent, string name, string type) {
65 pimpl_ = new Object_impl(this, parent, name, type);
66 if (parent != NULL)
67 parent->pimpl_->AddChild(this);
[2]68}
69
[15]70Object::~Object() {
71 if (pimpl_->parent != NULL)
72 pimpl_->parent->pimpl_->RemoveChild(this);
73 delete pimpl_;
[2]74}
75
[15]76string Object::ObjectName(void) const { return pimpl_->name; }
[2]77
[15]78string Object::ObjectType(void) const { return pimpl_->type; }
[2]79
[15]80const Object *Object::Parent(void) const { return pimpl_->parent; }
[2]81
[15]82vector<const Object *> *Object::TypeChilds(void) const {
83 return &(pimpl_->type_childs);
[2]84}
85
[15]86vector<const Object *> *Object::Childs(void) const { return &(pimpl_->childs); }
[2]87
[15]88void Object::ColorPrintf(color_t color, const char *function, int line,
89 const char *format, va_list *args) const {
[2]90#ifdef __XENO__
[15]91 if (rt_task_self() != NULL) {
92 rt_fprintf(stderr, "\033[%dm", color);
93 if (line) {
94 rt_fprintf(stderr, "%s - line %d, %s: ", function, line,
95 pimpl_->name.c_str());
96 } else {
97 rt_fprintf(stderr, "%s, %s: ", function, pimpl_->name.c_str());
[2]98 }
[15]99 rt_vfprintf(stderr, format, *args);
100 rt_fprintf(stderr, "\033[%dm", color_t::Auto);
101 } else
[2]102#endif
[15]103 {
104 fprintf(stderr, "\033[%dm", color);
105 if (line) {
106 fprintf(stderr, "%s - line %d, %s: ", function, line,
107 pimpl_->name.c_str());
108 } else {
109 fprintf(stderr, "%s, %s: ", function, pimpl_->name.c_str());
[2]110 }
[15]111 vfprintf(stderr, format, *args);
112 fprintf(stderr, "\033[%dm", color_t::Auto);
113 }
[2]114}
115
[15]116void Object::Information(const char *function, int line, const char *format,
117 ...) const {
118 va_list args;
119 va_start(args, format);
120 ColorPrintf(color_t::Green, function, line, format, &args);
121 va_end(args);
[2]122}
123
124void Object::Warning(const char *function, const char *format, ...) const {
[15]125 va_list args;
126 va_start(args, format);
127 ColorPrintf(color_t::Orange, function, 0, format, &args);
128 va_end(args);
[2]129}
130
131void Object::Error(const char *function, const char *format, ...) const {
[15]132 va_list args;
133 va_start(args, format);
134 ColorPrintf(color_t::Red, function, 0, format, &args);
135 va_end(args);
[2]136
[15]137 pimpl_->error_occured = true;
[2]138}
139
[15]140bool Object::ErrorOccured(bool recursive) const {
141 return pimpl_->ErrorOccured(recursive);
[2]142}
143
144} // end namespace core
145} // end namespace flair
Note: See TracBrowser for help on using the repository browser.