DAQ 3 Upgrade Code Examples

 

April 23, 2002

 

 

Orbix/E vxWorks Code changes

 

The gcc 2.7.2 limits the current implementation support:

 

Does not support TIE objects

Does not support persistent POA

       therefore does not support automatic server start via IMR

 

 

 

SAMPLE vxWorks Server

 

 

#include <vxWorks.h>

#include <stdlib.h>

#include <errno.h>

#include <string.h>

#include <iostream.h>

#include <OBE/CORBA.h>

#include <OBE/CosNaming.h>

#include <OBE/CORBA.h>

#include <OBE/BootManager.h>

#include <OBE/Properties.h>

#include "NsInit.h"

#include "ConnectionMgr.h"

 

 

void startGL1(int argc, char *argv[])

{ 

  CORBA::Environment ev;

  CORBA::ORB_var orb;

  int status = EXIT_SUCCESS;

 

 

 

    orb = CORBA::ORB_init(argc,argv,ev);

    if (ev.exception() != 0)

    {

      CORBA::Exception* ex = ev.exception();

      fprintf(stderr, "%s\n", ex->_rep_id());

      status = EXIT_FAILURE;

      return ;

    }

 

  //

  // Resolve Root POA

  //

  CORBA::Object_var poaObj = orb -> resolve_initial_references("RootPOA",ev);

  PortableServer::POA_var rootPOA = PortableServer::POA::_narrow(poaObj,ev);

   

  //

  // Get a reference to the POA manager

  //

  PortableServer::POAManager_var manager = rootPOA -> the_POAManager(ev);

  

  // create implementation object servant

 

  GL1_i* pGl1_i = new GL1_i(orb,rootPOA);

 

  /* if using tie  - NOT CURRENTLY SUPPORTED

  PortableServer::ServantBase_var servant1 = simpleTieImpl;

  SimpleObject_var simpleTie = pGl1_i -> _this();

  */

 

  PortableServer::ServantBase_var servant1 = pGl1_i;

    GL1_var gl1 = pGl1_i -> _this(ev);

 

  //

  // Resolve the BootManager and register the servers

  //

  CORBA::Object_var obj = orb -> resolve_initial_references("BootManager",ev);

  OB::BootManager_var bootManager = OB::BootManager::_narrow(obj,ev);

 

  //

  // give the object the name gl1Name

  // create persistent object

  //

  PortableServer::ObjectId_var gl1oid1 =

    PortableServer::string_to_ObjectId(gl1Name,ev);

  bootManager -> add_binding(gl1oid1.in(), gl1,ev);

  cout << "created GL1 object " << gl1Name << endl;

  //

  // activate the boot manager

  //

  manager -> activate(ev);

 

 

ConnectionMgr * connectionmgr= new ConnectionMgr(orb);

 

  // connect to the nameserver

  if (connectionmgr->bindNs() != SUCCESS )

    {

 

      // log message and exit

      cerr << "Server "<< serverName

       << " unable to bind to Ns " << endl;

    

    }

 

  connectionmgr->registerNs(gl1Name,gl1);

 

 

ALTERNATIVE REGISTRATION WITH NAMESERVER

 

NsInit * nsi = new NsInit(orb);

 

  cout << "Get initial NameServer reference " << endl;

  CosNaming::NamingContext_var nc;

  nc = nsi->resolve_initial_references("nsior");

  if(CORBA::is_nil(nc.in()))

    {

      cerr << ": `NameService' is a nil object reference"

       << endl;

     

    }

 

    cout << "Now bind GL1" << endl;

    // now bind the gltest object to the nameserver

    CosNaming::Name glName;

    glName.length(1);

    glName[0].id = CORBA::string_dup("GL1");

    glName[0].kind = CORBA::string_dup("");

 

    cout << "reBind "<< glName[0].id << " to nameservice " << endl;

 

    nc -> rebind(glName, gl1.in(), ev);

    if (ev.exception() != 0)

    {

      cout << "Rebind " << glName[0].id << endl;

       nc -> rebind(glName,gl1.in(),ev);

        return EXIT_FAILURE;

    }

 

 

cout << "activating GL1server POA manager" << endl;

 

  // accept events

  orb -> run(ev);

 

 

 

 

UPON SERVER SHUTDOWN

 

// release allocated resources

orb->shutdown(0);

 

 

THINGS TO WATCH OUT FOR

 

Returned strings must be created with  CORBA::string_alloc function:

Allocation with new char[xx]  is NOT allowed.

Functions MUST NOT return a null character pointer.

 

char* GL1_i::getOwner( CORBA::Environment &env )

{

 

 

  char *pcReturnOwner = CORBA::string_alloc(strlen( pcOwner ) );

  strcpy( pcReturnOwner, pcOwner );

 

  return pcReturnOwner;

}

 

Return type Any via parameter argument

 

long GL1_i::LV1_scancrate( CORBA::Any_out RtnData ) {

 

CORBA::Any_var temp = new CORBA::Any;

  temp.inout() <<= rtndata;

  RtnData = temp._retn();

 

 Return status;

}

 

 

 

 

 

 

JAVA Code Changes:

 

Generally minor changes:

 

import org.omg.CosNaming.*;

import org.omg.CORBA.*;

 

requires ORB initialization:

 

org.omg.CORBA.orb = ORB.init( String args[],null);

 

 

Use of ConnectionMgr is identical to previous version, although it’s internals are changed.

 

If you do not want to use the ConnectionMgr there is a helper class Ns.java in cutilities.jar which provides functional access to the OMG nameserver.

 

It provides functions to resolve and bind Object name strings and references.

Retreives NamingContext references.

Lists and deletes object references.


 

 CosNaming::Name_var tmpName;

 tmpName = new CosNaming::Name(1);

       try

        {

           

            tmpName->length(1);

 

            tmpName[0].id = CORBA::string_dup("HelloOB4");

            tmpName[0].kind = CORBA::string_dup("");

            obj = rootContext->resolve(tmpName);

        foundobject = 1;

    }

        catch (CosNaming::NamingContext::NotFound&)

        {

            cout << "Could not resolve " << tmpName[0].id << endl;

        }

        catch (CosNaming::NamingContext::InvalidName&)

        {

            cout << "Invalid name on CosNaming::NamingContext::bind." << endl;

        }

        catch (CORBA::SystemException &sysEx)

        {

            cerr << "Unexpected System Exception:" << endl;

            cerr << sysEx;

        }

        catch(...)

        {

            cerr << "Unexpected exception." << endl;

        }

 


 

 

 

 

OMG Nameserver features:

 

Returns an NamingContext reference

 

All references exist within a Naming Context

 

Requires object to be registered with a CosNaming  Name structure:

 

Struct Name{

  String id:

  String  kind;

}

 

Registered Object references to  dead servers , invalid objects etc are NOT

Automatically deleted from the nameserver.

 

It is up to the client to invoke reference methods within try/ catch  blocks

 

 

Any constructor

Org.omg.CORBA.AnyHolder seqLongHolder = new AnyHolder();

 

Any rtnany = ORB.init().create_any();

    Rtnany = seqLongHolder.value;

seqLongHelper.extract(rtnany);