예제 #1
0
 private bool IsValidIOMapping(ProcessingModule processingModule, TopicInputMapping inputMapping)
 {
     return(processingModule.Inputs.Any(input => input.InternalName == inputMapping.InputName));
 }
예제 #2
0
    private async Task <bool> ApplyInputMapping(ProcessingModule processingModule, TopicInputMapping inputMapping)
    {
        if (!IsValidIOMapping(processingModule, inputMapping))
        {
            Debug.LogError("PM-Manager: IO-Mapping for module " + processingModule.Name + "->" + inputMapping.InputName + " is invalid");
            return(false);
        }

        bool isLockstep = processingModule.ProcessingMode.Lockstep != null;

        if (inputMapping.TopicSourceCase == TopicInputMapping.TopicSourceOneofCase.Topic)
        {
            processingModule.SetInputGetter(inputMapping.InputName, () =>
            {
                var entry = this.topicDataProxy.Pull(inputMapping.Topic);
                return(entry);
            });

            if (!isLockstep)
            {
                Action <TopicDataRecord> callback = null;

                if (processingModule.ProcessingMode?.TriggerOnInput != null)
                {
                    callback = _ => { processingModule.Emit(PMEvents.NEW_INPUT, inputMapping.InputName); };
                }
                else
                {
                    callback = _ => {};
                }

                // subscribe to topic and save token
                try
                {
                    SubscriptionToken subscriptionToken = await this.topicDataProxy.SubscribeTopic(inputMapping.Topic, callback);

                    if (!pmTopicSubscriptions.ContainsKey(processingModule.Id))
                    {
                        pmTopicSubscriptions.Add(processingModule.Id, new List <SubscriptionToken>());
                    }
                    pmTopicSubscriptions[processingModule.Id].Add(subscriptionToken);
                }
                catch (Exception e)
                {
                    Debug.LogError(e);
                    return(false);
                }
            }
        }
        else if (inputMapping.TopicSourceCase == TopicInputMapping.TopicSourceOneofCase.TopicMux)
        {
            // ~TODO, device Manager ?
            string multiplexer;
            if (inputMapping.TopicMux.Id != null)
            {
                multiplexer = "missing code"; // this.deviceManager.getTopicMux(inputMapping.TopicMux.Id) in js file?
            }
            else
            {
                //multiplexer = this.deviceManager.createTopicMuxerBySpecs(inputMapping.TopicMux, topicDataProxy); in js file?
            }
            processingModule.SetInputGetter(inputMapping.InputName, () =>
            {
                //return multiplexer.Get()
                return(null);
            });
        }

        return(true);
    }