/* Network-Integrated Multimedia Middleware (NMM)
 * http://www.motama.com/nmm.html
 *  
 * Copyright (C) 2006-2007
 * Motama GmbH, Saarbruecken, Germany
 * http://www.motama.com
 *  
 * This file is part of NMM. 
 * 
 * NMM is free software; you can redistribute it and/or modify it    
 * under the terms of the GNU General Public License as published by 
 * the Free Software Foundation; only version 2 of the License.      
 * 
 * NMM is distributed in the hope that it will be useful, but WITHOUT 
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY 
 * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public 
 * License for more details.  
 * 
 * You should have received a copy of the GNU General Public License 
 * along with NMM; if not, write to the Free Software Foundation,    
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
 *
 */
#ifndef NMM_REGISTRYID_HPP
#define NMM_REGISTRYID_HPP

#include "nmm/nmm_prefix.hpp"

#include "nmm/comm/serialize/SerializedValue.hpp"
#include "nmm/comm/UserInfo.hpp"
#include "nmm/comm/NMMReference.hpp"

#include <string>
#include "visibility.hpp"

namespace NMM {

  class IValueStream;
  class OValueStream;

  /** The RegistryID is used to identify a Registry in the Network. 
   * To identify the process and the host a UserInfo is used. 
   * To identify a Registry in the application its NMMReference is used.
   */
  class DLLEXPORT RegistryID : public SerializedValue {
  public:
    /** @name Constructor & Destructor
     */
    //@{
    /** Constructor.
     */
    RegistryID();

    /** Constructor with registry name and reference to registry.
     *
     * @param reg_name name of registry
     * @param reference reference to registry
     */
    RegistryID(const string& reg_name, const NMMReference& reference);

    /** Copy constructor.
     *
     * @param reg_id RegistryID to copy
     */
    RegistryID(const RegistryID& reg_id);

    /** Virtual copy constructor.
     *
     * @return pointer to copy of this RegistryID
     */
    virtual RegistryID*     copy()                    const { return new RegistryID(*this);}
    //@}

    /** @name Access RegistryID information
     */
    //@{
    /** This method returns the name of the Registry.
     *
     * @return name of the Registry
     */
    inline const string&        getRegistryName()     const {return __reg_name.getRValue();}

    /** This method returns the NMMReference of the Registry.
     *
     * @return NMMReference of the Registry
     */
    inline const NMMReference&  getReference()        const {return __reference.getRValue();}

    /** This method returns the used UserInfo.
     *
     * @return used UserInfo
     */
    inline const UserInfo&      getUserInfo()         const {return __user_info;}
    //@}

    /** This method sets the UserInfo.
     *
     * @param user_info UserInfo to set
     */
    inline void setUserInfo(const UserInfo& user_info) { __user_info = user_info; }

    /** @name Operator
     */
    //@{
    /** Tests is this and given RegistryID are equal.
     * 
     * This operator compares a given RegistryID with this instance and returns true if
     * they are equal, otherwise false.
     *
     * @param id RegistryId to compare this one with
     * @return true if RegistryIDs are equal, false otherwise
     */
    bool operator==(const RegistryID& id)             const;

    /** Tests is this and given RegistryID are unequal.
     * 
     * This operator compares a given RegistryID with this instance and returns false if
     * they are equal, otherwise true.
     *
     * @param id RegistryId to compare this one with
     * @return true if RegistryIDs are unequal, false otherwise
     */
    bool operator!=(const RegistryID& id)             const { return !(*this == id); }
    //@}

  private:

    /** Register attributes for serialization/deserialization.
     */
    void allocate();


  private:

    TValue<string>            __reg_name;             ///< Stores the name of the Registry
    TValue<NMMReference>      __reference;            ///< Stores the NMMReference of the Registry
    UserInfo                  __user_info;            ///< Stores the UserInfo to identify the Registry
  };

  /** Writes member variables of RegistryID to ostream.
   *
   * @param os ostream to write to
   * @param reg_id RegistryID to be written
   */
  DLLEXPORT ostream& operator<<(ostream& os, const RegistryID& reg_id);

  /** Serialization operator for lists of RegistryIDs.
   *
   * @param ov OValueStream to write to
   * @param string_list list of RegistryIDs to serialize
   * @return reference to OValueStream given by argument
   */
  DLLEXPORT OValueStream& operator<<(OValueStream& ov, const list<RegistryID>& string_list);

  /** Deserialization operator for lists of RegistryIDs.
   *
   * @param iv IValueStream to read from
   * @param string_list list variable to write to
   * @return reference to IValueStream given by argument
   */
  DLLEXPORT IValueStream& operator>>(IValueStream& iv, list<RegistryID>& string_list);

}

#include "nmm/nmm_suffix.hpp"

#endif
