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 TypeInfo non-inline non-template implementation */
27 //#include "Beeper.ih"
31 #include <sys/ioctl.h>
34 #include <boost/bind.hpp>
35 #include "Exception.hh"
38 ///////////////////////////////cc.p////////////////////////////////////////
40 ///////////////////////////////////////////////////////////////////////////
43 prefix_ senf::Beeper::Beeper(std::string const & device)
44 : timer_( "senf::Beeper::timer", boost::bind(&Beeper::timeout, this), 0, false)
46 if ((fd_ = ::open(device.c_str(), O_WRONLY)) == -1) {
47 SENF_THROW_SYSTEM_EXCEPTION("Could not open device for Beeper.");
51 prefix_ senf::Beeper::~Beeper()
57 prefix_ bool senf::Beeper::start_beep(float freq)
59 return ::ioctl(fd_, KIOCSOUND, (int)(CLOCK_TICK_RATE/freq)) == 0;
62 prefix_ void senf::Beeper::stop_beep()
64 ::ioctl(fd_, KIOCSOUND, 0);
67 prefix_ void senf::Beeper::beep_sync(float freq, unsigned length, unsigned count, unsigned delay)
69 for (unsigned i = 0; i < count; ++i) {
70 if (! start_beep( freq)) return;
71 ::usleep( 1000 * length);
74 ::usleep( 1000 * delay);
78 prefix_ void senf::Beeper::beep_async(float freq, unsigned length, unsigned count, unsigned delay)
80 if (! start_beep( freq)) return;
81 timer_.timeout( senf::ClockService::now() + senf::ClockService::milliseconds(length));
82 params_.action = false; // stop beep
85 params_.length = length;
86 params_.count = count;
87 params_.delay = delay;
91 prefix_ void senf::Beeper::timeout()
94 if (! start_beep( params_.freq)) return;
95 timer_.timeout( senf::ClockService::now() + senf::ClockService::milliseconds(params_.length));
96 params_.action = false;
99 if (--params_.count > 0) {
100 timer_.timeout( senf::ClockService::now() + senf::ClockService::milliseconds(params_.delay));
101 params_.action = true;
106 ///////////////////////////////cc.e////////////////////////////////////////
113 // c-file-style: "senf"
114 // indent-tabs-mode: nil
115 // ispell-local-dictionary: "american"
116 // compile-command: "scons -u test"
117 // comment-column: 40