1 |
|
|
/* |
2 |
|
|
* Copyright 2010, |
3 |
|
|
* François Bleibel, |
4 |
|
|
* Olivier Stasse, |
5 |
|
|
* |
6 |
|
|
* CNRS/AIST |
7 |
|
|
* |
8 |
|
|
*/ |
9 |
|
|
|
10 |
|
|
/* --------------------------------------------------------------------- */ |
11 |
|
|
/* --- INCLUDE --------------------------------------------------------- */ |
12 |
|
|
/* --------------------------------------------------------------------- */ |
13 |
|
|
#include <list> |
14 |
|
|
#ifdef WIN32 |
15 |
|
|
#include <time.h> |
16 |
|
|
#endif /*WIN32*/ |
17 |
|
|
|
18 |
|
|
/* --- SOT --- */ |
19 |
|
|
#include <dynamic-graph/entity.h> |
20 |
|
|
|
21 |
|
|
#include <sot/core/debug.hh> |
22 |
|
|
#include <sot/core/feature-abstract.hh> |
23 |
|
|
#include <sot/core/pool.hh> |
24 |
|
|
#include <sot/core/task-abstract.hh> |
25 |
|
|
|
26 |
|
|
namespace dynamicgraph { |
27 |
|
|
namespace sot { |
28 |
|
|
/* --------------------------------------------------------------------- */ |
29 |
|
|
/* --- CLASS ----------------------------------------------------------- */ |
30 |
|
|
/* --------------------------------------------------------------------- */ |
31 |
|
|
|
32 |
|
|
PoolStorage::~PoolStorage(void) { |
33 |
|
|
sotDEBUGIN(15); |
34 |
|
|
|
35 |
|
|
sotDEBUGOUT(15); |
36 |
|
|
return; |
37 |
|
|
} |
38 |
|
|
|
39 |
|
|
/* --------------------------------------------------------------------- */ |
40 |
|
8 |
void PoolStorage::registerTask(const std::string &entname, TaskAbstract *ent) { |
41 |
✓✗ |
8 |
Tasks::iterator entkey = task.find(entname); |
42 |
✗✓ |
8 |
if (entkey != task.end()) // key does exist |
43 |
|
|
{ |
44 |
|
|
throw ExceptionFactory(ExceptionFactory::OBJECT_CONFLICT, |
45 |
|
|
"Another task already defined with the " |
46 |
|
|
"same name. ", |
47 |
|
|
"Task name is <%s>.", entname.c_str()); |
48 |
|
|
} else { |
49 |
|
|
sotDEBUG(10) << "Register task <" << entname << "> in the pool." |
50 |
|
|
<< std::endl; |
51 |
✓✗ |
8 |
task[entname] = ent; |
52 |
|
|
} |
53 |
|
8 |
} |
54 |
|
|
|
55 |
|
|
TaskAbstract &PoolStorage::getTask(const std::string &name) { |
56 |
|
|
Tasks::iterator entPtr = task.find(name); |
57 |
|
|
if (entPtr == task.end()) { |
58 |
|
|
SOT_THROW ExceptionFactory(ExceptionFactory::UNREFERED_OBJECT, |
59 |
|
|
"Unknown task.", " (while calling <%s>)", |
60 |
|
|
name.c_str()); |
61 |
|
|
} |
62 |
|
|
return *entPtr->second; |
63 |
|
|
} |
64 |
|
|
|
65 |
|
|
/* --------------------------------------------------------------------- */ |
66 |
|
12 |
void PoolStorage::registerFeature(const std::string &entname, |
67 |
|
|
FeatureAbstract *ent) { |
68 |
✓✗ |
12 |
Features::iterator entkey = feature.find(entname); |
69 |
✗✓ |
12 |
if (entkey != feature.end()) // key does exist |
70 |
|
|
{ |
71 |
|
|
throw ExceptionFactory(ExceptionFactory::OBJECT_CONFLICT, |
72 |
|
|
"Another feature already defined with the" |
73 |
|
|
" same name. ", |
74 |
|
|
"Feature name is <%s>.", entname.c_str()); |
75 |
|
|
} else { |
76 |
|
|
sotDEBUG(10) << "Register feature <" << entname << "> in the pool." |
77 |
|
|
<< std::endl; |
78 |
✓✗ |
12 |
feature[entname] = ent; |
79 |
|
|
} |
80 |
|
12 |
} |
81 |
|
|
|
82 |
|
|
FeatureAbstract &PoolStorage::getFeature(const std::string &name) { |
83 |
|
|
Features::iterator entPtr = feature.find(name); |
84 |
|
|
if (entPtr == feature.end()) { |
85 |
|
|
SOT_THROW ExceptionFactory(ExceptionFactory::UNREFERED_OBJECT, |
86 |
|
|
"Unknown feature.", " (while calling <%s>)", |
87 |
|
|
name.c_str()); |
88 |
|
|
} |
89 |
|
|
return *entPtr->second; |
90 |
|
|
} |
91 |
|
|
|
92 |
|
|
void PoolStorage::writeGraph(const std::string &aFileName) { |
93 |
|
|
size_t IdxPointFound = aFileName.rfind("."); |
94 |
|
|
std::string tmp1 = aFileName.substr(0, IdxPointFound); |
95 |
|
|
size_t IdxSeparatorFound = aFileName.rfind("/"); |
96 |
|
|
std::string GenericName; |
97 |
|
|
if (IdxSeparatorFound != std::string::npos) |
98 |
|
|
GenericName = tmp1.substr(IdxSeparatorFound, tmp1.length()); |
99 |
|
|
else |
100 |
|
|
GenericName = tmp1; |
101 |
|
|
|
102 |
|
|
/* Reading local time */ |
103 |
|
|
time_t ltime; |
104 |
|
|
ltime = time(NULL); |
105 |
|
|
struct tm ltimeformatted; |
106 |
|
|
#ifdef WIN32 |
107 |
|
|
localtime_s(<imeformatted, <ime); |
108 |
|
|
#else |
109 |
|
|
localtime_r(<ime, <imeformatted); |
110 |
|
|
#endif /*WIN32*/ |
111 |
|
|
|
112 |
|
|
/* Opening the file and writing the first comment. */ |
113 |
|
|
std::ofstream GraphFile; |
114 |
|
|
GraphFile.open(aFileName.c_str(), std::ofstream::out); |
115 |
|
|
GraphFile << "/* This graph has been automatically generated. " << std::endl; |
116 |
|
|
GraphFile << " " << 1900 + ltimeformatted.tm_year |
117 |
|
|
<< " Month: " << 1 + ltimeformatted.tm_mon |
118 |
|
|
<< " Day: " << ltimeformatted.tm_mday |
119 |
|
|
<< " Time: " << ltimeformatted.tm_hour << ":" |
120 |
|
|
<< ltimeformatted.tm_min; |
121 |
|
|
GraphFile << " */" << std::endl; |
122 |
|
|
GraphFile << "digraph " << GenericName << " { "; |
123 |
|
|
GraphFile << "\t graph [ label=\"" << GenericName |
124 |
|
|
<< "\" bgcolor = white rankdir=LR ]" << std::endl |
125 |
|
|
<< "\t node [ fontcolor = black, color = black, " |
126 |
|
|
"fillcolor = gold1, style=filled, shape=box ] ; " |
127 |
|
|
<< std::endl; |
128 |
|
|
GraphFile << "\tsubgraph cluster_Tasks { " << std::endl; |
129 |
|
|
GraphFile << "\t\t color=blue; label=\"Tasks\";" << std::endl; |
130 |
|
|
|
131 |
|
|
for (Tasks::iterator iter = task.begin(); iter != task.end(); iter++) { |
132 |
|
|
TaskAbstract *ent = iter->second; |
133 |
|
|
GraphFile << "\t\t" << ent->getName() << " [ label = \"" << ent->getName() |
134 |
|
|
<< "\" ," << std::endl |
135 |
|
|
<< "\t\t fontcolor = black, color = black, " |
136 |
|
|
"fillcolor = magenta, style=filled, shape=box ]" |
137 |
|
|
<< std::endl; |
138 |
|
|
} |
139 |
|
|
|
140 |
|
|
GraphFile << "}" << std::endl; |
141 |
|
|
|
142 |
|
|
GraphFile.close(); |
143 |
|
|
} |
144 |
|
|
|
145 |
|
|
void PoolStorage::writeCompletionList(std::ostream & /*os*/) {} |
146 |
|
|
|
147 |
|
20 |
PoolStorage *PoolStorage::getInstance() { |
148 |
✓✓ |
20 |
if (instance_ == 0) { |
149 |
✓✗ |
4 |
instance_ = new PoolStorage; |
150 |
|
|
} |
151 |
|
20 |
return instance_; |
152 |
|
|
} |
153 |
|
|
void PoolStorage::destroy() { |
154 |
|
|
delete instance_; |
155 |
|
|
instance_ = 0; |
156 |
|
|
} |
157 |
|
|
|
158 |
|
4 |
PoolStorage::PoolStorage() {} |
159 |
|
|
|
160 |
|
|
PoolStorage *PoolStorage::instance_ = 0; |
161 |
|
|
} // namespace sot |
162 |
|
|
} // namespace dynamicgraph |