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

Last change on this file since 360 was 294, checked in by Sanahuja Guillaume, 6 years ago

vrpn modifs

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(function) {
94 if (line) {
95 rt_fprintf(stderr, "%s - line %d, %s: ", function, line,
96 pimpl_->name.c_str());
97 } else {
98 rt_fprintf(stderr, "%s, %s: ", function, pimpl_->name.c_str());
99 }
100 }
101 rt_vfprintf(stderr, format, *args);
102 rt_fprintf(stderr, "\033[%dm", color_t::Auto);
103 } else
104#endif
105 {
106 fprintf(stderr, "\033[%dm", color);
107 if(function) {
108 if (line) {
109 fprintf(stderr, "%s - line %d, %s: ", function, line,
110 pimpl_->name.c_str());
111 } else {
112 fprintf(stderr, "%s, %s: ", function, pimpl_->name.c_str());
113 }
114 }
115 vfprintf(stderr, format, *args);
116 fprintf(stderr, "\033[%dm", color_t::Auto);
117 }
118}
119
120void Object::Information(const char *function, int line, const char *format,
121 ...) const {
122 va_list args;
123 va_start(args, format);
124 ColorPrintf(color_t::Green, function, line, format, &args);
125 va_end(args);
126}
127
128void Object::Warning(const char *function, const char *format, ...) const {
129 va_list args;
130 va_start(args, format);
131 ColorPrintf(color_t::Orange, function, 0, format, &args);
132 va_end(args);
133}
134
135void Object::Error(const char *function, const char *format, ...) const {
136 va_list args;
137 va_start(args, format);
138 ColorPrintf(color_t::Red, function, 0, format, &args);
139 va_end(args);
140
141 pimpl_->error_occured = true;
142}
143
144bool Object::ErrorOccured(bool recursive) const {
145 return pimpl_->ErrorOccured(recursive);
146}
147
148} // end namespace core
149} // end namespace flair
Note: See TracBrowser for help on using the repository browser.