コード例 #1
0
	//-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
	// DeviceArrived()
	//-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
	void PlugIn::DeviceArrived(UInt64 guid, const io_string_t registryPath)
	{
		try
		{	
			// Instantiate a new CMIODevice object in the DAL
			CMIODeviceID deviceID = 0;
			OSStatus err = CMIOObjectCreate(GetInterface(), kCMIOObjectSystemObject, kCMIODeviceClassID, &deviceID);
			ThrowIfError(err, CAException(err), "CMIO::DP::Sample::PlugIn::DeviceArrived: couldn't instantiate the CMIODevice object");

			// Make a device object
			Device* device = new Device(*this, deviceID, mAssistantPort, guid, registryPath);

			try
			{
				// Initialize the device
				device->Initialize();
				
				// Restore its settings if necessary
				if (DALA::System::IsMaster())
				{
					DP::DeviceSettings::RestoreFromPrefs(*device, DP::DeviceSettings::sStandardControlsToSave, DP::DeviceSettings::kStandardNumberControlsToSave);
				}
				
				// Set the object state mutex
				Object::SetObjectStateMutexForID(deviceID, device->GetObjectStateMutex());
				
				// Add it to the device list
				AddDevice(*device);

				// Unlock the mutex since CMIOObjectsPublishedAndDied() can callout to property listeners
				CAMutex::Unlocker unlocker(GetStateMutex());

				// Tell the DAL about the device
				err = CMIOObjectsPublishedAndDied(GetInterface(), kCMIOObjectSystemObject, 1, &deviceID, 0, 0);
				ThrowIfError(err, err, "CMIO::DP::Sample::PlugIn::DeviceArrived: couldn't tell the DAL about a new device");
			}
			catch (...)
			{
				// Remove it from the device list (which is always safe to attempt) and delete it
				RemoveDevice(*device);
				delete device;
			}
		}
		catch (...)
		{
		}
	}