/* Copyright (c) 20011 Hovanes Egiyan Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ #include "BaseIUChassisBus.hh" //! Constructor to create a new object and open new serial port. After //! creating the serial port object it creates the BaseIUBoard //! objects corresponding to the boards in this BaseIU bus. BaseIUChassisBus::BaseIUChassisBus(BaseIUVirtBusID& devID) : BaseIUVirtBus(devID) { if (bmDebFlag > 1) { cout << "BaseIUChassisBus::BaseIUChassisBus() : "; cout << "Bus for port " << hex << showbase << bmDevice->GetPortName() << " will create the boards " << endl; } // Create the parameters that belong to a chassis InitParameters(); //! Create a imaginary board with address equal to 0 //! This board will be used to request parameter readback from the whole bus BaseIUChassisBoard* fakeBoard = new BaseIUChassisBoard(*this, 0); MtxLock objLock(bmMutex); bvbBoard[0] = fakeBoard; objLock.Unlock(); vector addrVec = this->GetAddressVector(); if (bmDebFlag > 1) { cout << "BaseIUChassisBus::BaseIUChassisBus() : Got the address vector with size " << addrVec.size() << endl; } //! Loop over boards that responded to the broadcast and synch //! them with the hardware for (unsigned iBoard = 0; iBoard < addrVec.size(); iBoard++) { int address = addrVec[iBoard]; //! If board with this address did not exist create it on the fly if (bvbBoard.count(address) == 0) { if (bmDebFlag > 1) { cout << "BaseIUChassisBus::BaseIUChassisBus() : The board with address " << address << " does not exist in the board map for port name " << bmDevice->GetPortName() << endl; } BaseIUChassisBoard* tmpBoard = new BaseIUChassisBoard(*this, address); objLock.Lock(); bvbBoard[address] = tmpBoard; // cout << "Map should have an entry now " << endl; // bvbBoard[address] = tmpBoard; // cout << "Assignment is done " << endl; objLock.Unlock(); } } if (bmDebFlag > 1) cout << "BaseIUChassisBus::BaseIUChassisBus() : Finished constructing bus for port " << hex << showbase << bmDevice->GetPortName() << endl; return; } //! Copy constructor, should not be used BaseIUChassisBus::BaseIUChassisBus(BaseIUChassisBus& bus) : BaseIUVirtBus(bus) { cerr << "BaseIUChassisBus::BaseIUChassisBus() : Error, copy constructor cannot be used" << endl; return; }