module jacorb
{
  module imr
    {
      //typedef string Istring;
      typedef string LogicalServerName;
      typedef string StartupCommand;	
      typedef string POAName;
      typedef string HostName;
      typedef string IORString;
      typedef unsigned long PortNumber;

      typedef sequence<LogicalServerName> ServerNameSeq;
      typedef sequence<POAName> POANameSeq;


      struct ImRInfo{
	HostName host;
	PortNumber port;
      };

      struct POAInfo{
	POAName name;
	HostName host;
	PortNumber port;
	LogicalServerName server;
	boolean active;
      };
      typedef sequence<POAInfo> POAInfoSeq;

      struct ServerInfo{
	LogicalServerName name;
	StartupCommand command;
	POAInfoSeq poas;
	HostName host;
	boolean active;
	boolean holding;
      };
      typedef sequence<ServerInfo> ServerInfoSeq;

      exception UnknownServerName{
	LogicalServerName name;
      };

      exception ServerStartupFailed{
	string reason;
      };

      interface ServerStartupDaemon{

	// for load balancing
	long get_system_load();

	void start_server (in StartupCommand command)
	  raises (ServerStartupFailed);

      };//ServerStartupDaemon

      struct HostInfo{
	HostName name;
	ServerStartupDaemon ssd_ref;
	IORString ior_string;
      };

      typedef sequence<HostInfo> HostInfoSeq;

      interface Registration{
	exception IllegalHostName{
	  HostName name;
	};

	exception InvalidSSDRef{};

	exception IllegalPOAName{
	  POAName name;
	};

	exception DuplicatePOAName{
	  POAName name;
	};

	// Accessed only by SSD's
	void register_host (in HostInfo info)
	  raises (IllegalHostName, InvalidSSDRef);

	// tells the imr that the server has gone down
	void set_server_down (in LogicalServerName name)
	  raises (UnknownServerName);

	void register_poa	(in POAName name, in LogicalServerName server,
				 in HostName host, in PortNumber port)
	  raises (IllegalPOAName, DuplicatePOAName, UnknownServerName);

	ImRInfo get_imr_info ();

      }; // Registration
	

      interface Admin{
	exception IllegalServerName{
	  LogicalServerName name;
	};

	exception DuplicateServerName{
	  LogicalServerName name;
	};
		
	exception FileOpFailed{
	};

	exception UnknownHostName{
	  HostName name;
	};

	HostInfoSeq list_hosts();

	ServerInfoSeq list_servers ();
				
	ServerInfo get_server_info (in LogicalServerName name)
	  raises (UnknownServerName);

	void shutdown(in boolean wait);

	void save_server_table ()
	  raises (FileOpFailed);

	// A server that is registered, is assumed to be in state 'active'.
	void register_server   (in LogicalServerName name, 
				in StartupCommand command,
				in HostName host) 
	  raises (IllegalServerName, DuplicateServerName);

	// unregisters a server and all its associated POA's
	void unregister_server (in LogicalServerName name)
	  raises (UnknownServerName);

	// set new host / command for a server
	void edit_server   (in LogicalServerName name, 
			    in StartupCommand command,
			    in HostName host) 
	  raises (UnknownServerName);	

	void hold_server (in LogicalServerName name)
	  raises (UnknownServerName);

	void release_server (in LogicalServerName name)
	  raises (UnknownServerName);

	void start_server (in LogicalServerName name)
	  raises (UnknownServerName, ServerStartupFailed);

	void unregister_host (in HostName name)
	  raises (UnknownHostName);
      };

      interface ImplementationRepository : Registration, Admin{
      };

    };
};		
