Skip to content

Commit 46cf9c0

Browse files
committed
Remove unimportant isSensorModuleRegistered checks
1 parent dd14cce commit 46cf9c0

File tree

1 file changed

+5
-25
lines changed

1 file changed

+5
-25
lines changed

SensingKitLib/src/main/java/org/sensingkit/sensingkitlib/modules/SensorModuleManager.java

Lines changed: 5 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,11 @@ public boolean isSensorModuleSensing(SensorModuleType moduleType) throws SKExcep
112112
return getSensorModule(moduleType).isSensing();
113113
}
114114

115-
protected AbstractSensorModule getSensorModule(SensorModuleType moduleType) {
115+
protected AbstractSensorModule getSensorModule(SensorModuleType moduleType) throws SKException {
116+
117+
if (!isSensorModuleRegistered(moduleType)) {
118+
throw new SKException(TAG, "SensorModule is not registered.", SKExceptionErrorCode.UNKNOWN_ERROR);
119+
}
116120

117121
int sensorIndex = moduleType.ordinal();
118122
return mSensors.get(sensorIndex);
@@ -201,54 +205,34 @@ public DataInterface getDataFromSensor(SensorModuleType moduleType) throws SKExc
201205

202206
Log.i(TAG, "Get data from sensor: " + SensorModuleUtilities.getSensorModuleInString(moduleType) + ".");
203207

204-
if (!isSensorModuleRegistered(moduleType)) {
205-
throw new SKException(TAG, "SensorModule is not registered", SKExceptionErrorCode.UNKNOWN_ERROR);
206-
}
207-
208208
throw new SKException(TAG, "This feature is not supported just yet!", SKExceptionErrorCode.UNKNOWN_ERROR);
209209
}
210210

211211
public void subscribeSensorDataListener(SensorModuleType moduleType, SKSensorDataListener dataListener) throws SKException {
212212

213213
Log.i(TAG, "Subscribe to sensor: " + SensorModuleUtilities.getSensorModuleInString(moduleType) + ".");
214214

215-
if (!isSensorModuleRegistered(moduleType)) {
216-
throw new SKException(TAG, "SensorModule is not registered", SKExceptionErrorCode.UNKNOWN_ERROR);
217-
}
218-
219215
getSensorModule(moduleType).subscribeSensorDataListener(dataListener);
220216
}
221217

222218
public void unsubscribeSensorDataListener(SensorModuleType moduleType, SKSensorDataListener dataListener) throws SKException {
223219

224220
Log.i(TAG, "Unsubscribe from sensor: " + SensorModuleUtilities.getSensorModuleInString(moduleType) + ".");
225221

226-
if (!isSensorModuleRegistered(moduleType)) {
227-
throw new SKException(TAG, "SensorModule is not registered", SKExceptionErrorCode.UNKNOWN_ERROR);
228-
}
229-
230222
getSensorModule(moduleType).unsubscribeSensorDataListener(dataListener);
231223
}
232224

233225
public void unsubscribeAllSensorDataListeners(SensorModuleType moduleType) throws SKException {
234226

235227
Log.i(TAG, "Unsubscribe from all sensors.");
236228

237-
if (!isSensorModuleRegistered(moduleType)) {
238-
throw new SKException(TAG, "SensorModule is not registered", SKExceptionErrorCode.UNKNOWN_ERROR);
239-
}
240-
241229
getSensorModule(moduleType).unsubscribeAllSensorDataListeners();
242230
}
243231

244232
public void startContinuousSensingWithSensor(SensorModuleType moduleType) throws SKException {
245233

246234
Log.i(TAG, "Start sensing with sensor: " + SensorModuleUtilities.getSensorModuleInString(moduleType) + ".");
247235

248-
if (!isSensorModuleRegistered(moduleType)) {
249-
throw new SKException(TAG, "SensorModule is not registered.", SKExceptionErrorCode.UNKNOWN_ERROR);
250-
}
251-
252236
if (isSensorModuleSensing(moduleType)) {
253237
throw new SKException(TAG, "SensorModule is already sensing.", SKExceptionErrorCode.UNKNOWN_ERROR);
254238
}
@@ -261,10 +245,6 @@ public void stopContinuousSensingWithSensor(SensorModuleType moduleType) throws
261245

262246
Log.i(TAG, "Stop sensing with sensor: " + SensorModuleUtilities.getSensorModuleInString(moduleType) + ".");
263247

264-
if (!isSensorModuleRegistered(moduleType)) {
265-
throw new SKException(TAG, "SensorModule is not registered", SKExceptionErrorCode.UNKNOWN_ERROR);
266-
}
267-
268248
if (!isSensorModuleSensing(moduleType)) {
269249
throw new SKException(TAG, "SensorModule is already not sensing.", SKExceptionErrorCode.UNKNOWN_ERROR);
270250
}

0 commit comments

Comments
 (0)