CLI  2.9
exec_context_manager.h
Go to the documentation of this file.
1 /*
2  Copyright (c) 2006-2018, Alexis Royer, http://alexis.royer.free.fr/CLI
3 
4  All rights reserved.
5 
6  Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
7 
8  * Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
9  * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation
10  and/or other materials provided with the distribution.
11  * Neither the name of the CLI library project nor the names of its contributors may be used to endorse or promote products derived from this software
12  without specific prior written permission.
13 
14  THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
15  "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
16  LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
17  A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
18  CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
19  EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
20  PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
21  PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
22  LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
23  NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
24  SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
25 */
26 
27 
31 
32 #ifndef _CLI_EXEC_CONTEXT_MANAGER_H_
33 #define _CLI_EXEC_CONTEXT_MANAGER_H_
34 
35 #include "cli/namespace.h"
36 #include "cli/exec_context.h"
37 
38 
40 
41  // Forward declarations.
42  class OutputDevice;
43  class IODevice;
44  class TraceClass;
45 
46 
48  #define TRACE_EXEC_CTX ExecutionContextManager::GetTraceClass()
49 
52  {
53  public:
56  static const TraceClass& GetTraceClass(void);
57 
58  public:
60  explicit ExecutionContextManager(void);
61 
63  virtual ~ExecutionContextManager(void);
64 
65  private:
70 
71  public:
73  void UseInstance(
74  ExecutionContext& CLI_UserInstance
75  );
76 
79  void FreeInstance(
80  ExecutionContext& CLI_UserInstance
81  );
82 
83  public:
85  void StopAllExecutions(void);
86 
87  public:
90  const bool OpenUp(
91  ExecutionContext& CLI_Context,
92  IODevice& CLI_IODevice
93  );
94 
97  const bool CloseDown(
98  ExecutionContext& CLI_Context
99  );
100 
103  const bool IsRunning(void) const;
104 
107  const bool IsRunning(
108  const ExecutionContext& CLI_Context
109  ) const;
110 
113  ExecutionContext* const GetCurrentContext(void);
114 
115  public:
118  const IODevice& GetInput(void) const;
119 
122  const OutputDevice& GetStream(
123  const STREAM_TYPE E_StreamType
124  ) const;
125 
134  const bool SetStream(
135  const STREAM_TYPE E_StreamType,
136  OutputDevice& CLI_Stream
137  );
138 
141  const bool StreamEnabled(
142  const STREAM_TYPE E_StreamType
143  ) const;
144 
147  const bool EnableStream(
148  const STREAM_TYPE E_StreamType,
149  const bool B_Enable
150  );
151 
152  public:
154  void SetLang(
155  const ResourceString::LANG E_Lang
156  );
157 
160  const ResourceString::LANG GetLang(void) const;
161 
162  public:
164  void SetBeep(
165  const bool B_Enable
166  );
167 
170  const bool GetBeep(void) const;
171 
173  void Beep(void);
174 
175  private:
177  void ReleaseInput(void);
178 
179  private:
181  IODevice* m_pcliInput;
183  struct {
184  OutputDevice* pcliStream;
185  bool bEnable;
186  } m_artStream[STREAM_TYPES_COUNT];
188  ResourceString::LANG m_eLang;
190  bool m_bBeep;
192  tk::Queue<ExecutionContext*> m_tkUserInstances;
194  tk::Queue<ExecutionContext*> m_tkRunningContexts;
195  };
196 
198 
199 #endif // _CLI_EXEC_CONTEXT_MANAGER_H_
Main namespace of the CLI library.
const ResourceString::LANG GetLang(void) const
Language access.
void StopAllExecutions(void)
Stop execution of all running contexts.
void Beep(void)
Sends a beep signal.
Execution context manager class.
void SetBeep(const bool B_Enable)
Beep configuration setting.
virtual ~ExecutionContextManager(void)
Destructor.
Number of streams.
Definition: exec_context.h:58
#define CLI_NS_END(__ns)
End a namespace definition.
Definition: namespace.h:45
LANG
Languages identifiers.
const OutputDevice & GetStream(const STREAM_TYPE E_StreamType) const
Output stream accessor.
void UseInstance(ExecutionContext &CLI_UserInstance)
Instance registration.
const bool CloseDown(ExecutionContext &CLI_Context)
Release input and output devices after execution.
const bool OpenUp(ExecutionContext &CLI_Context, IODevice &CLI_IODevice)
Assumes input and output devices to be ready for execution.
void FreeInstance(ExecutionContext &CLI_UserInstance)
Instance deregistration.
Namespace management.
const bool StreamEnabled(const STREAM_TYPE E_StreamType) const
Enabled/disabled stream accessor.
Execution context class definition.
ExecutionContextManager(void)
Default constructor.
const bool EnableStream(const STREAM_TYPE E_StreamType, const bool B_Enable)
Enable/disable stream.
Execution context.
Definition: exec_context.h:149
Generic output device.
Definition: io_device.h:256
enum _STREAM_TYPE STREAM_TYPE
Output stream enumeration.
#define CLI_NS_BEGIN(__ns)
Begin a namespace definition.
Definition: namespace.h:38
void SetLang(const ResourceString::LANG E_Lang)
Language setting.
const bool SetStream(const STREAM_TYPE E_StreamType, OutputDevice &CLI_Stream)
Output stream positionning.
const bool IsRunning(void) const
Determines whether the execution context manager is currently running.
const bool GetBeep(void) const
Beep configuration access.
Trace class object.
Definition: traces.h:51
Generic input/output device.
Definition: io_device.h:581
ExecutionContext *const GetCurrentContext(void)
Returns the current execution context.
static const TraceClass & GetTraceClass(void)
Execution context trace class singleton.
const IODevice & GetInput(void) const
Input stream accessor.