4 // Fraunhofer Institute for Open Communication Systems (FOKUS)
5 // Competence Center NETwork research (NET), St. Augustin, GERMANY
6 // Thorsten Horstmann <tho@berlios.de>
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.
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.
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.
24 \brief Beeper non-inline non-template implementation */
27 //#include "Beeper.ih"
32 #include <boost/bind.hpp>
33 #include "Exception.hh"
36 ///////////////////////////////cc.p////////////////////////////////////////
38 ///////////////////////////////////////////////////////////////////////////
41 prefix_ senf::Beeper::Beeper(std::string const & device)
42 : timer_( "senf::Beeper::timer", boost::bind(&Beeper::timeout, this), 0, false)
44 if ((fd_ = ::open(device.c_str(), O_WRONLY)) == -1) {
45 SENF_THROW_SYSTEM_EXCEPTION("Could not open device for Beeper.");
49 prefix_ senf::Beeper::~Beeper()
55 prefix_ void senf::Beeper::beep_sync(float freq, unsigned length, unsigned count, unsigned delay)
57 for (unsigned i = 0; i < count; ++i) {
58 if (! start_beep( freq)) return;
59 ::usleep( 1000 * length);
62 ::usleep( 1000 * delay);
66 prefix_ void senf::Beeper::beep_async(float freq, unsigned length, unsigned count, unsigned delay)
68 if (! start_beep( freq)) return;
69 timer_.timeout( senf::ClockService::now() + senf::ClockService::milliseconds(length));
70 params_.action = false; // stop beep
73 params_.length = length;
74 params_.count = count;
75 params_.delay = delay;
79 prefix_ void senf::Beeper::timeout()
82 if (! start_beep( params_.freq)) return;
83 timer_.timeout( senf::ClockService::now() + senf::ClockService::milliseconds(params_.length));
84 params_.action = false;
87 if (--params_.count > 0) {
88 timer_.timeout( senf::ClockService::now() + senf::ClockService::milliseconds(params_.delay));
89 params_.action = true;
94 ///////////////////////////////cc.e////////////////////////////////////////
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