00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
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
00066
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
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