Beispiel #1
0
        private void FormDevices_Load(object sender, EventArgs e)
        {
            try {
                // create discovery system
                iListenerNotify = new SsdpListenerMulticast();

                // create device lists
                iDeviceListJukebox = new DeviceListUpnp(ServiceJukebox.ServiceType(1), iListenerNotify);

                // hook in to discovery events
                iDeviceListJukebox.EventDeviceAdded   += DeviceAlive;
                iDeviceListJukebox.EventDeviceRemoved += DeviceByeBye;

                NetworkInfoModel iface = iHelper.Interface.Interface.Info;
                if (iface != null)
                {
                    // start discovery process
                    iListenerNotify.Start(iface.IPAddress);
                    iDeviceListJukebox.Start(iface.IPAddress);

                    // improve discovery process
                    iDeviceListJukebox.Rescan();
                }
                else
                {
                    DiscoveryFailed("Device discovery failed: no valid network interface card selected");
                }
            }
            catch (Linn.Network.NetworkError ne) {
                DiscoveryFailed("NetworkError on device discovery: " + ne.Message);
            }
            catch (Exception exc) {
                DiscoveryFailed("Error on device discovery: " + exc.Message);
            }
        }
Beispiel #2
0
        public Boxes(Helper aHelper, EventServerUpnp aEventServer, ISsdpNotifyProvider aSsdpNotify, bool aDiscoverProxyDevices)
        {
            iLock           = new object();
            iHelper         = aHelper;
            iEventServer    = aEventServer;
            iListenerNotify = aSsdpNotify;
            iTree           = new Tree(aHelper);

            //listen to the volkano service
            iDeviceListVolkano = new DeviceListUpnp(ServiceVolkano.ServiceType(), iListenerNotify);
            iDeviceListVolkano.EventDeviceAdded   += VolkanoAddedHandler;
            iDeviceListVolkano.EventDeviceRemoved += VolkanoRemovedHandler;

            //listen to the proxy service
            if (aDiscoverProxyDevices)
            {
                iDeviceListProxy = new DeviceListUpnp(ServiceProxy.ServiceType(), iListenerNotify);
                iDeviceListProxy.EventDeviceAdded   += ProxyAddedHandler;
                iDeviceListProxy.EventDeviceRemoved += ProxyRemovedHandler;
            }

            // Configure Service Point Manager
            ServicePointManager.DefaultConnectionLimit = 50;
            ServicePointManager.Expect100Continue      = false;
            ServicePointManager.UseNagleAlgorithm      = false;
        }
Beispiel #3
0
        public Form1(Helper aHelper)
        {
            InitializeComponent();

            iDevices      = new SortedList <string, Device>();
            iDevicesMutex = new Mutex();

            iServiceDiagnosticsMutex = new Mutex();
            iResultMutex             = new Mutex();

            iRefresh      = 0;
            iTimerRefresh = new System.Threading.Timer(RefreshElapsed);
            iRefreshMutex = new Mutex();

            comboBoxRefresh.SelectedIndex = 0;

            iActionsStart = true;

            // create discovery system

            iHelper = aHelper;

            iListener = new SsdpListenerMulticast();

            iDeviceList = new DeviceListUpnp(ServiceDiagnostics.ServiceType(), iListener);
            iDeviceList.EventDeviceAdded   += DeviceAdded;
            iDeviceList.EventDeviceRemoved += DeviceRemoved;

            iHelper.Stack.SetStack(this);
            iHelper.Stack.Start();
        }
Beispiel #4
0
        public PlaylistManagers(ISsdpNotifyProvider aListenerNotify)
        {
            // create discovery system

            iDeviceListPlaylistManager = new DeviceListUpnp(ServicePlaylistManager.ServiceType(), aListenerNotify);
            iDeviceListPlaylistManager.EventDeviceAdded   += PlaylistManagerAdded;
            iDeviceListPlaylistManager.EventDeviceRemoved += PlaylistManagerRemoved;

            iLock             = new object();
            iJobList          = new List <IJob>();
            iJobReady         = new ManualResetEvent(false);
            iPlaylistManagers = new Dictionary <Device, PlaylistManager>();
        }
Beispiel #5
0
        public Senders(ISsdpNotifyProvider aListenerNotify)
        {
            // create discovery system

            iDeviceListSender = new DeviceListUpnp(ServiceSender.ServiceType(), aListenerNotify);
            iDeviceListSender.EventDeviceAdded   += SenderAdded;
            iDeviceListSender.EventDeviceRemoved += SenderRemoved;

            iMutex    = new Mutex();
            iJobList  = new List <IJob>();
            iJobReady = new ManualResetEvent(false);
            iDevices  = new Dictionary <string, Device>();
            iLock     = new object();
            iOpen     = false;
        }
Beispiel #6
0
        public Stack(ISsdpNotifyProvider aListenerNotify)
        {
            // create discovery system

            iDeviceListProduct = new DeviceListUpnp(ServiceProduct.ServiceType(), aListenerNotify);
            iDeviceListProduct.EventDeviceAdded   += ProductAdded;
            iDeviceListProduct.EventDeviceRemoved += ProductRemoved;

            iDeviceListUpnp = new DeviceListUpnp(ServiceAVTransport.ServiceType(), aListenerNotify);
            iDeviceListUpnp.EventDeviceAdded   += UpnpAdded;
            iDeviceListUpnp.EventDeviceRemoved += UpnpRemoved;

            iMutex    = new Mutex();
            iJobList  = new List <IJob>();
            iJobReady = new ManualResetEvent(false);
        }
Beispiel #7
0
        public Library(ISsdpNotifyProvider aListenerNotify)
        {
            // create discovery system

            iDeviceListContentDirectory = new DeviceListUpnp(ServiceContentDirectory.ServiceType(), aListenerNotify);
            iDeviceListContentDirectory.EventDeviceAdded   += ContentDirectoryAdded;
            iDeviceListContentDirectory.EventDeviceRemoved += ContentDirectoryRemoved;

            iMutex    = new Mutex();
            iJobList  = new List <IJob>();
            iJobReady = new ManualResetEvent(false);

            iCloudServers = new Dictionary <string, Device>();
            iMediaServers = new Dictionary <Device, MediaServer>();
            //iCloudServers.Add("http://89.238.133.245:26125/DeviceDescription.xml", new DeviceUpnp("http://89.238.133.245:26125/DeviceDescription.xml"));
        }
Beispiel #8
0
        public DeviceFinder(string aUglyName)
        {
            iUglyName = aUglyName;

            ServiceType type = ServiceVolkano.ServiceType();

            type.Version = 1;

            iListener = new SsdpListenerMulticast();

            iDeviceList = new DeviceListUpnp(type, iListener);

            iDeviceList.EventDeviceAdded += DeviceAdded;

            iSemaphore = new ManualResetEvent(false);

            iFound = false;
        }
Beispiel #9
0
        public Form1(Helper aHelper, string aFriendlyName, uint aIterations)
        {
            InitializeComponent();

            MinimizeBox = true;
            iHelper     = aHelper;

            iFriendlyName = aFriendlyName;
            iIterations   = aIterations;

            iListenerNotify    = new SsdpListenerMulticast();
            iDeviceListProduct = new DeviceListUpnp(ServiceProduct.ServiceType(), iListenerNotify);

            iDeviceListProduct.EventDeviceAdded   += EventDeviceAdded;
            iDeviceListProduct.EventDeviceRemoved += EventDeviceRemoved;

            iHelper.Stack.SetStack(this);
        }
Beispiel #10
0
        /*This class is written assuming a DS will gracefully close any viewer connections when it is shutdown, i.e
         * by sending a RST TCP packet. As of r22907 of the mainline volkano branch, it doesn't do this, so
         * ViewerManager's ConnectionClosed event is not fired as you would expect. However, ViewerManager signals
         * that services are no longer available by eventing when the DS sends out a multicast Upnp message signaling
         * its shutdown. We could use this signal to fire the ConnectionClosed event but it was decided that it would
         * be better not to work around this bug in the DS and rather write the Viewer to cope with a graceful shutdown only.
         */

        public ViewerManager()
        {
            iCurrentIPEndPoint = new IPEndPoint(IPAddress.Any, 0);
            iManualResetEvent  = new ManualResetEvent(false);

            iTcpListenerThread              = new Thread(new ThreadStart(RunTcpServer));
            iTcpListenerThread.Name         = "TcpListenerThread";
            iTcpListenerThread.IsBackground = true;
            iTcpListener = new TcpListener(IPAddress.Any, 0);
            iTcpListener.Start();
            iCurrentIPEndPoint.Port = ((IPEndPoint)iTcpListener.LocalEndpoint).Port;
            iManualResetEvent.Set();
            iState = TcpListenenerState.Accepting;

            iUdpClient = new UdpClient();

            iDeviceList = new DeviceListUpnp("linn.co.uk", "Volkano", 1, Dispatcher.CurrentDispatcher);
            iDeviceList.CollectionChanged += EventDeviceListCollectionChanged;
        }
Beispiel #11
0
        public bool FindDevice()
        {
            iIsFound.Reset();

            iDeviceList = new DeviceListUpnp(ServiceVolkano.ServiceType(), iListener);

            iDeviceList.EventDeviceAdded += DeviceAdded;

            iDeviceList.Start(iInterface);

            bool result = false;

            uint i = kMaxFindRetries;

            while (i-- > 0)
            {
                iConsole.Write("Finding " + iUglyName + " ................ ");

                if (WaitFor(iIsFound, kMaxFindSeconds))
                {
                    result = true;
                    break;
                }

                if (i > 0)
                {
                    iConsole.Write("Retry");
                    iConsole.Newline();
                    iDeviceList.Rescan();
                }
            }

            iDeviceList.EventDeviceAdded -= DeviceAdded;
            iDeviceList.Stop();

            return(result);
        }
Beispiel #12
0
        public WindowMain()
        {
            InitializeComponent();
            bool instantiated;

            iInstanceMutex = new Mutex(false, "ViewerMutex", out instantiated);
            if (!instantiated)
            {
                MessageBox.Show("Another instance of Viewer is already running. Please close all other instances and try again.", "Viewer is already running", MessageBoxButton.OK, MessageBoxImage.Warning);
                Application.Current.Shutdown();
            }

            iDebugLevels = new SortedList <string, DebugLevelItem>();
            UInt32 debugLevel;

            iDebugLevels.Add("Store", new DebugLevelItem("Store", debugLevel            = 1));
            iDebugLevels.Add("Flash", new DebugLevelItem("Flash", debugLevel           *= 2));
            iDebugLevels.Add("Common", new DebugLevelItem("Common", debugLevel         *= 2));
            iDebugLevels.Add("Boot", new DebugLevelItem("Boot", debugLevel             *= 2));
            iDebugLevels.Add("Thread", new DebugLevelItem("Thread", debugLevel         *= 2));
            iDebugLevels.Add("Bsp", new DebugLevelItem("Bsp", debugLevel               *= 2));
            iDebugLevels.Add("Network", new DebugLevelItem("Network", debugLevel       *= 2));
            iDebugLevels.Add("Event", new DebugLevelItem("Event", debugLevel           *= 2));
            iDebugLevels.Add("SysLib", new DebugLevelItem("SysLib", debugLevel         *= 2));
            iDebugLevels.Add("UpnpDevice", new DebugLevelItem("UpnpDevice", debugLevel *= 2));
            iDebugLevels.Add("Sdp", new DebugLevelItem("Sdp", debugLevel               *= 2));
            iDebugLevels.Add("Ess", new DebugLevelItem("Ess", debugLevel               *= 2));
            iDebugLevels.Add("Power", new DebugLevelItem("Power", debugLevel           *= 2));
            iDebugLevels.Add("Http", new DebugLevelItem("Http", debugLevel             *= 2));
            iDebugLevels.Add("Upnp", new DebugLevelItem("Upnp", debugLevel             *= 2));
            iDebugLevels.Add("Preamp", new DebugLevelItem("Preamp", debugLevel         *= 2));
            iDebugLevels.Add("Logical", new DebugLevelItem("Logical", debugLevel       *= 2));
            iDebugLevels.Add("Viewer", new DebugLevelItem("Viewer", debugLevel         *= 2));
            iDebugLevels.Add("Ui", new DebugLevelItem("Ui", debugLevel               *= 2));
            iDebugLevels.Add("Isr", new DebugLevelItem("Isr", debugLevel             *= 2));
            iDebugLevels.Add("Core", new DebugLevelItem("Core", debugLevel           *= 2));
            iDebugLevels.Add("Media", new DebugLevelItem("Media", debugLevel         *= 2));
            iDebugLevels.Add("Dac", new DebugLevelItem("Dac", debugLevel             *= 2));
            iDebugLevels.Add("Products", new DebugLevelItem("Products", debugLevel   *= 2));
            iDebugLevels.Add("Mechanism", new DebugLevelItem("Mechanism", debugLevel *= 2));
            iDebugLevels.Add("Bonjour", new DebugLevelItem("Bonjour", debugLevel     *= 2));
            iDebugLevels.Add("Ssdp", new DebugLevelItem("Ssdp", debugLevel           *= 2));
            iDebugLevels.Add("Queue", new DebugLevelItem("Queue", debugLevel         *= 2));
            iDebugLevels.Add("Codec", new DebugLevelItem("Codec", debugLevel         *= 4)); //skipping deprecated option here.
            iDebugLevels.Add("Control", new DebugLevelItem("Control", debugLevel     *= 2));
            iDebugLevels.Add("Verbose", new DebugLevelItem("Verbose", debugLevel     *= 2));
            foreach (DebugLevelItem i in iDebugLevels.Values)
            {
                i.PropertyChanged += EventDebugLevelChanged;
            }
            listBoxDebugLevel.ItemsSource = iDebugLevels.Values;
            DisableDebugLevels();
            this.DataContext = this;

            iInitParams = new InitParams();
            iLibrary    = new Library();
            iLibrary.Initialise(ref iInitParams);
            iLibrary.StartCp();
            iSubnetList = new SubnetList(iInitParams, Dispatcher, iLibrary);
            iDeviceList = new DeviceListUpnp("linn.co.uk", "Volkano", 1, this.Dispatcher);

            comboBoxSubnets.ItemsSource       = iSubnetList;
            comboBoxSubnets.SelectionChanged += EventSubnetSelectionChanged;

            iActivityLightTimer.Interval  = iActivityLightTimerTimeout;
            iActivityLightTimer.Elapsed  += EventActivityLightTimerExpired;
            iActivityLightTimer.AutoReset = false;

            iDelayMutexReleaseTimer.Interval  = iDelayMutexReleaseTimerTimeout;
            iDelayMutexReleaseTimer.Elapsed  += EventDelayMutexReleaseTimerExpired;
            iDelayMutexReleaseTimer.AutoReset = false;

            iRetryConnectTimer.Interval  = iRetryConnectTimerTimeout;
            iRetryConnectTimer.Elapsed  += EventRetryConnectTimerExpired;
            iRetryConnectTimer.AutoReset = true;

            MainWindow.Closing += new CancelEventHandler(this.EventWindowMainClosing);

            iViewerManager = new ViewerManager();
            iViewerManager.ViewerOutputAvailable += EventViewerOutputAvailable;
            iViewerManager.ConnectionAccepted    += EventConnectionAccepted;
            iViewerManager.ConnectionClosed      += EventConnectionClosed;
            iViewerManager.ConnectionRefused     += EventConnectionRefused;
            iViewerManager.ServicesAvailable     += EventServicesAvailable;
            iViewerManager.ServicesUnavailable   += EventServicesUnavailable;

            terminal.MaxVisibleLinesCountChanged += EventMaxVisibleLinesCountChanged;

            if (!Directory.Exists(iAppDataDir))
            {
                Directory.CreateDirectory(iAppDataDir);
            }

            iMainLogFile     = iAppDataDir + "\\Viewer-log.txt";
            iMainLogFileCopy = iAppDataDir + "\\Viewer-log-copy.txt";
            iTempLogFile     = iAppDataDir + "\\Viewer-log-Temp.txt";
            iSettingsFile    = iAppDataDir + "\\Viewer-Settings.txt";

            //Wipe the log file clean.
            if (!File.Exists(iMainLogFile))
            {
                iLogFileMutex.WaitOne();
                File.WriteAllText(iMainLogFile, "", new System.Text.UTF8Encoding());
                iLogFileMutex.ReleaseMutex();
            }

            if (File.Exists(iSettingsFile))
            {
                try
                {
                    iUserSettings = UserSettings.ReadSettingsFromFile(iSettingsFile);
                }
                catch (InvalidOperationException)
                {
                    iUserSettings = new UserSettings();
                    AppendToMainWindow("Settings file is corrupt, deleting...");
                    File.WriteAllText(iSettingsFile, "", new System.Text.UTF8Encoding());
                }
                catch (FileFormatException)
                {
                    iUserSettings = new UserSettings();
                    AppendToMainWindow("Settings file is corrupt, deleting...");
                    File.WriteAllText(iSettingsFile, "", new System.Text.UTF8Encoding());
                }
            }
            else
            {
                iUserSettings = new UserSettings();
            }
            if (iUserSettings.SelectedSubnet >= iSubnetList.length)
            {
                iUserSettings.SelectedSubnet = iSubnetList.length - 1;
            }
            comboBoxSubnets.SelectedIndex = iUserSettings.SelectedSubnet;
            iLibrary.SetCurrentSubnet(((Subnet)comboBoxSubnets.SelectedItem).Handle);
            if (!iUserSettings.UglyName.Equals(""))
            {
                selectDeviceButton.Content = iUserSettings.UglyName;
            }
            Connect(iUserSettings.UglyName);
        }