TimeoutExample.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::TimeoutExample
19 * @author Mirko Waechter (mirko.waechter at kit dot edu)
20 * @date 2012
21 * @copyright http://www.gnu.org/licenses/gpl-2.0.txt
22 * GNU General Public License
23 */
24 
25 #pragma once
26 
29 
31 
32 namespace armarx
33 {
35  virtual public StatechartContext
36  {
37  public:
38 
40 
41  // inherited from Component
42  std::string getDefaultName() const override
43  {
44  return "TimeoutExample";
45  };
46  void onInitStatechart() override;
47  void onConnectStatechart() override;
48  void run();
49  };
50  struct stateInstallTimeout;
51  DEFINEEVENT(Next)
52  DEFINEEVENT(TimerExpired)
54  {
55  void defineState() override
56  {
57  // setStateName("StatechartTimeoutexample");
58  }
59  void defineSubstates() override
60  {
61  //add substates
62  setInitState(addState<stateInstallTimeout>("InstallTimeout"));
63 
64  StateBasePtr finalSuccess = addState<SuccessState>("Success");
65  StateBasePtr finalFailure = addState<FailureState>("Failure");
66 
67  // add transition
68  addTransition<Next>(getInitState(),
69  getInitState());
70  addTransition<TimerExpired>(getInitState(),
71  finalFailure);
72  addTransition<Success>(getInitState(),
73  finalSuccess);
74 
75  }
76  };
77 
78 
79  struct DelayState;
80  struct stateInstallTimeout : StateTemplate<stateInstallTimeout>
81  {
82 
83 
84  void onEnter() override
85  {
86 
87  setTimeoutEvent(5000, createEvent<TimerExpired>());
88  }
89  void onExit() override
90  {
91 
92  }
93  };
94 
95 
96 }
97 
armarx::StateTemplate
Definition: State.h:39
armarx::stateInstallTimeout::onExit
void onExit() override
Definition: TimeoutExample.h:89
armarx::TimeoutExample
Definition: TimeoutExample.h:34
armarx::TimeoutExampleStatechart::defineState
void defineState() override
Definition: TimeoutExample.h:55
armarx::TimeoutExample::statechart
StatePtr statechart
Definition: TimeoutExample.h:39
armarx::stateInstallTimeout
Definition: TimeoutExample.h:80
Statechart.h
IceInternal::Handle< State >
ARMARXCOMPONENT_IMPORT_EXPORT
#define ARMARXCOMPONENT_IMPORT_EXPORT
Definition: ImportExportComponent.h:38
armarx::StatechartContext
This class contains a statechart and provides the interfaces to distributed components.
Definition: StatechartContext.h:89
Component.h
armarx::TimeoutExampleStatechart
Definition: TimeoutExample.h:53
armarx::TimeoutExample::getDefaultName
std::string getDefaultName() const override
Retrieve default name of component.
Definition: TimeoutExample.h:42
armarx::DEFINEEVENT
DEFINEEVENT(EvInit) struct StateRun
armarx
This file offers overloads of toIce() and fromIce() functions for STL container types.
Definition: ArmarXTimeserver.cpp:28
armarx::TimeoutExampleStatechart::defineSubstates
void defineSubstates() override
Definition: TimeoutExample.h:59
armarx::stateInstallTimeout::onEnter
void onEnter() override
Definition: TimeoutExample.h:84
ImportExportComponent.h