/// <summary>
        /// Method executes when smart control point notices that
        /// a upnp  media server has left the network.
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="device"></param>
        private void RemoveServer(UPnPSmartControlPoint sender, UPnPDevice device)
        {
            string udn = device.UniqueDeviceName;

            CpMediaServer removeThis = null;

            lock (LockHashes)
            {
                if (UdnToInitStatus.Contains(udn))
                {
                    InitStatus status = (InitStatus)UdnToInitStatus[udn];
                }

                if (UdnToServer.Contains(udn))
                {
                    removeThis = (CpMediaServer)UdnToServer[udn];
                    UdnToServer.Remove(udn);
                }
            }

            if (this.OnServerGone != null)
            {
                this.OnServerGone(this, device);
            }

            if (removeThis != null)
            {
                if (this.OnCpServerRemoved != null)
                {
                    this.OnCpServerRemoved(this, removeThis);
                }
            }

            System.GC.Collect();
        }
Ejemplo n.º 2
0
 private void Sink_OnServerAdded(MediaServerDiscovery sender, CpMediaServer server)
 {
     if (this.OnMediaServersChanged != null)
     {
         this.OnMediaServersChanged(this);
     }
 }
Ejemplo n.º 3
0
 /// <summary>
 /// <see cref="CpMediaServer"/>
 /// always instantiates a CpRootContainer with a pointer
 /// to itself. This is primarily so that a CpRootContainer
 /// can provide the server's friendly name, although
 /// future features may require more information
 /// from the CpMediaServer object.
 /// </summary>
 /// <param name="sourceMediaServer">the
 /// <see cref="CpMediaServer"/>
 /// object that owns this root container object.
 /// </param>
 internal CpRootContainer(CpMediaServer sourceMediaServer) : base()
 {
     // base class constructor chain will call Init()
     this.m_ID = "0";
     this.m_wrSourceMediaServer = new WeakReference(sourceMediaServer, true);
     InitWeakEvents(sourceMediaServer);
 }
 /// <summary>
 /// Method executes when a "good" server has done bye bye.
 /// </summary>
 /// <param name="sender"></param>
 /// <param name="server"></param>
 private void Sink_OnGoodServerRemoved(_MediaServerDiscovery sender, CpMediaServer server)
 {
     if (this.OnGoodServerRemoved != null)
     {
         this.OnGoodServerRemoved(this, server);
     }
 }
Ejemplo n.º 5
0
 public void Browse(CpMediaServer server, System.String ObjectID, OpenSource.UPnP.AV.CpContentDirectory.Enum_A_ARG_TYPE_BrowseFlag BrowseFlag, System.String Filter, System.UInt32 StartingIndex, System.UInt32 RequestedCount, System.String SortCriteria, object _Tag, Delegate_OnBrowseDone _Callback)
 {
     _RequestState state = new _RequestState();
     state.Callback = _Callback;
     state.Tag = _Tag;
     state.Server = server;
     server.ContentDirectory.Browse(ObjectID, BrowseFlag, Filter, StartingIndex, RequestedCount, SortCriteria, state, new OpenSource.UPnP.AV.CpContentDirectory.Delegate_OnResult_Browse(_OnBrowseDone));
 }
Ejemplo n.º 6
0
        private void InitWeakEvents(CpMediaServer sourceMediaServer)
        {
            this.weakEvent_ContainerUpdateIDs = new CpContentDirectory.StateVariableModifiedHandler_ContainerUpdateIDs(this.Sink_OnContainerUpdateIDsChanged);
            this.weakEvent_SystemUpdateId     = new CpContentDirectory.StateVariableModifiedHandler_SystemUpdateID(this.Sink_OnSystemUpdateIDChanged);

            sourceMediaServer.ContentDirectory.OnStateVariable_ContainerUpdateIDs += this.weakEvent_ContainerUpdateIDs;
            sourceMediaServer.ContentDirectory.OnStateVariable_SystemUpdateID     += this.weakEvent_SystemUpdateId;
        }
        /// <summary>
        /// When a MediaServer device is found, we add it to a temp list.
        /// Then we attempt to subscribe to its services.
        /// </summary>
        /// <param name="sender">the smart cp that found the device</param>
        /// <param name="device">the mediaserver device</param>
        private void Temporary_AddServer(UPnPSmartControlPoint sender, UPnPDevice device)
        {
            if (this.OnServerSeen != null)
            {
                this.OnServerSeen(this, device);
            }

            UPnPService sCD = device.GetServices(CpContentDirectory.SERVICE_NAME)[0];
            UPnPService sCM = device.GetServices(CpConnectionManager.SERVICE_NAME)[0];

            CpMediaServer newServer;

            try
            {
                newServer = new CpMediaServer(device);
            }
            catch (UPnPCustomException)
            {
                newServer = null;
            }

            if (newServer != null)
            {
                InitStatus status = new InitStatus();
                status.SubcribeCD = false;
                status.SubcribeCM = false;
                status.EventedCD  = false;
                status.EventedCM  = false;
                status.Server     = newServer;

                lock (LockHashes)
                {
                    UdnToInitStatus[device.UniqueDeviceName] = status;
                }

                newServer.ConnectionManager.OnSubscribe += new CpConnectionManager.SubscribeHandler(this.Sink_OnCmServiceSubscribe);
                newServer.ContentDirectory.OnSubscribe  += new CpContentDirectory.SubscribeHandler(this.Sink_OnCdServiceSubscribe);

                newServer.ConnectionManager.OnStateVariable_SourceProtocolInfo += new CpConnectionManager.StateVariableModifiedHandler_SourceProtocolInfo(this.Sink_OnCmEvented);
                newServer.ContentDirectory.OnStateVariable_SystemUpdateID      += new CpContentDirectory.StateVariableModifiedHandler_SystemUpdateID(this.Sink_OnCdEvented);

                newServer.ConnectionManager._subscribe(600);
                newServer.ContentDirectory._subscribe(600);
            }
        }
        /// <summary>
        /// Allows the programmer to request that a transfer stop.
        /// </summary>
        /// <param name="Tag">
        /// Miscellaneous, user-provided object for tracking this
        /// asynchronous call. Can be used as a means to pass a
        /// user-defined "state object" at invoke-time so that
        /// the executed callback during results-processing can be
        /// aware of the component's state at the time of the call.
        /// </param>
        /// <param name="callback">the callback to execute when results become available</param>
        /// <exception cref="ApplicationException">
        /// Thrown if the resource object associated with thsi transfer is null.
        /// Such an exception would indicate that the system has improperly instantiated the transfer object.
        /// </exception>
        /// <exception cref="NullReferenceException">
        /// Thrown if the transfer object cannot find its media server.
        /// </exception>
        public void RequestStopTransferResource(object Tag, CpMediaDelegates.Delegate_ResultStopTransferResource callback)
        {
            if (this.m_Resource == null)
            {
                throw new ApplicationException("Bad Evil. The resource associated with this transfer object is null.");
            }

            CpMediaServer server = (CpMediaServer)this.mwr_Server.Target;

            if (this.mwr_Server.IsAlive == false)
            {
                throw new NullReferenceException("The media server object is null. Media server may have disappeared from UPnP network.");
            }

            StopTransferResourceRequestTag rtag = new StopTransferResourceRequestTag();

            rtag.Tag      = Tag;
            rtag.Callback = callback;

            server.RequestStopTransferResource(this.m_TransferID, rtag, new CpContentDirectory.Delegate_OnResult_StopTransferResource(this.SinkResult_StopTransferResource));
        }
        /// <summary>
        /// Whenever Sink_Onxxx method executes, it calls this method to
        /// determine whether a server has been upgraded from non-good
        /// to good status.
        /// </summary>
        /// <param name="udn"></param>
        private void ProcessInitStatusChange(string udn)
        {
            CpMediaServer addedThis = null;

            InitStatus status = null;

            lock (LockHashes)
            {
                status = (InitStatus)UdnToInitStatus[udn];

                if (status != null)
                {
                    if (status.ZeroMeansDone == 0)
                    {
                        if (
                            (status.EventedCD) &&
                            (status.EventedCM) &&
                            (status.SubcribeCD) &&
                            (status.SubcribeCM)
                            )
                        {
                            // We were evented for both services
                            // and we subscribed successfully,
                            // so we're good to go.
                            UdnToInitStatus.Remove(udn);
                            UdnToServer[udn] = status.Server;
                            addedThis        = status.Server;
                        }
                        else
                        {
                            // we didn't subscribe successfully
                            // or we never got evented after
                            // we subscribed... but this
                            // code should never execute because
                            // we will have never decremented
                            // ZeroMeansDone==0
                        }
                    }

                    if (addedThis == null)
                    {
                        if (BadServersAreGoodServersToo)
                        {
                            // but since we're configured to be
                            // nice to crappy servers that
                            // don't event properly... we'll
                            // promote the server to full status
                            UdnToInitStatus.Remove(udn);
                            UdnToServer[udn] = status.Server;
                            addedThis        = status.Server;
                        }
                    }
                }
            }

            if (addedThis != null)
            {
                if (this.OnCpServerAdded != null)
                {
                    this.OnCpServerAdded(this, addedThis);
                }
            }
        }
 /// <summary>
 /// Method executes when a "good" server has done bye bye.
 /// </summary>
 /// <param name="sender"></param>
 /// <param name="server"></param>
 private void Sink_OnGoodServerRemoved(_MediaServerDiscovery sender, CpMediaServer server)
 {
     if(this.OnGoodServerRemoved != null)
     {
         this.OnGoodServerRemoved(this, server);
     }
 }
        private void InitWeakEvents(CpMediaServer sourceMediaServer)
        {
            this.weakEvent_ContainerUpdateIDs = new CpContentDirectory.StateVariableModifiedHandler_ContainerUpdateIDs (this.Sink_OnContainerUpdateIDsChanged);
            this.weakEvent_SystemUpdateId = new CpContentDirectory.StateVariableModifiedHandler_SystemUpdateID (this.Sink_OnSystemUpdateIDChanged);

            sourceMediaServer.ContentDirectory.OnStateVariable_ContainerUpdateIDs += this.weakEvent_ContainerUpdateIDs;
            sourceMediaServer.ContentDirectory.OnStateVariable_SystemUpdateID += this.weakEvent_SystemUpdateId;
        }
Ejemplo n.º 12
0
 public Error_MediaNotOnServer(ICpMedia mediaObj, CpMediaServer server)
     : base("Media object not on server")
 {
     this.Media  = mediaObj;
     this.Server = server;
 }
 /// <summary>
 /// internal constructor - public programmers should not instantiate
 /// their own transfer objects.
 /// </summary>
 /// <param name="transferID">
 /// The ID provided by the server.
 /// </param>
 /// <param name="isImport"></param>
 /// <param name="res"></param>
 /// <param name="uri"></param>
 /// <param name="server"></param>
 internal ResourceTransfer(System.UInt32 transferID, bool isImport, IMediaResource res, System.Uri uri, CpMediaServer server)
 {
     this.m_TransferID = transferID;
     this.m_IsImport   = isImport;
     this.m_Resource   = res;
     this.m_Uri        = uri;
     this.mwr_Server   = new WeakReference(server);
 }
 /// <summary>
 /// Executed when a server disappears.
 /// </summary>
 /// <param name="sender"></param>
 /// <param name="server"></param>
 private void Sink_OnServerRemoved(MediaServerDiscovery sender, CpMediaServer server)
 {
     this.AllRoots.RemoveRootContainer(server.Root);
     this.AllRoots.NotifyRootsOfChange();
 }
 /// <summary>
 /// Executed when a server shows up.
 /// </summary>
 /// <param name="sender"></param>
 /// <param name="server"></param>
 private void Sink_OnServerAdded(MediaServerDiscovery sender, CpMediaServer server)
 {
     server.Root.Update();
     this.AllRoots.AddRootContainer(server.Root);
     this.AllRoots.NotifyRootsOfChange();
 }
Ejemplo n.º 16
0
        private void Sink_OnBrowse(CpMediaServer server, System.String ObjectID, OpenSource.UPnP.AV.CpContentDirectory.Enum_A_ARG_TYPE_BrowseFlag BrowseFlag, System.String Filter, System.UInt32 StartingIndex, System.UInt32 RequestedCount, System.String SortCriteria, UPnPInvokeException e, Exception parseError, object _Tag, IUPnPMedia[] Result, System.UInt32 NumberReturned, System.UInt32 TotalMatches, System.UInt32 UpdateID)
        {
            if (server == this.m_Server)
            {
                if (ObjectID == this.m_Context)
                {
                    if (_Tag == this.m_Container)
                    {
                        if ((e != null) || (parseError != null))
                        {
                            //error encountered
                        }
                        else
                        {
                            // add children
                            this.m_Children.AddRange(Result);
                            this.m_Container.AddObjects(Result, true);

                            if (this.OnIncrementalUpdate != null)
                            {
                                this.OnIncrementalUpdate(this, Result);
                            }

                            if (
                                ((this.m_Children.Count == TotalMatches) && (NumberReturned > 0)) ||
                                ((TotalMatches == 0) && (NumberReturned > 0))
                                )
                            {
                                // more items to come
                                this.m_CurrentIndex = NumberReturned;
                                DoNextBrowse();
                            }
                            else
                            {
                                lock (this)
                                {
                                    // no more items, prune children from m_Container
                                    ArrayList remove = new ArrayList();
                                    foreach (IUPnPMedia m1 in this.m_Container.CompleteList)
                                    {
                                        bool found = false;
                                        foreach (IUPnPMedia m2 in this.m_Children)
                                        {
                                            if (m1 == m2)
                                            {
                                                found = true;
                                                break;
                                            }
                                        }
                                        if (found == false)
                                        {
                                            remove.Add(m1);
                                        }
                                    }
                                    this.m_Container.RemoveObjects(remove);
                                }

                                if (this.OnRefreshComplete != null)
                                {
                                    IUPnPMedia[] list = (IUPnPMedia[]) this.m_Children.ToArray(typeof(IUPnPMedia));
                                    this.OnRefreshComplete(this, list);
                                }
                            }
                        }
                    }
                }
            }
        }
Ejemplo n.º 17
0
        private void Sink_OnBrowse(CpMediaServer server, System.String ObjectID, OpenSource.UPnP.AV.CpContentDirectory.Enum_A_ARG_TYPE_BrowseFlag BrowseFlag, System.String Filter, System.UInt32 StartingIndex, System.UInt32 RequestedCount, System.String SortCriteria, UPnPInvokeException e, Exception parseError, object _Tag, IUPnPMedia[] Result, System.UInt32 NumberReturned, System.UInt32 TotalMatches, System.UInt32 UpdateID)
        {
            IMediaContainer[] tagC, ec;
            bool ok     = true;
            bool nomore = false;

            // ensure we're processing results for the current context
            lock (this)
            {
                tagC = (IMediaContainer[])_Tag;
                ec   = this.CurrentContext.EntireContext;

                for (int i = 0; i < ec.Length; i++)
                {
                    if (ec[i] != tagC[i])
                    {
                        ok = false;
                        break;
                    }
                }
            }

            if (ok)
            {
                // results are for current context, merge metadata results
                // with existing child list

                if ((e == null) && (parseError == null))
                {
                    lock (this)
                    {
                        // add to our media object
                        this.m_Children.AddRange(Result);
                        this.CurrentContext.ContainerContext.AddObjects(Result, true);

                        if (
                            ((this.m_Children.Count < TotalMatches) && (NumberReturned > 0)) ||
                            ((TotalMatches == 0) && (NumberReturned > 0))
                            )
                        {
                            // more items to come
                            this.m_CurrentIndex = NumberReturned;
                        }
                        else
                        {
                            // no more items, prune children from m_Container
                            ArrayList remove = new ArrayList();
                            foreach (IUPnPMedia m1 in this.CurrentContext.ContainerContext.CompleteList)
                            {
                                bool found = false;
                                foreach (IUPnPMedia m2 in this.m_Children)
                                {
                                    if (m1 == m2)
                                    {
                                        found = true;
                                        break;
                                    }
                                }
                                if (found == false)
                                {
                                    remove.Add(m1);
                                }
                            }
                            this.CurrentContext.ContainerContext.RemoveObjects(remove);
                            nomore = true;
                        }
                    }

                    if (this.OnIncrementalUpdate != null)
                    {
                        this.OnIncrementalUpdate(this, Result);
                    }

                    if (nomore)
                    {
                        if (this.OnRefreshComplete != null)
                        {
                            IUPnPMedia[] list = (IUPnPMedia[])this.m_Children.ToArray(typeof(IUPnPMedia));
                            this.OnRefreshComplete(this, list);
                        }
                    }
                }
                else
                {
                    // error occurred with the results...
                    // how should we report this?
                }
            }
        }
Ejemplo n.º 18
0
 /// <summary>
 /// Executed when a server shows up.
 /// </summary>
 /// <param name="sender"></param>
 /// <param name="server"></param>
 private void Sink_OnServerAdded(MediaServerDiscovery sender, CpMediaServer server)
 {
     server.Root.Update();
     this.AllRoots.AddRootContainer(server.Root);
     this.AllRoots.NotifyRootsOfChange();
 }
Ejemplo n.º 19
0
 public Error_ResourceNotOnServer(ICpResource resource, CpMediaServer server)
     : base("Resource object not on server")
 {
     this.Resource = resource;
     this.Server   = server;
 }
Ejemplo n.º 20
0
 /// <summary>
 /// Executed when a server disappears.
 /// </summary>
 /// <param name="sender"></param>
 /// <param name="server"></param>
 private void Sink_OnServerRemoved(MediaServerDiscovery sender, CpMediaServer server)
 {
     this.AllRoots.RemoveRootContainer(server.Root);
     this.AllRoots.NotifyRootsOfChange();
 }
 /// <summary>
 /// <see cref="CpMediaServer"/>
 /// always instantiates a CpRootContainer with a pointer
 /// to itself. This is primarily so that a CpRootContainer
 /// can provide the server's friendly name, although
 /// future features may require more information
 /// from the CpMediaServer object.
 /// </summary>
 /// <param name="sourceMediaServer">the 
 /// <see cref="CpMediaServer"/>
 /// object that owns this root container object.
 /// </param>
 internal CpRootContainer(CpMediaServer sourceMediaServer)
     : base()
 {
     // base class constructor chain will call Init()
     this.m_ID = "0";
     this.m_wrSourceMediaServer = new WeakReference(sourceMediaServer, true);
     InitWeakEvents(sourceMediaServer);
 }
Ejemplo n.º 22
0
        private void Sink_OnBrowse(CpMediaServer server, System.String ObjectID, OpenSource.UPnP.AV.CpContentDirectory.Enum_A_ARG_TYPE_BrowseFlag BrowseFlag, System.String Filter, System.UInt32 StartingIndex, System.UInt32 RequestedCount, System.String SortCriteria, UPnPInvokeException e, Exception parseError, object _Tag, IUPnPMedia[] Result, System.UInt32 NumberReturned, System.UInt32 TotalMatches, System.UInt32 UpdateID)
        {
            IMediaContainer[] tagC, ec;
            bool ok = true;
            bool nomore = false;

            // ensure we're processing results for the current context
            lock (this)
            {
                tagC = (IMediaContainer[]) _Tag;
                ec = this.CurrentContext.EntireContext;

                for (int i=0; i < ec.Length; i++)
                {
                    if (ec[i] != tagC[i])
                    {
                        ok = false;
                        break;
                    }
                }
            }

            if (ok)
            {
                // results are for current context, merge metadata results
                // with existing child list

                if ((e == null) && (parseError == null))
                {
                    lock (this)
                    {
                        // add to our media object
                        this.m_Children.AddRange(Result);
                        this.CurrentContext.ContainerContext.AddObjects(Result, true);

                        if (
                            ((this.m_Children.Count < TotalMatches) && (NumberReturned > 0)) ||
                            ((TotalMatches == 0) && (NumberReturned > 0))
                            )
                        {
                            // more items to come
                            this.m_CurrentIndex = NumberReturned;
                        }
                        else
                        {
                            // no more items, prune children from m_Container
                            ArrayList remove = new ArrayList();
                            foreach (IUPnPMedia m1 in this.CurrentContext.ContainerContext.CompleteList)
                            {
                                bool found = false;
                                foreach (IUPnPMedia m2 in this.m_Children)
                                {
                                    if (m1 == m2)
                                    {
                                        found = true;
                                        break;
                                    }
                                }
                                if (found == false)
                                {
                                    remove.Add(m1);
                                }
                            }
                            this.CurrentContext.ContainerContext.RemoveObjects(remove);
                            nomore = true;
                        }
                    }

                    if (this.OnIncrementalUpdate != null)
                    {
                        this.OnIncrementalUpdate(this, Result);
                    }

                    if (nomore)
                    {
                        if (this.OnRefreshComplete != null)
                        {
                            IUPnPMedia[] list = (IUPnPMedia[]) this.m_Children.ToArray(typeof(IUPnPMedia));
                            this.OnRefreshComplete(this, list);
                        }
                    }
                }
                else
                {
                    // error occurred with the results...
                    // how should we report this?
                }
            }
        }
        /// <summary>
        /// When a MediaServer device is found, we add it to a temp list.
        /// Then we attempt to subscribe to its services.
        /// </summary>
        /// <param name="sender">the smart cp that found the device</param>
        /// <param name="device">the mediaserver device</param>
        private void Temporary_AddServer(UPnPSmartControlPoint sender, UPnPDevice device)
        {
            if (this.OnServerSeen != null)
            {
                this.OnServerSeen(this, device);
            }

            UPnPService sCD = device.GetServices(CpContentDirectory.SERVICE_NAME)[0];
            UPnPService sCM = device.GetServices(CpConnectionManager.SERVICE_NAME)[0];

            CpMediaServer newServer;
            try
            {
                newServer = new CpMediaServer(device);
            }
            catch (UPnPCustomException)
            {
                newServer = null;
            }

            if (newServer != null)
            {
                InitStatus status = new InitStatus();
                status.SubcribeCD = false;
                status.SubcribeCM = false;
                status.EventedCD = false;
                status.EventedCM = false;
                status.Server = newServer;

                lock (LockHashes)
                {
                    UdnToInitStatus[device.UniqueDeviceName] = status;
                }

                newServer.ConnectionManager.OnSubscribe += new CpConnectionManager.SubscribeHandler(this.Sink_OnCmServiceSubscribe);
                newServer.ContentDirectory.OnSubscribe += new CpContentDirectory.SubscribeHandler(this.Sink_OnCdServiceSubscribe);

                newServer.ConnectionManager.OnStateVariable_SourceProtocolInfo += new CpConnectionManager.StateVariableModifiedHandler_SourceProtocolInfo(this.Sink_OnCmEvented);
                newServer.ContentDirectory.OnStateVariable_SystemUpdateID += new CpContentDirectory.StateVariableModifiedHandler_SystemUpdateID(this.Sink_OnCdEvented);

                newServer.ConnectionManager._subscribe(600);
                newServer.ContentDirectory._subscribe(600);
            }
        }
 /// <summary>
 /// internal constructor - public programmers should not instantiate
 /// their own transfer objects.
 /// </summary>
 /// <param name="transferID">
 /// The ID provided by the server.
 /// </param>
 /// <param name="isImport"></param>
 /// <param name="res"></param>
 /// <param name="uri"></param>
 /// <param name="server"></param>
 internal ResourceTransfer(System.UInt32 transferID, bool isImport, IMediaResource res, System.Uri uri, CpMediaServer server)
 {
     this.m_TransferID = transferID;
     this.m_IsImport = isImport;
     this.m_Resource = res;
     this.m_Uri = uri;
     this.mwr_Server = new WeakReference(server);
 }