Show
Ignore:
Timestamp:
02/25/10 13:56:33 (3 years ago)
Author:
shereef
Message:

a few component updates

Files:
1 modified

Legend:

Unmodified
Added
Removed
  • ossiedev/trunk/components/WFMDemod/main.cpp

    r9807 r9914  
    2222 
    2323#include <iostream> 
     24 
     25#ifndef HAVE_LEGACY 
     26#include <omniORB4/omniURI.h> 
     27#endif 
     28 
    2429#include "ossie/ossieSupport.h" 
    2530 
    2631#include "WFMDemod.h" 
    2732 
     33using namespace std; 
    2834 
    2935int main(int argc, char* argv[]) 
    30  
    3136{ 
    32     ossieSupport::ORB *orb = new ossieSupport::ORB; 
    33     omni_mutex component_running_mutex; 
    34     omni_condition *component_running = new omni_condition(&component_running_mutex); 
    35  
     37#ifdef HAVE_LEGACY 
    3638    if (argc != 3) { 
    37         std::cout << argv[0] << " <id> <usage name> " << std::endl; 
     39        cout << argv[0] << " <id> <usage name> " << endl; 
    3840        exit (-1); 
    3941    } 
     42 
     43    ossieSupport::ORB *orb = new ossieSupport::ORB; 
    4044 
    4145    char *uuid = argv[1]; 
    4246    char *label = argv[2]; 
    4347 
    44     std::cout << "Identifier - " << uuid << "  Label - " << label << std::endl; 
     48    cout << "Identifier - " << uuid << "  Label - " << label << endl; 
     49#else 
     50    if ( argc < 7 ) { 
     51        cout << argv[0] << " NAMING_CONTEXT_IOR <string> NAME_BINDING <string> COMPONENT_IDENTIFIER <string> " << endl; 
     52        exit(EXIT_FAILURE); 
     53    } 
     54 
     55    int i = 0; 
     56    char *uuid = NULL; 
     57    char *label = NULL; 
     58    char *ior = NULL; 
     59 
     60    while ( i < argc ) { 
     61        if ( strcmp("NAMING_CONTEXT_IOR", argv[i]) == 0 ) ior = argv[i+1]; 
     62        if ( strcmp("NAME_BINDING", argv[i]) == 0 ) label = argv[i+1]; 
     63        if ( strcmp("COMPONENT_IDENTIFIER", argv[i]) == 0 ) uuid = argv[i+1]; 
     64        ++i; 
     65    } 
     66 
     67    if ( uuid == NULL ) { 
     68        cout << "ERROR: " << argv[0] << " missing COMPONENT_IDENTIFIER argument" << endl; 
     69        exit(EXIT_FAILURE); 
     70    } 
     71 
     72    if ( label == NULL ) { 
     73        cout << "ERROR: " << argv[0] << " missing NAME_BINDING argument" << endl; 
     74        exit(EXIT_FAILURE); 
     75    } 
     76 
     77    if ( ior == NULL ) { 
     78        cout << "ERROR: " << argv[0] << " missing NAMING_CONTEXT_IOR argument" << endl; 
     79        exit(EXIT_FAILURE); 
     80    } 
     81 
     82    cout << argv[0] << " NAMING_CONTEXT_IOR " << ior << " NAME_BINDING " << label << " COMPONENT_IDENTIFIER " << uuid << endl; 
     83 
     84    ossieSupport::ORB::orb = CORBA::ORB_init( argc, argv ); 
     85 
     86    try { 
     87        CORBA::Object_ptr _ncobj = ossieSupport::ORB::orb->string_to_object(ior); 
     88        ossieSupport::ORB::inc = CosNaming::NamingContext::_narrow(_ncobj); 
     89        CORBA::release(_ncobj); 
     90    } catch ( ... ) { 
     91        cout << "ERROR: " << argv[0] << " Failed to narrow NamingContext from IOR" << endl; 
     92        exit(EXIT_FAILURE); 
     93    } 
     94 
     95    try { 
     96        CORBA::Object_ptr _poaobj = ossieSupport::ORB::orb->resolve_initial_references("RootPOA"); 
     97        ossieSupport::ORB::poa = PortableServer::POA::_narrow(_poaobj); 
     98        ossieSupport::ORB::pman = ossieSupport::ORB::poa->the_POAManager(); 
     99        ossieSupport::ORB::pman->activate(); 
     100    } catch ( ... ) { 
     101        cout << "ERROR: " << argv[0] << " Failed to initialize POA" << endl; 
     102        exit(EXIT_FAILURE); 
     103    } 
     104#endif 
     105    omni_mutex component_running_mutex; 
     106    omni_condition *component_running = new omni_condition(&component_running_mutex); 
    45107 
    46108    WFMDemod_i* wfmdemod_servant; 
     
    52114    wfmdemod_var = wfmdemod_servant->_this(); 
    53115 
     116#ifdef HAVE_LEGACY 
    54117    orb->bind_object_to_name((CORBA::Object_ptr) wfmdemod_var, label); 
     118#else 
     119    CosNaming::Name_var _bindingname = omni::omniURI::stringToName(label); 
     120    try { 
     121        ossieSupport::ORB::inc->rebind(_bindingname, (CORBA::Object_ptr) wfmdemod_var); 
     122    } catch ( ... ) { 
     123        cout << "ERROR: " << argv[0] << " Failed to rebind reference to NameService" << endl; 
     124        exit(EXIT_FAILURE); 
     125    } 
     126#endif 
    55127 
    56128// This bit is ORB specific 
     
    60132 
    61133    component_running->wait(); 
     134#ifdef HAVE_LEGACY 
    62135    orb->unbind_name(label); 
    63136    orb->orb->shutdown(0); 
    64  
     137#else 
     138    ossieSupport::ORB::inc->unbind(_bindingname); 
     139    ossieSupport::ORB::orb->destroy(); 
     140#endif 
     141    return 0; 
    65142}