CTR Pia  4.11.3
Game Communication Engine
common_StepSequenceJob.h
1 /*---------------------------------------------------------------------------*
2  Project: Pia
3  File: common_StepSequenceJob.h
4 
5  Copyright Nintendo. All rights reserved.
6 
7  These coded instructions, statements, and computer programs contain
8  proprietary information of Nintendo of America Inc. and/or Nintendo
9  Company Ltd., and are protected by Federal copyright law. They may
10  not be disclosed to third parties or copied or duplicated in any form,
11  in whole or in part, without the prior written consent of Nintendo.
12  *---------------------------------------------------------------------------*/
13 
14 
15 #pragma once
16 
17 #include <pia/common/common_definitions.h>
18 
19 #include <pia/common/common_RootObject.h>
20 #include <pia/common/common_Job.h>
21 #include <pia/common/common_Trace.h>
22 
23 
24 namespace nn
25 {
26 namespace pia
27 {
28 namespace common
29 {
30 
31 #define NN_PIA_JOBSTEP(STEP) Step(static_cast<StepMethod>(&STEP), #STEP)
32 
33 
34 /*!
35 @cond PRIVATE
36 @brief Represents the step execution jobs of the base class.
37 
38 @details Using this class enables you to execute jobs function-by-function.
39 
40 */
41 class StepSequenceJob : public nn::pia::common::Job
42 {
43 public:
44  typedef Job::ExecuteResult (StepSequenceJob::*StepMethod)();
45 
46  class Step : public nn::pia::common::RootObject
47  {
48  public:
49  Step(void)
50  : m_pStepMethod(NULL), m_pName(NULL)
51  {
52  }
53  Step(StepMethod pStepMethod, const char* pName)
54  : m_pStepMethod(pStepMethod), m_pName(pName)
55  {
56  }
57 
58  virtual ~Step(void)
59  {
60  }
61 
62  const char* GetName(void) const
63  {
64  return m_pName ? m_pName : "(no name)";
65  }
66 
67  Job::ExecuteResult Execute(StepSequenceJob* pJob)
68  {
69  return (pJob->*m_pStepMethod)();
70  }
71 
72  bool operator==(const Step& rhs) const;
73  bool operator!=(const Step& rhs) const { return !(*this == rhs); }
74 
75  virtual void Trace(u64 flag) const
76  {
77  PIA_TRACE(flag, "StepSequenceJob::Step::Trace() called. (%s)", GetName());
78  }
79 
80  private:
81  StepMethod m_pStepMethod;
82  const char* m_pName;
83  };
84 
85 
86 /*!
87 @brief Instantiates an object.
88 */
89  StepSequenceJob(void);
90 
91 
92 /*!
93 @brief Destroys the object.
94 */
95  virtual ~StepSequenceJob(void);
96 
97 
98  virtual void Reset(bool isCheck = true);
99 
100 
101  void CancelStepSequence()
102  {
103  m_IsCancelStepSequence = true;
104  }
105 
106  virtual void CancelCleanup()
107  {
108  }
109 
110 /*!
111 @brief Registers a function to be sequentially executed.
112 
113 @details This function makes the settings necessary to execute functions as a batch process.
114 
115 @param[in] step Specifies the <tt>Step</tt> instance containing the function to execute next.
116 This instance is usually created by the <tt>NN_PIA_JOBSTEP</tt> macro.
117 */
118  void SetStep(const Step& step)
119  {
120  m_NextStep = step;
121  }
122 
123  void WaitForCompletion(u32 sleepTime);
124 
125 /*!
126 @brief Sets tracing flags.
127 
128 @param[in] flags Specifies tracing flags.
129 */
130  void SetTraceFlags(u64 flags)
131  {
132  m_TraceFlags = flags;
133  }
134 
135 
136 /*!
137 @brief Gets tracing flags.
138 */
139  u64 GetTraceFlags(void) const
140  {
141  return m_TraceFlags;
142  }
143 
144 /*!
145 @brief Prints information that is useful for debugging.
146 
147 @param[in] flag Specifies the bitwise OR of trace flags. For more information, see the <tt>@ref TraceFlag</tt> type.
148 */
149  virtual void Trace(u64 flag) const;
150 
151 protected:
152  // Override.
153  virtual Job::ExecuteResult ExecuteCore();
154 
155  // Returns the instance registered with the <tt>SetStep</tt> function.
156  const Step& GetStep(void) const
157  {
158  return m_NextStep;
159  }
160 
161 private:
162  // The instance bundled in the next job to be executed.
163  Step m_NextStep;
164 
165  volatile bool m_IsCancelStepSequence;
166 
167  // The trace flag for this instance.
168  u64 m_TraceFlags;
169 };
170 //! @endcond
171 }
172 }
173 } // end of namespace nn::pia::common
Definition: assert.h:115
This is the common base class used inside the Pia library.
Definition: common_RootObject.h:40