void Mediator::AddDevice( Type type, Company company ) { Player *player; //Get relevant factory Player_Factory& factory = Player_Factory::GetFactory(company); //Create the player according to type (from factory); switch (type) { case VCR: player = factory.CreateVCRPlayer(); break; case CD: player = factory.CreateCDPlayer(); break; case DVD: player = factory.CreateDVDPlayer(); break; } //Insert player into devices list devices.insert(pair<deviceKey,Player *>(deviceKey(company,type), player)); }
nsresult sbDeviceXMLInfo::DeviceMatchesDeviceNode(nsIDOMNode* aDeviceNode, nsIPropertyBag2* aDeviceProperties, bool* aDeviceMatches) { NS_ENSURE_ARG_POINTER(aDeviceNode); NS_ENSURE_ARG_POINTER(aDeviceProperties); NS_ENSURE_ARG_POINTER(aDeviceMatches); nsresult rv; // Get the device node attributes. nsCOMPtr<nsIDOMNamedNodeMap> attributes; rv = aDeviceNode->GetAttributes(getter_AddRefs(attributes)); NS_ENSURE_SUCCESS(rv, rv); // Check if each device node attribute matches the device. bool matches = PR_TRUE; PRUint32 attributeCount; rv = attributes->GetLength(&attributeCount); NS_ENSURE_SUCCESS(rv, rv); for (PRUint32 attributeIndex = 0; attributeIndex < attributeCount; ++attributeIndex) { // Get the next attribute. nsCOMPtr<nsIDOMNode> attribute; rv = attributes->Item(attributeIndex, getter_AddRefs(attribute)); NS_ENSURE_SUCCESS(rv, rv); // Get the attribute name. nsAutoString attributeName; rv = attribute->GetNodeName(attributeName); NS_ENSURE_SUCCESS(rv, rv); // Get the attribute value. nsAutoString attributeValue; rv = attribute->GetNodeValue(attributeValue); NS_ENSURE_SUCCESS(rv, rv); // Get the corresponding device property key. nsAutoString deviceKey(NS_LITERAL_STRING(SB_DEVICE_PROPERTY_BASE)); deviceKey.Append(attributeName); // If the device property key does not exist, the device does not match. bool hasKey; rv = aDeviceProperties->HasKey(deviceKey, &hasKey); NS_ENSURE_SUCCESS(rv, rv); if (!hasKey) { matches = PR_FALSE; break; } // Get the device property value. nsCOMPtr<nsIVariant> deviceValue; rv = aDeviceProperties->Get(deviceKey, getter_AddRefs(deviceValue)); NS_ENSURE_SUCCESS(rv, rv); // If the device property value and the attribute value are not equal, the // device does not match. bool equal; rv = sbVariantsEqual(deviceValue, sbNewVariant(attributeValue), &equal); NS_ENSURE_SUCCESS(rv, rv); if (!equal) { matches = PR_FALSE; break; } } // Return results. *aDeviceMatches = matches; return NS_OK; }