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

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

sources reformatted with flair-format-dir script

File size: 3.5 KB
Line 
1// %flair:license{
2// This file is part of the Flair framework distributed under the
3// CECILL-C License, Version 1.0.
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
35namespace flair {
36namespace core {
37
38Time GetTime(void) {
39#ifdef __XENO__
40 return rt_timer_read();
41#else
42 struct timeval t;
43 gettimeofday(&t, NULL);
44 return (Time)((Time)(t.tv_sec) * 1000000 + (Time)(t.tv_usec)) * 1000;
45
46#endif
47}
48
49void Printf(const char *format, ...) {
50 va_list args;
51 va_start(args, format);
52#ifdef __XENO__
53 if (rt_task_self() != NULL) {
54 rt_vfprintf(stderr, format, args);
55 } else
56#endif
57 {
58 vfprintf(stderr, format, args);
59 }
60
61 va_end(args);
62}
63
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);
68}
69
70Object::~Object() {
71 if (pimpl_->parent != NULL)
72 pimpl_->parent->pimpl_->RemoveChild(this);
73 delete pimpl_;
74}
75
76string Object::ObjectName(void) const { return pimpl_->name; }
77
78string Object::ObjectType(void) const { return pimpl_->type; }
79
80const Object *Object::Parent(void) const { return pimpl_->parent; }
81
82vector<const Object *> *Object::TypeChilds(void) const {
83 return &(pimpl_->type_childs);
84}
85
86vector<const Object *> *Object::Childs(void) const { return &(pimpl_->childs); }
87
88void Object::ColorPrintf(color_t color, const char *function, int line,
89 const char *format, va_list *args) const {
90#ifdef __XENO__
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());
98 }
99 rt_vfprintf(stderr, format, *args);
100 rt_fprintf(stderr, "\033[%dm", color_t::Auto);
101 } else
102#endif
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());
110 }
111 vfprintf(stderr, format, *args);
112 fprintf(stderr, "\033[%dm", color_t::Auto);
113 }
114}
115
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);
122}
123
124void Object::Warning(const char *function, const char *format, ...) const {
125 va_list args;
126 va_start(args, format);
127 ColorPrintf(color_t::Orange, function, 0, format, &args);
128 va_end(args);
129}
130
131void Object::Error(const char *function, const char *format, ...) const {
132 va_list args;
133 va_start(args, format);
134 ColorPrintf(color_t::Red, function, 0, format, &args);
135 va_end(args);
136
137 pimpl_->error_occured = true;
138}
139
140bool Object::ErrorOccured(bool recursive) const {
141 return pimpl_->ErrorOccured(recursive);
142}
143
144} // end namespace core
145} // end namespace flair
Note: See TracBrowser for help on using the repository browser.