dove_supplier.cpp
来自「这是广泛使用的通信开源项目,对于大容量,高并发的通讯要求完全能够胜任,他广泛可用」· C++ 代码 · 共 526 行 · 第 1/2 页
CPP
526 行
// DOVE_Supplier.cpp,v 1.19 2003/10/28 18:34:47 bala Exp
// ============================================================================
//
// = FILENAME
// DOVE_Supplier.cpp
//
// = DESCRIPTION
// A wrapper around the event service initialization and
// marshalling
//
// = AUTHOR
// Michael Kircher (mk1@cs.wustl.edu)
//
// ============================================================================
#include "DOVE_Supplier.h"
#include "tao/ORB_Core.h"
ACE_RCSID (Event_Supplier,
DOVE_Supplier,
"DOVE_Supplier.cpp,v 1.19 2003/10/28 18:34:47 bala Exp")
// Static pointer member initialization for Singleton.
ACE_Scheduler_Factory::POD_RT_Info *
DOVE_Supplier::pod_rt_info_instance_ = 0;
// Constructor.
DOVE_Supplier::DOVE_Supplier ()
: initialized_ (0),
connected_ (0),
connection_params_list_ (0),
current_connection_params_ (0),
connection_count_ (0),
current_connection_index_ (0),
internal_DOVE_Supplier_ptr_ (0),
MIB_name_ (0)
{
ACE_NEW (internal_DOVE_Supplier_ptr_,
Internal_DOVE_Supplier (this));
if (internal_DOVE_Supplier_ptr_ == 0)
{
ACE_ERROR ((LM_ERROR,
"DOVE_Supplier::DOVE_Supplier internal "
"supplier not allocated."));
}
}
// Destructor.
DOVE_Supplier::~DOVE_Supplier ()
{
for (int i = 0; i < this->connection_count_; ++i)
{
delete (this->connection_params_list_ [i]);
}
delete [] this->connection_params_list_;
delete internal_DOVE_Supplier_ptr_;
}
// Initialize the ORB and the connection to the Name Service
int
DOVE_Supplier::init (void)
{
ACE_TRY_NEW_ENV
{
// Connect to the RootPOA.
CORBA::Object_var poaObject_var =
TAO_ORB_Core_instance()->orb()->resolve_initial_references("RootPOA"
ACE_ENV_ARG_PARAMETER);
ACE_TRY_CHECK;
if (CORBA::is_nil (poaObject_var.in ()))
ACE_ERROR_RETURN ((LM_ERROR,
" (%P|%t) Unable to initialize the POA.\n"),
-1);
this->root_POA_var_ =
PortableServer::POA::_narrow (poaObject_var.in () ACE_ENV_ARG_PARAMETER);
ACE_TRY_CHECK;
this->poa_manager_ =
root_POA_var_->the_POAManager (ACE_ENV_SINGLE_ARG_PARAMETER);
ACE_TRY_CHECK;
// Get the Naming Service object reference.
CORBA::Object_var namingObj_var =
TAO_ORB_Core_instance()->orb()->resolve_initial_references (
"NameService"
ACE_ENV_ARG_PARAMETER);
ACE_TRY_CHECK;
if (CORBA::is_nil (namingObj_var.in ()))
ACE_ERROR_RETURN ((LM_ERROR,
" (%P|%t) Unable to get the Naming Service.\n"),
-1);
this->namingContext_var_ =
CosNaming::NamingContext::_narrow (namingObj_var.in ()
ACE_ENV_ARG_PARAMETER);
ACE_TRY_CHECK;
}
ACE_CATCHANY
{
ACE_PRINT_EXCEPTION (ACE_ANY_EXCEPTION,
"DOVE_Supplier::init");
return -1;
}
ACE_ENDTRY;
initialized_ = 1;
return 0;
}
int
DOVE_Supplier::connect (const char* MIB_name,
const char* es_name,
const char * ss_name,
ACE_Scheduler_Factory::POD_RT_Info * pod_rt_info)
{
// Initialize the supplier if this has not already been done.
if ((initialized_ == 0) && (this->init () == -1))
{
ACE_ERROR_RETURN ((LM_ERROR,
" (%P|%t) Unable to initialize the DOVE_Supplier.\n"),
-1);
}
// Grab the default RT_Info settings if others were not provided.
if (pod_rt_info == 0)
{
// Get the default singleton if we were not passed the data
pod_rt_info = DOVE_Supplier::pod_rt_info_instance ();
if (pod_rt_info == 0)
{
ACE_ERROR_RETURN ((LM_ERROR,
" (%P|%t) Unable to obtain"
" the default RT_Info data.\n"),
-1);
}
}
// Save the passed MIB name
MIB_name_ = (MIB_name == 0) ? "MIB_unknown" : MIB_name;
// Create a new connection parameters structure.
Connection_Params * cp_temp = 0;
ACE_NEW_RETURN (cp_temp, Connection_Params, -1);
// Populate the known fields of the new connection params struct.
cp_temp->pod_rt_info_ = *pod_rt_info;
cp_temp->es_name_ = (es_name == 0) ? "EventService" : es_name;
cp_temp->ss_name_ = (ss_name == 0) ? "ScheduleService" : ss_name;
// Allocate a new connection parameters pointer array.
// Cannot use ACE_NEW_RETURN here, as we need to clean up
// cp_temp if we fail here, and we need what cp_temp points
// to after the current scope if we succeed here.
Connection_Params ** cp_list_temp;
cp_list_temp =
new Connection_Params * [this->connection_count_ + 1];
if (cp_list_temp == 0)
{
// Avoid a memory leak if we failed to allocate.
delete cp_temp;
ACE_ERROR_RETURN ((LM_ERROR,
" (%P|%t) DOVE_Supplier::connect could not "
"reallocate connection params list"),
-1);
}
// Copy the connection struct pointers from
// the old list (if any) to the new one.
for (int i = 0; i < this->connection_count_; ++i)
{
cp_list_temp [i] =
this->connection_params_list_ [i];
}
// Put a pointer to the new connection params structure
// in the new list, increment the connection params count,
// and point to the latest connection parameters.
cp_list_temp [this->connection_count_] = cp_temp;
this->current_connection_params_ = cp_temp;
current_connection_index_ = connection_count_;
++ (this->connection_count_);
// Replace the old list of pointers with the new one
delete [] this->connection_params_list_;
this->connection_params_list_ = cp_list_temp;
// Resolve the event service reference.
if (this->get_EventChannel () == -1)
{
ACE_ERROR_RETURN ((LM_ERROR,
" (%P|%t) Unable to resolve the event service.\n"),
-1);
}
// Resolve the scheduling service reference.
if (this->get_Scheduler () == -1)
{
ACE_ERROR_RETURN ((LM_ERROR,
" (%P|%t) Unable to resolve the scheduler.\n"),
-1);
}
// Connect to the event service as a supplier.
if (this->connect_Supplier () == -1)
{
ACE_ERROR_RETURN ((LM_ERROR,
" (%P|%t) Unable to connect to the event service.\n"),
-1);
}
return 0;
}
// This method is invoked after all connect calls are done.
void
DOVE_Supplier::connected ()
{
if (! connected_)
{
// Code to do post-connection-establishment
// one-time logic goes here.
connected_ = 1;
}
}
void
DOVE_Supplier::disconnect ()
{
}
void
DOVE_Supplier::notify (CORBA::Any &message)
{
// Finalize connection establishment no later than the first event notification
if (! connected_)
{
this->connected ();
}
ACE_TRY_NEW_ENV
{
RtecEventComm::Event event;
event.header.source = SOURCE_ID;
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?