www.pudn.com > apdb2ndb.rar > atn_conv_to_net.cc
#ifndef lint
static char copyright[] = "Copyright (C) FUJITSU LIMITED 2000" ;
static char id[] = "$Id: atn_conv_to_net.cc,v 1.4 2001/06/12 15:52:47 JST rad1 Exp $" ;
#endif
/*
* $Log: atn_conv_to_net.cc,v $
* Revision 1.4 2001/06/12 15:52:47 JST rad1
* 阪本(TSL)
* 名前の先頭の\追加機能
*
* Revision 1.3 2001/02/07 15:54:32 JST rad1
* 阪元(TSL)
* ・サフィックスの変換処理を修正
*
* Revision 1.2 2000/12/19 16:42:06 JST rad1
* 阪元(TSL)
* ・サフィックスの変換処理を修正
*
* $Com: 阪本(TSL)
* $Com: 名前の先頭の\追加機能
*/
//
//
//
//
#include "atn_inc.h"
static int atn_connect_net_port(atn_com &, AirNetInfo &,NDB_NETID);
ATN_FDEF int atn_conv_to_net(atn_com &com)
{
int rcode =0;
int rc = 0;
AirNetInfo *NetInfoArray;
int32_t num_of_nets;
if(atn_global::atn_debug)
com.PortConvTable->dump();
atn_debug(__FILE__,__LINE__,"**** BEGI NET ***\n");
AirSeq *seq_net = NULL;
atn_init_seq_read(com,&seq_net);
for(;;)
{
int get_net_rc;;
get_net_rc = seq_net->nets_in_arch(&NetInfoArray,num_of_nets);
if(get_net_rc == AIR_R_NOEXIST)
{
com.afm->message("atn0012",
AIR_MSG_CHR,"table","net",
AIR_MSG_END);
break;
}
if(get_net_rc == AIR_R_NOMEM)
{
// Error Message : Program Error
// No Enough Memory
com.afm->message("atn0800",
AIR_MSG_CHR,"file",__FILE__,
AIR_MSG_INT,"line",__LINE__,AIR_MSG_END);
rcode = -1;
goto exit_func;
}
const char *netname = NetInfoArray[0].get_netname();
int netid = NetInfoArray[0].get_netid();
const char *sfxname = NetInfoArray[0].get_suffixname();
atn_debug(__FILE__,__LINE__,"=== NET ===\n");
atn_debug(__FILE__,__LINE__,
" netid(%d) netname<%s> suffix<%s> num_of_net(%d)\n",
(int)netid,netname,sfxname?sfxname:"",num_of_nets);
NDB_NETID ndb_netid;
if(num_of_nets == 1)
{
/* 2001.5.23 */
char *ndb_name = atn_conv_to_ndb_name((char *)netname);
ndb_netid =
ndb_add_net(com.part_cntl,com.mid,ndb_name,NULL_PTR);
if(ndb_name != netname) free(ndb_name);
/* 2001.5.23 */
if(ndb_netid <= 0)
{
// 2001.4.9 add error message
// Error Message : Program Error
// No Enough Memory
com.afm->message("atn0800",
AIR_MSG_CHR,"file",__FILE__,
AIR_MSG_INT,"line",__LINE__,AIR_MSG_END);
/* error */
}
rc = atn_connect_net_port(com,NetInfoArray[0],ndb_netid);
if(ndb_netid <= 0)
{
// Error Message : Program Error
// No Enough Memory
com.afm->message("atn0800",
AIR_MSG_CHR,"file",__FILE__,
AIR_MSG_INT,"line",__LINE__,AIR_MSG_END);
/* error */
}
rc = atn_connect_net_port(com,NetInfoArray[0],ndb_netid);
}
else
{
int l = 0;
int r = 0;
rc = atn_get_range_of_net(com,NetInfoArray,num_of_nets,l,r);
/* count up array size */
NDB_RANGEINFO *range_info;
range_info = ndb_create_range(com.part_cntl,com.mid,
(int)1,&l,&r);
if(range_info == NULL)
{
// Error Message : Program Error
// No Enough Memory
com.afm->message("atn0800",
AIR_MSG_CHR,"file",__FILE__,
AIR_MSG_INT,"line",__LINE__,AIR_MSG_END);
/* no enough memory */
}
/* 2001.5.23 */
char *ndb_name = atn_conv_to_ndb_name((char *)netname);
ndb_netid =
ndb_add_net(com.part_cntl,com.mid,ndb_name,range_info);
if(ndb_name != netname) free(ndb_name);
/* 2001.5.23 */
if(ndb_netid <= 0)
{
// Error Message : Program Error
// No Enough Memory
com.afm->message("atn0800",
AIR_MSG_CHR,"file",__FILE__,
AIR_MSG_INT,"line",__LINE__,AIR_MSG_END);
/* error */
}
rc = ndb_clear_range(com.part_cntl,com.mid,range_info);
atn_sfx *sfx = new atn_sfx;
sfx->sort(NetInfoArray,num_of_nets);
// sfx->dump();
// sfx->dump_after_sort();
int num_of_sorted_rec = sfx->num_of_sorted_rec;
for(int i = 0; i sorted_sfx_rec[i] == NULL_PTR) continue;
int idx = sfx->sorted_sfx_rec[i]->idx;
if(idx < 0) continue;
rc = atn_connect_net_port(com,NetInfoArray[idx],ndb_netid+i);
// rc = atn_connect_net_port(com,NetInfoArray[0],ndb_netid+i);
}
delete sfx;
}
/* delete ptr. to net */
if(NetInfoArray)
{
delete [] NetInfoArray;
}
if(get_net_rc == AIR_R_FINISH)
{
// end of io-net
break;
}
}
exit_func:
if(seq_net) delete seq_net;
seq_net = NULL_PTR;
return rcode;
}
static int atn_connect_net_port(atn_com &com,
AirNetInfo &NetInfo,
NDB_NETID ndb_netid)
{
int rcode =0;
int rc = 0;
const char * netname = NetInfo.get_netname();
AirPortInfo PortInfo;
if(atn_global::atn_debug)
{
const char *netname = NetInfo.get_netname();
int netid = NetInfo.get_netid();
const char *sfxname = NetInfo.get_suffixname();
atn_debug(__FILE__,__LINE__,"=== in tn_connect_net_por NET ===\n");
atn_debug(__FILE__,__LINE__,
" netid(%d) netname<%s> suffix<%s> ndb_netid(%d)\n",
netid,netname,sfxname?sfxname:"",
ndb_netid);
}
AirSeq *seq_port = NULL_PTR;
atn_init_seq_read(com,&seq_port);
for(;;)
{
int get_port_rc;
get_port_rc = seq_port->port_on_net(PortInfo,NetInfo);
if(get_port_rc == AIR_R_NOEXIST)
{
// There is no port in net and this is not error
break;
}
if(get_port_rc == AIR_R_NOMEM)
{
// Error Message : Program Error
// No Enough Memory
com.afm->message("nta0800",
AIR_MSG_CHR,"file",__FILE__,
AIR_MSG_INT,"line",__LINE__,AIR_MSG_END);
rcode = -1;
goto exit_func;
}
const char *portname = PortInfo.get_portname();
const char *blockname = PortInfo.get_blockname();
int64_t portid = PortInfo.get_portid();
const char *sfxname = PortInfo.get_suffixname();
if(sfxname != NULL_PTR && strlen(sfxname)!=0)
{
atn_debug(__FILE__,__LINE__,"sfxname<%s> detected\n",sfxname);
}
atn_debug(__FILE__,__LINE__,"=== PORT ===\n");
atn_debug(__FILE__,__LINE__,
" portid(%d) blockname(%s) portname<%s> ssuffixname<%s>\n",
(int)portid,blockname,portname,sfxname?sfxname:"");
//
// get ndb_portid from apdb_poerid
NDB_IPORTID ndb_portid = com.PortConvTable->get_ndb_portid(portid);
atn_debug(__FILE__,__LINE__," ndb_portid = %d\n",(int)ndb_portid);
// prepare add net process
NDB_OBJ_KIND obj_kind =
com.PortConvTable->get_ndb_port_kind(portid);
NDB_IDINFO idinfo;
idinfo.kind = obj_kind;
switch(obj_kind)
{
case NDB_EPORT_OBJ:
idinfo.i.eportid = ndb_portid;
break;
case NDB_IPORT_OBJ:
idinfo.i.iportid = ndb_portid;
break;
}
// check item is conneced to net
NDB_NETID tmp_ndb_netid =
ndb_get_netid_from_port(com.part_cntl,com.mid,&idinfo);
if(tmp_ndb_netid<0)
{
com.afm->message("atn0410",
AIR_MSG_CHR,"func","ndb_get_netid_from_por",
AIR_MSG_CHR,"file",__FILE__,
AIR_MSG_INT,"line",__LINE__,AIR_MSG_END);
atn_ndb_msg(com.part_cntl);
goto exit_func;
}
// If port is nonnected with no net, add item to net
// else do nothing
if(tmp_ndb_netid == 0)
{
rc = ndb_add_item_to_net(com.part_cntl,com.mid,ndb_netid,&idinfo);
atn_debug(__FILE__,__LINE__,
" rcode of ndb_add_item_to_net (%d)\n",rc);
// do not finish forced
if(rc < 0)
{
com.afm->message("atn0410",
AIR_MSG_CHR,"func","ndb_add_item_to_net",
AIR_MSG_CHR,"file",__FILE__,
AIR_MSG_INT,"line",__LINE__,AIR_MSG_END);
atn_ndb_msg(com.part_cntl);
printf(" ndb_netid (%d) ndb_portid(%d)\n",ndb_netid,ndb_portid);
fflush(stdout);
const char *netname = NetInfo.get_netname();
int netid = NetInfo.get_netid();
const char *sfxname = NetInfo.get_suffixname();
cout << " netname <" << netname << "> ";
if(sfxname)
{
cout << "sfxname<" << sfxname <<">" ;
}
cout << "netid(" << netid << ")\n";
const char *portname = PortInfo.get_portname();
const char *blockname = PortInfo.get_blockname();
int64_t blockid = PortInfo.get_blockid();
int64_t portid = PortInfo.get_portid();
const char *port_sfxname = PortInfo.get_suffixname();
cout << "blockname(" << blockname << " blockid(" <<
blockid <<") portname (" << portname << ")";
if(port_sfxname)
{
cout << "<" << port_sfxname << ">";
}
cout << "\n";
}
}
if(get_port_rc == AIR_R_FINISH)
{
// end of io-port
break;
}
}
exit_func:
if(seq_port) delete seq_port;
seq_port = NULL_PTR;
return rcode;
}