// Crude initial attempt at a distributed version of
// matrix-vector product: 
// This is a server that provides a matrix object 
// equipped with a block_product function
//
#pragma warning (disable : 4786)
#include "matrix.h"
#include "omnithread.h"
#include <vector>
#include <iostream.h>
using namespace std;
#include "matrix_impl.h"
#include "namebind.cpp"

int main(int argc, char *argv[])
{
  assert(argc == 2);

  const int N = 1500;
 
  vector<double> r;
  vecrep m0;

  for (int i = 0; i < N; ++i) {
    r.erase(r.begin(), r.end());
    for (int j = 0; j < N; ++j)
      r.push_back(i*N + j);
    m0.push_back(r);
  }

  //  cout << "Matrix m0:" << endl;
  //  cout << m0 << endl;
  
  cout << "Server initializing." << endl;

  CORBA::ORB_var orb = CORBA::ORB_init(argc, argv, "omniORB2");
  CORBA::BOA_var boa = orb->BOA_init(argc, argv, "omniORB2_BOA");

  Matrix_impl matrix1(m0);
  matrix1._obj_is_ready(boa);

  // Register matrix1 with the Naming Service:
  {
    Matrix_var myobjRef = matrix1._this();
    if (!bindObjectToName(orb, myobjRef, "test", argv[1])) {
      return 1;
    }
  }

  boa->impl_is_ready();
  return 0;
}
