root/ossiedev/trunk/tools/WaveDev/wavedev/generate/templates/basic_ports/sampleMain.cpp @ 9912

Revision 9912, 3.3 KB (checked in by shereef, 3 years ago)

fixed data type code gen for unsigned and missing types

  • Property svn:eol-style set to native
Line 
1#include <iostream>
2#include "ossie/ossieSupport.h"
3#include "ossie/debug.h"
4
5#include "__IncludeFile__.h"
6
7using namespace std;
8using namespace standardInterfaces;  // For standard OSSIE interface classes
9
10int main(int argc, char* argv[])
11{
12    ossieDebugLevel = 0;
13
14    if ( argc < 7 ) {
15        cout << argv[0] << " NAMING_CONTEXT_IOR <string> NAME_BINDING <string> COMPONENT_IDENTIFIER <string> " << endl;
16        exit(EXIT_FAILURE);
17    }
18
19    int i = 0;
20    char *uuid = NULL;
21    char *label = NULL;
22    char *ior = NULL;
23
24    while ( i < argc ) {
25        if ( strcmp("NAMING_CONTEXT_IOR", argv[i]) == 0 ) ior = argv[i+1];
26        if ( strcmp("NAME_BINDING", argv[i]) == 0 ) label = argv[i+1];
27        if ( strcmp("COMPONENT_IDENTIFIER", argv[i]) == 0 ) uuid = argv[i+1];
28        ++i;
29    }
30
31    if ( uuid == NULL ) {
32        cout << "ERROR: " << argv[0] << " missing COMPONENT_IDENTIFIER argument" << endl;
33        exit(EXIT_FAILURE);
34    }
35
36    if ( label == NULL ) {
37        cout << "ERROR: " << argv[0] << " missing NAME_BINDING argument" << endl;
38        exit(EXIT_FAILURE);
39    }
40
41    if ( ior == NULL ) {
42        cout << "ERROR: " << argv[0] << " missing NAMING_CONTEXT_IOR argument" << endl;
43        exit(EXIT_FAILURE);
44    }
45
46    cout << argv[0] << " NAMING_CONTEXT_IOR " << ior << " NAME_BINDING " << label << " COMPONENT_IDENTIFIER " << uuid << endl;
47
48    ossieSupport::ORB::orb = CORBA::ORB_init( argc, argv );
49
50    try {
51        CORBA::Object_ptr _ncobj = ossieSupport::ORB::orb->string_to_object(ior);
52        ossieSupport::ORB::inc = CosNaming::NamingContext::_narrow(_ncobj);
53        CORBA::release(_ncobj);
54    } catch ( ... ) {
55        cout << "ERROR: " << argv[0] << " Failed to narrow NamingContext from IOR" << endl;
56        exit(EXIT_FAILURE);
57    }
58
59    try {
60        CORBA::Object_ptr _poaobj = ossieSupport::ORB::orb->resolve_initial_references("RootPOA");
61        ossieSupport::ORB::poa = PortableServer::POA::_narrow(_poaobj);
62        ossieSupport::ORB::pman = ossieSupport::ORB::poa->the_POAManager();
63        ossieSupport::ORB::pman->activate();
64    } catch ( ... ) {
65        cout << "ERROR: " << argv[0] << " Failed to initialize POA" << endl;
66        exit(EXIT_FAILURE);
67    }
68
69    omni_mutex component_running_mutex;
70    omni_condition *component_running = new omni_condition(&component_running_mutex);
71
72    __Class_name__* __CLASS_VAR___servant;
73    CF::Resource_var __CLASS_VAR___var;
74
75    // Create the __CLASS_VAR__ component servant and object reference
76
77    __CLASS_VAR___servant = new __Class_name__(uuid, component_running);
78    __CLASS_VAR___var = __CLASS_VAR___servant->_this();
79    __CLASS_VAR_ACE___servant->activate();
80
81    CosNaming::Name_var _bindingname = omni::omniURI::stringToName(label);
82    try {
83        ossieSupport::ORB::inc->rebind(_bindingname, (CORBA::Object_ptr) txdemo_var);
84    } catch ( ... ) {
85        cout << "ERROR: " << argv[0] << " Failed to rebind reference to NameService" << endl;
86        exit(EXIT_FAILURE);
87    }
88
89    // This bit is ORB specific
90    // omniorb is threaded and the servants are running at this point
91    // so we block on the condition
92    // The releaseObject method clear the condition and the component exits
93
94    component_running->wait();
95    ossieSupport::ORB::inc->unbind(_bindingname);
96    ossieSupport::ORB::orb->destroy();
97
98    return 0;
99}
100
Note: See TracBrowser for help on using the browser.