Unit ProxyListenerBaseUnit; { This listenes to the outgoing data feed to know if it is up or down. And it queues messages to that data feed. In theory we could have multiple types of data. Originally I was going to have seperate data nodes for TOS and L1 proxies. Eventually I decided to put those together for simplicity and effeciency. But this is still a logical place to break the code. } Interface Uses DataNodes, MessageQueues; Type TProxyListenerBase = Class(TDataNodeWithStringKey) Private Procedure Initialize; Procedure OnStart(Msg : TBroadcastMessage; Owner : TDataNode); Protected FMessageQueue : TMessageQueue; // This base class monitors the state of the output. It will also call // OnRestartOutput after updating OutputStarted each time the output // starts. Presumably the data node will want to tell the listener // the current state of the data. Procedure OnRestartOutput; Virtual; Function OutputStarted : Boolean; Constructor Create; Public // This is thread safe. We call this to notify the data nodes whether // the there is a listener on the socket or not. They stop sending // data when there is no listener. And they automatically send a // snapshot when we make a connection. The message queue only goes in // the other direction, from the realtick to the proxy clients. This // special message is going the other direction. We still use the // MessageQueue to decide which objects are connected. Class Procedure SetOutputState(Started : Boolean; MessageQueue : TMessageQueue); // This is similar to the above procedure, but it only sends the message // to the current data node. The result is to switch to the appropriate // thread and then call OnRestartOutput. This is better than // broadcasting the request for a number of reasons. Procedure SendRefresh; End; Implementation Uses DebugOutput, SysUtils; Constructor TProxyListenerBase.Create; Begin Inherited Create; DoInCorrectThread(Initialize) End; Procedure TProxyListenerBase.Initialize; Begin RegisterForBroadcast('TProxyListenerBase.Start.' + IntToStr(Integer(FMessageQueue)), OnStart) End; Procedure TProxyListenerBase.OnStart(Msg : TBroadcastMessage; Owner : TDataNode); Begin OnRestartOutput End; Procedure TProxyListenerBase.OnRestartOutput; Begin DebugOutputWindow.AddMessage('TProxyListenerBase.OnRestartOutput'); End; Function TProxyListenerBase.OutputStarted : Boolean; Begin Result := FMessageQueue.OutputStarted End; Procedure TProxyListenerBase.SendRefresh; Begin DoInCorrectThread(OnRestartOutput) End; Class Procedure TProxyListenerBase.SetOutputState(Started : Boolean; MessageQueue : TMessageQueue); Var Msg : TBroadcastMessage; Begin MessageQueue.OutputStarted := Started; If Started Then Begin Msg := TBroadcastMessage.Create; Msg.Send('TProxyListenerBase.Start.' + IntToStr(Integer(MessageQueue))) End End; End.