Emesary: refactor incoming bridge connection logic
This is mainly to allow unit testing.
This commit is contained in:
parent
160abde2a6
commit
6a68a623c9
1 changed files with 38 additions and 24 deletions
|
@ -26,21 +26,31 @@
|
||||||
# var outgoingBridge = emesary_mp_bridge.OutgoingMPBridge.new("F-15mp",routedNotifications);
|
# var outgoingBridge = emesary_mp_bridge.OutgoingMPBridge.new("F-15mp",routedNotifications);
|
||||||
#------------------------------------------------------------------
|
#------------------------------------------------------------------
|
||||||
#
|
#
|
||||||
# NOTES: Aircraft do not need to have both an incoming and outgoing bridge, but it is usual.
|
# NOTES:
|
||||||
# Only the notifications specified will be routed via the bridge.
|
# * Aircraft do not need to have both an incoming and outgoing bridge, but it is usual.
|
||||||
# Once routed a message will by default not be re-rerouted again by the outgoing bridge.
|
#
|
||||||
# Transmit frequency and message lifetime may need to be tuned.
|
# * Only the notifications specified will be routed via the bridge.
|
||||||
# IsDistinct messages must be absolute and self contained as a later message will
|
#
|
||||||
# supercede any earlier ones in the outgoing queue (possibly prior to receipt)
|
# * Once routed a message will by default not be re-rerouted again by the outgoing bridge.
|
||||||
# Use the message type and ident to identify distinct messages
|
#
|
||||||
# The outgoing 'port' is a multiplay/emesary/bridge index, however any available string property
|
# * Transmit frequency and message lifetime may need to be tuned.
|
||||||
# can be used by specifying it in the construction of the incoming or outgoing bridge.
|
#
|
||||||
# NOTE: This should not often be changed as it different versions of FG or model will
|
# * IsDistinct messages must be absolute and self contained as a later message will
|
||||||
# have to use the same properties to be able to communicate
|
# supercede any earlier ones in the outgoing queue (possibly prior to receipt)
|
||||||
# multiplay/emesary/bridge-type is used to identify the bridge that is in use. This is to
|
#
|
||||||
# protect against bridges being used for different purposes by different models.
|
# * Use the message type and ident to identify distinct messages
|
||||||
# The bridge-type property should contain an ID that identifies the purpose
|
#
|
||||||
# and thereore the message set that the bridge will be using.
|
# * The outgoing 'port' is a multiplay/emesary/bridge index, however any available string property
|
||||||
|
# can be used by specifying it in the construction of the incoming or outgoing bridge.
|
||||||
|
# NOTE: This should not often be changed as it different versions of FG or model will
|
||||||
|
# have to use the same properties to be able to communicate
|
||||||
|
#
|
||||||
|
# * multiplay/emesary/bridge-type is used to identify the bridge that is in use. This is to
|
||||||
|
# protect against bridges being used for different purposes by different models.
|
||||||
|
#
|
||||||
|
# * The bridge-type property should contain an ID that identifies the purpose
|
||||||
|
# and thereore the message set that the bridge will be using.
|
||||||
|
#
|
||||||
# - ! is used as a seperator between the elements that are used to send the
|
# - ! is used as a seperator between the elements that are used to send the
|
||||||
# notification (typeid, sequence, notification)
|
# notification (typeid, sequence, notification)
|
||||||
# - There is an extra ! at the start of the message that is used to indicate protocol version.
|
# - There is an extra ! at the start of the message that is used to indicate protocol version.
|
||||||
|
@ -403,15 +413,22 @@ var IncomingMPBridge =
|
||||||
print("IncomingBridge: ",n.NotificationType);
|
print("IncomingBridge: ",n.NotificationType);
|
||||||
}
|
}
|
||||||
return new_class;
|
return new_class;
|
||||||
}
|
},
|
||||||
,
|
connectIncomingBridge : func(path, notification_list, mpidx, transmitter, _propertybase){
|
||||||
|
var incomingBridge = emesary_mp_bridge.IncomingMPBridge.new(path, notification_list, mpidx, transmitter, _propertybase);
|
||||||
|
|
||||||
|
incomingBridge.Connect(path~"/");
|
||||||
|
me.incomingBridgeList[path] = incomingBridge;
|
||||||
|
return incomingBridge;
|
||||||
|
},
|
||||||
|
|
||||||
#
|
#
|
||||||
# Each multiplayer object will have its own incoming bridge. This is necessary to allow message ID
|
# Each multiplayer object will have its own incoming bridge. This is necessary to allow message ID
|
||||||
# tracking (as the bridge knows which messages have been already processed)
|
# tracking (as the bridge knows which messages have been already processed)
|
||||||
# Whenever a client connects over MP a new bridge is instantiated
|
# Whenever a client connects over MP a new bridge is instantiated
|
||||||
startMPBridge : func(notification_list, mpidx=19, transmitter=nil, _propertybase="emesary/bridge")
|
startMPBridge : func(notification_list, mpidx=19, transmitter=nil, _propertybase="emesary/bridge")
|
||||||
{
|
{
|
||||||
var incomingBridgeList = {};
|
me.incomingBridgeList = {};
|
||||||
|
|
||||||
#
|
#
|
||||||
# Create bridge whenever a client connects
|
# Create bridge whenever a client connects
|
||||||
|
@ -429,10 +446,7 @@ var IncomingMPBridge =
|
||||||
if (callsign == "" or callsign == nil)
|
if (callsign == "" or callsign == nil)
|
||||||
callsign = path;
|
callsign = path;
|
||||||
|
|
||||||
var incomingBridge = emesary_mp_bridge.IncomingMPBridge.new(path, notification_list, mpidx, transmitter, _propertybase);
|
me.connectIncomingBridge(path, notification_list, mpidx, transmitter, _propertybase);
|
||||||
|
|
||||||
incomingBridge.Connect(path~"/");
|
|
||||||
incomingBridgeList[path] = incomingBridge;
|
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@ -441,12 +455,12 @@ var IncomingMPBridge =
|
||||||
#
|
#
|
||||||
setlistener("/ai/models/model-removed", func(v){
|
setlistener("/ai/models/model-removed", func(v){
|
||||||
var path = v.getValue();
|
var path = v.getValue();
|
||||||
var bridge = incomingBridgeList[path];
|
var bridge = me.incomingBridgeList[path];
|
||||||
if (bridge != nil)
|
if (bridge != nil)
|
||||||
{
|
{
|
||||||
# print("Bridge removed for ",v.getValue());
|
# print("Bridge removed for ",v.getValue());
|
||||||
bridge.Remove();
|
bridge.Remove();
|
||||||
incomingBridgeList[path]=nil;
|
me.incomingBridgeList[path]=nil;
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
|
|
Loading…
Add table
Reference in a new issue