Main Page   Namespace List   Class Hierarchy   Compound List   File List   Compound Members  

pcbell.cpp

Go to the documentation of this file.
00001 // $Id
00002 
00003 //**********************************************************************
00004 //                                                                     *
00005 //    Description:   'Bell Master' implementation of block instrument  *
00006 //                   bell using PC (hardware to produce actual ring    *
00007 //                   abstracted by 'Note' class).                      *
00008 //                                                                     *
00009 //    Author:        Chris White (whitecf@bcs.org.uk)                  *
00010 //                                                                     *
00011 //    Copyright (C) 2003  Monitor Computing Services Ltd.              *
00012 //                                                                     *
00013 //    This program is free software; you can redistribute it and/or    *
00014 //    modify it under the terms of the GNU General Public License      *
00015 //    as published by the Free Software Foundation; either version 2   *
00016 //    of the License, or any later version.                            *
00017 //                                                                     *
00018 //    This program is distributed in the hope that it will be useful,  *
00019 //    but WITHOUT ANY WARRANTY; without even the implied warranty of   *
00020 //    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the    *
00021 //    GNU General Public License for more details.                     *
00022 //                                                                     *
00023 //    You should have received a copy of the GNU General Public        *
00024 //    License (http://www.gnu.org/copyleft/gpl.html) along with this   *
00025 //    program; if not, write to:                                       *
00026 //       The Free Software Foundation Inc.,                            *
00027 //       59 Temple Place - Suite 330,                                  *
00028 //       Boston, MA  02111-1307,                                       *
00029 //       USA.                                                          *
00030 //                                                                     *
00031 //**********************************************************************
00032 //                                                                     *
00033 //    Notes:                                                           *
00034 //                                                                     *
00035 //**********************************************************************
00036 
00037 
00038 #include <callback.h>
00039 #include "mytrace.h"
00040 #include <note.h>
00041 #include "timeout.h"
00042 
00043 #include "pcbell.h"
00044 
00045 
00046 
00047 using namespace Monitor::BellMaster;
00048 namespace Ut = Monitor::Utility;
00049 
00050 
00051 
00052 PcBell::PcBell(Ut::Note&    newNote) :
00053     currentSequence(0), note(newNote)
00054 {
00055     _USEMYTRACE_("PcBell::PcBell(newNote)")
00056 }
00057 
00058 
00059 
00060 PcBell::~PcBell()
00061 {
00062     _USEMYTRACE_("PcBell::~PcBell()")
00063 
00064 
00065     // Deletion shouldn't happen during ringing of a sequence but just in case
00066     // ensure things are tidied up.
00067     delete [] currentSequence, currentSequence = 0;
00068 }
00069 
00070 
00071 
00072 void
00073 PcBell::ring() const
00074 throw (Bell::Busy)
00075 {
00076     _USEMYTRACE_("PcBell::ring()")
00077 
00078 
00079     try
00080     {
00081         note.sound();
00082 
00083         Bell::ring();
00084     }
00085     catch (Ut::Note::Busy&    ex)
00086     {
00087         throw Busy();
00088     }
00089 }
00090 
00091 
00092 
00093 void
00094 PcBell::ring(unsigned*    newSequence)
00095 throw (Bell::Busy)
00096 {
00097     _USEMYTRACE_("Bell::ring(newSequence)")
00098 
00099 
00100     if (0 != currentSequence)
00101     {
00102         throw Busy();
00103     }
00104     else
00105     {
00106         currentSequence = newSequence;
00107 
00108         nextRing();
00109     }
00110 }
00111 
00112 
00113 
00114 Ut::Note&
00115 PcBell::getNote() const
00116 {
00117     _USEMYTRACE_("Bell::getNote()")
00118 
00119 
00120     return note;
00121 }
00122 
00123 
00124 
00125 void
00126 PcBell::nextRing()
00127 {
00128     _USEMYTRACE_("PcBell::nextRing")
00129 
00130 
00131     if (0 != currentSequence)
00132     {
00133         ring();
00134 
00135         if (0 < *currentSequence)
00136         {
00137             // Pause between rings
00138             new Ut::Timeout(Ut::Callback< PcBell >(*this, &PcBell::nextRing),
00139                             *currentSequence,
00140                             "next ring");
00141 
00142             ++currentSequence;
00143         }
00144         else
00145         {
00146             delete [] currentSequence, currentSequence = 0;
00147         }
00148     }
00149 }
00150 

Generated on Wed Oct 29 20:54:52 2003 for Bellmaster BC Common by doxygen1.2.14 written by Dimitri van Heesch, © 1997-2002