1 #ifndef COIN_SCXMLSTATEMACHINE_H
2 #define COIN_SCXMLSTATEMACHINE_H
3 
4 /**************************************************************************\
5  * Copyright (c) Kongsberg Oil & Gas Technologies AS
6  * All rights reserved.
7  *
8  * Redistribution and use in source and binary forms, with or without
9  * modification, are permitted provided that the following conditions are
10  * met:
11  *
12  * Redistributions of source code must retain the above copyright notice,
13  * this list of conditions and the following disclaimer.
14  *
15  * Redistributions in binary form must reproduce the above copyright
16  * notice, this list of conditions and the following disclaimer in the
17  * documentation and/or other materials provided with the distribution.
18  *
19  * Neither the name of the copyright holder nor the names of its
20  * contributors may be used to endorse or promote products derived from
21  * this software without specific prior written permission.
22  *
23  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
24  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
25  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
26  * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
27  * HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
28  * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
29  * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
30  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
31  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
32  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
33  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
34 \**************************************************************************/
35 
36 #include <Inventor/scxml/ScXMLEventTarget.h>
37 
38 #include <Inventor/SbName.h>
39 #include <Inventor/lists/SbList.h>
40 
41 class ScXMLEvent;
42 class ScXMLDocument;
43 class ScXMLStateMachine;
44 class ScXMLEvaluator;
45 class ScXMLElt;
46 
47 typedef void ScXMLStateMachineDeleteCB(void * userdata,
48                                        ScXMLStateMachine * statemachine);
49 typedef void ScXMLStateChangeCB(void * userdata,
50                                 ScXMLStateMachine * statemachine,
51                                 const char * stateidentifier,
52                                 SbBool enterstate,
53                                 SbBool success);
54 typedef void ScXMLParallelStateChangeCB(void * userdata,
55                                         ScXMLStateMachine * statemachine,
56                                         int numstates,
57                                         const char ** stateidentifiers,
58                                         SbBool enterstate,
59                                         SbBool success);
60 
61 class COIN_DLL_API ScXMLStateMachine : public ScXMLEventTarget {
62   typedef ScXMLEventTarget inherited;
63   SCXML_OBJECT_HEADER(ScXMLStateMachine)
64 
65 public:
66   static void initClass(void);
67   static void cleanClass(void);
68 
69  ScXMLStateMachine(void);
70   virtual ~ScXMLStateMachine(void);
71 
72   virtual void setName(const SbName & name);
73   const SbName & getName(void) const;
74 
75   virtual void setDescription(ScXMLDocument * document);
76   const ScXMLDocument * getDescription(void) const;
77 
78   virtual void setSessionId(const SbName & sessionid);
79   const SbName & getSessionId(void) const;
80 
81   virtual void initialize(void);
82 
83   virtual SbBool isActive(void) const;
84   virtual SbBool isFinished(void) const;
85 
86   virtual int getNumActiveStates(void) const;
87   virtual const ScXMLElt * getActiveState(int idx) const;
88 
89   virtual void addDeleteCallback(ScXMLStateMachineDeleteCB * callback,
90                                  void * userdata);
91   virtual void removeDeleteCallback(ScXMLStateMachineDeleteCB * callback,
92                                     void * userdata);
93 
94   virtual void addStateChangeCallback(ScXMLStateChangeCB * callback,
95                                       void * userdata);
96   virtual void removeStateChangeCallback(ScXMLStateChangeCB * callback,
97                                          void * userdata);
98 
99   virtual void setVariable(const char * name, const char * value);
100   virtual const char * getVariable(const char * name) const;
101 
102   static ScXMLStateMachine * getStateMachineForSessionId(const SbName & sessionid);
103 
104   virtual void setLogLevel(int loglevel);
105   int getLogLevel(void) const;
106 
107   virtual void setEvaluator(ScXMLEvaluator * evaluator);
108   ScXMLEvaluator * getEvaluator(void) const;
109 
110   SbBool isModuleEnabled(const char * modulename) const;
111   int getNumEnabledModules(void) const;
112   const char * getEnabledModuleName(int idx) const;
113   void setEnabledModulesList(const SbList<const char *> & modulenames);
114 
115 protected:
116   virtual SbBool processOneEvent(const ScXMLEvent * event);
117 
118 private:
119   ScXMLStateMachine(const ScXMLStateMachine & rhs); // N/A
120   ScXMLStateMachine & operator = (const ScXMLStateMachine & rhs); // N/A
121 
122   class PImpl;
123   SbPimplPtr<PImpl> pimpl;
124 
125 }; // ScXMLStateMachine
126 
127 #endif // !COIN_SCXMLSTATEMACHINE_H
128