libvisual  0.5.0
lv_time_c.cpp
1 #include "config.h"
2 #include "lv_time.h"
3 #include "lv_common.h"
4 //#include <thread>
5 #include <unistd.h>
6 
7 extern "C" {
8 
9  VisTime *visual_time_new ()
10  {
11  return new LV::Time;
12  }
13 
14  VisTime *visual_time_new_now ()
15  {
16  return new LV::Time (LV::Time::now ());
17  }
18 
19  VisTime *visual_time_new_with_values (long sec, long nsec)
20  {
21  return new LV::Time (sec, nsec);
22  }
23 
24  VisTime *visual_time_clone (VisTime *src)
25  {
26  visual_return_val_if_fail (src != nullptr, nullptr);
27 
28  return new LV::Time (*src);
29  }
30 
31  void visual_time_free (VisTime *self)
32  {
33  delete self;
34  }
35 
36  void visual_time_set (VisTime *self, long sec, long nsec)
37  {
38  visual_return_if_fail (self != nullptr);
39 
40  self->sec = sec;
41  self->nsec = nsec;
42  }
43 
44  void visual_time_copy (VisTime *self, VisTime *src)
45  {
46  visual_return_if_fail (self != nullptr);
47  visual_return_if_fail (src != nullptr);
48 
49  self->sec = src->sec;
50  self->nsec = src->nsec;
51  }
52 
53  void visual_time_get_now (VisTime *self)
54  {
55  visual_return_if_fail (self != nullptr);
56 
57  *self = LV::Time::now ();
58  }
59 
60  void visual_time_diff (VisTime *diff, VisTime *time1, VisTime *time2)
61  {
62  visual_return_if_fail (diff != nullptr);
63  visual_return_if_fail (time1 != nullptr);
64  visual_return_if_fail (time2 != nullptr);
65 
66  *diff = *time1 - *time2;
67  }
68 
69  int visual_time_is_past (VisTime *self, VisTime *ref)
70  {
71  visual_return_val_if_fail (self != nullptr, FALSE);
72  visual_return_val_if_fail (ref != nullptr, FALSE);
73 
74  return *self > *ref;
75  }
76 
77  double visual_time_to_secs (VisTime *self)
78  {
79  visual_return_val_if_fail (self != nullptr, 0.0);
80 
81  return self->to_secs ();
82  }
83 
84  uint64_t visual_time_to_msecs (VisTime *self)
85  {
86  visual_return_val_if_fail (self != nullptr, 0);
87 
88  return self->to_msecs ();
89  }
90 
91  uint64_t visual_time_to_usecs (VisTime *self)
92  {
93  visual_return_val_if_fail (self != nullptr, 0);
94 
95  return self->to_usecs ();
96  }
97 
98  void visual_usleep (uint64_t usecs)
99  {
100  LV::Time::usleep (usecs);
101  }
102 
103  VisTimer *visual_timer_new ()
104  {
105  return new LV::Timer;
106  }
107 
108  void visual_timer_free (VisTimer *self)
109  {
110  delete self;
111  }
112 
113  void visual_timer_reset (VisTimer *self)
114  {
115  visual_return_if_fail (self != nullptr);
116 
117  self->reset ();
118  }
119 
120  void visual_timer_start (VisTimer *self)
121  {
122  visual_return_if_fail (self != nullptr);
123 
124  self->start ();
125  }
126 
127  void visual_timer_stop (VisTimer *self)
128  {
129  visual_return_if_fail (self != nullptr);
130 
131  self->stop ();
132  }
133 
134  int visual_timer_is_active (VisTimer *self)
135  {
136  visual_return_val_if_fail (self != nullptr, FALSE);
137 
138  return self->is_active ();
139  }
140 
141  void visual_timer_elapsed (VisTimer *self, VisTime *time)
142  {
143  visual_return_if_fail (self != nullptr);
144  visual_return_if_fail (time != nullptr);
145 
146  *time = self->elapsed ();
147  }
148 
149  double visual_timer_elapsed_secs (VisTimer *self)
150  {
151  visual_return_val_if_fail (self != nullptr, 0.0);
152 
153  return self->elapsed ().to_secs ();
154  }
155 
156  uint64_t visual_timer_elapsed_msecs (VisTimer *self)
157  {
158  visual_return_val_if_fail (self != nullptr, 0);
159 
160  return self->elapsed ().to_msecs ();
161  }
162 
163  uint64_t visual_timer_elapsed_usecs (VisTimer *self)
164  {
165  visual_return_val_if_fail (self != nullptr, 0);
166 
167  return self->elapsed ().to_usecs ();
168  }
169 
170  int visual_timer_is_past (VisTimer *self, VisTime *time)
171  {
172  visual_return_val_if_fail (self != nullptr, FALSE);
173 
174  return self->elapsed() > *time;
175  }
176 
177  int visual_timer_is_past2 (VisTimer *self, long sec, long nsec)
178  {
179  visual_return_val_if_fail (self != nullptr, FALSE);
180 
181  return self->elapsed () > LV::Time (sec, nsec);
182  }
183 
184 } // C extern