Browse Source

UPD: bump to version 1.9.7 Engine

Giancarlo Voci 7 years ago
parent
commit
85774bd3d9

+ 1 - 1
cfg/config.bin

@@ -1 +1 @@
-eJyFUVtv2jAUfvevsHjaNDVxCNBuyNJCMJA2xCgXxFahKAQDURObOQ69IP77TMa0x1mydHR0Pn23530pNllZr8GShJFHA2wZfQMBJ4mpT50x7tQyNzvAddwZgRjGYUJA4uGmMHdScMX41gRjMkqmuAtI4NKxF0xxJ4kndw8dMPOmM1//GO80BwOPTmiwt2MhGT6fVVGxT5+/2FbfHiCELhcwjgLcqd7rX+W3g6gVLkWelddpeBRSYdtGg+F2w7OKYVGVBX/pgO2mqZnEUgil52NW11gcGa8KvgVzZ5WOfC94SmNvTtKIuNhGqF2HJA5/pBMaphMn8WNsIW1iiZVsGABDuMjUAYyciCShj80/XCDyYhI4c4Lp/M6/Lnw6pambRDGdk1Ab+n5DXC6m1sFUbRZVtme1WYq9MI58DzyXBukVlsT/u29Ui9BiIlayXMHXQ5EfYN7USlRMwrzUGMh4tikZ+CuilXeTC55dGhJjt1lfDUmxbXJVCA7aZK2vXcMaPBgWMqweAm28fdTr2S2fPGmCmEQxeGHv2EX/nmX17nuoa6P+PWjD/in3Hy+nR0mfeBC5fMGnH3ZzdgZsFgWr5akGWsfEC8YjuopIuPRcsgaRT8jiWommRC1hLvi2hkrA16xQcCck1HHAnS5xI970LE9FziAXCmanrChbz9PQcUm6IKFHx7duwW+0weDZ
+eJyFkV9v2jAUxd/vp4jytGlq4hCg3ZClhWAgbYhR/iC2CkUhGIia2Cxx2FrEd5/JOu1xlixdXfno/M7x86EU26xsNrAiYeTRAFvGwEDgJDH1qTPBelPnpg6u486JhrU4TAgkHm4Lc18LLhnfmTAh42SGe0ACl068YIb1JJ7ePegw92ZzX90Y75UHg0cnNNivU1EzfLnIomIfPn6yrYE9RAhdrzCJAqxXr82P8stRNBKXIs/K2zQ6iVpi20bD0W7Ls4phUZUFf9Fht20bVuNaCKnmU9Y0WJwYrwq+g4WzTse+FzylsbcgaURcbCPUrUMSh9/SKQ3TqZP4MbaQCrHCsm4ZwEhbZvIIYyciSehj848XRF5MAmdBMF3c+beFT2c0dZMopgsSqkBf3xXXq6k4mGzMosoOrDFLcRDGiR/Ac2mQ3mRJ/L/3rewUCiZiJcul9vNY5EctbxspKlZreak0GuPZtmTwF6LDe8eFZ5eGxNhvN7dAtdi1uSwEh65Z63PPsIYPhoUMq4+gq3eA+n2786vPyiAmUQwv7BW76N+xrP59H/VsNLiHruzv9eHt5fxY0yceRC5f8tmb3V6cIZtHwXp1bkBxTL1gMqbriIQrzyUbiHxClrcvUZYIljRU/ffsPvwGWErJmw==

+ 1 - 1
package.json

@@ -1,6 +1,6 @@
 {
 	"name": "OM-Link",
-	"version": "1.9.5",
+	"version": "1.9.7",
 	"private": true,
 	"description": "OM-Link Engine",
 	"author": "Open Mind",

+ 10 - 0
src/OpenMind/Admin/Pages.php

@@ -143,6 +143,16 @@ class Pages extends Controller
 					"err" => 0,
 					"value" => "{$configOBJ->labelid} unbind successfull"
 				]);
+				break;
+
+			case 'resetfailcounter':
+				$URI = "/1.0.0/index.php/smartesl.resetfailcounter/1.0.0/[[\"{$configOBJ->labelid}\"]]";
+				$this->findBoxCore->CallAPI($URI, "");
+
+				echo json_encode([
+					"err" => 0,
+					"value" => "{$configOBJ->labelid} Reset Fail Counter successfull"
+				]);
 
 				break;
 		}

+ 15 - 30
src/OpenMind/FindBox/FindBoxService.php

@@ -21,6 +21,7 @@ class FindBoxService
 	private $findBoxCore = null;
 	private $labelToBlink;
 	private $ServiceLogger;
+	private $qs_Server;
 
 	public function __construct()
 	{
@@ -37,6 +38,10 @@ class FindBoxService
 				sleep(1);
 			}
 		$this->labelToBlink = [];
+
+		$this->qs_Server = new QueueSystem();
+
+		$this->qs_Server->CreateService();
 	}
 
 	/**
@@ -47,17 +52,16 @@ class FindBoxService
 	public function Main($f3)
 	{
 		$this->ServiceLogger->write("Starting FindBoxService main loop", 'd/m/Y H:i:s');
+		$this->ServiceLogger->write("Opening socket listen {$f3->get('FINDBOXSERVICE.PORT')}", 'd/m/Y H:i:s');
 
 		while (true) {
 
-			$this->updateServiceStatus();
-
 			$this->getCurrentQueue();
 
 			foreach($this->labelToBlink as $labelId => &$label) {
 				switch ($label->operation) {
 
-					case Q_BLINK_OFF:
+					case QueueCommand::$Q_BLINK_OFF:
 						$this->ServiceLogger->write("BlinkOff for label {$label->id} requested", 'd/m/Y H:i:s');
 
 						$esl = new SmartESL($this->findBoxCore, [$label->id]);
@@ -68,7 +72,7 @@ class FindBoxService
 
 						break;
 
-					case Q_BLINK_ON:
+					case QueueCommand::$Q_BLINK_ON:
 						// Priority 1
 						// ----------
 						// Force exit and blink off if run time script > MAX_BLINK_TIME_SEC
@@ -101,53 +105,34 @@ class FindBoxService
 						break;
 				}
 			}
-
-			usleep($f3->get('FINDBOXSERVICE.SLEEPTIME') * 1000);
 		}
 
 		return;
 	}
 
-	private function updateServiceStatus()
-	{
-		$qs = new QueueSystem('FindBoxService_isAlive');
-		if ($qs->check()) {
-			$qs->reset();
-			$qs->command = time();
-			$qs->servicename = 'FindBoxService_isAlive';
-			$qs->save();
-		} else {
-			$qs->command = time();
-		}
-		$qs->update();
-	}
-
 	private function getCurrentQueue()
 	{
 		global $f3;
-		$table = new QueueSystem('FindBoxService');
-		while (!$table->check()) {
+
+		if ($this->qs_Server->check()) {
 
 			/** @var QueueCommand $qCommand */
-			$qCommand = $table->getCommandObject();
+			$qCommand = $this->qs_Server->getCommandObject();
 			switch ($qCommand->operation) {
-				case Q_SAVEPRODUCT:
+				case QueueCommand::$Q_SAVEPRODUCT:
 					$this->saveProduct($qCommand);
 					break;
-				case Q_BLINK_ON:
-				case Q_BLINK_OFF:
+				case QueueCommand::$Q_BLINK_ON:
+				case QueueCommand::$Q_BLINK_OFF:
 					$this->labelToBlink[$qCommand->id] = $qCommand;
 					$this->labelToBlink[$qCommand->id]->retryForFault = $f3->get('MAX_RETRY_FOR_FAULT');
 					break;
-				case Q_DISPLAY:
+				case QueueCommand::$Q_DISPLAY:
 					$this->ServiceLogger->write("Change display for label {$qCommand->id} requested", 'd/m/Y H:i:s');
 					$esl = new SmartESL($this->findBoxCore, [$qCommand->id]);
 					$esl->Display($qCommand->params['templateId'], $qCommand->params['barcode']);
 					break;
 			}
-
-			$table->erase();
-			$table->next();
 		}
 	}
 

+ 9 - 9
src/OpenMind/FindBox/QueueCommand.php

@@ -8,11 +8,6 @@
 
 namespace OpenMind\FindBox;
 
-define('Q_BLINK_ON', 1);
-define('Q_BLINK_OFF', 2);
-define('Q_SAVEPRODUCT', 3);
-define('Q_DISPLAY', 4);
-
 class QueueCommand
 {
 	public $id;
@@ -22,6 +17,11 @@ class QueueCommand
 	public $tsFirstBlink;
 	public $tsLastLongBlink;
 
+	static public $Q_BLINK_ON = 1;
+	static public $Q_BLINK_OFF = 2;
+	static public $Q_SAVEPRODUCT = 3;
+	static public $Q_DISPLAY =4;
+
 	public function __construct(string $labelID)
 	{
 		$this->id = $labelID;
@@ -54,7 +54,7 @@ class QueueCommand
 
 	public function setLeds(int $pattern, int $repeat, int $iter_time, int $iterations, int $color)
 	{
-		$this->operation = Q_BLINK_ON;
+		$this->operation = self::$Q_BLINK_ON;
 		list(
 			$this->params['pattern'],
 			$this->params['repeat'],
@@ -66,14 +66,14 @@ class QueueCommand
 
 	public function saveProducts(string $description, array $dataFields)
 	{
-		$this->operation = Q_SAVEPRODUCT;
+		$this->operation = self::$Q_SAVEPRODUCT;
 		$this->description = $description;
 		$this->params['dataFields'] = $dataFields;
 	}
 
 	public function setToBlinkOff()
 	{
-		$this->operation = Q_BLINK_OFF;
+		$this->operation = self::$Q_BLINK_OFF;
 	}
 
 	/**
@@ -94,7 +94,7 @@ class QueueCommand
 	 */
 	public function setDisplay(string $templateId, string $barcode)
 	{
-		$this->operation = Q_DISPLAY;
+		$this->operation = self::$Q_DISPLAY;
 		list(
 			$this->params['templateId'],
 			$this->params['barcode']

+ 43 - 26
src/OpenMind/System/QueueSystem.php

@@ -1,6 +1,6 @@
 <?php
 /**
- * Created by PhpStorm.
+ * Created by PhpStorm..
  * User: Giancarlo
  * Date: 09/08/2018
  * Time: 11:27
@@ -8,24 +8,22 @@
 
 namespace OpenMind\System;
 
-use DB\SQL\Mapper;
-
-class QueueSystem extends Mapper
+class QueueSystem
 {
-	private $f3;
-	private $serviceName;
-
 	// Used internally
-	private $initLoad;
+	private $sckFindBoxService;
+	private $serverPort;
 
-	public function __construct(string $serviceName)
+	public function __construct()
 	{
 		global $f3;
-		$this->f3 = $f3;
-
-		parent::__construct($f3->get('DB'), 'queuesystem');
+		$this->serverPort = $f3->get('FINDBOXSERVICE.PORT');
+	}
 
-		$this->serviceName = $serviceName;
+	public function CreateService()
+	{
+		$this->sckFindBoxService = @socket_create_listen($this->serverPort);
+		socket_set_nonblock($this->sckFindBoxService);
 	}
 
 	/**
@@ -33,14 +31,21 @@ class QueueSystem extends Mapper
 	 * send() serialize $obj before send to queue
 	 *
 	 * @param $obj
+	 * @return bool true = connection successful
 	 */
 	public function send($obj)
 	{
 		$serializedObject = serialize($obj);
-		$this->reset();
-		$this->servicename = $this->serviceName;
-		$this->command = base64_encode($serializedObject);
-		$this->save();
+		$command = base64_encode($serializedObject);
+
+		$socket = socket_create(AF_INET, SOCK_STREAM, SOL_TCP);
+
+		if ($connectOK = @socket_connect($socket, 'localhost', $this->serverPort))
+			socket_write($socket, $command, strlen($command));
+
+		socket_close($socket);
+
+		return $connectOK;
 	}
 
 	/**
@@ -50,7 +55,7 @@ class QueueSystem extends Mapper
 	 */
 	public function getCommandObject()
 	{
-		$decodedObj = base64_decode($this->command);
+		$decodedObj = base64_decode($this->clientRead);
 		$obj = unserialize($decodedObj);
 		return $obj;
 	}
@@ -62,20 +67,32 @@ class QueueSystem extends Mapper
 	 */
 	public function check()
 	{
-		if (!$this->initLoad) {
-			$this->initLoad = true;
-			$this->load(['servicename=?', $this->serviceName]);
+		$client = $this->SocketClientAccept($this->sckFindBoxService);
+		if ($client) {
+			$this->clientRead = socket_read($client, 1000);
+			socket_close($client);
+			return true;
 		}
-		return $this->dry();
+		return false;
 	}
 
 	/**
-	 * Delete all messages of <$serviceName>
+	 * Check if client connected and send data else return NULL
+	 *
+	 * @param $serverSocket
+	 * @return mixed|null
 	 */
-	public function deleteAll()
+	private function SocketClientAccept($serverSocket)
 	{
-		$this->reset();
-		$this->erase(['servicename=?', $this->serviceName]);
+		$null = NULL;
+		$read = [$serverSocket];
+		$which = socket_select($read, $null, $null, 0, 5);
+
+		if ($which == 0)
+			return NULL;
+
+		$whichSocket = $read[$which - 1];
+		return socket_accept($whichSocket);
 	}
 
 }

+ 7 - 10
src/OpenMind/System/System.php

@@ -96,16 +96,13 @@ class System extends PluginStrategy
 	 */
 	public function getServerStatus($f3)
 	{
-		$qs = new QueueSystem('FindBoxService_isAlive');
-		if (!$qs->check()) {
-			$lastUpdate = time() - $qs->command;
-			if ($lastUpdate > $f3->get('FINDBOXSERVICE.GRACE_PERIOD_SEC')) {
-				$omlNotifications = new Notifications();
-				$omlNotifications->notify(Notifications::FB_NOTALIVE, 'Errore: Servizio di FindBox non disponibile');
-			} else {
-				$omlNotifications = new Notifications();
-				$omlNotifications->Remove(Notifications::FB_NOTALIVE);
-			}
+		$qs = new QueueSystem();
+		if (!$qs->send('')) {
+			$omlNotifications = new Notifications();
+			$omlNotifications->notify(Notifications::FB_NOTALIVE, 'Errore: Servizio di FindBox non disponibile');
+		} else {
+			$omlNotifications = new Notifications();
+			$omlNotifications->Remove(Notifications::FB_NOTALIVE);
 		}
 
 		$ret = [];

+ 1 - 1
ui/admin/assets/js/admin.js

@@ -36,7 +36,7 @@ function ESLMultiOperations(method) {
 
 		OMGUtils.AjaxReq(`${BASEURL}/admin/config`, {
 			method: 'POST',
-			body: JSON.stringify({"method": "blinklabels", "labelid": labelID[1]})
+			body: JSON.stringify({"method": method, "labelid": labelID[1]})
 		})
 			.then(json => {
 				if (json.err == 0)

+ 1 - 1
ui/admin/labelstatus.tpl

@@ -6,7 +6,7 @@
 			</a>
 			<div class="dropdown-menu dropdown-menu-right">
 				<!-- item-->
-				<a href="javascript:void(0);" class="dropdown-item">Refresh Status</a>
+				<a href="javascript:ESLMultiOperations('resetfailcounter');" class="dropdown-item">Reset Fail Counter</a>
 				<!-- item-->
 				<a href="javascript:ESLMultiOperations('blinklabels')" class="dropdown-item">Blink</a>
 				<!-- item-->