/**
  * File: InternalDomainMessages.idl
  * Content: Corba definitions of the messages required to do the state transfer
  * Author: LuisM Pena
  * Date: 28th November 2000
  * Version: 0.51.00
  * Last change:
  *         12th April 2001: state transfer inclusion
  *
  *
  **/

#ifndef INTERNAL_DOMAIN_MESSAGES_IDL
#define INTERNAL_DOMAIN_MESSAGES_IDL

#include "DomainGroupHandler.idl"

module sensei
{

  module middleware
  {

    module domains
    {

      enum StateTransferType
      {
        STT_StateHandler,
        STT_BasicStateHandler,
        STT_ExtendedCheckpointable,
        STT_Checkpointable,
        STT_StatelessTransfer
      };

      /***********************************************************************/
      /************************* MESSAGE P ***********************************/
      /***********************************************************************/

      struct SubgroupProperties
      {
        SubgroupId id; //identity of the subgroup
        DynamicSubgroupInfo info; //associated info, not used on static groups
        StateTransferType type;
      };
      typedef sequence <SubgroupProperties> SubgroupsInfo;

      struct ReplicaInformation
      {
        GroupMemberId replicaId;
        GroupMemberIdList replicasToCoordinate;
      };
      typedef sequence <ReplicaInformation> ReplicasInformation;
      /**
       *  Message p is the initial message sent between DomainGroupHandlers to
       *  transfer their features, and any state transfer information required
       *  (but not the state itself).
       *  It contains:
       *  (a) generic information about the group itself
       *  (b) information about the subgroup layout
       *  (c) list of current statefull members, with their properties and
       *      members being coordinated
       **/
      valuetype MessageP : DomainMessage
      {
        public long viewId; //message can only be processed on the right view

        public BehaviourOnViewChanges behaviour;
        public boolean coordinatorElectorRegistered;
        public boolean dynamicSubgroupsAllowed;
        public long nextDynamicSubgroupId;

        public SubgroupsInfo subgroupsInformation;
        public MemberPropertiesList props;
        public ReplicasInformation replicasInfo;
      };

      /***********************************************************************/
      /************************* MESSAGE C ***********************************/
      /***********************************************************************/

      struct SubgroupCoordination
      {
        SubgroupId id;
        PhaseCoordination phase;
      };
      typedef sequence <SubgroupCoordination> SubgroupCoordinations;
      /**
       *  Message c is the reply message sent from a DomainGroupHandler that
       *  has received the message p. It contains its properties, and the
       *  coordination phases of the subgroups
       **/
      valuetype MessageC : DomainMessage
      {
        public long viewId; //message can only be processed on the right view, depending on the model
        public SubgroupCoordinations coordinations;
        public boolean containOwnProperties; //true if the next field props is valid
        public Properties props; //properties of the member being coordinated
      };

      /***********************************************************************/
      /************************* MESSAGE E ***********************************/
      /***********************************************************************/

      /**
       *  Message e is sent when a transfer has finished, containing
       *  the member that has received the state and its properties
       **/
      valuetype MessageE : DomainMessage
      {
        public long viewId; //message can only be processed on the right view, depending on the model
        public GroupMemberId member;
        public Properties props; //properties of the member getting state
      };

      /***********************************************************************/
      /************************* MESSAGE S ***********************************/
      /***********************************************************************/

      struct SubgroupState
      {
        SubgroupId id;
        PhaseCoordination phase;
        State subState;
      };
      typedef sequence <SubgroupState> SubgroupStates;
      /**
       *  Message S contains the states being sent, together with the
       *  coordinations
       **/
      valuetype MessageS : DomainMessage
      {
        public long viewId; //message can only be processed on the right view, depending on the model
        public SubgroupStates states;
      };

      /***********************************************************************/
      /************************* MESSAGE MEMBER PROPERTIES *******************/
      /***********************************************************************/

      valuetype MessageMemberProperties : DomainMessage
      {
        public Properties props;
      };

      /***********************************************************************/
      /************************* MESSAGE CREATE SUBGROUP *********************/
      /***********************************************************************/

      valuetype MessageCreateSubgroup : DomainMessage
      {
        public DynamicSubgroupInfo info;
        public long creatorId; //id only meaningfull for the message sender
      };

      /***********************************************************************/
      /************************* MESSAGE CREATE SUBGROUP *********************/
      /***********************************************************************/

      valuetype MessageRemoveSubgroup : DomainMessage
      {
        public SubgroupId subgroupToRemove;
        public DynamicSubgroupInfo info;
      };

      /***********************************************************************/
      /************************* CONCURRENCY MESSAGES ************************/
      /***********************************************************************/

      /**
       * Message sent to lock/unlock a monitor
       */
      valuetype MonitorMessage : DomainMessage
      {
        public boolean lock;
      };

      /**
       * Message sent when a transfer ends completely, with all the actions included
       */
      valuetype EndOfTransactionMessage : DomainMessage
      {
        public sequence<Message> actions;
      };

      /***********************************************************************/
      /************************* MONITOR STATE *******************************/
      /***********************************************************************/

      valuetype MonitorState : State
      {
        public GroupMemberIdList locks;
      };

    };
  };
};

#endif