summaryrefslogtreecommitdiffstats
path: root/src/ogProcess.py
diff options
context:
space:
mode:
authorAlvaro Neira Ayuso <aneira@soleta.eu>2019-12-16 10:39:08 +0100
committerAlvaro Neira Ayuso <alvaroneay@gmail.com>2020-01-19 19:50:44 +0100
commit77906be87fc67a49cf4a34fd0a03dfb7a10d74ae (patch)
treea378c29ab02681f5e4c88650a488d51100963ac1 /src/ogProcess.py
parent2997952bc97871c140f3724a63a6c7fed6310f57 (diff)
Include disconnect and send function on client side
To disconnect the socket or send a message we use in different parts of the code the attribute socket which is declared inside of the client. This way will create us important problem in the future if we want to change the behavior in our client sockets. This patch adds two new methods inside the client and we can use them in other classes giving us the easy way to send messages and disconnect the client.
Diffstat (limited to 'src/ogProcess.py')
-rw-r--r--src/ogProcess.py31
1 files changed, 17 insertions, 14 deletions
diff --git a/src/ogProcess.py b/src/ogProcess.py
index def76f1..27954a7 100644
--- a/src/ogProcess.py
+++ b/src/ogProcess.py
@@ -7,33 +7,36 @@ if platform.system() == 'Linux':
from src.linux import ogOperations
class ogProcess():
- def processOperation(self, op, URI, sock):
+ def processOperation(self, op, URI, client):
if ("poweroff" in URI):
- sock.send(bytes(ogRest.getResponse(ogRest.ogResponses.IN_PROGRESS), 'utf-8'))
- sock.close()
- self.process_poweroff()
- return 0
+ self.process_poweroff(client)
elif ("reboot" in URI):
- sock.send(bytes(ogRest.getResponse(ogRest.ogResponses.IN_PROGRESS), 'utf-8'))
- sock.close()
- self.process_reboot()
- return 0
+ self.process_reboot(client)
elif ("probe" in URI):
- sock.send(bytes(ogRest.getResponse(ogRest.ogResponses.OK), 'utf-8'))
+ self.process_probe(client)
else:
- sock.send(bytes(ogRest.getResponse(ogRest.ogResponses.BAD_REQUEST), 'utf-8'))
+ client.send(ogRest.getResponse(ogRest.ogResponses.BAD_REQUEST))
- return 1
+ return 0
- def process_reboot(self):
+ def process_reboot(self, client):
# Rebooting thread
def rebt():
ogOperations.reboot()
+
+ client.send(ogRest.getResponse(ogRest.ogResponses.IN_PROGRESS))
+ client.disconnect()
threading.Thread(target=rebt).start()
- def process_poweroff(self):
+ def process_poweroff(self, client):
# Powering off thread
def pwoff():
time.sleep(2)
ogOperations.poweroff()
+
+ client.send(ogRest.getResponse(ogRest.ogResponses.IN_PROGRESS))
+ client.disconnect()
threading.Thread(target=pwoff).start()
+
+ def process_probe(self, client):
+ client.send(ogRest.getResponse(ogRest.ogResponses.OK))