private IEnumerator ProcessMainMenu(){ this.Blocked = true; switch( this.inPut.text.ToUpperInvariant() ){ case "A": var task1 = SSClient.SearchForDevicesType(null); yield return new WaitUntil(() => task1.IsCompleted); break; case "R": var task2 = SSClient.SearchForDevicesType(""); yield return new WaitUntil(() => task2.IsCompleted); break; case "G": var task3 = SSClient.SearchForDevicesType("urn:sbtvd-org:service:GingaCCWebServices:1"); yield return new WaitUntil(() => task3.IsCompleted); break; case "I": yield return this.ConnectToGinga(); if( this.ssclient != null ){ // Change input treatment this.menuToProcess = this.ProcessGingaOptions; this.ShowGingaOptions(); this.Blocked = false; yield break; } break; case "?": break; case "X": Application.Quit(1); break; default: this.outPut.text += "Unknown command. Press ? for a list of valid commands.\n"; break; } this.ShowMenuOptions(); this.Blocked = false; }
// Syncronous private IEnumerator ConnectToGinga(){ // Step one: Discover every Ginga devices on the network with SSDP var findGingaDevices = SSClient.SearchForDevicesType("urn:sbtvd-org:service:GingaCCWebServices:1"); yield return new WaitUntil(() => findGingaDevices.IsCompleted); // Clean up var gingaDevices = findGingaDevices.Result; findGingaDevices.Dispose(); findGingaDevices = null; if( gingaDevices.Count == 0 ){ DebugStream.outPut += "\nNenhum dispositivo Ginga encontrado!\n"; yield break; } // Get a chosen discovered Ginga SSDP device Rssdp.DiscoveredSsdpDevice chosenGinga = gingaDevices.Values.First(); // Clean up gingaDevices.Clear(); gingaDevices = null; if( !chosenGinga.ResponseHeaders.Contains("LOCATION") ){ DebugStream.outPut += "\nGinga SSDP response header has no LOCATION key!\n"; yield break; } if( chosenGinga.ResponseHeaders.GetValues("LOCATION").Count() == 0 ){ DebugStream.outPut += "\nGinga SSDP LOCATION response header has no value!\n"; yield break; } var gingaHTTPLocation = new Uri(chosenGinga.ResponseHeaders.GetValues("LOCATION").First()); var finishHandShake = Task.Factory.StartNew(() => { try{ this.ssclient = new SSClient(gingaHTTPLocation,this.OnActionReceived,this.OnApplicationQuit); // Debug DebugStream.outPut += "Control connection stablished!\n"; DebugStream.outPut += "Socket.Connected: " + ssclient.Connected.ToString() + "\n"; }catch( Exception e){ DebugStream.outPut += "\nSSClient construction failed: " + e.ToString() + "\n"; Assert.IsNull(this.ssclient); } }); yield return new WaitUntil(() => finishHandShake.IsCompleted); finishHandShake.Dispose(); // If connected, it's also listenning if( this.ssclient != null ) this.ssclient.StartListenerCoroutineOn(this); }