//******************************************************************************
//
// Restricted Rights
// WARNING: This is a restricted distribution Zeligsoft file.
//
//******************************************************************************
//
// Copyright (C) 2006 Zeligsoft Inc. - All Rights Reserved
//

//******************************************************************************
//
//     FILE: zceCF_ResourceProvidesPort.cpp
//
//******************************************************************************


#include "zceOperatingEnvironment.h"

#include "zceCF_ResourceProvidesPort.h"


zceCF_ResourceProvidesPort::zceCF_ResourceProvidesPort( const std::string name, int portIdentifier, zceCF_ResourcePortHandler* cons ZCE_EXC_ENV_ARG )
	 : zceAbstractProvidesPort(name), cons_(cons), portIdentifier_(portIdentifier )
{

	ZCE_ASSERT_EXCEPTION_VOID;
	
}

zceCF_ResourceProvidesPort::~zceCF_ResourceProvidesPort()
{

	//ZCE_ASSERT_EXCEPTION_VOID;
	
}

void zceCF_ResourceProvidesPort::Destroy( ZCE_EXC_ENV_SINGLE_ARG )
{
	ZCE_ASSERT_EXCEPTION_VOID;
	
	if( !destroyed_ )
	{
		destroyed_  = true;

	}
}

/*!
 * \brief The start operation is provided to command a Resource implementing this
 * interface to start internal processing.
 *
 * Specification reference:  3.1.3.1.6.5.2
 *
 * The start operation puts the Resource in an operating condition.
 *
 * \return This operation does not return a value.
 *
 * \throw StartError The start operation shall raise the StartError exception if
 * an error occurs while starting the resource.
 *
 */
void zceCF_ResourceProvidesPort::start( ZCE_EXC_ENV_SINGLE_ARG )
	throw( CORBA::SystemException, ::CF::Resource::StartError )
{

	ZCE_ASSERT_EXCEPTION_VOID;
	if ( cons_ == 0)
	{
		ZCE_EXC_THROW ( CORBA::OBJECT_NOT_EXIST,(0, CORBA::COMPLETED_NO) );
	}

	cons_->CF_Resource_start(portIdentifier_  ZCE_EXC_ENV_PARAM );
}

/*!
 * \brief The stop operation is provided to command a Resource implementing this
 * interface to stop internal processing.
 *
 * Specification reference:  3.1.3.1.6.5.1
 *
 * The stop operation shall disable all current operations and put the Resource in
 * a non-operating condition. Subsequent configure, query, and start operations
 * are not inhibited by the stop operation.
 *
 * \return This operation does not return a value.
 *
 * \throw StopError The stop operation shall raise the StopError exception if an
 * error occurs while stopping the resource.
 *
 */
void zceCF_ResourceProvidesPort::stop( ZCE_EXC_ENV_SINGLE_ARG )
	throw( CORBA::SystemException, ::CF::Resource::StopError )
{

	ZCE_ASSERT_EXCEPTION_VOID;
	if ( cons_ == 0)
	{
		ZCE_EXC_THROW ( CORBA::OBJECT_NOT_EXIST,(0, CORBA::COMPLETED_NO) );
	}

	cons_->CF_Resource_stop(portIdentifier_  ZCE_EXC_ENV_PARAM );
}

char* zceCF_ResourceProvidesPort::identifier( ZCE_EXC_ENV_SINGLE_ARG )
	throw( CORBA::SystemException )
{

	char* _retval;
	ZCE_ASSERT_EXCEPTION(_retval);
	if ( cons_ == 0)
	{
		ZCE_EXC_THROW ( CORBA::OBJECT_NOT_EXIST,(0, CORBA::COMPLETED_NO) );
	}

	return cons_->CF_Resource_identifier(portIdentifier_ ZCE_EXC_ENV_PARAM );
}

/*!
 * \brief The configure operation allows id/value pair configuration properties to
 * be assigned to components implementing this interface.
 *
 * Specification reference:  3.1.3.1.5.5.1
 *
 * The configure operation shall assign values to the properties as indicated in
 * the configProperties argument. Valid properties for the configure operation
 * shall at a minimum be the configure readwrite and writeonly properties
 * referenced in the component's SPD.
 *
 * \param configProperties (::CF::Properties ) 
 *
 * \return This operation does not return a value.
 *
 * \throw PartialConfiguration The configure operation shall raise a
 * PartialConfiguration exception when some configuration properties were
 * successfully set and some configuration properties were not successfully set.
 *
 * \throw InvalidConfiguration The configure operation shall raise an
 * InvalidConfiguration exception when a configuration error occurs that prevents
 * any property configuration on the component.
 *
 */
void zceCF_ResourceProvidesPort::configure( const CF::Properties& configProperties ZCE_EXC_ENV_ARG )
	throw( CORBA::SystemException, ::CF::PropertySet::InvalidConfiguration, ::CF::PropertySet::PartialConfiguration )
{

	ZCE_ASSERT_EXCEPTION_VOID;
	if ( cons_ == 0)
	{
		ZCE_EXC_THROW ( CORBA::OBJECT_NOT_EXIST,(0, CORBA::COMPLETED_NO) );
	}

	cons_->CF_PropertySet_configure(portIdentifier_ , configProperties ZCE_EXC_ENV_PARAM );
}

/*!
 * \brief The query operation allows a component to be queried to retrieve its
 * properties.
 *
 * Specification reference:  3.1.3.1.5.5.2
 *
 * The query operation shall return all component properties if the
 * configProperties are zero size.
 *
 * The query operation shall return only those id/value pairs specified in the
 * configProperties if the configProperties are not zero size. Valid properties
 * for the query operation shall at a minimum be the configure, readwrite, and
 * readonly properties, and allocation properties that have an action value of
 * "external" as referenced in the component's SPD.
 *
 * \param configProperties (::CF::Properties ) 
 *
 * \return This operation does not return a value.
 *
 * \throw  The query operation shall raise the CF UnknownProperties exception when
 * one or more properties being requested are not known by the component.
 *
 */
void zceCF_ResourceProvidesPort::query( CF::Properties& configProperties ZCE_EXC_ENV_ARG )
	throw( CORBA::SystemException, ::CF::UnknownProperties )
{

	ZCE_ASSERT_EXCEPTION_VOID;
	if ( cons_ == 0)
	{
		ZCE_EXC_THROW ( CORBA::OBJECT_NOT_EXIST,(0, CORBA::COMPLETED_NO) );
	}

	cons_->CF_PropertySet_query(portIdentifier_ , configProperties ZCE_EXC_ENV_PARAM );
}

/*!
 * \brief The getPort operation provides a mechanism to obtain a specific consumer
 * or producer Port. A PortSupplier may contain zero-to-many consumer and producer
 * port components. The exact number is specified in the component’s Software
 * Profile SCD (section 3.1.3.4). Multiple input and/or output ports provide
 * flexibility for PortSuppliers that must manage varying priority levels and
 * categories of incoming and outgoing messages, provide multi-threaded message
 * handling, or other special message processing.
 *
 * Specification reference:  3.1.3.1.4.5.1
 *
 * The getPort operation returns the object reference to the named port as stated
 * in the component's SCD.
 *
 * \param name (string ) The name of the port being requested.
 *
 * \return The getPort operation shall return the CORBA object reference that is
 * associated with the input port name.
 *
 * \throw UnknownPort The getPort operation shall raise an UnknownPort exception
 * if the port name is invalid.
 *
 */
CORBA::Object_ptr zceCF_ResourceProvidesPort::getPort( const char* name ZCE_EXC_ENV_ARG )
	throw( CORBA::SystemException, ::CF::PortSupplier::UnknownPort )
{

	CORBA::Object_ptr _retval;
	ZCE_ASSERT_EXCEPTION(_retval);
	if ( cons_ == 0)
	{
		ZCE_EXC_THROW ( CORBA::OBJECT_NOT_EXIST,(0, CORBA::COMPLETED_NO) );
	}

	return cons_->CF_PortSupplier_getPort(portIdentifier_ , name ZCE_EXC_ENV_PARAM );
}

/*!	\brief
 *
 *	 Describe operation here.
 * 
 *	\throw ::CF::LifeCycle::InitializeError
 * 
 */
void zceCF_ResourceProvidesPort::initialize( ZCE_EXC_ENV_SINGLE_ARG )
	throw( CORBA::SystemException, ::CF::LifeCycle::InitializeError )
{

	ZCE_ASSERT_EXCEPTION_VOID;
	if ( cons_ == 0)
	{
		ZCE_EXC_THROW ( CORBA::OBJECT_NOT_EXIST,(0, CORBA::COMPLETED_NO) );
	}

	cons_->CF_LifeCycle_initialize(portIdentifier_  ZCE_EXC_ENV_PARAM );
}

/*!	\brief
 *
 *	 Describe operation here.
 * 
 *	\throw ::CF::LifeCycle::ReleaseError
 * 
 */
void zceCF_ResourceProvidesPort::releaseObject( ZCE_EXC_ENV_SINGLE_ARG )
	throw( CORBA::SystemException, ::CF::LifeCycle::ReleaseError )
{

	ZCE_ASSERT_EXCEPTION_VOID;
	if ( cons_ == 0)
	{
		ZCE_EXC_THROW ( CORBA::OBJECT_NOT_EXIST,(0, CORBA::COMPLETED_NO) );
	}

	cons_->CF_LifeCycle_releaseObject(portIdentifier_  ZCE_EXC_ENV_PARAM );
}

/*!
 * \brief The runTest operation allows components to be "blackbox" tested. This
 * allows Built-In Test (BIT) to be implemented and this provides a means to
 * isolate faults (both software and hardware) within the system.
 *
 * Specification reference:  3.1.3.1.3.5.1
 *
 * The runTest operation shall use the testId parameter to determine which of its
 * predefined test implementations should be performed. The testValues parameter
 * CF Properties (id/value pair(s)) shall be used to provide additional
 * information to the implementation-specific test to be run. The runTest
 * operation shall return the result(s) of the test in the testValues parameter.
 *
 * \param testId (unsigned long ) Use the testId parameter to determine which of
 * its predefined test implementations should be performed
 *
 * \param testValues (::CF::Properties ) The testValues parameter CF Properties
 * (id/value pair(s)) shall be used to provide additional information to the
 * implementation-specific test to be run. The runTest operation shall return the
 * result(s) of the test in the testValues parameter.
 *
 * \return The runTest operation shall return the result(s) of the test in the
 * testValues parameter.
 *
 * \throw UnknownTest The runTest operation shall raise the UnknownTest exception
 * when there is no underlying test implementation that is associated with the
 * input testId given.
 *
 * \throw UnknownProperties The runTest operation shall raise the
 * UnknownProperties exception when the input parameter testValues contains any
 * DataTypes that are not known by the component's test implementation or any
 * values that are out of range for the requested test. 
 *
 */
void zceCF_ResourceProvidesPort::runTest( CORBA::ULong testid, CF::Properties& testValues ZCE_EXC_ENV_ARG )
	throw( CORBA::SystemException, ::CF::TestableObject::UnknownTest, ::CF::UnknownProperties )
{

	ZCE_ASSERT_EXCEPTION_VOID;
	if ( cons_ == 0)
	{
		ZCE_EXC_THROW ( CORBA::OBJECT_NOT_EXIST,(0, CORBA::COMPLETED_NO) );
	}

	cons_->CF_TestableObject_runTest(portIdentifier_ , testid, testValues ZCE_EXC_ENV_PARAM );
}




// End-Of-File
//------------------------------------------------------------------------------
