Пример #1
0
	def prepare_response(self,req):
		# Eventually, this wil parse the request and create a valid 
		# response.  For now, it will jsut respond with the default 
		# packet

		resp = {
				"source":"command_center",
				"message":"OK"
				}

		if resp["messsage"] != None:
			self.write_buffer += libcc.json_to_pkt(resp)
Пример #2
0
	def handle_write(self):
		# Check the Websockets for pending messages
		ws = self.db["websockets"]
		for key in ws:
			# Check if the Websocket is not empty
			if len(ws[key].inbox) > 0:
				# Create a Response object
				resp = {
					"source":"command_center",
					"message":ws[key].recv_msg()
				}
				# Add it to the Write Buffer
				self.write_buffer += libcc.json_to_pkt(resp)
	
		# Send a chunk of data from the write buffer
		sent = self.send(self.write_buffer)
		# Clear the data the was sent from the buffer
		self.write_buffer[sent:]
Пример #3
0
    def handle_write(self):
        # Check the Websockets for pending messages
        ws = self.db["websockets"]
        for key in ws:
            # Check if the Websocket is not empty
            if len(ws[key].inbox) > 0:
                # Create a Response object
                resp = {
                    "source": "command_center",
                    "message": ws[key].recv_msg()
                }
                # Add it to the Write Buffer
                self.write_buffer += libcc.json_to_pkt(resp)

        # Send a chunk of data from the write buffer
        sent = self.send(self.write_buffer)
        # Clear the data the was sent from the buffer
        self.write_buffer[sent:]
Пример #4
0
	def prepare_response(self,req):
		# Setup a default response object. "OK" is the default response
		# if there is no error with the daemon update.
		resp = {
			"source":"command_center",
			"message":"OK"
			}

		#------------------------------------------------
		# Analyze the Request Message and Create Response
		#------------------------------------------------
		# Check if a source is not given
		if "source" not in req:
			resp["message"] = "Error: Source Field not Provided"
		
		# If the request if from the device discoverer daemon
		elif req["source"] == "discoverer":
			self.handle_discoverer(req,resp)
			
		# If the request is from the Media Converter (transcoder)
		elif req["source"] == "converter":
			self.handle_converter(req,resp)

		# If the request is coming from one of the user interfaces
		elif req["source"] in ["cli","webui"]:
			self.handle_user(req,resp)
				
		# If the request is coming from the Filesystem scanner
		elif req["source"] == "scanner":
			self.handle_scanner(req,resp)

		#  If the source is something else, return an error
		else:
			resp["message"] = "Source is invalid"

		#----------------------
		# Send Response Message
		#----------------------
		# If a message was given, respond. 
		if resp["message"] != None:
			self.write_buffer += libcc.json_to_pkt(resp)
Пример #5
0
    def prepare_response(self, req):
        # Setup a default response object. "OK" is the default response
        # if there is no error with the daemon update.
        resp = {"source": "command_center", "message": "OK"}

        #------------------------------------------------
        # Analyze the Request Message and Create Response
        #------------------------------------------------
        # Check if a source is not given
        if "source" not in req:
            resp["message"] = "Error: Source Field not Provided"

        # If the request if from the device discoverer daemon
        elif req["source"] == "discoverer":
            self.handle_discoverer(req, resp)

        # If the request is from the Media Converter (transcoder)
        elif req["source"] == "converter":
            self.handle_converter(req, resp)

        # If the request is coming from one of the user interfaces
        elif req["source"] in ["cli", "webui"]:
            self.handle_user(req, resp)

        # If the request is coming from the Filesystem scanner
        elif req["source"] == "scanner":
            self.handle_scanner(req, resp)

        #  If the source is something else, return an error
        else:
            resp["message"] = "Source is invalid"

        #----------------------
        # Send Response Message
        #----------------------
        # If a message was given, respond.
        if resp["message"] != None:
            self.write_buffer += libcc.json_to_pkt(resp)