1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315
|
/* Copyright (c) 1996-2004, Adaptec Corporation
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* - Redistributions of source code must retain the above copyright notice, this
* list of conditions and the following disclaimer.
* - Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation
* and/or other materials provided with the distribution.
* - Neither the name of the Adaptec Corporation nor the names of its
* contributors may be used to endorse or promote products derived from this
* software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*/
/****************************************************************************
*
* Created: 7/17/98
*
*****************************************************************************
*
* File Name: ScsiList.cpp
* Module:
* Contributors: Lee Page
* Description: Encapsulates an array of SCSI items. Used as a least-common denominator
solution in coding C++ without STL.
* Version Control:
*
* $Revision$
* $NoKeywords: $
* $Log$
* Revision 1.1.1.1 2004-04-29 10:20:14 bap
* Imported upstream version 0.0.4.
*
*****************************************************************************/
/*** INCLUDES ***/
#include "debug.hpp"
#include "scsilist.hpp"
#include "log_core.hpp"
#include <string.h>
/*** CONSTANTS ***/
/*** TYPES ***/
/*** STATIC DATA ***/
/*** MACROS ***/
/*** PROTOTYPES ***/
/*** FUNCTIONS ***/
SCSI_Addr_List::SCSI_Addr_List():
num_Items( 0 ),
items( 0 ),
next_Item_Index( 0 )
{
ENTER( "SCSI_Addr_List::SCSI_Addr_List():" );
EXIT();
}
SCSI_Addr_List::SCSI_Addr_List( const SCSI_Addr_List &right )
{
ENTER( "SCSI_Addr_List::SCSI_Addr_List( const SCSI_Addr_List &right )" );
Copy_Items( right );
num_Items = right.num_Items;
next_Item_Index = right.next_Item_Index;
EXIT();
}
SCSI_Addr_List::~SCSI_Addr_List()
{
ENTER( "SCSI_Addr_List::~SCSI_Addr_List()" );
Destroy_Items();
EXIT();
}
SCSI_Addr_List &SCSI_Addr_List::operator += ( const SCSI_Addr_List &right )
{
ENTER( "SCSI_Addr_List &SCSI_Addr_List::operator += ( const SCSI_Addr_List &right )" );
int int_Index;
SCSI_Address **temp_Items;
// allocate a larger buffer and copy over the existing entries
temp_Items = new SCSI_Address *[ num_Items + right.num_Items ];
memcpy( temp_Items, items, num_Items * sizeof( SCSI_Address * ) );
delete items;
items = temp_Items;
// now copy over the ones being added
for( int_Index = 0;
int_Index < right.num_Items;
int_Index++ )
{
items[ int_Index + num_Items ] = &right.get_Item( int_Index );
}
num_Items += right.num_Items;
EXIT();
return( *this );
}
const SCSI_Addr_List & SCSI_Addr_List::operator = ( const SCSI_Addr_List &right )
{
ENTER( "const SCSI_Addr_List & SCSI_Addr_List::operator = ( const SCSI_Addr_List &right )" );
Destroy_Items();
Copy_Items( right );
num_Items = right.num_Items;
next_Item_Index = right.next_Item_Index;
EXIT();
return( *this );
}
/****************************************************************************
*
* Function Name: add_Address(), Created:7/17/98
*
* Description: Appends a address to the end of the list of items.
*
* Notes:
*
*****************************************************************************/
void SCSI_Addr_List::add_Item( const SCSI_Address &address )
{
ENTER( "void SCSI_Addr_List::add_Item( const SCSI_Address &address )" );
SCSI_Address **temp_Addresses;
// create a new table large enough to contain the previously entered items
// plus this new one.
temp_Addresses = new SCSI_Address *[ num_Items + 1 ];
if( temp_Addresses )
{
num_Items++;
if( items )
{
//Copy all the previous items over to the new array
memcpy( temp_Addresses, items, num_Items * sizeof( SCSI_Address *) );
// we don't need this old one any more.
delete[] items;
}
items = temp_Addresses;
items[ num_Items - 1 ] = new SCSI_Address( address );
}
EXIT();
}
/****************************************************************************
*
* Function Name: get_Address(), Created:7/17/98
*
* Description: Fetches the nth address (0 based). The user should not
deallocate the returned address. It is owned by the
object.
*
* Notes:
*
*****************************************************************************/
SCSI_Address &SCSI_Addr_List::get_Item( int index ) const
{
ENTER( "SCSI_Address &SCSI_Addr_List::get_Item( int index ) const" );
SCSI_Address *ret_Address = 0;
if( index < num_Items )
{
ret_Address = items[ index ];
}
EXIT();
return( *ret_Address );
}
/****************************************************************************
*
* Function Name: get_Next_Address(), Created:7/17/98
*
* Description: Fetches the next address. The user should not deallocate
the returned address. It is owned by the object.
*
* Return: C-address
*
* Notes:
*
*****************************************************************************/
SCSI_Address &SCSI_Addr_List::get_Next_Item()
{
ENTER( "SCSI_Address &SCSI_Addr_List::get_Next_Item()" );
SCSI_Address *ret_Address = 0;
if( next_Item_Index < num_Items )
{
ret_Address = items[ next_Item_Index ];
next_Item_Index++;
}
EXIT();
return( *ret_Address );
}
/****************************************************************************
*
* Function Name: shift_Item(), Created:7/28/98
*
* Description: FIFO. Removes the first item from the list, and returns it.
*
* Return: The first item in the list.
*
* Notes: This is a destructive read.
*
*****************************************************************************/
SCSI_Address SCSI_Addr_List::shift_Item()
{
ENTER( "SCSI_Address SCSI_Addr_List::shift_Item()" );
SCSI_Address ret_Item( *items[ 0 ] );
int copy_Index;
delete items[ 0 ];
for( copy_Index = 0; copy_Index < num_Items - 1; copy_Index++ )
{
items[ copy_Index ] = items[ copy_Index + 1 ];
}
num_Items--;
next_Item_Index = ( next_Item_Index > 0 )?next_Item_Index - 1:0;
EXIT();
return( ret_Item );
}
/****************************************************************************
*
* Function Name: reset_Next_Index(), Created:7/17/98
*
* Description: Resets the get_Next_Address index to point to the first item.
*
* Notes:
*
*****************************************************************************/
void SCSI_Addr_List::reset_Next_Index()
{
ENTER( "void SCSI_Addr_List::reset_Next_Index()" );
next_Item_Index = 0;
EXIT();
}
int SCSI_Addr_List::num_Left() const
{
ENTER( "int SCSI_Addr_List::num_Left() const" );
EXIT();
return( num_Items - next_Item_Index );
}
void SCSI_Addr_List::Destroy_Items()
{
ENTER( "void SCSI_Addr_List::Destroy_Items()" );
int address_Index;
for( address_Index = 0; address_Index < num_Items; address_Index++ )
{
delete items[ address_Index ];
}
delete[] items;
EXIT();
}
void SCSI_Addr_List::Copy_Items( const SCSI_Addr_List &right )
{
ENTER( "void SCSI_Addr_List::Copy_Items( const SCSI_Addr_List &right )" );
int address_Index;
items = new SCSI_Address *[ right.num_Items ];
num_Items = right.num_Items;
for( address_Index = 0; address_Index < num_Items; address_Index++ )
{
items[ address_Index ] = new SCSI_Address( right.get_Item( address_Index ) );
}
EXIT();
}
// returns true if addr is already in the list, false otherwise
bool SCSI_Addr_List::In_List (const SCSI_Address &addr)
{
for (int i = 0; i < num_Items; i++)
{
if ((items [i]->hba == addr.hba) &&
(items [i]->bus == addr.bus) &&
(items [i]->id == addr.id) &&
(items [i]->lun == addr.lun))
return true;
}
return false;
}
/*** END OF FILE ***/
|