#ifndef SUPPLIER_H
#define SUPPLIER_H

#if !defined (ACE_LACKS_PRAGMA_ONCE)
# pragma once
#endif /* ACE_LACKS_PRAGMA_ONCE */

#include "ace/Task.h"
#include "event_comm_i.h"
#include "lrsinterface_server.h"
#include "event_sup.h"
#include "notifier_handler.h"


// -*- C++ -*-
// supplier.h,v 1.1 1999/02/10 03:45:37 bala Exp 

// ============================================================================
//
// = LIBRARY
//    TAO/example/Event_Comm
//
// = FILENAME
//    supplier.h
//
// = DESCRIPTION
//    This class implements  driver for the Publish/Subscribe example
//
// = AUTHOR
//
// ============================================================================


class Supplier : public ACE_Event_Handler, public ShutdownCallback
{
  // = TITLE
  //   Supplier driver for the TAO Publish/Subscribe example.
  //
  // = DESCRIPTION
  //    This class starts up the <Supplier_Input_Handler> and
  //    <Notifier_Handler> objects.
public:
  // Initialization and Termination methods.
  Supplier (ACE_Thread_Manager *thr_mgr, LrsApp *app);
  // Constructor.

  ~Supplier (void);
  // Destructor.

  int init (int argc, char *argv[]);
  // Initialization method. returns 0 on success, -1 on error.

  virtual void close (void);
  // Shutdown the application.

  void queue_event(CORBA::Any data);
  // queue events to send to notifier
  // wrapper function for queue_event call to locally contained <Event_Supplier>

   int activate (void);
  // Execute the supplier tasks
  // Returns -1 on error

protected:
 
  virtual int run(void);
  // Run the supplier

  class SupplierTask: public ACE_Task<ACE_SYNCH>
  {
  public:
	  SupplierTask(ACE_Thread_Manager *thr_mgr, Supplier *supplier) 
		  :ACE_Task<ACE_SYNCH> (thr_mgr),
		  _supplier(supplier)
	  {

	  };
	  virtual int svc(void)
	  {
		  return _supplier->run();
	  };
  private:
	  Supplier *_supplier;
  };
  
  friend class SupplierTask;

  // This Supplier task is a task wrapper for this class so we can spawn this
  // as a tasks. Cannot subclass ace_task in Supplier because already has a base class
  SupplierTask _task;


private:

  virtual int initORB(int argc, char *argv[]);
  // Initialize the ORB

  virtual int initNamingService(int argc, char *argv[]);
  // Initialize the naming service

  virtual int handle_signal (int signum,
			     siginfo_t *,
			     ucontext_t *);
  // Handle shutdown signals.

  LRSInterface_Server _lrsinterfaces;
  // Interface server. Handles initializing LRS interfaces with orb

  Event_Supplier _es;
  // Event supplier. Handler for events coming from application

  Notifier_Handler _nh;
  // The notifier handler.

  TAO_ORB_Manager _orb_Manager;
  // ORB Manager
  
  CosNaming::NamingContext_var _namingContext_var; 
  // Naming context for the naming service.
  // Where all objects will be registered
};

#endif