/* 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_USER_INFO_HPP
#define NMM_USER_INFO_HPP NMM_USER_INFO_HPP

#include "nmm/nmm_prefix.hpp"

#include "nmm/comm/serialize/SerializedValue.hpp"
#include "nmm/comm/serialize/TValue.hpp"

#include "visibility.hpp"

namespace NMM {
  
  class UserInfo;
  
  DLLEXPORT ostream& operator<<(ostream&, const UserInfo& );
  
  /** The UserInfo stores information, that can be used to identify a specifc process on
   * the network. To identify the host, its IP-address is used, which is unique in the network.
   * To identify the process on a host, the process-id is used.
   */
  class DLLEXPORT UserInfo : public SerializedValue {
  public:
    /** Constructor tag for static constructor.
     */
    enum Static { STATIC };
  
  public:
    /** @name Constructor & Destructor
     */
    //@{
    /** Constructor.
     */
    UserInfo();

    /** Copy-Constructor.
     *
     * @param ui UserInfo to be copied
     */
    UserInfo(const UserInfo& ui);

    /** Virtual Copy-Constructor.
     *
     * @return copy of this UserInfo
     */
    virtual UserInfo*    copy()           const { return new UserInfo(*this); }
    //@}

    /** @name Access UserInfo information
     */
    //@{
    /** This method returns the hostname of the host that created the object.
     *
     * @return hostname of the host that created the object
     */
    inline const std::string& getHostname()    const { return __hostname.getRValue(); }

    /** This method returns the domainname of the host that created the object.
     *
     * @return domainname of the host that created the object
     */
    inline const std::string& getDomainname()  const { return __domainname.getRValue(); }

    /** This method returns the user name of the user that created the object.
     *
     * @return user name of the user that created the object
     */
    inline const std::string& getUsername()    const { return __username.getRValue(); }

    /** This method returns the password.
     *
     * @return password
     */
    inline const std::string& getPasswd()    const { return __passwd.getRValue(); }

    /** This method returns the pid of the application that created the object.
     *
     * @return pid of the application that created the object
     */
    inline int           getPid()         const { return __pid.getRValue(); }
    //@}

    /** @name Operators
     */
    //@{
    /** The assignment operator stores all information from given UserInfo in this object.
     *
     * @param u_info UserInfo that should be assigned with this instance
     * @return reference to the argument UserInfo
     */
    const UserInfo& operator=(const UserInfo& u_info);

    /** Tests if this and the given UserInfo are equal. 
     *
     * This operator compares a given UserInfo with this instance and returns true if
     * they are equal, otherwise false.
     *
     * @param info UserInfo to compare with this one
     * @return true if the two UserInfo are equal, false otherwise
     */
    bool operator==(const UserInfo& info) const;

    /** Tests if this and the given UserInfo are unequal. 
     *
     * This operator compares a given UserInfo with this instance and returns true if
     * they are unequal, false otherwise.
     *
     * @param info UserInfo to compare with this one
     * @return true if the two UserInfo are unequal, false otherwise
     */
    bool operator!=(const UserInfo& info) const { return !(*this == info);}
    //@}
  private://method
    /** This method adds all attributes for serialization/deserialization.
     */
    void registerAttributes();

    /** Private assignment method.
     *
     * @param ui UserInfo to take values to assign to this UserInfo
     */
    void assign(const UserInfo& ui);

  private:
    TValue<std::string> __hostname;             ///< stores the hostname
    TValue<std::string> __domainname;           ///< stores the domainname
    TValue<std::string> __username;             ///< stores the username
    TValue<std::string> __passwd;               ///< stores the passwd
    TValue<nmm_int32>    __pid;                       ///< stores the process id
  };
  
}

#include "nmm/nmm_suffix.hpp"

#endif
