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

//******************************************************************************
//
//     FILE: zceAssemblyControllerServant.h
//
//******************************************************************************

#ifndef __ZCEASSEMBLYCONTROLLERSERVANT_H
#define __ZCEASSEMBLYCONTROLLERSERVANT_H


#if defined(OS_WIN32)
//use STL without warnings
#pragma warning(disable:4786)
#endif

#if defined(DEBUG_MSGS)
#include <iostream>
#endif

#include <string>

#include "zceOperatingEnvironment.h"

#include "zceOrbHeader.h"

#include "zceComponentState.h"

#include "zceAssemblyControllerPorts.h"

#include "CF_s.h"


#include "zceCF_ResourceUsesPort.h"
#include "zceCF_DeviceUsesPort.h"

/**
 *  Forward declaration of the component worker 
 */
class zceAssemblyControllerWorker;

/**
 *  This class contains all of the executable parameters for zceAssemblyControllerServant
 */
class AssemblyController_params
{
	public : 
		std::string		NAMING_CONTEXT_IOR;
		std::string		NAME_BINDING;
		std::string		COMPONENT_IDENTIFIER;
};

class zceAssemblyControllerServant : 
		public virtual POA_CF::Resource, 
		public virtual PortableServer::RefCountServantBase 
{

	public:
		zceAssemblyControllerServant( const CORBA::ORB_ptr& orb, const AssemblyController_params& execParams ZCE_EXC_ENV_ARG);

		/*!
		 * \brief The readonly identifier attribute shall contain the unique identifier
		 * for a resource instance.
		 *
		 * Specification reference:  3.1.3.1.6.4.1
		 *
		 */
		virtual char* identifier(ZCE_EXC_ENV_SINGLE_ARG)
			throw (CORBA::SystemException);

		/*!
		 * \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.
		 *
		 */
		virtual void start(ZCE_EXC_ENV_SINGLE_ARG)
			throw (CORBA::SystemException, CF::Resource::StartError);

		/*!
		 * \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.
		 *
		 */
		virtual void stop(ZCE_EXC_ENV_SINGLE_ARG)
			throw (CORBA::SystemException, CF::Resource::StopError);

		/*!
		 * \brief The purpose of the initialize operation is to provide a mechanism to set
		 * a component to a known initial state. (For example, data structures may be set
		 * to initial values, memory may be allocated, hardware devices may be configured
		 * to some state, etc.)
		 *
		 * Specification reference:  3.1.3.1.2.5.1
		 *
		 * Initialization behavior is implementation dependent.
		 *
		 * \return This operation does not return a value.
		 *
		 * \throw InitializeError The initialize operation shall raise an InitializeError
		 * exception when an initialization error occurs.
		 *
		 */
		virtual void initialize(ZCE_EXC_ENV_SINGLE_ARG)
			throw (CORBA::SystemException, CF::LifeCycle::InitializeError);

		/*!
		 * \brief The purpose of the releaseObject operation is to provide a means by
		 * which an instantiated component may be torn down.
		 *
		 * Specification reference:  3.1.3.1.2.5.2
		 *
		 * The releaseObject operation releases components from the OE. The releaseObject
		 * operation shall release all internal memory allocated by the component during
		 * the life of the component. The releaseObject operation shall tear down the
		 * component (i.e. released from the CORBA environment).
		 *
		 * \return This operation does not return a value.
		 *
		 * \throw ReleaseError The releaseObject operation shall raise a ReleaseError
		 * exception when a release error occurs.
		 *
		 */
		virtual void releaseObject(ZCE_EXC_ENV_SINGLE_ARG)
			throw (CORBA::SystemException, CF::LifeCycle::ReleaseError);

		/*!
		 * \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. 
		 *
		 */
		virtual void runTest( CORBA::ULong, CF::Properties& ZCE_EXC_ENV_ARG)
		    throw (
			    CORBA::SystemException,
			    CF::TestableObject::UnknownTest, 
			    CF::UnknownProperties
		    );

		/*!
		 * \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.
		 *
		 */
		virtual void configure( const CF::Properties& ZCE_EXC_ENV_ARG)
			throw (
				CORBA::SystemException, 
				CF::PropertySet::InvalidConfiguration, 
				CF::PropertySet::PartialConfiguration
			);

		/*!
		 * \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.
		 *
		 */
		virtual void query( CF::Properties& ZCE_EXC_ENV_ARG)
			throw (CORBA::SystemException, CF::UnknownProperties);

		/*!
		 * \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.
		 *
		 */
		virtual CORBA::Object* getPort( const char* name ZCE_EXC_ENV_ARG )
			throw (CORBA::SystemException, CF::PortSupplier::UnknownPort);


	protected:
		virtual ~zceAssemblyControllerServant();

	private:
		zceCF_ResourceUsesPort* out_portSendReceiveData;

		zceCF_DeviceUsesPort* out_portAudioDevice;

		zceCF_ResourceUsesPort* out_portProcessRx;

		zceCF_ResourceUsesPort* out_portProcessTx;

		zceCF_ResourceUsesPort* out_portCaptureData;

		zceCF_ResourceUsesPort* out_portWriteData;

		zceCF_ResourceUsesPort* out_portReadData;

		zceCF_ResourceUsesPort* out_portPlayData;

		zceAssemblyControllerWorker* worker_;

		AssemblyController_params params_;
		ComponentState state_;
		Mutex mutex_;

		CORBA::ORB_var orb_;

};
#endif     // __ZCEASSEMBLYCONTROLLERSERVANT_H

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