00001
00002
00003 #include "tasks/<%= task.basename %>Base.hpp"
00004
00005 using namespace <%= component.name %>;
00006
00007 <% code_before, code_after =
00008 task.base_implementation_code.partition(&:first)
00009 code_before.map! { |_, c| c.call }
00010 code_after.map! { |_, c| c.call }
00011 %>
00012
00013 <%= code_before.join("\n") %>
00014
00015 <%= task.basename %>Base::<%= task.basename %>Base(std::string const& name<%= ", TaskCore::TaskState state" unless task.fixed_initial_state? %>)
00016 <% if task.superclass.fixed_initial_state? %>
00017 : ::<%= task.superclass.name %>(name)
00018 <% elsif task.needs_configuration? %>
00019 : ::<%= task.superclass.name %>(name, TaskCore::PreOperational)
00020 <% else %>
00021 : ::<%= task.superclass.name %>(name, state)
00022 <% end %>
00023 <%= task.self_base_members.
00024 sort_by { |m| [m.kind, m.name] }.
00025 map { |m|
00026 ret = m.with_indent(4, :initializer)
00027 if(ret)
00028 ", " + ret.strip
00029 else
00030 nil
00031 end
00032 }.
00033 compact.join("\n ") %>
00034 {
00035 <%= task.self_base_members.
00036 sort_by { |m| [m.kind, m.name] }.
00037 map { |m| m.with_indent(4, :constructor) }.
00038 compact.join("\n") %>
00039
00040 <% if task.extended_state_support? %>
00041 _state.keepLastWrittenValue(true);
00042 _state.write(getTaskState());
00043 <% end %>
00044 }
00045
00046 <%= task.basename %>Base::~<%= task.basename %>Base()
00047 {
00048 <%= task.self_base_members.
00049 sort_by { |m| [m.kind, m.name] }.
00050 map { |m| m.with_indent(4, :destructor) }.
00051 compact.join("\n") %>
00052 }
00053
00054 <%= task.self_base_methods.
00055 sort_by { |m| [m.name] }.
00056 map { |m| m.with_indent(0, :definition) }.
00057 compact.join("\n") %>
00058
00059 <% if task.extended_state_support? %>
00060 void <%= task.basename %>Base::state(States state)
00061 {
00062 _state.write(state);
00063 }
00064 void <%= task.basename %>Base::error(States state)
00065 {
00066 _state.write(state);
00067 TaskContext::error();
00068 }
00069 void <%= task.basename %>Base::exception(States state)
00070 {
00071 _state.write(state);
00072 TaskContext::exception();
00073 }
00074 void <%= task.basename %>Base::fatal(States state)
00075 {
00076 _state.write(state);
00077 TaskContext::fatal();
00078 }
00079 <%= task.basename %>Base::States <%= task.basename %>Base::state() const
00080 {
00081 return static_cast<<%= task.basename %>Base::States>(_state.getLastWrittenValue());
00082 }
00083 <% end %>
00084
00085 <% if task.extended_state_support? && !task.superclass.extended_state_support? %>
00086 struct StateExporter
00087 {
00088 RTT::TaskContext const& task;
00089 RTT::OutputPort<int>& port;
00090
00091 StateExporter(RTT::TaskContext const& task, RTT::OutputPort<int>& port)
00092 : task(task), port(port) {}
00093 ~StateExporter()
00094 {
00095 port.write(task.getTaskState());
00096 }
00097 };
00098 <% end %>
00099
00100 bool <%= task.basename %>Base::start()
00101 {
00102 <% if task.extended_state_support? && !task.superclass.extended_state_support? %>
00103 StateExporter exporter(*this, _state);
00104 <% end %>
00105 bool started = <%= superclass.name %>::start();
00106 if (!started)
00107 return false;
00108
00109 <% task.self_ports.find_all { |p| p.kind_of?(InputPort) }.each do |port| %>
00110 _<%= port.name %>.clear();
00111 <% end %>
00112 return true;
00113 }
00114
00115 <% if task.extended_state_support? && !task.superclass.extended_state_support? %>
00116 bool <%= task.basename %>Base::configure()
00117 {
00118 StateExporter exporter(*this, _state);
00119 return <%= superclass.name %>::configure();
00120 }
00121 bool <%= task.basename %>Base::recover()
00122 {
00123 StateExporter exporter(*this, _state);
00124 return <%= superclass.name %>::recover();
00125 }
00126 bool <%= task.basename %>Base::stop()
00127 {
00128 StateExporter exporter(*this, _state);
00129 return <%= superclass.name %>::stop();
00130 }
00131 bool <%= task.basename %>Base::cleanup()
00132 {
00133 StateExporter exporter(*this, _state);
00134 return <%= superclass.name %>::cleanup();
00135 }
00136 void <%= task.basename %>Base::fatal()
00137 { return fatal(FATAL_ERROR); }
00138 void <%= task.basename %>Base::error()
00139 { return error(RUNTIME_ERROR); }
00140 void <%= task.basename %>Base::exception()
00141 { return exception(EXCEPTION); }
00142 <% end %>
00143
00144 <% task.base_hook_code.keys.sort.each do |hook_name| %>
00145 <% snippets = task.base_hook_code[hook_name] %>
00146 <% next if snippets.empty? %>
00147 <% is_boolean = (hook_name == "start" || hook_name == "configure") %>
00148 <%= (is_boolean ? 'bool' : 'void') %> <%= task.basename %>Base::<%= hook_name %>Hook()
00149 {
00150 <% if is_boolean %>
00151 if (! <%= task.superclass.name %>::<%= hook_name %>Hook())
00152 return false;
00153 <% end %>
00154
00155 <% snippets.each do |code| %>
00156 <% if code.respond_to?(:to_str) %>
00157 <%= code %>
00158 <% else %>
00159 <%= code.call %>
00160 <% end %>
00161 <% end %>
00162
00163 <% if is_boolean %>
00164 return true;
00165 <% end %>
00166 }
00167 <% end %>
00168
00169 <%= code_after.join("\n") %>
00170