// 
// File:          TAO_Environment_Impl.cc
// Symbol:        TAO.Environment-v0.3
// Symbol Type:   class
// Babel Version: 0.10.2
// Description:   Server-side implementation for TAO.Environment
// 
// WARNING: Automatically generated; only changes within splicers preserved
// 
// babel-version = 0.10.2
// 
#include "TAO_Environment_Impl.hh"

// DO-NOT-DELETE splicer.begin(TAO.Environment._includes)
#include "tao.h"
#include <iostream>
//TODO: what about these?
static int hasBeenInitialized;
static int nargs;
static char **args;
// DO-NOT-DELETE splicer.end(TAO.Environment._includes)

// user-defined constructor.
void TAO::Environment_impl::_ctor() {
  // DO-NOT-DELETE splicer.begin(TAO.Environment._ctor)
  // add construction details here
  // DO-NOT-DELETE splicer.end(TAO.Environment._ctor)
}

// user-defined destructor.
void TAO::Environment_impl::_dtor() {
  // DO-NOT-DELETE splicer.begin(TAO.Environment._dtor)
  // add destruction details here
  // DO-NOT-DELETE splicer.end(TAO.Environment._dtor)
}

// static class initializer.
void TAO::Environment_impl::_load() {
  // DO-NOT-DELETE splicer.begin(TAO.Environment._load)
  // Insert-Code-Here {TAO.Environment._load} (class initialization)
  // DO-NOT-DELETE splicer.end(TAO.Environment._load)
}

// user-defined static methods: (none)

// user-defined non-static methods:
/**
 * Method:  Initialize[]
 */
int32_t
TAO::Environment_impl::Initialize (
  /* in */ ::sidl::array< ::std::string> argv ) 
throw () 
{
  // DO-NOT-DELETE splicer.begin(TAO.Environment.Initialize)
  int info;
  int i;
  if (hasBeenInitialized)
    return 0;

  nargs = argv.upper(0) - argv.lower(0) +1;  
  args = (char**)malloc(sizeof(char*)*nargs);
  for (i=0;i<nargs;i++) {
    args[i] = (char*)malloc(sizeof(char)*argv.get(i).length()+1);
    strncpy(args[i], argv.get(i).c_str(), argv.get(i).length()+1);
  }

  info = PetscInitialize(&nargs,&args,0,0);
  info = ::TaoInitialize(&nargs,&args,0,0);
  CHKERRQ(info);

  hasBeenInitialized = 1;
  return 0;

  // DO-NOT-DELETE splicer.end(TAO.Environment.Initialize)
}

/**
 * Method:  InitializeNoArgs[]
 */
int32_t
TAO::Environment_impl::InitializeNoArgs ()
throw () 

{
  // DO-NOT-DELETE splicer.begin(TAO.Environment.InitializeNoArgs)
  char *blank = "unknown";
  char **blankptr = &blank;
  int info;
  int one = 1;

  if (hasBeenInitialized)
    return 0;

 info = PetscInitialize(&one,&blankptr,PETSC_NULL,PETSC_NULL); CHKERRQ(info);
  info = ::TaoInitialize(&one,&blankptr,0,0); CHKERRQ(info);
  hasBeenInitialized = 1;
  return 0;

  // DO-NOT-DELETE splicer.end(TAO.Environment.InitializeNoArgs)
}

/**
 * Method:  Finalize[]
 */
int32_t
TAO::Environment_impl::Finalize ()
throw () 

{
  // DO-NOT-DELETE splicer.begin(TAO.Environment.Finalize)
  TaoFinalize();
  PetscFinalize();
  return 0;
  // DO-NOT-DELETE splicer.end(TAO.Environment.Finalize)
}


// DO-NOT-DELETE splicer.begin(TAO.Environment._misc)
// Put miscellaneous code here
// DO-NOT-DELETE splicer.end(TAO.Environment._misc)

