www.pudn.com > apdb2ndb.rar > atn_conv_to_eport.cc
#ifndef lint
static char copyright[] = "Copyright (C) FUJITO LIMITED 2000 ";
static char id[]= "$Id: atn_conv_to_eport.cc,v 1.5 2001/06/12 15:51:47 JST rad1 Exp $";
#endif
/*
* $Log: atn_conv_to_eport.cc,v $
* Revision 1.5 2001/06/12 15:51:47 JST rad1
* 阪本(TSL)
* 名前の先頭の\追加機能
*
* Revision 1.4 2001/02/07 15:54:28 JST rad1
* 阪本(TSL)
* ・サフィックスの変換規則の追加
* ・サフィックス処理クラスatn_sfxにより整列
*
* Revision 1.3 2000/12/19 16:42:05 JST rad1
* 阪本(TSL)
* ・サフィックスの変換処理を修正
*
* Revision 1.2 2000/12/07 16:43:23 JST rad1
* deleted.
*
* $Com: 阪本(TSL)
* $Com: 名前の先頭の\追加機能
*/
// Convert Io Block and IO component to NDB-inst
//
//
#include "atn_inc.h"
static int atn_ioport2eport(atn_com &com, AirComponentInfo &CompInfo);
//
// conv_to_eport begin
//
ATN_FDECL int atn_conv_to_eport(atn_com &com)
{
int rcode = 0;
int rc = 0;
AirBlockInfo BlockInfo;
// get component id and name
int64_t blockid = com.top_blockid;
BlockInfo.clear();
BlockInfo.set_blockid(blockid);
BlockInfo.set_io_f(1);
rc = com.arch->block_search(BlockInfo);
AirComponentInfo CompInfo;
// Get compInfo and ndb_compid from BlockInfo
CompInfo.clear();
int64_t compid = com.top_compid;
CompInfo.set_componentid(compid);
rc = com.arch->component_search(CompInfo);
const char *compname = CompInfo.get_componentname();
rc = atn_ioport2eport(com,CompInfo);
atn_debug(__FILE__,__LINE__,"=== enter atn_conv_to_eport\n");
atn_debug(__FILE__,__LINE__," componanr name (%s)\n",compname);
//
// Fase 1 : count # of compent port usig seq. read
//
AirSeq *seq_cport = NULL_PTR;
atn_init_seq_read(com,&seq_cport);
int num_cports ;
for(num_cports=0;;)
{
int num_array = 0;
AirComponentPortInfo *CompPortInfo = NULL_PTR;
int rc_get_cport =
seq_cport->
componentports_in_component(&CompPortInfo,num_array,
CompInfo);
if(rc_get_cport == AIR_R_NOEXIST)
{
#if 0
com.afm->message("atn0012",
AIR_MSG_CHR,"table","component",
AIR_MSG_END);
#endif
break;
}
if(rc_get_cport == 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;
return rcode;
}
if(num_array == 1)
{
num_cports++;
}
else
{
atn_sfx *sfx = new atn_sfx;
sfx->sort(CompPortInfo,num_array);
int num_of_sorted_rec = sfx->num_of_sorted_rec;
num_cports += num_of_sorted_rec;
#ifdef DEBUG
if(my_debug) {
cout << "1st !stage after sort\n";
cout << " FILE = " << " " __FILE__ << "LINE = " <<__LINE__ << "
\n";
cout << " num_of_sorted_rec2 = " << num_of_sorted_rec;
cout << "\n";
}
#endif
delete sfx;
}
if(rc_get_cport == AIR_R_FINISH)
{
// end of io-componentport
break;
}
}
atn_debug(__FILE__,__LINE__," # of cports(%d)\n",num_cports);
// ninish of 1st fase ( count up coprt process )
if(seq_cport)
{
delete seq_cport;
seq_cport = NULL;
}
//
// 2nd fase : Make up array of PortInfo
//
// Remark : PortInfo not to be delete bacause they will refered in
// atn_conv_to_net
if(num_cports == 0)
{
return rcode;
}
AirPortInfo *PortInfo = new AirPortInfo[num_cports];
const char *blockname = BlockInfo.get_blockname();
atn_init_seq_read(com,&seq_cport);
for(int i=0;;)
{
int num_array = 0;
AirComponentPortInfo *CompPortInfo = NULL_PTR;
int rc_get_cport =
seq_cport->
componentports_in_component(&CompPortInfo,num_array,
CompInfo);
if(rc_get_cport == AIR_R_NOEXIST)
{
#if 0
com.afm->message("atn0012",
AIR_MSG_CHR,"table","component",
AIR_MSG_END);
#endif
break;
}
if(rc_get_cport == 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;
return rcode;
// goto exit_func;
}
if(num_array == 1)
{
const char *cportname = CompPortInfo[0].get_componentportname();
const char *sfx = CompPortInfo[0].get_suffixname();
PortInfo[i].clear();
PortInfo[i].set_blockid(blockid);
PortInfo[i].set_blockname(blockname);
PortInfo[i].set_portname(cportname);
if(sfx) PortInfo[i].set_suffixname(sfx);
rc=com.arch->port_search(PortInfo[i]);
#ifdef DEBUG
if(my_debug) {
cout << __FILE__ << " " << __LINE__ << '\n';
cout << " i= " << i << "\n";
cout << "num_cports = " << num_cports << '\n' ;
cout << "blockname = " << blockname << "\n";
cout << "cportname = " << cportname << "\n";
}
#endif
i++;
}
else
{
atn_sfx *asfx = new atn_sfx;
asfx->sort(CompPortInfo,num_array);
int num_of_sorted_rec = asfx->num_of_sorted_rec;
#ifdef DEBUG
if(my_debug) {
cout << __FILE__ << " " << __LINE__ << '\n';
asfx->dump();
asfx->dump_after_sort();
cout << "\n";
}
#endif
for(int j = 0; j sorted_sfx_rec[j]==NULL_PTR) continue;
int idx = asfx->sorted_sfx_rec[j]->idx;
if(idx < 0) continue;
if(i+idx >= num_cports)
{
#ifdef DEBUG
if(my_debug) {
cout << __FILE__ << " " << __LINE__ << '\n';
cout << " idx = " << idx << "\n";
cout << " i= " << i << "\n";
cout << "j = " << j << "\n";
cout << "num_array = " << num_array << '\n' ;
cout << "num_cports = " << num_cports << '\n' ;
cout << "blockname = " << blockname << "\n";
}
#endif
cout << __FILE__ << " " << __LINE__ << "\n";
cout << "Program Error\n";
fflush(stdout);
exit(-1);
}
const char *cportname =
CompPortInfo[idx].get_componentportname();
const char *sfx = CompPortInfo[idx].get_suffixname();
PortInfo[i+idx].set_blockid(blockid);
PortInfo[i+idx].set_blockname(blockname);
PortInfo[i+idx].set_portname(cportname);
if(sfx) PortInfo[i+idx].set_suffixname(sfx);
rc=com.arch->port_search(PortInfo[i+idx]);
}
delete asfx;
i += num_of_sorted_rec;
}
if(rc_get_cport == AIR_R_FINISH)
{
// end of io-componentport
break;
}
}
// ninish of 1st fase ( count up coprt process )
if(seq_cport)
{
delete seq_cport;
seq_cport = NULL;
}
//
// 3rd fase : get ndb_eport (top)
//
NDB_IPORTID ndb_top_eportid =
ndb_get_eportid(com.part_cntl,com.mid,NDB_TOP);
if(ndb_top_eportid <= 0 )
{
// Program error
rcode = -1;
goto exit_func;
}
if(ndb_top_eportid == 0)
{
/* this is not error */
goto exit_func;
}
//
// 4th fase : entry ndb_eportid and PortInfo to PortConvTable
//
for(int i=0;ientry_port
(NDB_IPORT_OBJ,ndb_top_eportid+i,&PortInfo[i]);
}
catch(...)
{
com.afm->message("nta0800",
AIR_MSG_CHR,"file",__FILE__,
AIR_MSG_INT,"line",__LINE__,AIR_MSG_END);
}
}
exit_func:
return rcode;
}
//
// convert component port to ndb eport
//
static int atn_ioport2eport(atn_com &com,
AirComponentInfo &CompInfo)
{
int rcode =0;
int rc = 0;
int rc_get_componentport;
int go = 0;
int64_t compid = CompInfo.get_componentid();
NDB_EPORTID ndb_eportid;
int ndb_io_mode = 0;
AirComponentPortInfo *CompPortInfoPtr = NULL_PTR;
AirComponentPortInfo CompPortInfo;
int num_array;
AirPortInfo *IoPortInfo = NULL_PTR;
AirSeq *seq_cport;
atn_init_seq_read(com,&seq_cport);
for(int portlist_no=1;;portlist_no++)
{
int num_ports = 0;
rc_get_componentport =
seq_cport->componentports_in_component(&CompPortInfoPtr,num_ports,
CompInfo);
if(rc_get_componentport == AIR_R_NOEXIST)
{
// This is not error case
break;
}
if(rc_get_componentport == 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 *componentportname =
strdup(CompPortInfoPtr->get_componentportname());
int compid = CompPortInfoPtr->get_componentid();
const char *top_sfx = CompPortInfoPtr->get_suffixname();
int64_t io = -1;
com.arch->componentport_get_info(CompPortInfoPtr[0],AIR_KEY_IO,io);
if(componentportname == NULL_PTR)
{
atn_debug(__FILE__,__LINE__,"internal error");
com.afm->message("atn0420",
AIR_MSG_CHR,"msg",__FILE__,
AIR_MSG_CHR,"file",__FILE__,
AIR_MSG_INT,"line",__LINE__,AIR_MSG_END);
rcode = -1;
return -1;
}
NDB_RANGEINFO *rangeinfo=NULL_PTR;
if(top_sfx != NULL_PTR || num_ports > 1)
{
int left = 0;
int right = 0;
int dim = 1;
rc =
atn_get_range_of_cport(com,CompPortInfoPtr,num_ports,left,right);
/* create range */
rangeinfo = ndb_create_range(com.part_cntl,com.mid,dim,
&left,&right);
if(rangeinfo == NULL_PTR)
{
{
atn_debug(__FILE__,__LINE__,"faulure to add component\n");
rcode = -1;
goto exit_func;
}
}
}
else
{
rangeinfo = NULL_PTR;
}
// convert apdb io mode to ndb io mode
ndb_io_mode = atn_conv_iomode(io);
// Add ext. port to ndb
/* 2001.5.23 */
char *ndb_name = atn_conv_to_ndb_name((char *)componentportname);
ndb_eportid =
ndb_add_eport(com.part_cntl,com.mid,
(char *)ndb_name,
rangeinfo,ndb_io_mode,portlist_no,NULL,0,0);
atn_debug(__FILE__,__LINE__,"result of add_eport (%d)\n",ndb_eportid);
if(ndb_name != componentportname) free(ndb_name);
/* 2001.5.23 */
if(ndb_eportid <= 0)
{
com.afm->message("nta0410",
AIR_MSG_CHR,"func",ndb_add_eport,
AIR_MSG_CHR,"file",__FILE__,
AIR_MSG_INT,"line",__LINE__,AIR_MSG_END);
}
if(rangeinfo)
{
ndb_clear_range(com.part_cntl,com.mid,rangeinfo);
}
if(rc_get_componentport == AIR_R_FINISH)
{
// end of io-componentport
break;
}
}
exit_func:
if(seq_cport)
{
delete seq_cport;
}
return rcode;
}