CF::AllocationManager::AllocationResponseSequence* AllocationManager_impl::allocateDevices(const CF::AllocationManager::AllocationRequestSequence &requests, ossie::DeviceList& devices, const std::string& domainName) { LOG_TRACE(AllocationManager_impl, "Servicing " << requests.length() << " allocation request(s)"); CF::AllocationManager::AllocationResponseSequence_var response = new CF::AllocationManager::AllocationResponseSequence(); typedef std::list<ossie::AllocationType*> LocalAllocationList; LocalAllocationList local_allocations; for (unsigned int request_idx=0; request_idx<requests.length(); request_idx++) { const CF::AllocationManager::AllocationRequestType& request = requests[request_idx]; const std::string requestID(request.requestID); LOG_TRACE(AllocationManager_impl, "Allocation request " << requestID << " contains " << request.allocationProperties.length() << " properties"); // Get device identifiers, and ensure that no device references are nil std::vector<std::string> requestedDeviceIDs; for (unsigned int device_idx = 0; device_idx < request.requestedDevices.length(); ++device_idx) { CF::Device_ptr device = request.requestedDevices[device_idx]; if (!CORBA::is_nil(device)) { requestedDeviceIDs.push_back(ossie::corba::returnString(device->identifier())); } } if (requestedDeviceIDs.size() != request.requestedDevices.length()) { // At least one requested device was nil continue; } // If a requested device list was given, skip devices not in list ossie::DeviceList requestedDevices = devices; if (!requestedDeviceIDs.empty()) { for (ossie::DeviceList::iterator node = requestedDevices.begin(); node != requestedDevices.end(); ++node) { if (std::find(requestedDeviceIDs.begin(), requestedDeviceIDs.end(), (*node)->identifier) == requestedDeviceIDs.end()) { node = requestedDevices.erase(node); } } } std::pair<ossie::AllocationType*,ossie::DeviceList::iterator> result = allocateRequest(requestID, request.allocationProperties, requestedDevices, std::vector<std::string>(), std::vector<ossie::SPD::NameVersionPair>(), domainName); if (result.first) { local_allocations.push_back(result.first); ossie::AllocationType* allocation(result.first); const std::string requestID(request.requestID); ossie::corba::push_back(response, ossie::assembleResponse(requestID, allocation->allocationID, allocation->allocationProperties, allocation->allocatedDevice, allocation->allocationDeviceManager)); } } // Update the database boost::recursive_mutex::scoped_lock lock(allocationAccess); for (LocalAllocationList::iterator alloc = local_allocations.begin(); alloc != local_allocations.end(); ++alloc) { this->_allocations[(*alloc)->allocationID] = **alloc; delete *alloc; } if (response->length() != 0) { this->_domainManager->updateLocalAllocations(this->_allocations); } return response._retn(); }
void AggregateDevice_impl::addDevice(CF::Device_ptr associatedDevice) { unsigned int devSeqLength = _devices->length(); for (unsigned int i = 0; i < devSeqLength; i++) { if (!strcmp(associatedDevice->identifier(), (*_devices)[i]->identifier())) { return; } } _devices->length(devSeqLength + 1); (*_devices)[devSeqLength] = CF::Device::_duplicate(associatedDevice); }
void AggregateDevice_impl::removeDevice(CF::Device_ptr associatedDevice) { unsigned int devSeqLength = _devices->length(); for (unsigned int i = 0; i < devSeqLength; i++) { if (!strcmp(associatedDevice->identifier(), (*_devices)[i]->identifier())) { for (unsigned int j = i + 1; j < devSeqLength; i++) { (*_devices)[j-1] = (*_devices)[j]; } _devices->length(devSeqLength - 1); } } return; }