// **********************************************************************
//
// Copyright (c) 2002
// IONA Technologies, Inc.
// Waltham, MA, USA
//
// All Rights Reserved
//
// **********************************************************************

#ifndef OB_IMR_IDL
#define OB_IMR_IDL

#include <OB/IMRState.idl>

#pragma prefix "ooc.com"

module IMR
{

/** Information on a POA. */
struct POAInfo
{
    POAName poa; // The POA name
    POAStatus state; // The POA status
};
 
/** A sequence of POAInfos */
typedef sequence< POAInfo > POAInfoSeq;

/**
 *
 * An OADAlreadyExists exception indicates that the OAD record
 * detailed in the member <code>name</code> already exists.
 *
 */
exception OADAlreadyExists
{
    string name;
};

/**
 *
 * An OADRunning exception indicates that the OAD detailed in the
 * member <code>name</code> is up.
 *
 */
exception OADRunning
{
    string name;
};

/**
 *
 * An ServerRunning exception indicates that the Server detailed in the
 * member <code>name</code> is active.
 *
 */
exception ServerRunning
{
    string name;
};

/**
 *
 * A ServerNotRunning exception indicates that the Server detailed in the
 * member <code>host</code> isn't running.
 *
 */
exception ServerNotRunning
{
    string name;
};

/**
 *
 * A POAAlreadyRegistered exception indicates that the POA detailed in
 * the member <code>poa</code> doesn't exist in the server specified
 * in in the member <code>name</code>.
 *
 **/
exception POAAlreadyRegistered
{
    string name;
    POAName poa;
};

/**
 *
 * The Server interface.
 *
 **/
interface Server
{
    /** The server id. */
    readonly attribute ServerID id;

    /** The server status. */
    readonly attribute ServerStatus status;
    
    /** Was this process manually started? */
    readonly attribute boolean manual;

    /** The last update time. */
    readonly attribute long updateTime;

    /** The number of times restarted. */
    readonly attribute short timesForked;

    /** The server name. */
    attribute string name;

    /** The server host. */
    attribute string host;

    /** The exec string for the server. */
    attribute string exec;

    /** The server's command-line arguments. */
    attribute ArgList args;

    /** The server's runtime directory. */
    attribute string directory;

    /** The server mode */
    attribute ServerActivationMode mode;

    /** The update timeout. */
    attribute long updateTimeout;

    /** The failure timeout. */
    attribute long failureTimeout;

    /** The maximum number of forks. */
    attribute short maxForks;

    /** Allow implicit POA activation. */
    attribute boolean activatePOAs;

    /**
     *
     * Create a POA record.
     *
     * @param poa The POA to create
     *
     **/
    void create_poa_record(in POAName poa)
	raises(POAAlreadyRegistered);

    /**
     *
     * Remove a POA record.
     *
     * @param poa The POA to remove
     *
     **/
    void remove_poa_record(in POAName poa)
	raises(NoSuchPOA);

    /**
     *
     * Retrieve POA info record.
     *
     * @param poa The POA name
     *
     * @return The POA info record.
     *
     */
    POAInfo get_poa_info(in POAName poa)
	raises(NoSuchPOA);

    /**
     *
     * List the poas.
     *
     * @return A sequence of poa names.
     *
     */
    POAInfoSeq list_poas();

    /**
     *
     * Clear the servers error state
     *
     */
    void clear_error_state();

    /**
     *
     * Start the server, if not running.
     *
     **/
    void start()
        raises(ServerRunning);

    /**
     *
     * Stop the server, if running.
     *
     **/
    void stop()
        raises(OADNotRunning, ServerNotRunning);

    /**
     *
     * Destroy the server record.
     *
     **/
    void destroy()
        raises(ServerRunning);
};

/** A sequence of Servers. */
typedef sequence< Server > ServerSeq;

interface ServerFactory
{
    /**
     *
     * Retrieve a server record.
     *
     * @param server The server name
     *
     * @return The server record.
     *
     */
    Server get_server(in string server)
        raises(NoSuchServer);

    /**
     *
     * Create server record.
     *
     * @param server The server name
     *
     * @return The ID of the created server
     *
     */
    Server create_server_record(in string server)
	raises(ServerAlreadyRegistered);

    /**
     *
     * List all the server records.
     *
     * @return A sequence of server records.
     *
     */
    ServerSeq list_servers();

    /**
     *
     * List the server records for a particular OAD/Host.
     *
     * @return A sequence of server records.
     *
     **/
    ServerSeq list_servers_by_host(in string host);

    /**
     *
     * List the orphaned server records.
     *
     * @return A sequence of server records.
     *
     **/
    ServerSeq list_orphaned_servers();
};

/** Information on an OAD. */
struct OADInfo
{
    /** The host. */
    string host;

    /** The OAD state. */
    boolean up;
};

/** A sequence of OADInfos. */
typedef sequence< OADInfo > OADInfoSeq;

interface ServerDomain : Domain
{
    /**
     *
     * Retrieve the Server Factory.
     *
     * @return The reference to the server factory.
     *
     */
    ServerFactory get_server_factory();

    /**
     *
     * Create OAD record.
     *
     * @param host The host name
     *
     */
    void create_oad_record(in string host)
        raises(OADAlreadyExists);

    /**
     *
     * Remove an OAD record.
     *
     * @param host The OAD's host
     *
     */
    void remove_oad_record(in string host)
        raises(NoSuchOAD, OADRunning);

    /**
     *
     * Retrieve an OAD record.
     *
     * @param host The OAD's host
     *
     * @return The OAD record.
     *
     */
    OADInfo get_oad_record(in string host)
        raises(NoSuchOAD);

    /**
     *
     * List the Object Activation Daemons.
     *
     * @return A sequence of OADInfo's.
     *
     **/
    OADInfoSeq list_oads();
};

}; // End module IMR

#endif // OB_IMR_IDL
