/**
  * File: GroupMembershipService.idl
  * Content: CORBA specification of members with reliable multicast
  *          communications, based on the virtual synchronous model
  * Author: LuisM Pena
  * Date: 3nd July 2000
  * Version: 0.95.00, 4th September 2001
  * Last changes:
  *             v0.95: GroupMember receives the event changingView when the view got blocked
  *
  **/

#ifndef VIRTUAL_SYNCHRONY_IDL
#define VIRTUAL_SYNCHRONY_IDL

module sensei
{

  module middleware
  {

    module gms
    {

      /***********************************************************************/
      /************************* GROUP MEMBER ID *****************************/
      /***********************************************************************/

      /**
        * 0 is considered an invalid member id
        **/
      typedef long GroupMemberId;

      const GroupMemberId INVALID_GROUP_MEMBER_ID = 0;

      /**
        * List of group member ids
        **/
      typedef sequence <GroupMemberId> GroupMemberIdList;

      /***********************************************************************/
      /************************* VIEW ****************************************/
      /***********************************************************************/

      /**
        * View, as defined in the virtual synchrony model. Every
        * group member shares the same view of the group
        **/
      struct View
      {
        long viewId;
        GroupMemberIdList members;
        GroupMemberIdList newMembers;
        GroupMemberIdList expulsedMembers;
      };

      /***********************************************************************/
      /************************* MESSAGE *************************************/
      /***********************************************************************/

      valuetype Message
      {
      };

      /***********************************************************************/
      /************************* GROUP HANDLER *******************************/
      /***********************************************************************/

      /**
        * GroupHandler defines the interface that allows to the application to
        * make group communications.
        */
      interface GroupHandler
      {
        /**
          * Returns the GroupMemberId handled by this GroupHandler
          * If the member is not active, the returned value is random - negative.
          **/
        GroupMemberId getGroupMemberId();

        /**
          * Returns true if the member belong to a group
          **/
        boolean isValidGroup();

        /**
          * Leaves the group
          * @returns true if the member was belonging to a group
          **/
        boolean leaveGroup();

        /**
          * Sends a message to every member in the view, returning
          * true if the message is sent on this view
          * @param message The message to send
          * @returns true if the message is sent on the current view
          **/
        boolean castMessage(in Message msg);

        /**
          * Sends a message to the specified member in the view, returning
          * true if the message is sent on this view. This call allows
          * to keep the order between cast and point-to-point messages
          * @param target The member receiving the message
          * @param message The message to send
          * @returns true if the message is sent on the current view
          **/
        boolean sendMessage(in GroupMemberId target, in Message msg);
      };

      /***********************************************************************/
      /************************* GROUP MEMBER ********************************/
      /***********************************************************************/

      /**
        * GroupMember specifies the interface to be implemented by group members
        */
      interface GroupMember
      {
        /**
          * The member receives a point to point message to be processed
          * @param message The message to process
          **/
        void processPTPMessage(in GroupMemberId sender, in Message msg);

        /**
          * The member receives a group message to be processed
          * @param message The message to process
          **/
        void processCastMessage(in GroupMemberId sender, in Message msg);

        /**
          * The member is accepted in the group, and receives its identity and the
          *  first view. It receives as well the group handler to use for communications
          **/
        void memberAccepted(in GroupMemberId identity, in GroupHandler handler, in View theView);

        /**
          * The group is going to change the view, any new message will be sent on the next view
          **/
        void changingView();

        /**
          * The member receives a new view, including the list of members
          * @param message The message to process
          **/
        void installView(in View theView);

        /**
          * The member is excluded from the group, because it has requested it or because
          * it's considered to be faulty.
          **/
        void excludedFromGroup();

      };

    };
  };
};

#endif