Fix documentation build under maverick (doxygen 1.7.1)
[senf.git] / senf / Utils / Beeper.cc
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 non-inline non-template implementation */
25
26 #include "Beeper.hh"
27 //#include "Beeper.ih"
28
29 // Custom includes
30 #include <unistd.h>
31 #include <fcntl.h>
32 #include <boost/bind.hpp>
33 #include "Exception.hh"
34
35 #define prefix_
36 //-/////////////////////////////////////////////////////////////////////////////////////////////////
37
38 //-/////////////////////////////////////////////////////////////////////////////////////////////////
39 // senf::Beeper
40
41 prefix_ senf::Beeper::Beeper(std::string const & device)
42     : timer_( "senf::Beeper::timer", boost::bind(&Beeper::timeout, this), 0, false)
43 {
44     if ((fd_ = ::open(device.c_str(), O_WRONLY)) == -1) {
45         SENF_THROW_SYSTEM_EXCEPTION("Could not open device for Beeper.");
46     }
47 }
48
49 prefix_ senf::Beeper::~Beeper()
50 {
51     stop_beep();
52     ::close(fd_);
53 }
54
55 prefix_ void senf::Beeper::beep_sync(float freq, unsigned length, unsigned count, unsigned delay)
56 {
57     for (unsigned i = 0; i < count; ++i) {
58         if (! start_beep( freq)) return;
59         ::usleep( 1000 * length);
60         stop_beep();
61         if ( i+1 < count)
62            ::usleep( 1000 * delay);
63     }
64 }
65
66 prefix_ void senf::Beeper::beep_async(float freq, unsigned length, unsigned count, unsigned delay)
67 {
68     if (! start_beep( freq)) return;
69     timer_.timeout( senf::ClockService::now() + senf::ClockService::milliseconds(length));
70     params_.action = false;  // stop beep
71     if (count > 1) {
72         params_.freq = freq;
73         params_.length = length;
74         params_.count = count;
75         params_.delay = delay;
76     }
77 }
78
79 prefix_ void senf::Beeper::timeout()
80 {
81     if (params_.action) {
82         if (! start_beep( params_.freq)) return;
83         timer_.timeout( senf::ClockService::now() + senf::ClockService::milliseconds(params_.length));
84         params_.action = false;
85     } else {
86         stop_beep();
87         if (--params_.count > 0) {
88             timer_.timeout( senf::ClockService::now() + senf::ClockService::milliseconds(params_.delay));
89             params_.action = true;
90         }
91     }
92 }
93
94 //-/////////////////////////////////////////////////////////////////////////////////////////////////
95 #undef prefix_
96
97 \f
98 // Local Variables:
99 // mode: c++
100 // fill-column: 100
101 // c-file-style: "senf"
102 // indent-tabs-mode: nil
103 // ispell-local-dictionary: "american"
104 // compile-command: "scons -u test"
105 // comment-column: 40
106 // End: