1 #ifndef CONNECTION_H
2 #define CONNECTION_H
3
4 using namespace std;
5
6 #include "mailsystem.h"
7 #include "telephone.h"
8 #include "mailbox.h"
9
10 /**
11 Connects a phone to the voice mail system.
12 The purpose of this class is to keep track
13 of the state of a connection, because the phone
14 itself is only the source of individual key presses.
15 */
16 class Connection
17 {
18 public:
19 /**
20 Construct a Connection object
21 @param s a MailSystemn object
22 @param p a Telephone object
23 */
24 Connection(MailSystem& s, Telephone& p);
25
26 /**
27 Respond to the user's pressing a key
28 on the phone touchpad.
29 @param key the phone key pressed by the user
30 */
31 void dial(string key);
32
33 /**
34 Record voice
35 @param voice voice spoken by the user
36 */
37 void record(string voice);
38
39 /**
40 The user hangs up the phone.
41 */
42 void hangup();
43
44 private:
45 /**
46 Reset the connection to the initial state
47 and prompt for mailbox number
48 */
49 void reset_connection();
50
51 /**
52 Try to connect the user with the specified mailbox
53 @param key the phone key pressed by the user
54 */
55 void connect(string key);
56
57 /**
58 Try to log in the user
59 @param key the phone key pressed by the user
60 */
61 void login(string key);
62
63 /**
64 Change passcode
65 @param key the phone key pressed by the user
66 */
67 void change_passcode(string key);
68
69 /**
70 Change greeting.
71 @param key the phone key presed by the user
72 */
73 void change_greeting(string key);
74
75 /**
76 Respond to the users selection from mailbox menu
77 @param key the phone key pressed by the user
78 */
79 void mailbox_menu(string key);
80
81 /**
82 Respond to the user's selection from message menu
83 @param key the phone key pressed by the user
84 */
85 void message_menu(string key);
86
87 MailSystem& system;
88 Mailbox* current_mailbox;
89 string current_recording;
90 string accumulated_keys;
91 Telephone& phone;
92
93 enum states {DISCONNECTED, CONNECTED, RECORDING,
94 MAILBOX_MENU, MESSAGE_MENU,
95 CHANGE_PASSCODE, CHANGE_GREETING};
96 enum states state;
97
98 const string INITIAL_PROMPT;
99 const string MAILBOX_MENU_TEXT;
100 const string MESSAGE_MENU_TEXT;
101 };
102
103 #endif