📄 be_interface_strategy.cpp
字号:
// be_interface_strategy.cpp,v 1.24 2003/04/30 12:30:57 elliott_c Exp
// ============================================================================
//
// = LIBRARY
// TAO IDL
//
// = FILENAME
// be_interface_strategy.cpp
//
// = DESCRIPTION
// A strategy to cover the differences between various variants
// of an interface
//
// = AUTHOR
// Michael Kircher
//
// ============================================================================
#include "be_interface_strategy.h"
#include "be_interface.h"
#include "be_extern.h"
#include "utl_identifier.h"
ACE_RCSID (be,
be_interface_strategy,
"be_interface_strategy.cpp,v 1.24 2003/04/30 12:30:57 elliott_c Exp")
be_interface_strategy::be_interface_strategy (be_interface *node,
Strategy_Kind strategy_type)
: local_name_(0),
full_name_(0),
flat_name_(0),
repoID_(0),
full_skel_name_(0),
full_coll_name_(0),
local_coll_name_(0),
relative_skel_name_(0),
node_ (node),
cached_type_ (-1),
strategy_type_ (strategy_type)
{
}
be_interface_strategy::~be_interface_strategy (void)
{
if (this->local_name_ != 0)
{
delete [] this->local_name_;
this->local_name_ = 0;
}
if (this->full_name_ != 0)
{
delete [] this->full_name_;
this->full_name_ = 0;
}
if (this->flat_name_ != 0)
{
delete [] this->flat_name_;
this->flat_name_ = 0;
}
if (this->repoID_ != 0)
{
delete [] this->repoID_;
this->repoID_ = 0;
}
if (this->full_skel_name_ != 0)
{
delete [] this->full_skel_name_;
this->full_skel_name_ = 0;
}
if (this->full_coll_name_ != 0)
{
delete [] this->full_coll_name_;
this->full_coll_name_ = 0;
}
if (this->local_coll_name_ != 0)
{
delete [] this->local_coll_name_;
this->local_coll_name_ = 0;
}
if (this->relative_skel_name_ != 0)
{
delete [] this->relative_skel_name_;
this->relative_skel_name_ = 0;
}
}
// Interface Type Strategy Base Class
// Relative skeleton name.
const char *
be_interface_strategy::relative_skel_name (const char *skel_name)
{
return be_interface::relative_name (this->full_skel_name (),
skel_name);
}
// Compute stringified fully qualified collocated class name.
void
be_interface_strategy::compute_coll_names (int type,
const char *prefix,
const char *suffix)
{
if (type == this->cached_type_ && this->full_coll_name_ != 0)
{
return;
}
else
{
this->cached_type_ = type;
delete [] this->full_coll_name_;
delete [] this->local_coll_name_;
}
static const char *collocated_names[] = {"_tao_thru_poa_collocated_",
"_tao_direct_collocated_"};
static const char *poa = "POA_";
// Reserve enough room for the "POA_" prefix, the "_tao_collocated_"
// prefix and the local name and the (optional) "::"
const char *collocated = collocated_names[type];
size_t name_len = ACE_OS::strlen (collocated)
+ ACE_OS::strlen (poa)
+ 1;
if (prefix)
{
name_len += ACE_OS::strlen (prefix);
}
if (suffix)
{
name_len += ACE_OS::strlen (suffix);
}
for (UTL_IdListActiveIterator i (this->node_->name ());
!i.is_done ();
i.next ())
{
// Reserve 2 characters for "::".
name_len += ACE_OS::strlen (i.item ()->get_string ()) + 2;
}
ACE_NEW (this->full_coll_name_,
char[name_len + 1]);
// Null terminate the string.
this->full_coll_name_[0] = 0;
// Only the first component get the "POA_" preffix.
int poa_added = 0;
// Iterate again.
// Must advance the iterator explicitly inside the loop.
for (UTL_IdListActiveIterator j (this->node_->name ());
!j.is_done ();)
{
const char *item = j.item ()->get_string ();
// Increase right away, so we can test for the final component
// in the loop.
j.next ();
// We add the POA_ preffix only if the first component is not
// the global scope...
if (ACE_OS::strcmp (item, "") != 0)
{
if (!j.is_done ())
{
// We only add the POA_ preffix if there are more than
// two components in the name, in other words, if the
// class is inside some scope.
if (!poa_added)
{
ACE_OS::strcat (this->full_coll_name_, poa);
poa_added = 1;
}
ACE_OS::strcat (this->full_coll_name_, item);
ACE_OS::strcat (this->full_coll_name_, "::");
}
else
{
ACE_OS::strcat (this->full_coll_name_, collocated);
if (prefix)
{
ACE_OS::strcat (this->full_coll_name_, prefix);
}
ACE_OS::strcat (this->full_coll_name_, item);
if (suffix)
{
ACE_OS::strcat (this->full_coll_name_, suffix);
}
}
}
}
// Compute the local name for the collocated class.
char *local_name = this->node_->AST_Interface::local_name ()->get_string ();
size_t local_len = ACE_OS::strlen (collocated)
+ ACE_OS::strlen (local_name)
+ 1;
if (prefix)
{
local_len += ACE_OS::strlen (prefix);
}
if (suffix)
{
local_len += ACE_OS::strlen (suffix);
}
ACE_NEW (this->local_coll_name_,
char[local_len]);
ACE_OS::strcpy (this->local_coll_name_,
collocated);
if (prefix)
{
ACE_OS::strcat (this->local_coll_name_,
prefix);
}
ACE_OS::strcat (this->local_coll_name_,
node_->AST_Interface::local_name ()->get_string ());
if (suffix)
{
ACE_OS::strcat (this->local_coll_name_, suffix);
}
}
void
be_interface_strategy::compute_names (const char *name,
const char *prefix,
const char *suffix,
char *&new_name)
{
if (!prefix || !suffix)
{
return;
}
size_t name_length = ACE_OS::strlen (name) +
ACE_OS::strlen (prefix) +
ACE_OS::strlen (suffix);
ACE_NEW (new_name,
char[name_length + 1]);
// Copy it in.
ACE_OS::strcpy (new_name, name);
const char *interface_name = 0;
size_t i = ACE_OS::strlen (name);
for (;i >= 1; i--)
{
if (name[i-1] == ':' && name[i] == ':')
{
interface_name = &name[i+1];
break;
}
else if (i >= 3)
{
if (name[i-3] == 'P' &&
name[i-2] == 'O' &&
name[i-1] == 'A' &&
name[i] == '_')
{
interface_name = &name[i+1];
break;
}
}
}
if (interface_name == 0)
{
interface_name = name;
}
ACE_OS::strcpy (&new_name[name_length
- ACE_OS::strlen (prefix)
- ACE_OS::strlen (interface_name)
- ACE_OS::strlen (suffix)],
prefix);
ACE_OS::strcpy (&new_name[name_length
- ACE_OS::strlen (interface_name)
- ACE_OS::strlen (suffix)],
interface_name);
ACE_OS::strcpy (&new_name[name_length
- ACE_OS::strlen(suffix)],
suffix);
}
TAO_OutStream *
be_interface_strategy::get_out_stream (void)
{
// Outstream.
return tao_cg->server_skeletons ();
}
const char *
be_interface_strategy::get_out_stream_fname (void)
{
return be_global->be_get_server_skeleton_fname ();
}
int
be_interface_strategy::strategy_type (void)
{
return strategy_type_;
}
TAO_CodeGen::CG_STATE
be_interface_strategy::next_state (TAO_CodeGen::CG_STATE current_state,
int /* is_extra_state */)
{
return current_state;
}
int
be_interface_strategy::has_extra_code_generation (
TAO_CodeGen::CG_STATE /* current_state */
)
{
return 0;
}
be_interface *
be_interface_strategy::replacement (void)
{
return 0;
}
// ****************************************************************
// AMI Hander Strategy
be_interface_ami_handler_strategy::be_interface_ami_handler_strategy (
be_interface *node
)
: be_interface_default_strategy (node,
AMI_HANDLER)
{
}
be_interface_ami_handler_strategy::~be_interface_ami_handler_strategy (void)
{
}
TAO_CodeGen::CG_STATE
be_interface_ami_handler_strategy::next_state (
TAO_CodeGen::CG_STATE current_state,
int /*is_extra_state */
)
{
return current_state;
}
// ****************************************************************
// AMI Exception Holder Strategy
be_interface_ami_exception_holder_strategy::
be_interface_ami_exception_holder_strategy (be_interface *node)
: be_interface_default_strategy (node,
AMI_EXCEPTION_HOLDER)
{
}
be_interface_ami_exception_holder_strategy
::~be_interface_ami_exception_holder_strategy (void)
{
}
TAO_CodeGen::CG_STATE
be_interface_ami_exception_holder_strategy::next_state (
TAO_CodeGen::CG_STATE current_state,
int is_extra_state
)
{
if (is_extra_state)
{
switch (current_state)
{
case TAO_CodeGen::TAO_VALUETYPE_OBV_CH:
return TAO_CodeGen::TAO_AMI_EXCEPTION_HOLDER_VALUETYPE_CH;
case TAO_CodeGen::TAO_VALUETYPE_OBV_CS:
return TAO_CodeGen::TAO_AMI_EXCEPTION_HOLDER_VALUETYPE_CS;
default:
return current_state;
}
}
else
{
return current_state;
}
}
int
be_interface_ami_exception_holder_strategy::has_extra_code_generation (
TAO_CodeGen::CG_STATE current_state
)
{
if (current_state == TAO_CodeGen::TAO_VALUETYPE_OBV_CH
|| current_state == TAO_CodeGen::TAO_VALUETYPE_OBV_CS)
{
return 1;
}
else
{
return 0;
}
}
// ****************************************************************
// AMI Strategy
be_interface_ami_strategy::be_interface_ami_strategy (be_interface *node,
be_interface *handler)
: be_interface_default_strategy (node,
AMI_INTERFACE),
handler_ (handler)
{
}
be_interface_ami_strategy::~be_interface_ami_strategy (void)
{
}
TAO_CodeGen::CG_STATE
be_interface_ami_strategy::next_state (TAO_CodeGen::CG_STATE current_state,
int is_extra_state)
{
if (is_extra_state)
{
switch (current_state)
{
case TAO_CodeGen::TAO_AMI_INTERFACE_CH:
return TAO_CodeGen::TAO_INTERFACE_CH;
default:
return current_state;
}
}
else
{
switch (current_state)
{
case TAO_CodeGen::TAO_INTERFACE_CH:
return TAO_CodeGen::TAO_AMI_INTERFACE_CH;
default:
return current_state;
}
}
}
int
be_interface_ami_strategy::has_extra_code_generation (
TAO_CodeGen::CG_STATE current_state
)
{
if (current_state == TAO_CodeGen::TAO_AMI_INTERFACE_CH)
{
return 1;
}
else
{
return 0;
}
}
be_interface *
be_interface_ami_strategy::replacement (void)
{
return handler_;
}
// ****************************************************************
// Default Strategy
const char *be_interface_default_strategy::suffix_table_[] =
{
"_Proxy_Impl",
"_Proxy_Broker"
};
const char *be_interface_default_strategy::tag_table_[] =
{
"_Remote",
"_ThruPOA",
"_Direct",
"_Strategized",
"_TAO_"
};
be_interface_default_strategy::be_interface_default_strategy (
be_interface *node,
Strategy_Kind strategy_kind
)
: be_interface_strategy (node,
strategy_kind),
base_proxy_impl_name_ (0),
remote_proxy_impl_name_ (0),
thruPOA_proxy_impl_name_ (0),
direct_proxy_impl_name_ (0),
full_base_proxy_impl_name_ (0),
full_remote_proxy_impl_name_ (0),
full_thruPOA_proxy_impl_name_ (0),
full_direct_proxy_impl_name_ (0),
base_proxy_broker_ (0),
remote_proxy_broker_ (0),
strategized_proxy_broker_ (0),
full_base_proxy_broker_name_ (0),
full_remote_proxy_broker_name_ (0),
full_strategized_proxy_broker_name_(0),
client_scope_ (0),
flat_client_scope_ (0),
server_scope_ (0),
flat_server_scope_ (0)
{
}
be_interface_default_strategy::~be_interface_default_strategy (void)
{
if (this->base_proxy_impl_name_ != 0)
{
delete [] this->base_proxy_impl_name_;
this->base_proxy_impl_name_ = 0;
}
if (this->remote_proxy_impl_name_ != 0)
{
delete [] this->remote_proxy_impl_name_;
this->remote_proxy_impl_name_ = 0;
}
if (this->thruPOA_proxy_impl_name_ != 0)
{
delete [] this->thruPOA_proxy_impl_name_;
this->thruPOA_proxy_impl_name_ = 0;
}
if (this->direct_proxy_impl_name_ != 0)
{
delete [] this->direct_proxy_impl_name_;
this->direct_proxy_impl_name_ = 0;
}
if (this->full_base_proxy_impl_name_ != 0)
{
delete [] this->full_base_proxy_impl_name_;
this->full_base_proxy_impl_name_ = 0;
}
if (this->full_remote_proxy_impl_name_ != 0)
{
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -