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

Copyright 2007 Virginia Polytechnic Institute and State University

This file is part of the OSSIE Demodulator.

OSSIE Demodulator is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.

OSSIE Demodulator is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
GNU General Public License for more details.

You should have received a copy of the GNU General Public License
along with OSSIE Demodulator; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA

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

#include <iostream>

#include "ossie/ossieSupport.h"
#include "ossie/debug.h"

#include "Demodulator.h"


int main(int argc, char* argv[])

{
    ossieDebugLevel = 3;

    ossieSupport::ORB *orb = new ossieSupport::ORB;
    omni_mutex component_running_mutex;
    omni_condition *component_running = new omni_condition(&component_running_mutex);

    ossieSupport::ossieComponent demodulator(orb, argc, argv);

    Demodulator_i* demodulator_servant;
    CF::Resource_var demodulator_var;

    // Create the demodulator component servant and object reference

    demodulator_servant = new Demodulator_i(demodulator.getUuid(), component_running);
    demodulator_var = demodulator_servant->_this();

    PortableServer::ObjectId_var servantId = orb->poa->reference_to_id(demodulator_var);

    demodulator.bind(demodulator_var);

    // This bit is ORB specific
    // omniorb is threaded and the servants are running at this point
    // so we block on the condition
    // The releaseObject method clear the condition and the component exits

    component_running->wait();

    demodulator.unbind();

    DEBUG(4, Demodulator, "Deactivate object.");
    orb->poa->deactivate_object(servantId);

    DEBUG(4, Demodulator, "Destroy POA.");
    orb->poa->destroy(false, false);

    DEBUG(4, Demodulator, "Shutdown orb.");
    orb->orb->shutdown(0);

}
