Beispiel #1
0
    public IEnumerator startServerAndAllClients()
    {
        if (androidDevice)
        {
            //Start Server
            Debug.Log("Started: " + BufferServicesControllerInterface.startServer());

            yield return(new WaitForSeconds(10));           //These waits are for the Services to have time to pass around their intents

            //Start Clients
            Debug.Log("Started: " + BufferServicesControllerInterface.startClients());

            yield return(new WaitForSeconds(1));

            //Start FilePlayback client
            string[] result = BufferServicesControllerInterface.getAllThreadsNamesAndIDs();
            while (result.Length == 0)          //Wait until the ClientsService updates the controller with all the available threads
            {
                yield return(new WaitForSeconds(1));

                result = BufferServicesControllerInterface.getAllThreadsNamesAndIDs();
            }
            for (int i = 0; i < result.Length; ++i)
            {
                if (result[i].Split(':')[1] == "File Playback")
                {
                    Debug.Log("Starting FilePlayback");
                    threadID = int.Parse(result[i].Split(':')[0]);
                    BufferServicesControllerInterface.startThread(threadID);
                }
            }
            yield return(new WaitForSeconds(1));

            //Start the internal buffer client
            GameObject.Find("Sphere").GetComponent <MovingWithAlphaLatEvents>().initializeBuffer();
        }
    }
Beispiel #2
0
    private IEnumerator startThread(int threadID, GameObject button)
    {
        if (androidDevice)
        {
            //Get the clientIDs of all the clients running before we start a new one
            List <int> oldRunningClientIDs = new List <int>();
            int[]      result = BufferServicesControllerInterface.getClientIDs();
            for (int i = 0; i < result.Length; ++i)
            {
                oldRunningClientIDs.Add(result[i]);
            }
            if (verbose)
            {
                Debug.Log("size of old clients list = " + oldRunningClientIDs.Count);
            }

            //Start a new thread (client)
            BufferServicesControllerInterface.startThread(threadID);
            if (verbose)
            {
                Debug.Log("Starting thread: " + threadID.ToString());
            }
            yield return(new WaitForSeconds(1f));


            //Get the new client ID by comparing the old returned list of ids with the new one
            List <int> newRunningClientIDs = new List <int>();
            result = BufferServicesControllerInterface.getClientIDs();
            for (int i = 0; i < result.Length; ++i)
            {
                newRunningClientIDs.Add(result[i]);
            }
            if (verbose)
            {
                Debug.Log("size of new clients list = " + newRunningClientIDs.Count);
            }

            //Client IDs get created but do not get deleted so connect a new client ID to a thread ID or call a preexisting client ID by the button's thread ID
            int clientID = -1;
            IEnumerable <int> newClientID = new List <int>();
            newClientID = (from s in newRunningClientIDs where !oldRunningClientIDs.Contains(s) select s);
            if (newClientID.Count() > 0)
            {
                clientID = newClientID.ElementAt(0);
                threadIDsToClientIDs.Add(threadID, clientID);
            }
            else
            {
                clientID = threadIDsToClientIDs[threadID];
            }

            //Make the info panel
            GameObject clientInfo = (GameObject)Instantiate(clientInfoPanel);
            clientInfo.transform.SetParent(button.transform);
            clientInfo.tag = "clientID " + clientID.ToString();
            RectTransform clientInfoTransform = clientInfo.GetComponent <RectTransform>();
            clientInfoTransform.anchoredPosition = new Vector3(0, 0, 0);
            clientInfo.transform.Find("ClientIDText").GetComponent <Text>().text = "Client ID: " + clientID.ToString();

            updateClientInfo = true;
            clientIDsToUpdateInfo.Add(clientID);
        }
    }