/*******************************************************************************
 * Copyright (c) 2015-2016 ONERA.
 * Ce logiciel est la propriété de l’ONERA (the French Aerospace Lab).
 * Tous droits réservés.
 *
 * Ce programme et les éléments qui l'accompagnent sont mis à disposition
 * aux conditions définies par le contrat de licence logiciel CeCILL-C soumise
 * au droit français et respectant les principes de diffusion des logiciels libres.
 * Vous pouvez utiliser, modifier et/ou redistribuer ce programme
 * sous les conditions de la licence CeCILL-C (http://www.cecill.info).

 * This software is property of ONERA (the French Aerospace Lab).
 * All rights reserved.
 *
 * This program and the accompanying materials are made available under
 * the terms of the CeCILL-C license under French law and
 * abiding by the rules of distribution of free software.
 * You can  use, modify and/ or redistribute the software under the terms of
 * the CeCILL-C license (http://www.cecill.info).
 *
 * Contributeurs/contributors:
 *     Guillaume Infantes (ONERA - Centre de Toulouse) - initial API and implementation
 *
 *******************************************************************************/

#ifndef ALTA_SYNC_H_
#define ALTA_SYNC_H_

#include <vector>
#include <string>

namespace epoch {
  namespace altarica {

    class Node;
    class MetaEvent;
    class Event;
    class MemberAccess;
    class AltaricaState;
    class AltaricaModel;

    class Synchronisation {
    protected:
      std::vector<MemberAccess*> broadcastList_;
      std::vector<Event*> broadcastListMandatoryEvents_;
      std::vector<Event*> broadcastListOptionalEvents_;
      std::vector<bool> optionalBcast_;
      short constraint_type_;
      int numerical_constant_;
      short max_;
      MemberAccess *ma_;
      Node * node_;
    public:
      Synchronisation();
      ~Synchronisation();
      Synchronisation(MemberAccess *ma);

      void addEvent(MemberAccess* e, bool optional);
      void setConstraintType(short ct);
      void setNumConstant(int n);
      void setMax();
      void setMin();

      void setNode(Node *n);

      Synchronisation* clone();

      void matchEvents();

      std::string toString() const;

      bool syncEvent(Event* e);

      const std::vector<Event*> * getOptionalEvents();
      const std::vector<Event*> * getMandatoryEvents();

      std::vector<MetaEvent*> * buildSynchronisedEvents(const AltaricaModel *am,
                                                        AltaricaState *s);

      const MemberAccess* getMA() const { return ma_; }
      short getConstraintType() const { return constraint_type_; }
      int getNumericalConstant() const { return numerical_constant_; }
      short getMinMaxType() const { return max_; }
    };
  }
}

#endif
