completed decode procedure framework

This commit is contained in:
strawmanbobi
2019-01-07 22:34:31 +08:00
parent 105bdecb02
commit 9b36d9e715
3 changed files with 43 additions and 14 deletions

View File

@@ -1,12 +1,15 @@
package net.irext.decoder.businesslogic;
import net.irext.decoder.alioss.OSSHelper;
import net.irext.decoder.cache.IDecodeSessionRepository;
import net.irext.decoder.model.IRBinary;
import net.irext.decoder.model.RemoteIndex;
import net.irext.decoder.cache.IIRBinaryRepository;
import net.irext.decoder.utils.FileUtil;
import net.irext.decoder.utils.LoggerUtil;
import net.irext.decoder.utils.MD5Util;
import net.irext.decodesdk.IRDecode;
import net.irext.decodesdk.bean.ACStatus;
import org.apache.commons.io.IOUtils;
import javax.servlet.ServletContext;
@@ -90,10 +93,31 @@ public class DecodeLogic {
return null;
}
public int[] decode() {
public int[] decode(IIRBinaryRepository irBinaryRepository, IDecodeSessionRepository decodeSessionRepository,
String sessionId, int remoteIndexId, ACStatus acStatus, int keyCode, int changeWindDirection) {
// since the binary is already opened and probably cached to redis, we just need to load it
Integer cachedRemoteIndexId = decodeSessionRepository.find(sessionId);
int []decoded = null;
if (null != cachedRemoteIndexId) {
byte[] remoteBinary = irBinaryRepository.find(cachedRemoteIndexId);
IRDecode irDecode = IRDecode.getInstance();
int ret = 0;
// int ret = irDecode.openBinary(categoryId, subCate, binaryContent, binaryContent.length);
if (0 == ret) {
decoded = irDecode.decodeBinary(keyCode, acStatus, changeWindDirection);
}
irDecode.closeBinary();
return decoded;
} else {
LoggerUtil.getInstance().trace(TAG, "session cache missed, need to re-open binary");
}
return null;
}
public void close(IDecodeSessionRepository decodeSessionRepository, String sessionId) {
decodeSessionRepository.delete(sessionId);
}
// helper methods
private FileInputStream getFile(File binFile, String downloadPath, String fileName, String checksum) {
try {

View File

@@ -12,22 +12,21 @@ package net.irext.decoder.request;
*/
public class CloseRequest {
private int indexId;
private String sessionId;
public CloseRequest(int indexId) {
this.indexId = indexId;
public CloseRequest(String sessionId) {
this.sessionId = sessionId;
}
public CloseRequest() {
}
public int getIndexId() {
return indexId;
public String getSessionId() {
return sessionId;
}
public void setIndexId(int indexId) {
this.indexId = indexId;
public void setSessionId(String sessionId) {
this.sessionId = sessionId;
}
}

View File

@@ -102,13 +102,20 @@ public class IRDecodeService extends AbstractBaseService {
public DecodeResponse irDecode(@RequestBody DecodeRequest decodeRequest) {
try {
int indexId = decodeRequest.getIndexId();
ACStatus acstatus = decodeRequest.getAcStatus();
ACStatus acStatus = decodeRequest.getAcStatus();
int keyCode = decodeRequest.getKeyCode();
int changeWindDir = decodeRequest.getChangeWindDir();
String sessionId = decodeRequest.getSessionId();
DecodeResponse response = new DecodeResponse();
int[] irArray = DecodeLogic.getInstance().decode();
int[] irArray = DecodeLogic.getInstance().decode(
irBinaryRepository,
decodeSessionRepository,
sessionId,
indexId,
acStatus,
keyCode,
changeWindDir);
return response;
} catch (Exception e) {
@@ -120,10 +127,9 @@ public class IRDecodeService extends AbstractBaseService {
@PostMapping("/close")
public ServiceResponse irClose(@RequestBody CloseRequest closeRequest) {
try {
String sessionId = closeRequest.getSessionId();
ServiceResponse response = new ServiceResponse();
DecodeLogic.getInstance().decode();
DecodeLogic.getInstance().close(sessionId);
return response;
} catch (Exception e) {
e.printStackTrace();