Search:

SENF Extensible Network Framework

  • Home
  • Download
  • Wiki
  • BerliOS
  • ChangeLog
  • Browse SVN
  • Bug Tracker
  • Overview
  • Examples
  • HowTos
  • Glossary
  • PPI
  • Packets
  • Scheduler
  • Socket
  • Utils
  • Console
  • Daemon
  • Logger
  • Termlib
  • Main Page
  • Related Pages
  • Modules
  • Namespaces
  • Classes
  • Files
  • File List
  • File Members

Beeper.cc

Go to the documentation of this file.
00001 // $Id: Beeper.cc 1742 2010-11-04 14:51:56Z g0dil $
00002 //
00003 // Copyright (C) 2010
00004 // Fraunhofer (FOKUS)
00005 // Competence Center NETwork research (NET), St. Augustin, GERMANY
00006 //     Thorsten Horstmann <tho@berlios.de>
00007 //
00008 // This program is free software; you can redistribute it and/or modify
00009 // it under the terms of the GNU General Public License as published by
00010 // the Free Software Foundation; either version 2 of the License, or
00011 // (at your option) any later version.
00012 //
00013 // This program is distributed in the hope that it will be useful,
00014 // but WITHOUT ANY WARRANTY; without even the implied warranty of
00015 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00016 // GNU General Public License for more details.
00017 //
00018 // You should have received a copy of the GNU General Public License
00019 // along with this program; if not, write to the
00020 // Free Software Foundation, Inc.,
00021 // 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
00022 
00026 #include "Beeper.hh"
00027 //#include "Beeper.ih"
00028 
00029 // Custom includes
00030 #include <unistd.h>
00031 #include <fcntl.h>
00032 #include <boost/bind.hpp>
00033 #include "Exception.hh"
00034 
00035 #define prefix_
00036 //-/////////////////////////////////////////////////////////////////////////////////////////////////
00037 
00038 //-/////////////////////////////////////////////////////////////////////////////////////////////////
00039 // senf::Beeper
00040 
00041 prefix_ senf::Beeper::Beeper(std::string const & device)
00042     : timer_( "senf::Beeper::timer", boost::bind(&Beeper::timeout, this), 0, false)
00043 {
00044     if ((fd_ = ::open(device.c_str(), O_WRONLY)) == -1) {
00045         SENF_THROW_SYSTEM_EXCEPTION("Could not open device for Beeper.");
00046     }
00047 }
00048 
00049 prefix_ senf::Beeper::~Beeper()
00050 {
00051     stop_beep();
00052     ::close(fd_);
00053 }
00054 
00055 prefix_ void senf::Beeper::beep_sync(float freq, unsigned length, unsigned count, unsigned delay)
00056 {
00057     for (unsigned i = 0; i < count; ++i) {
00058         if (! start_beep( freq)) return;
00059         ::usleep( 1000 * length);
00060         stop_beep();
00061         if ( i+1 < count)
00062            ::usleep( 1000 * delay);
00063     }
00064 }
00065 
00066 prefix_ void senf::Beeper::beep_async(float freq, unsigned length, unsigned count, unsigned delay)
00067 {
00068     if (! start_beep( freq)) return;
00069     timer_.timeout( senf::ClockService::now() + senf::ClockService::milliseconds(length));
00070     params_.action = false;  // stop beep
00071     if (count > 1) {
00072         params_.freq = freq;
00073         params_.length = length;
00074         params_.count = count;
00075         params_.delay = delay;
00076     }
00077 }
00078 
00079 prefix_ void senf::Beeper::timeout()
00080 {
00081     if (params_.action) {
00082         if (! start_beep( params_.freq)) return;
00083         timer_.timeout( senf::ClockService::now() + senf::ClockService::milliseconds(params_.length));
00084         params_.action = false;
00085     } else {
00086         stop_beep();
00087         if (--params_.count > 0) {
00088             timer_.timeout( senf::ClockService::now() + senf::ClockService::milliseconds(params_.delay));
00089             params_.action = true;
00090         }
00091     }
00092 }
00093 
00094 //-/////////////////////////////////////////////////////////////////////////////////////////////////
00095 #undef prefix_
00096 
00097 
00098 // Local Variables:
00099 // mode: c++
00100 // fill-column: 100
00101 // c-file-style: "senf"
00102 // indent-tabs-mode: nil
00103 // ispell-local-dictionary: "american"
00104 // compile-command: "scons -u test"
00105 // comment-column: 40
00106 // End:

Contact: senf-dev@lists.berlios.de | © 2006-2010 Fraunhofer Institute for Open Communication Systems, Network Research