/****************************************************************************

Copyright 2010 by your_name_or_organization, all rights reserved.

****************************************************************************/


#ifndef PACKETDECODER_IMPL_H
#define PACKETDECODER_IMPL_H

#include <stdlib.h>
#include "ossie/cf.h"
#include "ossie/PortTypes.h"
#include "ossie/Resource_impl.h"
#include "ossie/debug.h"

#include "standardinterfaces/realChar.h"
#include "standardinterfaces/realChar_u.h"
#include "standardinterfaces/realChar_p.h"

#include <liquid/liquid.h>

/** \brief
 *
 *
 */
class PacketDecoder_i : public virtual Resource_impl
{
  public:
    /// Initializing constructor
    PacketDecoder_i(const char *uuid, omni_condition *sem);

    /// Destructor
    ~PacketDecoder_i(void);

    /// Static function for omni thread
    static void Run( void * data );

    ///
    void start() throw (CF::Resource::StartError, CORBA::SystemException);

    ///
    void stop() throw (CF::Resource::StopError, CORBA::SystemException);

    ///
    CORBA::Object_ptr getPort( const char* portName )
        throw (CF::PortSupplier::UnknownPort, CORBA::SystemException);

    ///
    void releaseObject() throw (CF::LifeCycle::ReleaseError, CORBA::SystemException);

    ///
    void initialize() throw (CF::LifeCycle::InitializeError, CORBA::SystemException);

    /// Query properties from .prf.xml
    void query(CF::Properties&)
        throw (CORBA::SystemException,
                CF::UnknownProperties);

    /// Configures properties read from .prf.xml
    void configure(const CF::Properties&)
        throw (CORBA::SystemException,
            CF::PropertySet::InvalidConfiguration,
            CF::PropertySet::PartialConfiguration);


  private:
    /// Disallow default constructor
    PacketDecoder_i();

    /// Disallow copy constructor
    PacketDecoder_i(PacketDecoder_i&);

    /// Main signal processing method
    void ProcessData();
    bool continue_processing();
    volatile bool thread_started;
    omni_mutex processing_mutex;
   
    omni_condition *component_running;  ///< for component shutdown
    omni_thread *processing_thread;     ///< for component writer function
        
    CORBA::Boolean simple_0_value;
    CORBA::Short simple_1_value;
    CORBA::Short simple_2_value;

    
    // list components provides and uses ports
    standardInterfaces_i::realChar_p *portCodedDataIn;
    standardInterfaces_i::realChar_u *portDecodedDataOut;
    
    // dsp objects
    packetizer p;               ///< packetizer object
    fec_scheme fec_inner;       ///< inner FEC scheme
    fec_scheme fec_outer;       ///< outer FEC scheme
    crc_scheme crc;
    unsigned int dec_msg_len;   ///< decoded message length
    unsigned int enc_msg_len;   ///< encoded message length
    
};
#endif
