Пример #1
0
    private void ApplyOutputMapping(ProcessingModule processingModule, TopicOutputMapping outputMapping)
    {
        if (!IsValidIOMapping(processingModule, outputMapping))
        {
            Debug.LogError("ProcessingModuleManager: IO-Mapping for module " + processingModule.Name + "->" + outputMapping.OutputName + " is invalid");
        }

        if (outputMapping.TopicDestinationCase == TopicOutputMapping.TopicDestinationOneofCase.Topic)
        {
            processingModule.SetOutputSetter(outputMapping.OutputName, (TopicDataRecord record) =>
            {
                record.Topic = outputMapping.Topic;
                topicDataProxy.Publish(record);
            });
        }
        else if (outputMapping.TopicDestinationCase == TopicOutputMapping.TopicDestinationOneofCase.TopicDemux)
        {
            //let demultiplexer = undefined;
            //if (topicDestination.Id)
            //{
            //    demultiplexer = this.deviceManager.getTopicDemux(topicDestination.Id);
            //}
            //else
            //{
            //    let topicDataBuffer = isLockstep ? this.lockstepTopicData : this.topicData;
            //    demultiplexer = this.deviceManager.createTopicDemuxerBySpecs(topicDestination, topicDataBuffer);
            //}
            //processingModule.setOutputSetter(outputMapping.outputName, (value) => {
            //    demultiplexer.push(value);
            //});
        }
    }
Пример #2
0
    /// <summary>
    /// Creates a PM from given specs and adds it to the dictionary on success
    /// </summary>
    /// <param name="specs">PM specs</param>
    /// <returns>Created PM</returns>
    public ProcessingModule CreateModule(Ubii.Processing.ProcessingModule specs)
    {
        ProcessingModule pm = null;

        if (pmDatabase.HasEntry(specs.Name))
        {
            Ubii.Processing.ProcessingModule detailedSpecs = pmDatabase.GetEntry(specs.Name).GetSpecifications();
            detailedSpecs.Id        = specs.Id;
            detailedSpecs.NodeId    = specs.NodeId;
            detailedSpecs.SessionId = specs.SessionId;

            pm = pmDatabase.CreateInstance(detailedSpecs);
        }
        else
        {
            if (specs.OnProcessingStringified == null || specs.OnProcessingStringified == string.Empty)
            {
                Debug.Log("ProcessingModuleManager can't create PM " + specs.Name + " based on specs, missing OnProcessing definition.");
                return(null);
            }
            pm = new ProcessingModule(specs);
        }

        bool success = AddModule(pm);

        if (!success)
        {
            return(null);
        }
        else
        {
            pm.OnCreated();
            return(pm);
        }
    }
Пример #3
0
    /// <summary>
    /// Callback for start session subscription
    /// </summary>
    /// <param name="record"></param>
    public async void OnStartSession(TopicDataRecord record)
    {
        List <ProcessingModule> localPMs = new List <ProcessingModule>();

        foreach (Ubii.Processing.ProcessingModule pm in record.Session.ProcessingModules)
        {
            if (pm.NodeId == this.GetID())
            {
                //Debug.Log("UbiiNode.OnStartSession() - applicable pm: " + pm);
                ProcessingModule newModule = this.processingModuleManager.CreateModule(pm);
                //Debug.Log("UbiiNode.OnStartSession() - created instance: " + newModule.ToString());
                if (newModule != null)
                {
                    localPMs.Add(newModule);
                }
            }
        }

        Google.Protobuf.Collections.RepeatedField <Ubii.Processing.ProcessingModule> elements = new Google.Protobuf.Collections.RepeatedField <Ubii.Processing.ProcessingModule>();
        foreach (ProcessingModule pm in localPMs)
        {
            elements.Add(pm.ToProtobuf());
        }
        ServiceRequest pmRuntimeAddRequest = new ServiceRequest
        {
            Topic = UbiiConstants.Instance.DEFAULT_TOPICS.SERVICES.PM_RUNTIME_ADD,
            ProcessingModuleList = new Ubii.Processing.ProcessingModuleList
            {
                Elements = { elements }
            }
        };
        //Debug.Log(nameof(OnStartSession) + " - runtime add request: " + pmRuntimeAddRequest);

        ServiceReply reply = await CallService(pmRuntimeAddRequest);

        //Debug.Log("start session runtime add PMs reply: " + reply);
        if (reply.Success != null)
        {
            try
            {
                bool success = await this.processingModuleManager.ApplyIOMappings(record.Session.IoMappings, record.Session.Id);

                foreach (var pm in localPMs)
                {
                    this.processingModuleManager.StartModule(new Ubii.Processing.ProcessingModule {
                        Id = pm.Id
                    });
                }
            }
            catch (Exception e)
            {
                Debug.LogError(e.ToString());
            }
        }
        else
        {
            //TODO: delete modules
        }
    }
Пример #4
0
    /// <summary>
    ///
    /// </summary>
    /// <param name="pmSpecs"></param>
    /// <param name="sessionID"></param>
    /// <returns>Processing module matching given specs</returns>
    public ProcessingModule GetModuleBySpecs(Ubii.Processing.ProcessingModule pmSpecs, string sessionID)
    {
        ProcessingModule module = GetModuleByID(pmSpecs.Id);

        if (module == null)
        {
            module = GetModuleByName(pmSpecs.Name, sessionID);
        }
        return(module);
    }
Пример #5
0
    /// <summary>
    /// Add given pm
    /// </summary>
    /// <param name="pm">PM to add</param>
    /// <returns><see langword="true"/> if pm was added successfully, <see langword="false"/> if given pm had no id</returns>
    private bool AddModule(ProcessingModule pm)
    {
        if (pm.Id == null || pm.Id == string.Empty)
        {
            Debug.LogError("ProcessingModuleManager: Module " + pm.Name + " does not have an ID, can't add it");
            return(false);
        }

        this.processingModules.Add(pm.Id, pm);
        //Debug.Log("ProcessingModuleManager.AddModule() - " + pm.ToString());
        return(true);
    }
Пример #6
0
    /// <summary>
    /// Stops module and unsubscribes its tokens from the topic data proxy
    /// </summary>
    /// <param name="pmSpec">Processing module to stop</param>
    public void StopModule(Ubii.Processing.ProcessingModule pmSpec)
    {
        ProcessingModule pm = processingModules[pmSpec.Id];

        pm?.Stop();

        List <SubscriptionToken> subs = pmTopicSubscriptions[pmSpec.Id];

        if (subs != null)
        {
            foreach (SubscriptionToken token in subs)
            {
                topicDataProxy.Unsubscribe(token);
            }
        }
    }
Пример #7
0
    /// <summary>
    /// Removes a module and unsubscribes all its tokens
    /// </summary>
    /// <param name="pm">PM to remove</param>
    /// <returns><see langword="true"/>, if pm could be removed successfully. <see langword="false"/> if no pm with that id is registered</returns>
    public bool RemoveModule(ProcessingModule pm)
    {
        if (pm.Id == null || pm.Id == string.Empty)
        {
            Debug.LogError("ProcessingModuleManager: Module " + pm.Name + " does not have an ID, can't remove it");
            return(false);
        }

        if (pmTopicSubscriptions.ContainsKey(pm.Id))
        {
            List <SubscriptionToken> subscriptionTokens = pmTopicSubscriptions[pm.Id];
            subscriptionTokens?.ForEach(token => topicDataProxy.Unsubscribe(token));
            pmTopicSubscriptions.Remove(pm.Id);
        }

        pmTopicSubscriptions.Remove(pm.Id);
        return(true);
    }
Пример #8
0
    /// <summary>
    /// Applies IO Mappings
    /// </summary>
    /// <param name="ioMappings"></param>
    /// <param name="sessionID"></param>
    public async Task <bool> ApplyIOMappings(RepeatedField <IOMapping> ioMappings, string sessionID)
    {
        //Debug.Log("ApplyIOMappings - ioMappings: " + ioMappings);

        // TODO: Check this when ioMappings type changes?
        IEnumerable <IOMapping> applicableIOMappings = ioMappings.Where(ioMapping => processingModules.ContainsKey(ioMapping.ProcessingModuleId));

        foreach (IOMapping mapping in applicableIOMappings)
        {
            //Debug.Log("ApplyIOMappings - applicableIOMapping: " + mapping);
            this.ioMappings[mapping.ProcessingModuleId] = mapping;
            ProcessingModule processingModule = GetModuleByID(mapping.ProcessingModuleId) != null?GetModuleByID(mapping.ProcessingModuleId) : GetModuleByName(mapping.ProcessingModuleName, sessionID);

            if (processingModule is null)
            {
                Debug.LogError("ProcessingModuleManager: can't find processing module for I/O mapping, given: ID = " +
                               mapping.ProcessingModuleId + ", name = " + mapping.ProcessingModuleName + ", session ID = " + sessionID);
                return(false);
            }

            foreach (TopicInputMapping inputMapping in mapping.InputMappings)
            {
                bool success = await ApplyInputMapping(processingModule, inputMapping);

                if (!success)
                {
                    return(false);
                }
            }
            foreach (TopicOutputMapping outputMapping in mapping.OutputMappings)
            {
                ApplyOutputMapping(processingModule, outputMapping);
            }
        }

        return(true);
    }
Пример #9
0
        public void MergeFrom(ServiceRequest other)
        {
            if (other == null)
            {
                return;
            }
            if (other.Topic.Length != 0)
            {
                Topic = other.Topic;
            }
            switch (other.TypeCase)
            {
            case TypeOneofCase.Client:
                if (Client == null)
                {
                    Client = new global::Ubii.Clients.Client();
                }
                Client.MergeFrom(other.Client);
                break;

            case TypeOneofCase.Device:
                if (Device == null)
                {
                    Device = new global::Ubii.Devices.Device();
                }
                Device.MergeFrom(other.Device);
                break;

            case TypeOneofCase.TopicSubscription:
                if (TopicSubscription == null)
                {
                    TopicSubscription = new global::Ubii.Services.Request.TopicSubscription();
                }
                TopicSubscription.MergeFrom(other.TopicSubscription);
                break;

            case TypeOneofCase.Session:
                if (Session == null)
                {
                    Session = new global::Ubii.Sessions.Session();
                }
                Session.MergeFrom(other.Session);
                break;

            case TypeOneofCase.SessionList:
                if (SessionList == null)
                {
                    SessionList = new global::Ubii.Sessions.SessionList();
                }
                SessionList.MergeFrom(other.SessionList);
                break;

            case TypeOneofCase.ProcessingModule:
                if (ProcessingModule == null)
                {
                    ProcessingModule = new global::Ubii.Processing.ProcessingModule();
                }
                ProcessingModule.MergeFrom(other.ProcessingModule);
                break;

            case TypeOneofCase.ProcessingModuleList:
                if (ProcessingModuleList == null)
                {
                    ProcessingModuleList = new global::Ubii.Processing.ProcessingModuleList();
                }
                ProcessingModuleList.MergeFrom(other.ProcessingModuleList);
                break;

            case TypeOneofCase.TopicMux:
                if (TopicMux == null)
                {
                    TopicMux = new global::Ubii.Devices.TopicMux();
                }
                TopicMux.MergeFrom(other.TopicMux);
                break;

            case TypeOneofCase.TopicMuxList:
                if (TopicMuxList == null)
                {
                    TopicMuxList = new global::Ubii.Devices.TopicMuxList();
                }
                TopicMuxList.MergeFrom(other.TopicMuxList);
                break;

            case TypeOneofCase.TopicDemux:
                if (TopicDemux == null)
                {
                    TopicDemux = new global::Ubii.Devices.TopicDemux();
                }
                TopicDemux.MergeFrom(other.TopicDemux);
                break;

            case TypeOneofCase.TopicDemuxList:
                if (TopicDemuxList == null)
                {
                    TopicDemuxList = new global::Ubii.Devices.TopicDemuxList();
                }
                TopicDemuxList.MergeFrom(other.TopicDemuxList);
                break;

            case TypeOneofCase.ClientList:
                if (ClientList == null)
                {
                    ClientList = new global::Ubii.Clients.ClientList();
                }
                ClientList.MergeFrom(other.ClientList);
                break;

            case TypeOneofCase.DeviceList:
                if (DeviceList == null)
                {
                    DeviceList = new global::Ubii.Devices.DeviceList();
                }
                DeviceList.MergeFrom(other.DeviceList);
                break;

            case TypeOneofCase.LockstepProcessingRequest:
                if (LockstepProcessingRequest == null)
                {
                    LockstepProcessingRequest = new global::Ubii.Processing.LockstepProcessingRequest();
                }
                LockstepProcessingRequest.MergeFrom(other.LockstepProcessingRequest);
                break;
            }

            _unknownFields = pb::UnknownFieldSet.MergeFrom(_unknownFields, other._unknownFields);
        }
Пример #10
0
        public override int GetHashCode()
        {
            int hash = 1;

            if (Topic.Length != 0)
            {
                hash ^= Topic.GetHashCode();
            }
            if (typeCase_ == TypeOneofCase.Client)
            {
                hash ^= Client.GetHashCode();
            }
            if (typeCase_ == TypeOneofCase.Device)
            {
                hash ^= Device.GetHashCode();
            }
            if (typeCase_ == TypeOneofCase.TopicSubscription)
            {
                hash ^= TopicSubscription.GetHashCode();
            }
            if (typeCase_ == TypeOneofCase.Session)
            {
                hash ^= Session.GetHashCode();
            }
            if (typeCase_ == TypeOneofCase.SessionList)
            {
                hash ^= SessionList.GetHashCode();
            }
            if (typeCase_ == TypeOneofCase.ProcessingModule)
            {
                hash ^= ProcessingModule.GetHashCode();
            }
            if (typeCase_ == TypeOneofCase.ProcessingModuleList)
            {
                hash ^= ProcessingModuleList.GetHashCode();
            }
            if (typeCase_ == TypeOneofCase.TopicMux)
            {
                hash ^= TopicMux.GetHashCode();
            }
            if (typeCase_ == TypeOneofCase.TopicMuxList)
            {
                hash ^= TopicMuxList.GetHashCode();
            }
            if (typeCase_ == TypeOneofCase.TopicDemux)
            {
                hash ^= TopicDemux.GetHashCode();
            }
            if (typeCase_ == TypeOneofCase.TopicDemuxList)
            {
                hash ^= TopicDemuxList.GetHashCode();
            }
            if (typeCase_ == TypeOneofCase.ClientList)
            {
                hash ^= ClientList.GetHashCode();
            }
            if (typeCase_ == TypeOneofCase.DeviceList)
            {
                hash ^= DeviceList.GetHashCode();
            }
            if (typeCase_ == TypeOneofCase.LockstepProcessingRequest)
            {
                hash ^= LockstepProcessingRequest.GetHashCode();
            }
            hash ^= (int)typeCase_;
            if (_unknownFields != null)
            {
                hash ^= _unknownFields.GetHashCode();
            }
            return(hash);
        }
Пример #11
0
        public void MergeFrom(ServiceReply other)
        {
            if (other == null)
            {
                return;
            }
            switch (other.TypeCase)
            {
            case TypeOneofCase.Success:
                if (Success == null)
                {
                    Success = new global::Ubii.General.Success();
                }
                Success.MergeFrom(other.Success);
                break;

            case TypeOneofCase.Error:
                if (Error == null)
                {
                    Error = new global::Ubii.General.Error();
                }
                Error.MergeFrom(other.Error);
                break;

            case TypeOneofCase.Client:
                if (Client == null)
                {
                    Client = new global::Ubii.Clients.Client();
                }
                Client.MergeFrom(other.Client);
                break;

            case TypeOneofCase.Device:
                if (Device == null)
                {
                    Device = new global::Ubii.Devices.Device();
                }
                Device.MergeFrom(other.Device);
                break;

            case TypeOneofCase.Server:
                if (Server == null)
                {
                    Server = new global::Ubii.Servers.Server();
                }
                Server.MergeFrom(other.Server);
                break;

            case TypeOneofCase.Session:
                if (Session == null)
                {
                    Session = new global::Ubii.Sessions.Session();
                }
                Session.MergeFrom(other.Session);
                break;

            case TypeOneofCase.SessionList:
                if (SessionList == null)
                {
                    SessionList = new global::Ubii.Sessions.SessionList();
                }
                SessionList.MergeFrom(other.SessionList);
                break;

            case TypeOneofCase.ProcessingModule:
                if (ProcessingModule == null)
                {
                    ProcessingModule = new global::Ubii.Processing.ProcessingModule();
                }
                ProcessingModule.MergeFrom(other.ProcessingModule);
                break;

            case TypeOneofCase.ProcessingModuleList:
                if (ProcessingModuleList == null)
                {
                    ProcessingModuleList = new global::Ubii.Processing.ProcessingModuleList();
                }
                ProcessingModuleList.MergeFrom(other.ProcessingModuleList);
                break;

            case TypeOneofCase.StringList:
                if (StringList == null)
                {
                    StringList = new global::Ubii.DataStructure.StringList();
                }
                StringList.MergeFrom(other.StringList);
                break;

            case TypeOneofCase.TopicMux:
                if (TopicMux == null)
                {
                    TopicMux = new global::Ubii.Devices.TopicMux();
                }
                TopicMux.MergeFrom(other.TopicMux);
                break;

            case TypeOneofCase.TopicMuxList:
                if (TopicMuxList == null)
                {
                    TopicMuxList = new global::Ubii.Devices.TopicMuxList();
                }
                TopicMuxList.MergeFrom(other.TopicMuxList);
                break;

            case TypeOneofCase.TopicDemux:
                if (TopicDemux == null)
                {
                    TopicDemux = new global::Ubii.Devices.TopicDemux();
                }
                TopicDemux.MergeFrom(other.TopicDemux);
                break;

            case TypeOneofCase.TopicDemuxList:
                if (TopicDemuxList == null)
                {
                    TopicDemuxList = new global::Ubii.Devices.TopicDemuxList();
                }
                TopicDemuxList.MergeFrom(other.TopicDemuxList);
                break;

            case TypeOneofCase.ClientList:
                if (ClientList == null)
                {
                    ClientList = new global::Ubii.Clients.ClientList();
                }
                ClientList.MergeFrom(other.ClientList);
                break;

            case TypeOneofCase.DeviceList:
                if (DeviceList == null)
                {
                    DeviceList = new global::Ubii.Devices.DeviceList();
                }
                DeviceList.MergeFrom(other.DeviceList);
                break;

            case TypeOneofCase.Service:
                if (Service == null)
                {
                    Service = new global::Ubii.Services.Service();
                }
                Service.MergeFrom(other.Service);
                break;

            case TypeOneofCase.ServiceList:
                if (ServiceList == null)
                {
                    ServiceList = new global::Ubii.Services.ServiceList();
                }
                ServiceList.MergeFrom(other.ServiceList);
                break;

            case TypeOneofCase.LockstepProcessingReply:
                if (LockstepProcessingReply == null)
                {
                    LockstepProcessingReply = new global::Ubii.Processing.LockstepProcessingReply();
                }
                LockstepProcessingReply.MergeFrom(other.LockstepProcessingReply);
                break;
            }

            _unknownFields = pb::UnknownFieldSet.MergeFrom(_unknownFields, other._unknownFields);
        }
Пример #12
0
        public override int GetHashCode()
        {
            int hash = 1;

            if (typeCase_ == TypeOneofCase.Success)
            {
                hash ^= Success.GetHashCode();
            }
            if (typeCase_ == TypeOneofCase.Error)
            {
                hash ^= Error.GetHashCode();
            }
            if (typeCase_ == TypeOneofCase.Client)
            {
                hash ^= Client.GetHashCode();
            }
            if (typeCase_ == TypeOneofCase.Device)
            {
                hash ^= Device.GetHashCode();
            }
            if (typeCase_ == TypeOneofCase.Server)
            {
                hash ^= Server.GetHashCode();
            }
            if (typeCase_ == TypeOneofCase.Session)
            {
                hash ^= Session.GetHashCode();
            }
            if (typeCase_ == TypeOneofCase.SessionList)
            {
                hash ^= SessionList.GetHashCode();
            }
            if (typeCase_ == TypeOneofCase.ProcessingModule)
            {
                hash ^= ProcessingModule.GetHashCode();
            }
            if (typeCase_ == TypeOneofCase.ProcessingModuleList)
            {
                hash ^= ProcessingModuleList.GetHashCode();
            }
            if (typeCase_ == TypeOneofCase.StringList)
            {
                hash ^= StringList.GetHashCode();
            }
            if (typeCase_ == TypeOneofCase.TopicMux)
            {
                hash ^= TopicMux.GetHashCode();
            }
            if (typeCase_ == TypeOneofCase.TopicMuxList)
            {
                hash ^= TopicMuxList.GetHashCode();
            }
            if (typeCase_ == TypeOneofCase.TopicDemux)
            {
                hash ^= TopicDemux.GetHashCode();
            }
            if (typeCase_ == TypeOneofCase.TopicDemuxList)
            {
                hash ^= TopicDemuxList.GetHashCode();
            }
            if (typeCase_ == TypeOneofCase.ClientList)
            {
                hash ^= ClientList.GetHashCode();
            }
            if (typeCase_ == TypeOneofCase.DeviceList)
            {
                hash ^= DeviceList.GetHashCode();
            }
            if (typeCase_ == TypeOneofCase.Service)
            {
                hash ^= Service.GetHashCode();
            }
            if (typeCase_ == TypeOneofCase.ServiceList)
            {
                hash ^= ServiceList.GetHashCode();
            }
            if (typeCase_ == TypeOneofCase.LockstepProcessingReply)
            {
                hash ^= LockstepProcessingReply.GetHashCode();
            }
            hash ^= (int)typeCase_;
            if (_unknownFields != null)
            {
                hash ^= _unknownFields.GetHashCode();
            }
            return(hash);
        }
Пример #13
0
 private bool IsValidIOMapping(ProcessingModule processingModule, TopicOutputMapping outputMapping)
 {
     return(processingModule.Outputs.Any(output => output.InternalName == outputMapping.OutputName));
 }
Пример #14
0
 private bool IsValidIOMapping(ProcessingModule processingModule, TopicInputMapping inputMapping)
 {
     return(processingModule.Inputs.Any(input => input.InternalName == inputMapping.InputName));
 }
Пример #15
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);
    }
Пример #16
0
    /// <summary>
    /// Starts processing module
    /// </summary>
    /// <param name="pmSpec">Processing module to start</param>
    public void StartModule(Ubii.Processing.ProcessingModule pmSpec)
    {
        ProcessingModule pm = processingModules[pmSpec.Id];

        pm?.Start();
    }