コード例 #1
0
        /// <summary>
        /// Returns the contents of the respective sessionID (if available).
        /// Otherwise false is returned, whereas the specific message is provided in the LogData.
        /// </summary>
        /// <param name="sessionID"></param>
        /// <param name="sessionContent"></param>
        /// <param name="avatarContent"></param>
        /// <returns></returns>
        public MBoolResponse GetContents(string sessionID, out SessionContent sessionContent, out AvatarContent avatarContent)
        {
            sessionContent = null;
            avatarContent  = null;


            MBoolResponse sessionResult = GetSessionContent(sessionID, out sessionContent);

            if (!sessionResult.Successful)
            {
                return(sessionResult);
            }

            SessionID idContainer = new SessionID(sessionID);


            if (!sessionContent.AvatarContent.TryGetValue(idContainer.AvatarID, out avatarContent))
            {
                //Session content not available
                return(new MBoolResponse(false)
                {
                    LogData = new List <string>()
                    {
                        "Avatar content not available " + sessionID + ", avatarId: " + idContainer.AvatarID
                    }
                });
            }


            return(new MBoolResponse(true));
        }
コード例 #2
0
        /// <summary>
        /// Returns the session content (if available)
        /// </summary>
        /// <param name="sessionID"></param>
        /// <param name="sessionContent"></param>
        /// <returns></returns>
        public MBoolResponse GetSessionContent(string sessionID, out SessionContent sessionContent)
        {
            sessionContent = null;

            //First check if session id is valid
            if (sessionID == null)
            {
                return(new MBoolResponse(false)
                {
                    LogData = new List <string>()
                    {
                        "Session id is null"
                    }
                });
            }

            SessionID idContainer = new SessionID(sessionID);

            //Get session content
            if (!SessionContents.TryGetValue(idContainer.SceneID, out sessionContent))
            {
                //Session content not available
                return(new MBoolResponse(false)
                {
                    LogData = new List <string>()
                    {
                        "Session content not available " + sessionID
                    }
                });
            }

            return(new MBoolResponse(true));
        }
コード例 #3
0
        /// <summary>
        /// Removes the session content with the specific ID
        /// </summary>
        /// <param name="sessionID"></param>
        /// <returns></returns>
        public MBoolResponse RemoveSessionContent(string sessionID)
        {
            //Get the ids
            string sceneId  = null;
            string avatarId = null;

            SessionID.GetSplittedIDs(sessionID, out sceneId, out avatarId);

            //Check if sessionID is available
            if (SessionContents.ContainsKey(sceneId))
            {
                //Try to remove the respective session content
                SessionContent sessionContent = null;
                if (SessionContents.TryRemove(sceneId, out sessionContent))
                {
                    return(new MBoolResponse(true));
                }
            }

            Logger.Log(Log_level.L_ERROR, $"Session content not available: {sessionID}");


            return(new MBoolResponse(false)
            {
                LogData = new List <string>()
                {
                    "Session content not available " + sessionID
                }
            });
        }
コード例 #4
0
        public virtual List <MConstraint> GetBoundaryConstraints(MInstruction instruction, string mmuID, string sessionID)
        {
            SessionContent sessionContent = null;
            AvatarContent  avatarContent  = null;

            MBoolResponse sessionResult = SessionData.GetContents(sessionID, out sessionContent, out avatarContent);

            if (!sessionResult.Successful)
            {
                return(new List <MConstraint>());
            }

            sessionContent.UpdateLastAccessTime();

            return(avatarContent.MMUs[mmuID].GetBoundaryConstraints(instruction));
        }
コード例 #5
0
        public virtual List <MMUDescription> GetMMus(string sessionID)
        {
            SessionContent sessionContent = null;
            AvatarContent  avatarContent  = null;

            MBoolResponse sessionResult = SessionData.GetContents(sessionID, out sessionContent, out avatarContent);

            if (!sessionResult.Successful)
            {
                return(new List <MMUDescription>());
            }

            sessionContent.UpdateLastAccessTime();

            return(SessionData.MMUDescriptions.Where(s => avatarContent.MMUs.Keys.Contains(s.ID)).ToList());
        }
コード例 #6
0
        public virtual MBoolResponse Dispose(string mmuID, string sessionID)
        {
            SessionContent sessionContent = null;
            AvatarContent  avatarContent  = null;

            MBoolResponse sessionResult = SessionData.GetContents(sessionID, out sessionContent, out avatarContent);

            if (!sessionResult.Successful)
            {
                return(sessionResult);
            }

            sessionContent.UpdateLastAccessTime();

            //Call the dispose method of the respective MMU
            return(avatarContent.MMUs[mmuID].Dispose(new Dictionary <string, string>()));
        }
コード例 #7
0
        public virtual MBoolResponse Abort(string instructionId, string mmuID, string sessionID)
        {
            SessionContent sessionContent = null;
            AvatarContent  avatarContent  = null;

            MBoolResponse sessionResult = SessionData.GetContents(sessionID, out sessionContent, out avatarContent);

            if (!sessionResult.Successful)
            {
                return(sessionResult);
            }

            sessionContent.UpdateLastAccessTime();

            //Abort the respective MMU
            return(avatarContent.MMUs[mmuID].Abort(instructionId));
        }
コード例 #8
0
        /// <summary>
        /// Returns the session content given the current session id
        /// </summary>
        /// <param name="sessionId"></param>
        /// <returns></returns>
        public SessionContent CreateSessionContent(string sessionId)
        {
            if (sessionId == null)
            {
                Logger.Log(Log_level.L_ERROR, "Warning: Session id is null!");
                return(null);
            }

            //Get the ids
            string sceneId  = null;
            string avatarId = null;

            SessionID.GetSplittedIDs(sessionId, out sceneId, out avatarId);

            //Create a new session content
            SessionContent sessionContent = null;


            //Session already avilable
            if (SessionContents.TryGetValue(sceneId, out sessionContent))
            {
                //Check avatar content -> If not available add it
                if (!sessionContent.AvatarContent.ContainsKey(avatarId))
                {
                    AvatarContent avatarContent = new AvatarContent(avatarId);
                    sessionContent.AvatarContent.TryAdd(avatarId, avatarContent);
                }
            }

            //Session not available -> Create new
            else
            {
                Logger.Log(Log_level.L_INFO, $"Create new session id: {sessionId})");

                //Create new session content
                sessionContent = new SessionContent(this, sceneId);


                AvatarContent avatarContent = new AvatarContent(avatarId);

                sessionContent.AvatarContent.TryAdd(avatarId, avatarContent);
                SessionContents.TryAdd(sceneId, sessionContent);
            }

            return(sessionContent);
        }
コード例 #9
0
        /// <summary>
        /// Basic initialization of a MMMU
        /// </summary>
        /// <param name="mmuID"></param>
        /// <param name="sessionID"></param>
        public virtual MBoolResponse Initialize(MAvatarDescription avatarDescription, Dictionary <string, string> properties, string mmuID, string sessionID)
        {
            SessionContent sessionContent = null;
            AvatarContent  avatarContent  = null;

            MBoolResponse sessionResult = SessionData.GetContents(sessionID, out sessionContent, out avatarContent);

            this.skeletonAccess = new IntermediateSkeleton();
            this.skeletonAccess.InitializeAnthropometry(avatarDescription);

            //Skip if invalid session result
            if (!sessionResult.Successful)
            {
                return(sessionResult);
            }

            try
            {
                //Update the access time
                sessionContent.UpdateLastAccessTime();

                //Get the corresponding MMU
                IMotionModelUnitDev mmu = avatarContent.MMUs[mmuID];

                Logger.Log(Log_level.L_INFO, "MMU initialized: " + mmu.Name + " " + sessionID);

                //Call the respective MMU
                return(avatarContent.MMUs[mmuID].Initialize(avatarDescription, properties));
            }
            catch (Exception e)
            {
                Logger.Log(Log_level.L_ERROR, $"Problem at initializing MMU: {mmuID}, message: {e.Message}");

                return(new MBoolResponse(false)
                {
                    LogData = new List <string>()
                    {
                        e.Message,
                        e.StackTrace,
                        e.InnerException.ToString(),
                        e.StackTrace
                    }
                });
            }
        }
コード例 #10
0
        public virtual MBoolResponse CheckPrerequisites(MInstruction instruction, string mmuID, string sessionID)
        {
            SessionContent sessionContent = null;
            AvatarContent  avatarContent  = null;

            MBoolResponse sessionResult = SessionData.GetContents(sessionID, out sessionContent, out avatarContent);

            if (!sessionResult.Successful)
            {
                return(sessionResult);
            }


            sessionContent.UpdateLastAccessTime();

            //Execute the method of the MMU
            return(avatarContent.MMUs[mmuID].CheckPrerequisites(instruction));
        }
コード例 #11
0
        /// <summary>
        /// Basic do step routine which triggers the simulation update of the repsective MMU
        /// </summary>
        /// <param name="time"></param>
        /// <param name="simulationState"></param>
        /// <param name="mmuID"></param>
        /// <param name="sessionID"></param>
        /// <returns></returns>
        public virtual MSimulationResult DoStep(double time, MSimulationState simulationState, string mmuID, string sessionID)
        {
            SessionContent sessionContent = null;
            AvatarContent  avatarContent  = null;

            MBoolResponse sessionResult = SessionData.GetContents(sessionID, out sessionContent, out avatarContent);

            //Skip if invalid session result
            if (!sessionResult.Successful)
            {
                return(null);
            }

            sessionContent.UpdateLastAccessTime();

            //Execute the do step of the respective MMU
            return(avatarContent.MMUs[mmuID].DoStep(time, simulationState));
        }
コード例 #12
0
        public virtual MBoolResponse RestoreCheckpoint(string mmuID, string sessionID, byte[] checkpointData)
        {
            SessionContent sessionContent = null;
            AvatarContent  avatarContent  = null;

            MBoolResponse sessionResult = SessionData.GetContents(sessionID, out sessionContent, out avatarContent);

            if (!sessionResult.Successful)
            {
                return(sessionResult);
            }

            sessionContent.UpdateLastAccessTime();

            Logger.Log(Log_level.L_INFO, $"Restore checkpoint of {mmuID}");


            return(avatarContent.MMUs[mmuID].RestoreCheckpoint(checkpointData));
        }
コード例 #13
0
        public Dictionary <string, string> ExecuteFunction(string name, Dictionary <string, string> parameters, string mmuID, string sessionID)
        {
            SessionContent sessionContent = null;
            AvatarContent  avatarContent  = null;

            MBoolResponse sessionResult = SessionData.GetContents(sessionID, out sessionContent, out avatarContent);

            if (!sessionResult.Successful)
            {
                return(null);
            }

            sessionContent.UpdateLastAccessTime();


            Logger.Log(Log_level.L_DEBUG, $"Ecexute function {name} of {mmuID}");

            return(avatarContent.MMUs[mmuID].ExecuteFunction(name, parameters));
        }
コード例 #14
0
        /// <summary>
        /// Creates a checkpoint for all specified MMUs.
        /// The checkpoint contains the internal state of each MMU whoch can be later used to restore the state.
        /// </summary>
        /// <param name="mmuIDs"></param>
        /// <param name="sessionID"></param>
        /// <param name="checkpointID"></param>
        public virtual byte[] CreateCheckpoint(string mmuID, string sessionID)
        {
            SessionContent sessionContent = null;
            AvatarContent  avatarContent  = null;

            MBoolResponse sessionResult = SessionData.GetContents(sessionID, out sessionContent, out avatarContent);

            if (!sessionResult.Successful)
            {
                return(null);
            }

            sessionContent.UpdateLastAccessTime();

            //Add method to interface
            byte[] checkpointData = avatarContent.MMUs[mmuID].CreateCheckpoint();

            Logger.Log(Log_level.L_INFO, $"Checkpoint of {mmuID} sucessfully created ({checkpointData.Length} bytes)");

            return(checkpointData);
        }
コード例 #15
0
        /// <summary>
        /// Should work
        /// </summary>
        /// <param name="sceneManipulations"></param>
        /// <param name="sessionID"></param>
        public virtual MBoolResponse PushScene(MSceneUpdate sceneUpdates, string sessionID)
        {
            SessionContent sessionContent = null;

            //Get the session content for the id
            MBoolResponse sessionResult = SessionData.GetSessionContent(sessionID, out sessionContent);

            //Skip if invalid session result
            if (!sessionResult.Successful)
            {
                Debug.Fail(sessionResult.LogData.ToString());
                return(sessionResult);
            }


            //Set the last access time
            sessionContent.UpdateLastAccessTime();

            //Synchronize the respective scene
            return(sessionContent.SceneBuffer.Apply(sceneUpdates));
        }
コード例 #16
0
        /// <summary>
        /// Returns the deltas of the last frame
        /// </summary>
        /// <param name="sessionID"></param>
        /// <returns></returns>
        public virtual MSceneUpdate GetSceneChanges(string sessionID)
        {
            SessionContent sessionContent = null;

            MBoolResponse sessionResult = SessionData.GetSessionContent(sessionID, out sessionContent);

            if (sessionResult.Successful)
            {
                //Set the last access time
                sessionContent.UpdateLastAccessTime();

                return(sessionContent.SceneBuffer.GetSceneChanges());
            }

            else
            {
                Logger.Log(Log_level.L_ERROR, sessionResult.LogData.ToString());
            }

            return(new MSceneUpdate());
        }
コード例 #17
0
        /// <summary>
        /// Execute command of a MMU
        /// </summary>
        /// <param name="instruction"></param>
        /// <param name="simulationState"></param>
        /// <param name="hierarchy"></param>
        /// <param name="mmuID"></param>
        /// <param name="sessionID"></param>
        public virtual MBoolResponse AssignInstruction(MInstruction instruction, MSimulationState simulationState, string mmuID, string sessionID)
        {
            SessionContent sessionContent = null;
            AvatarContent  avatarContent  = null;

            MBoolResponse sessionResult = SessionData.GetContents(sessionID, out sessionContent, out avatarContent);

            //Directly return if not successfull
            if (!sessionResult.Successful)
            {
                return(sessionResult);
            }

            sessionContent.UpdateLastAccessTime();


            Logger.Log(Log_level.L_DEBUG, $"Execute instruction {instruction.Name}, {mmuID}");


            //Directly assign the instruction
            return(avatarContent.MMUs[mmuID].AssignInstruction(instruction, simulationState));
        }
コード例 #18
0
        /// <summary>
        /// Method which manages and cleans up the sessions
        /// </summary>
        private void ManageSessions()
        {
            //Do while no cancellation requested
            while (!this.cts.IsCancellationRequested)
            {
                //This can be done every n seconds
                Thread.Sleep(this.UpdateTime);

                //Check all sessions for timeout
                for (int i = SessionData.SessionContents.Count - 1; i >= 0; i--)
                {
                    SessionContent sessionContent = SessionData.SessionContents.ElementAt(i).Value;
                    string         sessionID      = SessionData.SessionContents.ElementAt(i).Key;

                    if (sessionContent.LastAccess != null && (DateTime.Now - sessionContent.LastAccess).Duration() > this.Timeout)
                    {
                        SessionData.SessionContents.TryRemove(sessionID, out sessionContent);

                        Logger.Log(Log_level.L_INFO, $"Session {sessionID} automatically removed due to timeout");
                    }
                }
            }
        }
コード例 #19
0
        /// <summary>
        /// Returns the scene contained within the adapter
        /// </summary>
        /// <param name="sessionID"></param>
        /// <returns></returns>
        public virtual List <MSceneObject> GetScene(string sessionID)
        {
            SessionContent sessionContent = null;

            MBoolResponse sessionResult = SessionData.GetSessionContent(sessionID, out sessionContent);

            if (sessionResult.Successful)
            {
                //Set the last access time
                sessionContent.UpdateLastAccessTime();

                Logger.Log(Log_level.L_INFO, "Transfer all scene objects");

                return(sessionContent.SceneBuffer.GetSceneObjects());
            }

            else
            {
                Debug.Fail(sessionResult.LogData.ToString());
            }

            return(new List <MSceneObject>());
        }
コード例 #20
0
        /// <summary>
        /// Creates a new session for the specified id
        /// </summary>
        /// <param name="sessionID"></param>
        public virtual MBoolResponse CreateSession(string sessionID)
        {
            //Skip if the sessionID is invalid
            if (sessionID == null || sessionID.Count() == 0)
            {
                return new MBoolResponse(false)
                       {
                           LogData = new List <string>()
                           {
                               "Session ID invalid"
                           }
                       }
            }
            ;

            //Skip if sessionID already available
            if (SessionData.SessionIDAvailable(sessionID))
            {
                return new MBoolResponse(false)
                       {
                           LogData = new List <string>()
                           {
                               "Session ID already available"
                           }
                       }
            }
            ;

            //Create a new session content using the specified id
            SessionContent sessionContent = SessionData.CreateSessionContent(sessionID);

            //Set the last access time
            sessionContent.UpdateLastAccessTime();

            return(new MBoolResponse(true));
        }
コード例 #21
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="mmus"></param>
        /// <param name="sessionID"></param>
        /// <returns>A mapping from MMUID to a specific instance id</returns>
        public virtual Dictionary <string, string> LoadMMUs(List <string> mmus, string sessionID)
        {
            SessionContent sessionContent = null;
            SessionID      idContainer    = new SessionID(sessionID);

            //Get the session content for the id
            MBoolResponse sessionResult = SessionData.GetSessionContent(sessionID, out sessionContent);

            //Skip if invalid session result
            if (!sessionResult.Successful)
            {
                Logger.Log(Log_level.L_ERROR, "Cannot generate session content");
                return(new Dictionary <string, string>());
            }

            //Set the last access time
            sessionContent.UpdateLastAccessTime();

            Dictionary <string, string> mmuInstanceMapping = new Dictionary <string, string>();

            //Iterate over each desired MMU
            foreach (string mmuID in mmus)
            {
                MMULoadingProperty mmuLoadingProperty = null;

                //Skip MMU is not contained in adapter
                if (!SessionData.MMULoadingProperties.TryGetValue(mmuID, out mmuLoadingProperty))
                {
                    continue;
                }

                IMotionModelUnitDev mmu = null;

                //Instantiate MMU
                try
                {
                    mmu = this.mmuInstantiator.InstantiateMMU(mmuLoadingProperty);
                }
                catch (Exception e)
                {
                    Logger.Log(Log_level.L_ERROR, $"Problem at loading MMU {mmuLoadingProperty.Description.Name}, Exception: {e.Message}, {e.StackTrace}");

                    return(new Dictionary <string, string>());
                }

                //Assign the service access
                mmu.ServiceAccess = sessionContent.ServiceAccess;

                //Assign the scene
                mmu.SceneAccess = sessionContent.SceneBuffer;

                //Assign a new instance of the skeleton access
                mmu.SkeletonAccess = this.skeletonAccess;//new SkeletonAccess();

                //Set the instance as the adapter
                mmu.AdapterEndpoint = new AdapterEndpoint()
                {
                    Instance           = SessionData.AdapterInstance,
                    Description        = SessionData.AdapterDescription,
                    MMIRegisterAddress = SessionData.MMIRegisterAddress
                };


                Logger.Log(Log_level.L_INFO, $"Loaded MMU: {mmuLoadingProperty.Description.Name} for session: {sessionID}");

                //Add to the specific avatar content
                AvatarContent avatarContent = null;

                if (!sessionContent.AvatarContent.TryGetValue(idContainer.AvatarID, out avatarContent))
                {
                    avatarContent = new AvatarContent(idContainer.AvatarID);

                    sessionContent.AvatarContent.TryAdd(idContainer.AvatarID, avatarContent);
                }

                //Add the mmu
                avatarContent.MMUs.Add(mmuLoadingProperty.Description.ID, mmu);

                //To do -> create a unique instance ID
                mmuInstanceMapping.Add(mmuLoadingProperty.Description.ID, "tbd");
            }

            return(mmuInstanceMapping);
        }