1 |
578 |
markom |
# ----------------------------------------------------------------------
|
2 |
|
|
# PURPOSE: Electrical outlet supplying power for Appliances.
|
3 |
|
|
#
|
4 |
|
|
# AUTHOR: Michael J. McLennan Phone: (610)712-2842
|
5 |
|
|
# AT&T Bell Laboratories E-mail: michael.mclennan@att.com
|
6 |
|
|
#
|
7 |
|
|
# RCS: $Id: Outlet.tcl,v 1.1.1.1 2002-01-16 10:24:47 markom Exp $
|
8 |
|
|
# ----------------------------------------------------------------------
|
9 |
|
|
# Copyright (c) 1993 AT&T Bell Laboratories
|
10 |
|
|
# ======================================================================
|
11 |
|
|
# Permission to use, copy, modify, and distribute this software and its
|
12 |
|
|
# documentation for any purpose and without fee is hereby granted,
|
13 |
|
|
# provided that the above copyright notice appear in all copies and that
|
14 |
|
|
# both that the copyright notice and warranty disclaimer appear in
|
15 |
|
|
# supporting documentation, and that the names of AT&T Bell Laboratories
|
16 |
|
|
# any of their entities not be used in advertising or publicity
|
17 |
|
|
# pertaining to distribution of the software without specific, written
|
18 |
|
|
# prior permission.
|
19 |
|
|
#
|
20 |
|
|
# AT&T disclaims all warranties with regard to this software, including
|
21 |
|
|
# all implied warranties of merchantability and fitness. In no event
|
22 |
|
|
# shall AT&T be liable for any special, indirect or consequential
|
23 |
|
|
# damages or any damages whatsoever resulting from loss of use, data or
|
24 |
|
|
# profits, whether in an action of contract, negligence or other
|
25 |
|
|
# tortuous action, arising out of or in connection with the use or
|
26 |
|
|
# performance of this software.
|
27 |
|
|
# ======================================================================
|
28 |
|
|
|
29 |
|
|
itcl_class Outlet {
|
30 |
|
|
constructor {config} {}
|
31 |
|
|
method config {config} {}
|
32 |
|
|
|
33 |
|
|
destructor {
|
34 |
|
|
if {$usage > 0} bill
|
35 |
|
|
}
|
36 |
|
|
|
37 |
|
|
method use {power} {
|
38 |
|
|
set usage [expr $usage+$power]
|
39 |
|
|
}
|
40 |
|
|
|
41 |
|
|
method sendBill {} {
|
42 |
|
|
if {[catch "open /tmp/bill w" fout] != 0} {
|
43 |
|
|
error "cannot create bill in /tmp"
|
44 |
|
|
} else {
|
45 |
|
|
set amount [format "$%.2f" [expr $usage*$rate]]
|
46 |
|
|
puts $fout "----------------------------------------"
|
47 |
|
|
puts $fout "/////////// MEGA-POWER, INC. ///////////"
|
48 |
|
|
puts $fout "----------------------------------------"
|
49 |
|
|
puts $fout " Customer: $owner"
|
50 |
|
|
puts $fout " Outlet: $this"
|
51 |
|
|
puts $fout " Usage: $usage kilowatt-hours"
|
52 |
|
|
puts $fout " "
|
53 |
|
|
puts $fout " Amount Due: $amount"
|
54 |
|
|
puts $fout "----------------------------------------"
|
55 |
|
|
close $fout
|
56 |
|
|
exec mail $owner < /tmp/bill
|
57 |
|
|
set usage 0
|
58 |
|
|
}
|
59 |
|
|
}
|
60 |
|
|
|
61 |
|
|
proc bill {{customer *}} {
|
62 |
|
|
foreach outlet [itcl_info objects -class Outlet] {
|
63 |
|
|
set owner [$outlet info public owner -value]
|
64 |
|
|
if {[string match $customer $owner]} {
|
65 |
|
|
$outlet sendBill
|
66 |
|
|
}
|
67 |
|
|
}
|
68 |
|
|
}
|
69 |
|
|
|
70 |
|
|
proc rate {{newval ""}} {
|
71 |
|
|
if {$newval == ""} {
|
72 |
|
|
return $rate
|
73 |
|
|
}
|
74 |
|
|
set rate $newval
|
75 |
|
|
}
|
76 |
|
|
|
77 |
|
|
public owner {}
|
78 |
|
|
protected usage 0
|
79 |
|
|
|
80 |
|
|
common rate 0.05
|
81 |
|
|
}
|