/**********************************************************************
 *
 * corbaclient.cpp -- 
 * Copyright (C) 1999  The New Zealand Digital Library Project
 *
 * A component of the Greenstone digital library software
 * from the New Zealand Digital Library Project at the
 * University of Waikato, New Zealand.
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 2 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
 *
 * $Id: corbaclient.mpp 25231 2012-03-16 08:38:01Z ak19 $
 *
 *********************************************************************/

#include "receptionist.h"
#include "cgiwrapper.h"
#include "corbaproto.h"
#include "collectserver.h"
#include "filter.h"
#include "browsefilter.h"
#include "queryfilter.h"
#ifdef ENABLE_MG
#include "mgsearch.h"
#endif
#include "fileutil.h"
#include <assert.h>

#include "action.h"
#include "statusaction.h"
#include "pageaction.h"
#include "pingaction.h"
#include "queryaction.h"
#include "documentaction.h"
#include "authenaction.h"
#include "usersaction.h"
#include "authenaction.h"
#include "extlinkaction.h"
#include "tipaction.h"
#include "collectoraction.h"

#include "browserclass.h"
#include "vlistbrowserclass.h"
#include "hlistbrowserclass.h"
#include "datelistbrowserclass.h"
#include "invbrowserclass.h"
#include "pagedbrowserclass.h"
#include "htmlbrowserclass.h"

// #include "gsdlhome.h"
#include "gsdlsitecfg.h"

int main (int argc, char *argv[]) {
  receptionist recpt;
  corbaproto*  cproto_array[argc];
  text_t       gsdlhome;
  text_t       collecthome;
  text_t       httpdomain;
  text_t       httpprefix;
  
  cproto_array[0] = NULL; // unused

  if (argc == 1)
  { cout << "Content-type: text/html" << endl << endl;
    cout << "Usage: " << argv[0] << " site1.objid [site2.objid ....]" << endl;
    return 0;
  }

  // Strictly speaking httpdomain and httpprefix are not needed.
  // Need to modifiy site_cfg_read to eliminate this dependency. // ****
  site_cfg_read(gsdlhome, collecthome, httpdomain, httpprefix);

  for (int i=1; i<argc; i ++)
    {
      // add the protocol to the receptionist
      cproto_array[i] = new corbaproto(argv[i]);
      recpt.add_protocol(cproto_array[i]);
    }

//  cout << "GRB 2" << endl;

  // the list of actions. Note: these actions will become invalid
  // at the end of this function.
  tipaction atipaction;
  recpt.add_action(&atipaction);

  statusaction astatusaction;
  astatusaction.set_receptionist (&recpt);
  recpt.add_action (&astatusaction);

  pageaction apageaction;
  apageaction.set_receptionist (&recpt);
  recpt.add_action (&apageaction);

  pingaction apingaction;
  recpt.add_action (&apingaction);

  queryaction aqueryaction;
  aqueryaction.set_receptionist (&recpt);
  recpt.add_action (&aqueryaction);

  documentaction adocumentaction;
  adocumentaction.set_receptionist (&recpt);
  recpt.add_action (&adocumentaction);

  usersaction ausersaction;
  recpt.add_action (&ausersaction);

  extlinkaction anextlinkaction;
  recpt.add_action (&anextlinkaction);

  authenaction aauthenaction;
  aauthenaction.set_receptionist(&recpt);
  recpt.add_action (&aauthenaction);

  collectoraction acollectoraction;
  acollectoraction.set_receptionist (&recpt);
  recpt.add_action(&acollectoraction);

//  cout << "GRB 3" << endl;

  // list of browsers
  vlistbrowserclass avlistbrowserclass;
  recpt.add_browser (&avlistbrowserclass);
  recpt.setdefaultbrowser ("VList");

  hlistbrowserclass ahlistbrowserclass;
  recpt.add_browser (&ahlistbrowserclass);

  datelistbrowserclass adatelistbrowserclass;
  recpt.add_browser (&adatelistbrowserclass);

  invbrowserclass ainvbrowserclass;
  recpt.add_browser (&ainvbrowserclass);

  pagedbrowserclass apagedbrowserclass;
  recpt.add_browser (&apagedbrowserclass);

  htmlbrowserclass ahtmlbrowserclass;
  recpt.add_browser (&ahtmlbrowserclass);

  cgiwrapper (recpt, "");

  for (int i=1; i< argc; i++)
    {
      delete cproto_array[i];
    }

  return 0;
}

