072a9d7894020f8a365a3d5184b8f4d53d793d41
[senf.git] / senf / Utils / Beeper.hh
1 // $Id$
2 //
3 // Copyright (C) 2010
4 // Fraunhofer Institute for Open Communication Systems (FOKUS)
5 // Competence Center NETwork research (NET), St. Augustin, GERMANY
6 //     Thorsten Horstmann <tho@berlios.de>
7 //
8 // This program is free software; you can redistribute it and/or modify
9 // it under the terms of the GNU General Public License as published by
10 // the Free Software Foundation; either version 2 of the License, or
11 // (at your option) any later version.
12 //
13 // This program is distributed in the hope that it will be useful,
14 // but WITHOUT ANY WARRANTY; without even the implied warranty of
15 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16 // GNU General Public License for more details.
17 //
18 // You should have received a copy of the GNU General Public License
19 // along with this program; if not, write to the
20 // Free Software Foundation, Inc.,
21 // 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
22
23 /** \file
24     \brief Beeper public header */
25
26 #ifndef HH_SENF_Utils_Beeper_
27 #define HH_SENF_Utils_Beeper_ 1
28
29 // Custom includes
30 #include <string>
31 #include <senf/Scheduler/TimerEvent.hh>
32
33 ///////////////////////////////hh.p////////////////////////////////////////
34
35 namespace senf {
36
37     /** \brief Helper class to beep the pc speaker
38
39         This helper class allows you to beep the pc speaker with precision like frequency and
40         duration. The beep can be played synchronous and asynchronous.
41
42         Typically the <tt>/dev/console</tt> device is used to control the local pc
43         speaker. Note, that opening <tt>/dev/console</tt> is a privileged operation on
44         most systems.
45
46         \see manual page console_ioctl(4) for the according ioctl <tt>KIOCSOUND</tt>
47       */
48     class Beeper
49     {
50     public:
51         Beeper(std::string const & device = "/dev/console");
52                                         ///< Construct a new Beeper for the given device.
53         ~Beeper();
54
55         void beep_sync(float freq, unsigned length, unsigned count = 1, unsigned delay = 100);
56                                         ///< play beep synchronous
57                                         /**< \param freq frequency in Hz, where 0 < \e freq < 20000.
58                                                  The regular terminal beep is around 750Hz.
59                                              \param length duration in milliseconds.
60                                              \param count number of repetitions (defaults to 1).
61                                              \param delay delay between repetitions in milliseconds. */
62         void beep_async(float freq, unsigned length, unsigned count = 1, unsigned delay = 100);
63                                         ///< play beep asynchronous
64                                         /**< \param freq frequency in Hz, where 0 < \e freq < 20000.
65                                                  The regular terminal beep is around 750Hz.
66                                              \param length duration in milliseconds.
67                                              \param count number of repetitions (defaults to 1).
68                                              \param delay delay between repetitions in milliseconds. */
69
70         void stop_beep();               ///< stop playing.
71         bool start_beep(float freq);    ///< start playing.
72                                         /**< start playing until any other member is called.
73                                              \param freq frequency in Hz, where 0 < \e freq < 20000.
74                                              \returns \a true on success.*/
75
76     private:
77         static const unsigned CLOCK_TICK_RATE = 1193180;
78
79         int fd_;
80         scheduler::TimerEvent timer_;
81
82 #ifndef DOXYGEN
83         struct {
84             float freq;
85             unsigned length;
86             unsigned count;
87             unsigned delay;
88             bool action;
89         } params_;
90 #endif
91
92         void timeout();
93     };
94
95 }
96
97 ///////////////////////////////hh.e////////////////////////////////////////
98 #include "Beeper.cci"
99 //#include "Beeper.ct"
100 //#include "Beeper.cti"
101 #endif
102
103 \f
104 // Local Variables:
105 // mode: c++
106 // fill-column: 100
107 // c-file-style: "senf"
108 // indent-tabs-mode: nil
109 // ispell-local-dictionary: "american"
110 // compile-command: "scons -u test"
111 // comment-column: 40
112 // End: