|
|
|
@ -672,9 +672,17 @@ public class DefaultTransportService implements TransportService { |
|
|
|
long deviceProfileIdMSB = deviceProfile.getId().getId().getMostSignificantBits(); |
|
|
|
long deviceProfileIdLSB = deviceProfile.getId().getId().getLeastSignificantBits(); |
|
|
|
sessions.forEach((id, md) -> { |
|
|
|
//TODO: if transport types are different - we should close the session.
|
|
|
|
if (md.getSessionInfo().getDeviceProfileIdMSB() == deviceProfileIdMSB |
|
|
|
&& md.getSessionInfo().getDeviceProfileIdLSB() == deviceProfileIdLSB) { |
|
|
|
transportCallbackExecutor.submit(() -> md.getListener().onProfileUpdate(deviceProfile)); |
|
|
|
TransportProtos.SessionInfoProto newSessionInfo = TransportProtos.SessionInfoProto.newBuilder() |
|
|
|
.mergeFrom(md.getSessionInfo()) |
|
|
|
.setDeviceProfileIdMSB(deviceProfileIdMSB) |
|
|
|
.setDeviceProfileIdLSB(deviceProfileIdLSB) |
|
|
|
.setDeviceType(deviceProfile.getName()) |
|
|
|
.build(); |
|
|
|
md.setSessionInfo(newSessionInfo); |
|
|
|
transportCallbackExecutor.submit(() -> md.getListener().onDeviceProfileUpdate(newSessionInfo, deviceProfile)); |
|
|
|
} |
|
|
|
}); |
|
|
|
} |
|
|
|
@ -684,28 +692,27 @@ public class DefaultTransportService implements TransportService { |
|
|
|
long deviceIdLSB = device.getId().getId().getLeastSignificantBits(); |
|
|
|
long deviceProfileIdMSB = device.getDeviceProfileId().getId().getMostSignificantBits(); |
|
|
|
long deviceProfileIdLSB = device.getDeviceProfileId().getId().getLeastSignificantBits(); |
|
|
|
for (Map.Entry<UUID, SessionMetaData> entry : sessions.entrySet()) { |
|
|
|
SessionMetaData md = entry.getValue(); |
|
|
|
if ((md.getSessionInfo().getDeviceIdMSB() == deviceIdMSB |
|
|
|
&& md.getSessionInfo().getDeviceIdLSB() == deviceIdLSB) |
|
|
|
&& (md.getSessionInfo().getDeviceProfileIdMSB() != deviceProfileIdMSB |
|
|
|
&& md.getSessionInfo().getDeviceProfileIdLSB() != deviceProfileIdLSB)) { |
|
|
|
updateSessionMetadata(device, entry, md); |
|
|
|
sessions.forEach((id, md) -> { |
|
|
|
if ((md.getSessionInfo().getDeviceIdMSB() == deviceIdMSB && md.getSessionInfo().getDeviceIdLSB() == deviceIdLSB)) { |
|
|
|
DeviceProfile newDeviceProfile; |
|
|
|
if (md.getSessionInfo().getDeviceProfileIdMSB() != deviceProfileIdMSB |
|
|
|
&& md.getSessionInfo().getDeviceProfileIdLSB() != deviceProfileIdLSB) { |
|
|
|
//TODO: if transport types are different - we should close the session.
|
|
|
|
newDeviceProfile = deviceProfileCache.get(new DeviceProfileId(new UUID(deviceProfileIdMSB, deviceProfileIdLSB))); |
|
|
|
} else { |
|
|
|
newDeviceProfile = null; |
|
|
|
} |
|
|
|
TransportProtos.SessionInfoProto newSessionInfo = TransportProtos.SessionInfoProto.newBuilder() |
|
|
|
.mergeFrom(md.getSessionInfo()) |
|
|
|
.setDeviceProfileIdMSB(deviceProfileIdMSB) |
|
|
|
.setDeviceProfileIdLSB(deviceProfileIdLSB) |
|
|
|
.setDeviceName(device.getName()) |
|
|
|
.setDeviceType(device.getType()) |
|
|
|
.build(); |
|
|
|
md.setSessionInfo(newSessionInfo); |
|
|
|
transportCallbackExecutor.submit(() -> md.getListener().onDeviceUpdate(newSessionInfo, device, Optional.ofNullable(newDeviceProfile))); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
private void updateSessionMetadata(Device device, Map.Entry<UUID, SessionMetaData> entry, SessionMetaData md) { |
|
|
|
TransportProtos.SessionInfoProto newSessionInfo = TransportProtos.SessionInfoProto.newBuilder() |
|
|
|
.mergeFrom(md.getSessionInfo()) |
|
|
|
.setDeviceProfileIdMSB(device.getDeviceProfileId().getId().getMostSignificantBits()) |
|
|
|
.setDeviceProfileIdLSB(device.getDeviceProfileId().getId().getLeastSignificantBits()) |
|
|
|
.setDeviceType(device.getType()) |
|
|
|
.build(); |
|
|
|
SessionMetaData newSessionMetaData = new SessionMetaData(newSessionInfo, md.getSessionType(), md.getListener()); |
|
|
|
entry.setValue(newSessionMetaData); |
|
|
|
transportCallbackExecutor.submit(() -> newSessionMetaData.getListener().onDeviceProfileUpdate(device, |
|
|
|
newSessionMetaData.getSessionInfo())); |
|
|
|
}); |
|
|
|
} |
|
|
|
|
|
|
|
protected UUID toSessionId(TransportProtos.SessionInfoProto sessionInfo) { |
|
|
|
|