aboutsummaryrefslogtreecommitdiff
path: root/src/org/traccar
diff options
context:
space:
mode:
Diffstat (limited to 'src/org/traccar')
-rw-r--r--src/org/traccar/BasePipelineFactory.java8
-rw-r--r--src/org/traccar/MainModule.java22
-rw-r--r--src/org/traccar/config/Keys.java6
-rw-r--r--src/org/traccar/handler/EngineHoursHandler.java (renamed from src/org/traccar/EngineHoursHandler.java)14
4 files changed, 41 insertions, 9 deletions
diff --git a/src/org/traccar/BasePipelineFactory.java b/src/org/traccar/BasePipelineFactory.java
index cb60b20a7..1b3be36fc 100644
--- a/src/org/traccar/BasePipelineFactory.java
+++ b/src/org/traccar/BasePipelineFactory.java
@@ -37,6 +37,7 @@ import org.traccar.events.OverspeedEventHandler;
import org.traccar.handler.ComputedAttributesHandler;
import org.traccar.handler.CopyAttributesHandler;
import org.traccar.handler.DistanceHandler;
+import org.traccar.handler.EngineHoursHandler;
import org.traccar.handler.FilterHandler;
import org.traccar.handler.GeocoderHandler;
import org.traccar.handler.GeolocationHandler;
@@ -56,7 +57,6 @@ public abstract class BasePipelineFactory extends ChannelInitializer<Channel> {
private final TrackerServer server;
private int timeout;
- private EngineHoursHandler engineHoursHandler;
private CopyAttributesHandler copyAttributesHandler;
private ComputedAttributesHandler computedAttributesHandler;
@@ -78,10 +78,6 @@ public abstract class BasePipelineFactory extends ChannelInitializer<Channel> {
timeout = Context.getConfig().getInteger(Keys.SERVER_TIMEOUT);
}
- if (Context.getConfig().getBoolean("processing.engineHours.enable")) {
- engineHoursHandler = new EngineHoursHandler();
- }
-
if (Context.getConfig().getBoolean("processing.copyAttributes.enable")) {
copyAttributesHandler = new CopyAttributesHandler();
}
@@ -164,7 +160,7 @@ public abstract class BasePipelineFactory extends ChannelInitializer<Channel> {
Main.getInjector().getInstance(FilterHandler.class),
Main.getInjector().getInstance(GeocoderHandler.class),
Main.getInjector().getInstance(MotionHandler.class),
- engineHoursHandler,
+ Main.getInjector().getInstance(EngineHoursHandler.class),
copyAttributesHandler,
computedAttributesHandler);
diff --git a/src/org/traccar/MainModule.java b/src/org/traccar/MainModule.java
index 0c3c5be51..cd5f2568e 100644
--- a/src/org/traccar/MainModule.java
+++ b/src/org/traccar/MainModule.java
@@ -44,7 +44,9 @@ import org.traccar.geolocation.MozillaGeolocationProvider;
import org.traccar.geolocation.OpenCellIdGeolocationProvider;
import org.traccar.geolocation.UnwiredGeolocationProvider;
import org.traccar.handler.DistanceHandler;
+import org.traccar.handler.EngineHoursHandler;
import org.traccar.handler.FilterHandler;
+import org.traccar.handler.GeocoderHandler;
import org.traccar.handler.GeolocationHandler;
import org.traccar.handler.HemisphereHandler;
import org.traccar.handler.MotionHandler;
@@ -211,10 +213,30 @@ public class MainModule extends AbstractModule {
@Singleton
@Provides
+ public static GeocoderHandler provideGeocoderHandler(
+ Config config, @Nullable Geocoder geocoder, IdentityManager identityManager,
+ StatisticsManager statisticsManager) {
+ if (geocoder != null) {
+ return new GeocoderHandler(config, geocoder, identityManager, statisticsManager);
+ }
+ return null;
+ }
+
+ @Singleton
+ @Provides
public static MotionHandler provideMotionHandler(TripsConfig tripsConfig) {
return new MotionHandler(tripsConfig.getSpeedThreshold());
}
+ @Singleton
+ @Provides
+ public static EngineHoursHandler provideEngineHoursHandler(Config config, IdentityManager identityManager) {
+ if (config.getBoolean(Keys.PROCESSING_ENGINE_HOURS_ENABLE)) {
+ return new EngineHoursHandler(identityManager);
+ }
+ return null;
+ }
+
@Override
protected void configure() {
binder().requireExplicitBindings();
diff --git a/src/org/traccar/config/Keys.java b/src/org/traccar/config/Keys.java
index 7449bfdf5..6c1225a9b 100644
--- a/src/org/traccar/config/Keys.java
+++ b/src/org/traccar/config/Keys.java
@@ -180,6 +180,12 @@ public final class Keys {
"processing.remoteAddress.enable", Boolean.class);
/**
+ * Enable engine hours calculation on the server side. It uses ignition value to determine engine state.
+ */
+ public static final ConfigKey PROCESSING_ENGINE_HOURS_ENABLE = new ConfigKey(
+ "processing.engineHours.enable", Boolean.class);
+
+ /**
* Boolean flag to enable or disable reverse geocoder.
*/
public static final ConfigKey GEOCODER_ENABLE = new ConfigKey(
diff --git a/src/org/traccar/EngineHoursHandler.java b/src/org/traccar/handler/EngineHoursHandler.java
index c9fbc186c..92da84e6b 100644
--- a/src/org/traccar/EngineHoursHandler.java
+++ b/src/org/traccar/handler/EngineHoursHandler.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2018 Anton Tananaev (anton@traccar.org)
+ * Copyright 2018 - 2019 Anton Tananaev (anton@traccar.org)
* Copyright 2018 Andrey Kunitsyn (andrey@traccar.org)
*
* Licensed under the Apache License, Version 2.0 (the "License");
@@ -14,18 +14,26 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-package org.traccar;
+package org.traccar.handler;
import io.netty.channel.ChannelHandler;
+import org.traccar.BaseDataHandler;
+import org.traccar.database.IdentityManager;
import org.traccar.model.Position;
@ChannelHandler.Sharable
public class EngineHoursHandler extends BaseDataHandler {
+ private final IdentityManager identityManager;
+
+ public EngineHoursHandler(IdentityManager identityManager) {
+ this.identityManager = identityManager;
+ }
+
@Override
protected Position handlePosition(Position position) {
if (!position.getAttributes().containsKey(Position.KEY_HOURS)) {
- Position last = Context.getIdentityManager().getLastPosition(position.getDeviceId());
+ Position last = identityManager.getLastPosition(position.getDeviceId());
if (last != null) {
long hours = last.getLong(Position.KEY_HOURS);
if (last.getBoolean(Position.KEY_IGNITION) && position.getBoolean(Position.KEY_IGNITION)) {