81 lines
2.3 KiB
PHP
81 lines
2.3 KiB
PHP
<?php
|
|
class hook
|
|
{
|
|
public $hookName = "";
|
|
public $active = true;
|
|
public $initialized = false;
|
|
protected $devicelist;
|
|
protected $propertyInitialized;
|
|
|
|
// list of devices we are listening to
|
|
function __construct()
|
|
{
|
|
logger(INFO, _("Initializing hook: ") . $this->hookName);
|
|
//$this->installHooks();
|
|
foreach ($this->devicelist as $ieeeAddress => $property)
|
|
{
|
|
$this->propertyInitialized[$ieeeAddress][$property] = false;
|
|
}
|
|
if (method_exists($this, "init"))
|
|
{
|
|
$this->init();
|
|
}
|
|
}
|
|
|
|
function installHooks(&$indexDevices)
|
|
{
|
|
global $devices;
|
|
$result = true;
|
|
// assigne the function to the sensors devices
|
|
if ($this->active === true)
|
|
{
|
|
foreach ($this->devicelist as $ieeeAddress => $property)
|
|
{
|
|
if (array_key_exists($ieeeAddress, $devices))
|
|
{
|
|
logger(DEBUG, _("Device: ") . $ieeeAddress, __FILE__ . ":" . __LINE__);
|
|
if ($this->propertyInitialized[$ieeeAddress][$property] === false)
|
|
{
|
|
logger(DEBUG, _("Trying to store callback"), __FILE__ . ":" . __LINE__);
|
|
if (array_key_exists("functions", $indexDevices[$ieeeAddress]->properties[$property]))
|
|
{
|
|
$indexDevices[$ieeeAddress]->properties[$property]["functions"][$this->hookName] = array($this,"callback");
|
|
$this->propertyInitialized[$ieeeAddress][$property] = true;
|
|
logger(DEBUG, sprintf(_("Property '%s' of %s is initialized with callback"), $property, $indexDevices[$ieeeAddress]->friendlyName), __FILE__ . ":" . __LINE__);
|
|
|
|
}else
|
|
{
|
|
logger(WARNING, sprintf(_("Hook %s can not initialize Property '%s' of device %s"), $this->hookName, $property, $ieeeAddress), __FILE__ . ":" . __LINE__);
|
|
$result = false;
|
|
}
|
|
}else
|
|
{
|
|
logger(DEBUG, _("Callback already installed"), __FILE__ . ":" . __LINE__);
|
|
}
|
|
}else
|
|
{
|
|
logger(ERROR, $ieeeAddress . (" does not exists"), __FILE__ . ":" . __LINE__);
|
|
mkIndexes();
|
|
}
|
|
|
|
}
|
|
//echo "result => "; var_dump($result);
|
|
if ($result === true)
|
|
{
|
|
$this->initialized = true;
|
|
logger(INFO, $this->hookName . _(" initialized"), __FILE__ . ":" . __LINE__);
|
|
//var_dump($this);
|
|
}
|
|
}/*else
|
|
{
|
|
$this->initialized = true;
|
|
logger(INFO, $this->hookName . _("hook is disabled"), __FILE__ . ":" . __LINE__);
|
|
}*/
|
|
//print(var_export($indexDevices[$ieeeAddress],true));
|
|
//storeDB($devices,"debug.devices");
|
|
return $result;
|
|
}
|
|
}
|
|
|
|
?>
|