Refactoring of of inheritance structure, ControllerManagers will now also be able to be provided through plugins

This commit is contained in:
Ziver Koc 2021-03-16 22:24:43 +01:00
parent 28bc108921
commit c0188cd5cc
73 changed files with 1083 additions and 991 deletions

View file

@ -0,0 +1,71 @@
package se.hal.plugin.nvr;
import se.hal.intf.HalAbstractControllerManager;
import se.hal.plugin.nvr.intf.HalCameraConfig;
import se.hal.plugin.nvr.intf.HalCameraController;
import se.hal.plugin.nvr.struct.Camera;
import se.hal.struct.AbstractDevice;
import zutil.log.LogUtil;
import zutil.plugin.PluginManager;
import java.util.Collection;
import java.util.List;
import java.util.logging.Logger;
public class CameraControllerManager extends HalAbstractControllerManager<HalCameraController, Camera, HalCameraConfig> {
private static final Logger logger = LogUtil.getLogger();
private static CameraControllerManager instance;
@Override
public void register(Camera device) {
}
@Override
public void deregister(Camera device) {
}
@Override
public List<Class<? extends HalCameraConfig>> getAvailableDeviceConfigs() {
return null;
}
@Override
public List<Camera> getRegisteredDevices() {
return null;
}
@Override
public List<Camera> getDetectedDevices() {
return null;
}
@Override
public void addAvailableDevice(Class deviceConfigClass) {
}
@Override
public void clearDetectedDevices() {
}
@Override
public Collection<HalCameraController> getControllers() {
return null;
}
public void initialize(PluginManager pluginManager){
super.initialize(pluginManager);
instance = this;
}
public static CameraControllerManager getInstance(){
return instance;
}
}

View file

@ -1,48 +0,0 @@
/*
* The MIT License (MIT)
*
* Copyright (c) 2021 Ziver Koc
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/
package se.hal.plugin.nvr;
import se.hal.intf.HalAbstractController;
import se.hal.plugin.nvr.device.HalCameraConfig;
import se.hal.plugin.nvr.device.HalCameraReportListener;
public interface HalCameraController extends HalAbstractController {
/**
* Will register a camera to be handled by this controller.
*/
void register(HalCameraConfig cameraConfig);
/**
* Deregisters a camera from this controller, the controller
* will no longer handle camera device.
*/
void deregister(HalCameraConfig cameraConfig);
/**
* Set a listener that will receive all reports from the the registered camera.
*/
void setListener(HalCameraReportListener listener);
}

View file

@ -1,10 +0,0 @@
package se.hal.plugin.nvr.device;
import se.hal.plugin.nvr.HalCameraController;
/**
* Listener to be called by the {@link HalCameraController} to report that a camera event has been observed.
*/
public interface HalCameraReportListener {
}

View file

@ -22,15 +22,10 @@
* THE SOFTWARE.
*/
package se.hal.plugin.nvr.device;
package se.hal.plugin.nvr.intf;
import se.hal.plugin.nvr.HalCameraController;
import se.hal.intf.HalDeviceConfig;
public interface HalCameraConfig {
/**
* @return the Controller class where CameraData should be registered on
*/
Class<? extends HalCameraController> getCameraControllerClass();
public interface HalCameraConfig extends HalDeviceConfig {
}

View file

@ -22,8 +22,11 @@
* THE SOFTWARE.
*/
package se.hal.plugin.nvr;
package se.hal.plugin.nvr.intf;
public class StreamRecorder {
import se.hal.intf.HalAbstractController;
public interface HalCameraController extends HalAbstractController {
}

View file

@ -22,7 +22,7 @@
* THE SOFTWARE.
*/
package se.hal.plugin.nvr.device;
package se.hal.plugin.nvr.intf;
import se.hal.intf.HalDeviceData;

View file

@ -24,11 +24,11 @@
package se.hal.plugin.nvr.page;
import se.hal.ControllerManager;
import se.hal.HalContext;
import se.hal.intf.HalWebPage;
import se.hal.page.HalAlertManager;
import se.hal.plugin.nvr.device.Camera;
import se.hal.plugin.nvr.CameraControllerManager;
import se.hal.plugin.nvr.struct.Camera;
import se.hal.struct.ClassConfigurationData;
import se.hal.struct.User;
import zutil.ObjectUtil;
@ -36,7 +36,6 @@ import zutil.db.DBConnection;
import zutil.io.file.FileUtil;
import zutil.log.LogUtil;
import zutil.parser.Templator;
import zutil.ui.UserMessageManager;
import java.util.ArrayList;
import java.util.Map;
@ -56,7 +55,7 @@ public class CameraConfigWebPage extends HalWebPage {
super.getRootNav().createSubNav("Settings").createSubNav(this.getId(), "Camera Settings").setWeight(200);
cameraConfigurations = new ArrayList<>();
for(Class c : ControllerManager.getInstance().getAvailableEvents())
for(Class c : CameraControllerManager.getInstance().getAvailableDeviceConfigs())
cameraConfigurations.add(new ClassConfigurationData(c));
}

View file

@ -26,7 +26,7 @@ package se.hal.plugin.nvr.page;
import se.hal.HalContext;
import se.hal.intf.HalWebPage;
import se.hal.plugin.nvr.device.Camera;
import se.hal.plugin.nvr.struct.Camera;
import se.hal.struct.Event;
import se.hal.util.DeviceNameComparator;
import zutil.ObjectUtil;

View file

@ -3,6 +3,8 @@
"name": "Hal-NVR",
"description": "A Network Video Recorder plugin for recording network streams.",
"interfaces": [
{"se.hal.intf.HalAbstractControllerManager": "se.hal.plugin.nvr.CameraControllerManager"},
{"se.hal.intf.HalWebPage": "se.hal.plugin.nvr.page.CameraConfigWebPage"},
{"se.hal.intf.HalWebPage": "se.hal.plugin.nvr.page.CameraOverviewWebPage"},
{"se.hal.intf.HalWebPage": "se.hal.plugin.nvr.page.MonitorWebPage"}

View file

@ -24,8 +24,9 @@
package se.hal.plugin.nvr.rtsp;
import se.hal.plugin.nvr.HalCameraController;
import se.hal.plugin.nvr.device.HalCameraConfig;
import se.hal.intf.HalDeviceData;
import se.hal.plugin.nvr.intf.HalCameraController;
import se.hal.plugin.nvr.intf.HalCameraConfig;
public class RTSPCameraConfig implements HalCameraConfig {
@ -38,8 +39,18 @@ public class RTSPCameraConfig implements HalCameraConfig {
}
public String getRtspUrl() {
return rtspUrl;
}
@Override
public Class<? extends HalCameraController> getCameraControllerClass() {
public Class<? extends HalCameraController> getDeviceControllerClass() {
return RTSPController.class;
}
@Override
public Class<? extends HalDeviceData> getDeviceDataClass() {
return null; // TODO:
}
}

View file

@ -0,0 +1,38 @@
package se.hal.plugin.nvr.rtsp;
import zutil.log.LogUtil;
import java.util.logging.Level;
import java.util.logging.Logger;
/**
* A instance of this class will manage a RTSP stream from a specified source.
*/
public class RTSPCameraRecorder implements Runnable {
private static final Logger logger = LogUtil.getLogger();
private RTSPCameraConfig camera;
public RTSPCameraRecorder(RTSPCameraConfig camera) {
this.camera = camera;
}
@Override
public void run() {
logger.info("Starting up RTSP Stream recording thread for: " + camera.getRtspUrl());
try {
} catch (Exception e) {
logger.log(Level.SEVERE, "RTSP Stream recording thread has crashed for: " + camera.getRtspUrl(), e);
} finally {
logger.info("Shutting down RTSP Stream recording thread for: " + camera.getRtspUrl());
}
}
public void close() {
camera = null;
}
}

View file

@ -24,9 +24,9 @@
package se.hal.plugin.nvr.rtsp;
import se.hal.plugin.nvr.HalCameraController;
import se.hal.plugin.nvr.device.HalCameraConfig;
import se.hal.plugin.nvr.device.HalCameraReportListener;
import se.hal.intf.HalDeviceConfig;
import se.hal.intf.HalDeviceReportListener;
import se.hal.plugin.nvr.intf.HalCameraController;
import zutil.log.LogUtil;
import java.util.ArrayList;
@ -40,7 +40,7 @@ public class RTSPController implements HalCameraController {
private static final String CONFIG_RECORDING_PATH = "nvr.recording_path";
private List<RTSPCameraConfig> cameras = new ArrayList<>();
private HalCameraReportListener listener;
private HalDeviceReportListener listener;
public RTSPController() {}
@ -51,7 +51,7 @@ public class RTSPController implements HalCameraController {
// ----------------------------------------------------
@Override
public void initialize() throws Exception {
public void initialize() {
}
@ -65,14 +65,14 @@ public class RTSPController implements HalCameraController {
// ----------------------------------------------------
@Override
public void register(HalCameraConfig cameraConfig) {
if (cameraConfig instanceof RTSPCameraConfig)
cameras.add((RTSPCameraConfig) cameraConfig);
public void register(HalDeviceConfig deviceConfig) {
if (deviceConfig instanceof RTSPCameraConfig)
cameras.add((RTSPCameraConfig) deviceConfig);
}
@Override
public void deregister(HalCameraConfig cameraConfig) {
cameras.remove(cameraConfig);
public void deregister(HalDeviceConfig deviceConfig) {
cameras.remove(deviceConfig);
}
@Override
@ -81,7 +81,7 @@ public class RTSPController implements HalCameraController {
}
@Override
public void setListener(HalCameraReportListener listener) {
public void setListener(HalDeviceReportListener listener) {
this.listener = listener;
}

View file

@ -22,9 +22,11 @@
* THE SOFTWARE.
*/
package se.hal.plugin.nvr.device;
package se.hal.plugin.nvr.struct;
import se.hal.intf.HalAbstractController;
import se.hal.plugin.nvr.intf.HalCameraConfig;
import se.hal.plugin.nvr.intf.HalCameraData;
import se.hal.struct.AbstractDevice;
import zutil.db.DBConnection;
import zutil.db.bean.DBBean;
@ -46,7 +48,7 @@ public class Camera extends AbstractDevice<Camera, HalCameraConfig, HalCameraDat
@Override
public Class<? extends HalAbstractController> getController() {
return getDeviceConfig().getCameraControllerClass();
return getDeviceConfig().getDeviceControllerClass();
}
@Override