RemoteAccessableState.h
Go to the documentation of this file.
1/*
2* This file is part of ArmarX.
3*
4* Copyright (C) 2011-2016, High Performance Humanoid Technologies (H2T), Karlsruhe Institute of Technology (KIT), all rights reserved.
5*
6* ArmarX is free software; you can redistribute it and/or modify
7* it under the terms of the GNU General Public License version 2 as
8* published by the Free Software Foundation.
9*
10* ArmarX is distributed in the hope that it will be useful, but
11* WITHOUT ANY WARRANTY; without even the implied warranty of
12* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13* GNU General Public License for more details.
14*
15* You should have received a copy of the GNU General Public License
16* along with this program. If not, see <http://www.gnu.org/licenses/>.
17*
18* @package ArmarXCore::StatechartExamples::RemoteAccessableStateExample::
19* @author Mirko Waechter ( mirko.waechter at kit dot edu)
20* @date 20122012
21* @copyright http://www.gnu.org/licenses/gpl-2.0.txt
22* GNU General Public License
23*/
24
25#pragma once
26
27
30
31namespace armarx
32{
34 virtual public RemoteStateOfferer<StatechartContext>
35 {
36 public:
37 // inherited from Component
38 std::string
39 getStateOffererName() const override
40 {
41 return "RemoteAccessable";
42 }
43
44 // inherited from RemoteStateOfferer
45 void onInitRemoteStateOfferer() override;
46 };
47
48 struct Stateadd_x_to_y : StateTemplate<Stateadd_x_to_y>
49 {
50 void
52 {
53 addToInput("x", VariantType::Float, false);
54 addToInput("y", VariantType::Float, false);
55
56 addToOutput("result", VariantType::Float, false);
57 }
58
59 void
60 defineSubstates() override
61 {
62 setInitState(addState<State>("DummySubstate1"));
63 addState<State>("DummySubstate2");
64 }
65
66 void
67 onEnter() override
68 {
69 float result = getInput<float>("x") + getInput<float>("y");
70 setOutput("result", result);
71 ARMARX_INFO << "result: " << result << std::endl;
73 }
74 };
75
76
77} // namespace armarx
#define ARMARXCOMPONENT_IMPORT_EXPORT
std::string getStateOffererName() const override
Implement this function to specify the RemoteStateOfferer prefix.
void sendEvent(const EventPtr event, StateBasePtr eventProcessor=nullptr)
Function to send an event to a specific state from an onEnter()-function. Must not be called anywhere...
Definition StateUtil.cpp:40
void setOutput(std::string const &key, const Variant &value)
setOuput() sets an output parameter of this state.
Definition State.cpp:482
StateBasePtr addState(StateBasePtr pNewState)
Definition State.cpp:140
bool addToInput(const std::string &key, const ContainerType &type, bool optional, VariantContainerBasePtr defaultValue=VariantContainerBasePtr())
Adds a key,type-pair to the input parameters.
Definition State.cpp:309
std::enable_if_t< std::is_base_of_v< VariantDataClass, T >, IceInternal::Handle< T > > getInput(const std::string &key) const
getInput can be used to access a specific input parameter.
Definition State.h:620
StateBasePtr setInitState(StateBasePtr initState, ParameterMappingPtr initialStateMapping=ParameterMappingPtr())
Sets the initial substate of this state.
Definition State.cpp:354
bool addToOutput(const std::string &key, VariantTypeId type, bool optional)
Adds a key,type-pair to the output parameters.
Definition State.cpp:319
#define ARMARX_INFO
The normal logging level.
Definition Logging.h:181
const VariantTypeId Float
Definition Variant.h:919
This file offers overloads of toIce() and fromIce() functions for STL container types.
Class that holds states, which offer functionality for other states over Ice.
void defineParameters() override
Virtual function, in which input/local/output parameters can be specified.
void onEnter() override
Virtual function, in which the behaviour of state is defined, when it is entered. Can be overridden,...
void defineSubstates() override
Virtual function, in which substates, transition and mappings can be added.