www.pudn.com > apdb2ndb.rar > atnPortConvTable.cc


#ifndef lint 
static char copyright[] = "Copyright (C) FUJITO LIMITED 2000 "; 
static char id[]= "$ID$"; 
#endif 
/* 
 * $Log: atnPortConvTable.cc,v $ 
 * Revision 1.1.1.1  2000/12/04 10:22:28 JST  rad1 
 * 
 * 
 * $COM: Written by T.Maekawa 2000  
 */ 
// error message is complete 
// 
// member functions of class atnPortConvTable  
// 
// 
#include "atn_inc.h" 
 
// 
// allocate table with a given number 
// 
atnPortConvTable::atnPortConvTable(int64_t n) 
{ 
  max_portid = n; 
 
  port_conv_table = (atnPortConv **)calloc( (size_t)(max_portid + 1), 
				       sizeof(atnPortConv *)); 
  if(port_conv_table == NULL) 
    { 
      /* error */ 
      atn_global::com.afm->message("atn0800",AIR_MSG_CHR,__FILE__, 
                       AIR_MSG_INT,__LINE__, 
                       AIR_MSG_END); 
    } 
} 
 
// 
// destructer of PortConvTable 
// 
atnPortConvTable::~atnPortConvTable(void)  
{ 
  try { 
    // 1st, delete PortConv entry if it is freed  
    for(int64_t i=1;i<= max_portid;i++) 
      { 
	if(port_conv_table[i]) 
	  delete(port_conv_table[i]); 
      } 
 
    // delete table 
    free(port_conv_table); 
 
    // reset counter 
    max_portid = 0; 
  } 
  catch(...) { 
    // aeeror during free table 
    atn_global::com.afm->message("atn0800", 
	AIR_MSG_CHR,"error during dekete rot conv", 
	AIR_MSG_CHR,__FILE__, 
        AIR_MSG_INT,__LINE__, 
        AIR_MSG_END); 
  } 
} 
 
// 
// Entry NDB portid and APDB PortInfo 
// 
atnPortConvTable::entry_port(NDB_OBJ_KIND obj_kind,int ndb_pid, 
			     AirPortInfo* PortInfo) 
{ 
  int rcode = 0; 
  int64_t a_portid = PortInfo->get_portid(); 
					     
  atnPortConv *PortConv; 
  try  
    { 
      PortConv = get_1_item(a_portid); 
      if(PortConv == NULL_PTR) 
	{ 
	  atn_debug(__FILE__,__LINE__,"can not catch get_1_item"); 
	  rcode = -1; 
	  goto exit_func; 
	} 
    } 
  catch(...)  
    { 
      atn_debug(__FILE__,__LINE__,"catch get_1_item"); 
      rcode = -1; 
      goto exit_func; 
    } 
  PortConv->obj_kind = obj_kind; 
  PortConv->ndb_pid = ndb_pid; 
 
  PortConv->apdb_pid = a_portid; 
  PortConv->PortInfo = PortInfo; 
 
  port_conv_table[a_portid] = PortConv; 
 
 exit_func: 
  return rcode; 
} 
 
// 
// return APDB portid for given a NDB portid 
// 
int atnPortConvTable::get_ndb_portid(int64_t a_portid) 
{ 
  int n_portid =0; 
  if(port_conv_table == NULL) 
    { 
      return 0; 
    } 
  atnPortConv* PortConv =  port_conv_table[a_portid]; 
  if( port_conv_table[a_portid]==NULL) 
  { 
	return 0; 
  } 
  n_portid =  port_conv_table[a_portid]->ndb_pid; 
  return n_portid;;  
} 
 
// 
// return APDB port  for given a APDN portid 
// 
NDB_OBJ_KIND atnPortConvTable::get_ndb_port_kind(int64_t a_portid) 
{ 
  NDB_OBJ_KIND obj_kind; 
  if(port_conv_table == NULL) 
    { 
      return (NDB_OBJ_KIND)0; 
    } 
  if(a_portid >= max_portid) 
  { 
    if(atn_global::atn_debug) 
	{ 
	 atn_debug(__FILE__,__LINE__, 
		    "a_portid(%d) .gt. max_portid(%d)\n", 
		    a_portid,max_portid);  
	} 
	return((NDB_OBJ_KIND)0); 
  } 
  atnPortConv* PortConv =  port_conv_table[a_portid]; 
  if( port_conv_table[a_portid]==NULL) 
  { 
	return (NDB_OBJ_KIND)0; 
  } 
  obj_kind =  port_conv_table[a_portid]->obj_kind; 
  return obj_kind;  
} 
 
 
 
void atnPortConvTable::dump(void) 
{ 
  char buf[128]; 
  cout << " === PortConvTableDump ===\n"; 
  sprintf(buf,"     max_portid(%d) port_conv_table (%x)\n", 
	  max_portid,port_conv_table); 
  for(int i = 1; i <= max_portid;i++) 
    if(port_conv_table[i])  
      { 
	port_conv_table[i]->dump(); 
      } 
} 
 
atnPortConv *atnPortConvTable::get_1_item(int64_t n) 
{ 
  if(n >= max_portid) 
    { 
	int new_size  = max_portid + 100 ; 
  	port_conv_table = (atnPortConv **) 
	  realloc( port_conv_table, 
		   (size_t)(new_size+1)*sizeof(atnPortConv *)); 
	for(int i=max_portid+1;i<=new_size;i++) 
	  port_conv_table[i] = NULL_PTR; 
	max_portid = new_size-1; 
    } 
  /* another case is as follows (not implemented) */ 
  if(port_conv_table[n]) 
	{ 
		cout << " Duplicate entry of PortConvTab (" << n <<")\n"; 
		exit(-1); 
	} 
  port_conv_table[n] = new atnPortConv(); 
  return port_conv_table[n]; 
} 
 
 
void atnPortConv::dump(void) 
{ 
  char buf[130]; 
  sprintf(buf," === PortConv (kind,ndb_pid,apdb_pid,PortInfo) = (%d,%d,%d,%x)\n", 
	  (int)obj_kind,(int)ndb_pid,(int)apdb_pid,PortInfo); 
  cout << buf; 
  if(PortInfo == 0) return; 
  atn_global::com.arch->port_search(*PortInfo); 
  const char *apdb_portname = PortInfo->get_portname(); 
  int64_t apdb_blockid = PortInfo->get_blockid(); 
  const char *sfx_name = PortInfo->get_suffixname();  
  if(sfx_name==NULL_PTR)   
    sprintf(buf,"    blockid <%d> portname <%s>\n", 
	    (int)apdb_blockid,apdb_portname); 
  else  
    sprintf(buf,"    blockid <%d> portname <%s> sfxname <%s>\n", 
	    (int) apdb_blockid,apdb_portname,sfx_name); 
  cout << buf; 
}