| 1 | /**************************************************************************** |
|---|
| 2 | Copyright 2007 Virginia Polytechnic Institute and State University |
|---|
| 3 | This file is part of the OSSIE __COMP_NAME__. |
|---|
| 4 | OSSIE __COMP_NAME__ is free software; you can redistribute it and/or modify |
|---|
| 5 | it under the terms of the GNU General Public License as published by |
|---|
| 6 | the Free Software Foundation; either version 2 of the License, or |
|---|
| 7 | "(at your option) any later version |
|---|
| 8 | OSSIE __COMP_NAME__ is distributed in the hope that it will be useful, |
|---|
| 9 | but WITHOUT ANY WARRANTY; without even the implied warranty of |
|---|
| 10 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|---|
| 11 | GNU General Public License for more details. |
|---|
| 12 | You should have received a copy of the GNU General Public License |
|---|
| 13 | along with OSSIE __COMP_NAME__; if not, write to the Free Software |
|---|
| 14 | Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
|---|
| 15 | ****************************************************************************/ |
|---|
| 16 | #include <iostream> |
|---|
| 17 | #include <omniORB4/omniURI.h> |
|---|
| 18 | #include "ossie/ossieSupport.h" |
|---|
| 19 | #include "ossie/debug.h" |
|---|
| 20 | |
|---|
| 21 | #include "voiceToPacket.h" |
|---|
| 22 | |
|---|
| 23 | using namespace std; |
|---|
| 24 | //using namespace standardInterfaces; // For standard OSSIE interface classes |
|---|
| 25 | |
|---|
| 26 | int main(int argc, char* argv[]) |
|---|
| 27 | { |
|---|
| 28 | ossieDebugLevel = 0; |
|---|
| 29 | |
|---|
| 30 | if ( argc < 7 ) { |
|---|
| 31 | cout << argv[0] << " NAMING_CONTEXT_IOR <string> NAME_BINDING <string> COMPONENT_IDENTIFIER <string> " << endl; |
|---|
| 32 | exit(EXIT_FAILURE); |
|---|
| 33 | } |
|---|
| 34 | |
|---|
| 35 | int i = 0; |
|---|
| 36 | char *uuid = NULL; |
|---|
| 37 | char *label = NULL; |
|---|
| 38 | char *ior = NULL; |
|---|
| 39 | |
|---|
| 40 | while ( i < argc ) { |
|---|
| 41 | if ( strcmp("NAMING_CONTEXT_IOR", argv[i]) == 0 ) ior = argv[i+1]; |
|---|
| 42 | if ( strcmp("NAME_BINDING", argv[i]) == 0 ) label = argv[i+1]; |
|---|
| 43 | if ( strcmp("COMPONENT_IDENTIFIER", argv[i]) == 0 ) uuid = argv[i+1]; |
|---|
| 44 | ++i; |
|---|
| 45 | } |
|---|
| 46 | |
|---|
| 47 | if ( uuid == NULL ) { |
|---|
| 48 | cout << "ERROR: " << argv[0] << " missing COMPONENT_IDENTIFIER argument" << endl; |
|---|
| 49 | exit(EXIT_FAILURE); |
|---|
| 50 | } |
|---|
| 51 | |
|---|
| 52 | if ( label == NULL ) { |
|---|
| 53 | cout << "ERROR: " << argv[0] << " missing NAME_BINDING argument" << endl; |
|---|
| 54 | exit(EXIT_FAILURE); |
|---|
| 55 | } |
|---|
| 56 | |
|---|
| 57 | if ( ior == NULL ) { |
|---|
| 58 | cout << "ERROR: " << argv[0] << " missing NAMING_CONTEXT_IOR argument" << endl; |
|---|
| 59 | exit(EXIT_FAILURE); |
|---|
| 60 | } |
|---|
| 61 | |
|---|
| 62 | cout << argv[0] << " NAMING_CONTEXT_IOR " << ior << " NAME_BINDING " << label << " COMPONENT_IDENTIFIER " << uuid << endl; |
|---|
| 63 | |
|---|
| 64 | ossieSupport::ORB::orb = CORBA::ORB_init( argc, argv ); |
|---|
| 65 | |
|---|
| 66 | try { |
|---|
| 67 | CORBA::Object_ptr _ncobj = ossieSupport::ORB::orb->string_to_object(ior); |
|---|
| 68 | ossieSupport::ORB::inc = CosNaming::NamingContext::_narrow(_ncobj); |
|---|
| 69 | CORBA::release(_ncobj); |
|---|
| 70 | } catch ( ... ) { |
|---|
| 71 | cout << "ERROR: " << argv[0] << " Failed to narrow NamingContext from IOR" << endl; |
|---|
| 72 | exit(EXIT_FAILURE); |
|---|
| 73 | } |
|---|
| 74 | |
|---|
| 75 | try { |
|---|
| 76 | CORBA::Object_ptr _poaobj = ossieSupport::ORB::orb->resolve_initial_references("RootPOA"); |
|---|
| 77 | ossieSupport::ORB::poa = PortableServer::POA::_narrow(_poaobj); |
|---|
| 78 | ossieSupport::ORB::pman = ossieSupport::ORB::poa->the_POAManager(); |
|---|
| 79 | ossieSupport::ORB::pman->activate(); |
|---|
| 80 | } catch ( ... ) { |
|---|
| 81 | cout << "ERROR: " << argv[0] << " Failed to initialize POA" << endl; |
|---|
| 82 | exit(EXIT_FAILURE); |
|---|
| 83 | } |
|---|
| 84 | |
|---|
| 85 | omni_mutex component_running_mutex; |
|---|
| 86 | omni_condition *component_running = new omni_condition(&component_running_mutex); |
|---|
| 87 | |
|---|
| 88 | voiceToPacket_i* voicetopacket_servant; |
|---|
| 89 | CF::Resource_var voicetopacket_var; |
|---|
| 90 | |
|---|
| 91 | // Create the voicetopacket component servant and object reference |
|---|
| 92 | |
|---|
| 93 | voicetopacket_servant = new voiceToPacket_i(uuid, component_running); |
|---|
| 94 | voicetopacket_var = voicetopacket_servant->_this(); |
|---|
| 95 | |
|---|
| 96 | CosNaming::Name_var _bindingname = omni::omniURI::stringToName(label); |
|---|
| 97 | try { |
|---|
| 98 | ossieSupport::ORB::inc->rebind(_bindingname, (CORBA::Object_ptr) voicetopacket_var); |
|---|
| 99 | } catch ( ... ) { |
|---|
| 100 | cout << "ERROR: " << argv[0] << " Failed to rebind reference to NameService" << endl; |
|---|
| 101 | exit(EXIT_FAILURE); |
|---|
| 102 | } |
|---|
| 103 | |
|---|
| 104 | // This bit is ORB specific |
|---|
| 105 | // omniorb is threaded and the servants are running at this point |
|---|
| 106 | // so we block on the condition |
|---|
| 107 | // The releaseObject method clear the condition and the component exits |
|---|
| 108 | |
|---|
| 109 | component_running->wait(); |
|---|
| 110 | ossieSupport::ORB::inc->unbind(_bindingname); |
|---|
| 111 | ossieSupport::ORB::orb->destroy(); |
|---|
| 112 | |
|---|
| 113 | return 0; |
|---|
| 114 | } |
|---|
| 115 | |
|---|