Click here to Skip to main content
16,019,876 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi guys

I'm trying to work with UPnPLib 1.0 for a ControlPoint.
I call the UPnPDeviceFinder but the callback doesn't get called.

UPDATE: 10.11.2010
Now i have time to make some private work. I improved my code, but still no callback.

Please help me :)

namespace UPnPServices {
    public delegate void UPnPDeviceFinderDelegate(IUPnPDevice device, string udn, int id);

    public class UPnPControlPoint {
        #region Fields
        private UPnPDeviceFinderDelegate UPnPDeviceFinderCallback;

        private UPnPDeviceFinder _deviceFinder;
        #endregion

        public UPnPControlPoint() {
            UPnPDeviceFinderCallback = new UPnPDeviceFinderDelegate(UPnPDeviceFinderCalledback);

            if (_deviceFinder == null)
                _deviceFinder = new UPnPDeviceFinder();
        }

        public void FindDevice() {
            int finderResult = _deviceFinder.CreateAsyncFind("urn:schemas-upnp-org:device:MediaServer:1", 0, UPnPDeviceFinderCallback);
            Console.WriteLine("[UPnPControlPoint] StartAsyncFind");
            _deviceFinder.StartAsyncFind(finderResult);
        }

        public void UPnPDeviceFinderCalledback(IUPnPDevice device, string udn, int id) {
            Console.WriteLine("[UPnPControlPoint] UPnPDeviceFinderCalledback");
            switch (id) {
                case 0: //device added
                    Console.WriteLine("[UPnPControlPoint] UPnPDeviceFinderCalledback Device added: {0}", device.FriendlyName);
                    break;
                case 1: // device removed
                    Console.WriteLine("[UPnPControlPoint] UPnPDeviceFinderCalledback Device removed: {0}", udn);
                    break;
                case 2: // search completed
                    Console.WriteLine("[UPnPControlPoint] UPnPDeviceFinderCalledback Search Completed");
                    break;
                default:
                    Console.WriteLine("[UPnPControlPoint] UPnPDeviceFinderCalledback Default");
                    break;
            }
        }
    }
}
Posted
Updated 10-Nov-10 9:30am
v3

where is the call to

_deviceFinder.StartAsyncFind(finderResult);


This call will invoke the search.

So the complete code will look like :

C#
public delegate void UPnPDeviceFinderDelegate(IUPnPDevice device, string udn, int i);
private UPnPDeviceFinder _deviceFinder = new UPnPDeviceFinder();
int finderResult = _deviceFinder.CreateAsyncFind("urn:schemas-upnp-org:device:MediaServer:1", 0, UPnPDeviceFinderCallback
);
_deviceFinder.StartAsyncFind(finderResult);


After the StartAsyncFind is called the device would be searched based on deviceid specified as finderResult.
 
Share this answer
 
Hi,
I stumbled over this problem myself. Could not get the delegate callback to work.

Try implementing a class with the IUPnPDeviceFinderCallback interface, and using that instead of a delegate. That worked for me! :)

C#
public class DeviceFinderCallback : IUPnPDeviceFinderCallback
{
	public void DeviceAdded(int lFindData, UPnPDevice pDevice)
	{
		// Do stuff
	}

	public void DeviceRemoved(int lFindData, string bstrUDN)
	{
		// Do stuff
	}

	public void SearchComplete(int lFindData)
	{
		// Do stuff
	}
}


C#
static void Main(string[] args)
{
	var finder = new UPnPDeviceFinder();
	int id = finder.CreateAsyncFind(
		"upnp:rootdevice", 0, new DeviceFinderCallback());
	finder.StartAsyncFind(id);
	Console.ReadLine();
}
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
Top Experts
Last 24hrsThis month


CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900