Jamoma API  0.6.0.a19
System.h
Go to the documentation of this file.
1 /** @file
2  *
3  * @ingroup modularSystem
4  *
5  * @brief System clock class is based on the time of the system
6  *
7  * @details
8  *
9  * @authors Théo de la Hogue
10  *
11  * @copyright © 2013, Théo de la Hogue @n
12  * This code is licensed under the terms of the "New BSD License" @n
13  * http://creativecommons.org/licenses/BSD/
14  */
15 
16 
17 #ifndef __SYSTEM_H__
18 #define __SYSTEM_H__
19 
20 #include "TTClock.h"
21 #ifdef TT_PLATFORM_WIN
22  #include "../Minuit/includes/Time2.hpp"
23 #else
24  #include <sys/time.h>
25 #endif
26 #include <thread>
27 #include <mutex>
28 
29 class System : public TTClock {
30 
31  TTCLASS_SETUP(System)
32 
33 private:
34 
35  TTFloat64 mGranularity; ///< ATTRIBUTE : the minimun time between each tick (in ms)
36  std::thread mThread; ///< ATTRIBUTE : a thread to launch the clock execution
37  std::mutex mThreadMutex; ///< ATTRIBUTE : prevents the thread object from being used concurrently
38  TTUInt64 mLastTime; ///< a time reference used to compute delta time between each tick (in µs)
39 
40  /** Get specific parameters names needed by this clock
41  @return an error code if the clock fails to give his specific parameters */
42  TTErr getParameterNames(TTValue& value);
43 
44  /** Start the clock
45  @return an error code if the clock fails to start */
46  TTErr Go();
47 
48  /** Halt the sheduler
49  @return an error code if the clock fails to stop */
50  TTErr Stop();
51 
52  /** Pause the sheduler progression
53  @return an error code if the clock fails to pause */
54  TTErr Pause();
55 
56  /** Resume the sheduler progression
57  @return an error code if the clock fails to resume */
58  TTErr Resume();
59 
60  /** Called every time a new step should be processed
61  @return an error code if the clock step fails */
62  TTErr Tick();
63 
64  /** Internal method to compute the amount of time spent since the last call */
65  TTFloat64 computeDeltaTime();
66 
67  /** Called by the System queue
68  @param baton ..
69  @param data ..
70  @return an error code */
71  void SystemThreadCallback();
72 
73  void stopThread();
74 
75 };
76 typedef System* SystemPtr;
77 
78 #endif // __SYSTEM_H__
std::uint64_t TTUInt64
64 bit unsigned integer
Definition: TTBase.h:180
STL namespace.
double TTFloat64
64 bit floating point number
Definition: TTBase.h:188
#define TTCLASS_SETUP(className)
TODO Doxygen: need more comments here.
Definition: TTFoundation.h:54
TTErr
Jamoma Error Codes Enumeration of error codes that might be returned by any of the TTBlue functions a...
Definition: TTBase.h:342
TTClock is the base class for all Clock Unit.
Definition: TTClock.h:46
A Clock interface.
[doxygenAppendixC_copyExample]
Definition: TTValue.h:34