• Main Page
  • Related Pages
  • Namespaces
  • Data Structures
  • Files
  • File List
  • Globals

I_Machine.h

Go to the documentation of this file.
00001 /** @file
00002 
00003   Machine
00004 
00005   @section license License
00006 
00007   Licensed to the Apache Software Foundation (ASF) under one
00008   or more contributor license agreements.  See the NOTICE file
00009   distributed with this work for additional information
00010   regarding copyright ownership.  The ASF licenses this file
00011   to you under the Apache License, Version 2.0 (the
00012   "License"); you may not use this file except in compliance
00013   with the License.  You may obtain a copy of the License at
00014 
00015       http://www.apache.org/licenses/LICENSE-2.0
00016 
00017   Unless required by applicable law or agreed to in writing, software
00018   distributed under the License is distributed on an "AS IS" BASIS,
00019   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
00020   See the License for the specific language governing permissions and
00021   limitations under the License.
00022 
00023   @section details Details
00024 
00025   Part of the utils library which contains classes that use multiple
00026   components of the IO-Core to implement some useful functionality. The
00027   classes also serve as good examples of how to use the IO-Core.
00028 
00029  */
00030 
00031 #ifndef _I_Machine_h
00032 #define _I_Machine_h
00033 
00034 
00035 /**
00036   The Machine is a simple place holder for the hostname and the ip
00037   address of an internet host.
00038 
00039   If a hostname or an IP address is not provided in the constructor,
00040   the hostname defaults to the name of the current processor and the
00041   IP address is the address of the current host.  If the host has
00042   multiple IP addresses, the numerically lowest IP address is used.
00043   The IP address is stored in the network byte order.
00044 
00045   @internal This does not handle multi-homed systems. That should be
00046   fixed.
00047 
00048  */
00049 struct Machine {
00050   typedef Machine self; ///< Self reference type.
00051 
00052   char *hostname;               // name of the internet host
00053   int hostname_len;             // size of the string pointed to by hostname
00054 
00055   IpEndpoint ip;      ///< Prefered IP address of the host (network order)
00056   IpEndpoint ip4;     ///< IPv4 address if present.
00057   IpEndpoint ip6;     ///< IPv6 address if present.
00058 
00059   ip_text_buffer ip_string;              // IP address of the host as a string.
00060   int ip_string_len;
00061 
00062   char ip_hex_string[TS_IP6_SIZE*2 + 1]; ///< IP address as hex string
00063   int ip_hex_string_len;
00064 
00065   ~Machine();
00066 
00067   /** Initialize the singleton.
00068       If @a hostname or @a ip are @c NULL then system defaults are used.
00069 
00070       @note This must be called before called @c instance so that the
00071       singleton is not @em inadvertently default initialized.
00072   */
00073   static self* init(
00074     char const* name = 0, ///< Host name of the machine.
00075     sockaddr const* addr = 0 ///< Primary IP adddress of the machine.
00076   );
00077   /// @return The global instance of this class.
00078   static self* instance();
00079 
00080 protected:
00081   Machine(char const* hostname, sockaddr const* addr);
00082 
00083   static self* _instance; ///< Singleton for the class.
00084 };
00085 
00086 /**
00087   Creates a Machine Object with the hostname and IP address.  If no
00088   hostname or IP address is given, the hostname defaults to the name of
00089   the current processor.
00090 
00091  */
00092 void create_this_machine(char *hostname = 0, unsigned int ip = 0);
00093 
00094 /**
00095   Returns the Machine object created by create_this_machine().
00096 
00097  */
00098 Machine *this_machine();
00099 
00100 #endif

Generated by  doxygen 1.7.1