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