Thread Rating:
  • 0 Votes - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Pure virtual function error in CpDeviceCUdn function
02-05-2013, 02:58 PM
Post: #11
RE: Pure virtual function error in CpDeviceCUdn function
(02-05-2013 10:02 AM)simonc Wrote:  It isn't safe for Java code to act on a CpDevice it doesn't hold a reference to (the one exception to this is inside device added/removed callbacks where a device handle is guaranteed valid).

What is the recommended application protocol for deviceRemoved and removeRef()?

1) Is the application's deviceRemoved callback required to call removeRef() for all the application's references to the removed device?

2) If the application's deviceRemoved callback doesn't call removeRef() for all the application's references to the removed device, does the CpiDevice become unsafe to use immediately after the deviceRemoved callback returns, or is the CpiDevice still safe to use until the application calls removeRef()?

I'm asking this because MinimServer currently defers some cleanup until after the deviceRemoved callback returns, which results in some getUdn() calls to the removed device after the deviceRemoved callback has returned. If I can't ensure this is safe by deferring the removeRef() call(s) until this cleanup has completed, I'll need to slightly reorganise the cleanup logic.
Find all posts by this user
02-05-2013, 03:24 PM (This post was last modified: 02-05-2013 03:24 PM by simonc.)
Post: #12
RE: Pure virtual function error in CpDeviceCUdn function
(02-05-2013 02:58 PM)simoncn Wrote:  What is the recommended application protocol for deviceRemoved and removeRef()?

It is safe to use a device as long as you hold a reference to it.

The moment you call removeRef(), it is no longer safe to use the device. You cannot assume anyone else holds a reference to it so the device may be destroyed during the removeRef() call. The only exception to this is deviceAdded & deviceRemoved callbacks - the device passed in here is guaranteed valid for the duration of these functions.
Find all posts by this user
02-05-2013, 10:22 PM
Post: #13
RE: Pure virtual function error in CpDeviceCUdn function
(02-05-2013 12:37 PM)simoncn Wrote:  I've got multiple device lists listening for new devices (CpDeviceListUpnpDeviceType and CpDeviceListUpnpServiceType). It's possible for a new device to match more than one of these device lists. In this case, the Java bindings will create multiple Java CpDevice objects to pass to the deviceAdded() or deviceRemoved() callback of each list. All these Java CpDevice objects will have the same native handle. As soon as the last active reference is removed by calling removeRef() on any of these Java CpDevice objects, all other Java CpDevice objects with the same handle will become unsafe for method calls even though no removeRef() call has been made on these other Java CpDevice objects.

I tried this, and it turns out that each Java CpDevice object has a unique handle (native CpiDevice object). So the issue I was concerned about here doesn't apply. This is very helpful, as it means no Java CpDevice object will be invalidated by a removeRef() call on some other Java CpDevice object.
Find all posts by this user


Forum Jump: