forked from MeghnaM/chat-service-protocol
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathresponse_handler.py
More file actions
106 lines (89 loc) · 3.54 KB
/
Copy pathresponse_handler.py
File metadata and controls
106 lines (89 loc) · 3.54 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
"""
CS 544 - Computer Networks
5.29.2017
Group 5: Chat Service Protocol
File: response_handler.py
Members: Ted, Shivam, Meghna, Jeshuran
File summary:
The purpose of this file is to handle the responses coming from the server. The responses first reach the client file
and control is passed to this response_handler file. The ResponseHandler class has the runResponseCodeAction function
which calls the required function based on the response code received from the server.
Almost all of the functions defined in this class just involves printing the payload that has been returned back
from the server
"""
"""ResponseHandler class is used by the client to handle all the incoming responses from the server.
Almost all functions of ResponseHandler would be printing something to notify the client"""
class ResponseHandler:
"""Constructor for ResponseHandler"""
def __init__(self, obj):
self.obj = obj
## STATEFUL - calls a different function to handle each request being sent from a different state ##
"""Calls the associated function of the response code received"""
def runResponseCodeAction(self, resp_code):
if resp_code == "100":
return self.acknowledgeConnectionAction(self.obj)
elif resp_code == "130":
return self.receiveListOfChannelsAction()
elif resp_code == "140":
return self.receiveQueuedMessagesAction()
elif resp_code == "180":
return self.groupJoinedAction()
elif resp_code == "190":
return self.leftGroupAction()
elif resp_code == "191":
return self.banSuccessAction()
elif resp_code == "192":
return self.kickSuccessAction()
elif resp_code == "230":
return self.groupCreationFailedAction()
elif resp_code == "240":
return self.joinGroupFailedAction()
elif resp_code == "250":
return self.banFailedAction()
elif resp_code == "260":
return self.kickFailedAction()
elif resp_code == "330":
return self.incompatibleVersionAction()
"""Prints payload"""
def banSuccessAction(self):
print "****", self.obj.payload, "****"
"""Prints payload"""
def banFailedAction(self):
print "****", self.obj.payload, "****"
"""Prints payload"""
def kickSuccessAction(self):
print "****", self.obj.payload, "****"
"""Prints payload"""
def kickFailedAction(self):
print "****", self.obj.payload, "****"
"""Prints payload"""
def acknowledgeConnectionAction(self, data):
print self.obj.payload
"""Prints list of groups"""
def receiveListOfChannelsAction(self):
print "Choose Group"
chatList = self.obj.payload
for i in range(0, len(chatList)):
print i+1, ":", chatList[i]
"""Prints payload"""
def receiveQueuedMessagesAction(self):
print self.obj.payload
"""Prints payload"""
def groupCreationFailedAction(self):
# print self.obj.payload
pass
"""Prints payload"""
def joinGroupFailedAction(self):
print "****", self.obj.payload, "****"
"""Prints payload"""
def groupJoinedAction(self):
print "****", self.obj.payload, "****"
# , allows next print to be on the same line
print "-> ",
"""Prints payload"""
def leftGroupAction(self):
print "****", self.obj.payload, "****"
print ""
"""Prints payload"""
def incompatibleVersionAction(self):
print "****", self.obj.payload, "****"