DUNE-DAQ
DUNE Trigger and Data Acquisition software
Loading...
Searching...
No Matches
OksSystem::LocalHost Class Reference

Network host - localhost. More...

#include <Host.hpp>

Inheritance diagram for OksSystem::LocalHost:
[legend]
Collaboration diagram for OksSystem::LocalHost:
[legend]

Public Member Functions

 LocalHost () throw ()
 
 ~LocalHost () throw ()
 
const std::string & os_name () const throw ()
 name of the operating system
 
const std::string & os_release () const throw ()
 release of the operating system
 
const std::string & os_version () const throw ()
 version of the operating system
 
const std::string & machine () const throw ()
 version of the operating system
 
const std::string & description () const throw ()
 machine type *‍/
 
- Public Member Functions inherited from OksSystem::Host
 Host (const Host &other)
 copy constructor
 
 Host (const std::string &name)
 constructor from name
 
 Host (struct sockaddr_in ip_addr)
 constructor from ip address
 
virtual ~Host () throw ()
 destructor
 
 operator struct sockaddr_in () const throw ()
 cast to ip address
 
bool equals (const Host &other) const throw ()
 equality method
 
struct sockaddr_in ip () const throw ()
 get ip address
 
const std::string & name () const throw ()
 get name
 
const std::string & full_name () const throw ()
 get fully qualified name
 
std::string ip_string () const throw ()
 get ip in string mode
 

Static Public Member Functions

static const std::string & local_name () throw ()
 localhostname
 
static const std::string & full_local_name () throw ()
 fully qualified local host name
 
static const LocalHostinstance () throw ()
 pointer to the singleton local host
 
- Static Public Member Functions inherited from OksSystem::Host
static struct sockaddr_in resolve (const std::string &name) throw ()
 name to ip conversion
 
static std::string resolve (struct sockaddr_in address) throw ()
 ip to name conversion
 
static std::string expand (const std::string &name) throw ()
 expands to full name
 
static std::string to_string (struct sockaddr_in ip_addr)
 ip to string conversion
 

Protected Attributes

std::string m_os_name
 name of the operating system
 
std::string m_release
 release of the operating system
 
std::string m_version
 version of the operating system
 
std::string m_machine
 machine type
 
std::string m_description
 machine description (cached)
 
- Protected Attributes inherited from OksSystem::Host
std::string m_name
 name of the host
 
std::string m_full_name
 cached fully qualified host name
 

Static Protected Attributes

static LocalHosts_instance = 0
 singleton for local host
 

Additional Inherited Members

- Protected Member Functions inherited from OksSystem::Host
 Host () throw ()
 constructor for current host
 

Detailed Description

Network host - localhost.

This class represents the local host It has some additional fields with additional information about the host

Version
1.1
Author
Matthias Wiesmann

Definition at line 62 of file Host.hpp.

Constructor & Destructor Documentation

◆ LocalHost()

OksSystem::LocalHost::LocalHost ( )
throw ( )

Constructor You should not construct new instances, use instance to get the singleton instance.

Definition at line 233 of file Host.cpp.

233 : Host() {
234 struct utsname u_name_data;
235 const int status = ::uname(&u_name_data);
236 if (status==0) {
237 m_name = u_name_data.nodename;
238 m_os_name = u_name_data.sysname;
239 m_release = u_name_data.release;
240 m_version = u_name_data.version;
241 m_machine = u_name_data.machine;
242 } else {
243 char buffer[NI_MAXHOST];
244 const int host_status = gethostname(buffer,sizeof(buffer));
245 if (host_status==0) {
246 m_name = buffer;
247 } else { // both uname and gethostname screwed
248 m_name.clear();
249 } // check for host_name
250 } // uname failed.
251} // LocalHost
std::string m_name
name of the host
Definition Host.hpp:30
Host()
constructor for current host
Definition Host.cpp:92
std::string m_os_name
name of the operating system
Definition Host.hpp:66
std::string m_version
version of the operating system
Definition Host.hpp:68
std::string m_machine
machine type
Definition Host.hpp:69
std::string m_release
release of the operating system
Definition Host.hpp:67

◆ ~LocalHost()

OksSystem::LocalHost::~LocalHost ( )
throw ( )

Definition at line 253 of file Host.cpp.

253 {
254 // delete s_instance;
255}

Member Function Documentation

◆ description()

const std::string & OksSystem::LocalHost::description ( ) const
throw ( )

machine type *‍/

This method builds a description of the localhost This contains all the of the information handled by this class.

Returns
description text

Definition at line 286 of file Host.cpp.

286 {
287 if (m_description.empty()) {
288 std::ostringstream stream;
289 stream << m_os_name << " " << m_release << "/" << m_machine;
290 m_description = stream.str();
291 }
292 return m_description;
293} // description
std::string m_description
machine description (cached)
Definition Host.hpp:70

◆ full_local_name()

const std::string & OksSystem::LocalHost::full_local_name ( )
throw ( )
static

fully qualified local host name

Short-cut method - gives the fully qualified local hostname

Returns
fully qualified hostname
See also
OksSystem::LocalHost::full_name()

Definition at line 211 of file Host.cpp.

211 {
212 return instance()->full_name();
213} // fulllocalhostname
const std::string & full_name() const
get fully qualified name
Definition Host.cpp:161
static const LocalHost * instance()
pointer to the singleton local host
Definition Host.cpp:221

◆ instance()

const OksSystem::LocalHost * OksSystem::LocalHost::instance ( )
throw ( )
static

pointer to the singleton local host

This method returns a pointer to the singleton instance. There is no need to ever create any instance of LocalHost

Returns
pointer to singleton instance
Note
utility methods like full_local_name use this instance class

Definition at line 221 of file Host.cpp.

221 {
222 if (0==s_instance) {
223 s_instance = new LocalHost();
224 } //
225 return s_instance;
226} // instance
static LocalHost * s_instance
singleton for local host
Definition Host.hpp:65

◆ local_name()

const std::string & OksSystem::LocalHost::local_name ( )
throw ( )
static

localhostname

Short-cut method - gives the local hostname This name is not guaranteed to be a fully qualified name.

Returns
hostname
See also
OksSystem::LocalHost::name()

Definition at line 202 of file Host.cpp.

202 {
203 return instance()->name();
204} // localhostname
const std::string & name() const
get name
Definition Host.cpp:149

◆ machine()

const std::string & OksSystem::LocalHost::machine ( ) const
throw ( )

version of the operating system

Returns
machine name

Definition at line 277 of file Host.cpp.

277 {
278 return m_machine;
279} // machine

◆ os_name()

const std::string & OksSystem::LocalHost::os_name ( ) const
throw ( )

name of the operating system

Returns
Operating OksSystem name

Definition at line 259 of file Host.cpp.

259 {
260 return m_os_name;
261} // os_name

◆ os_release()

const std::string & OksSystem::LocalHost::os_release ( ) const
throw ( )

release of the operating system

Returns
Operating OksSystem release

Definition at line 265 of file Host.cpp.

265 {
266 return m_release;
267} // os_release

◆ os_version()

const std::string & OksSystem::LocalHost::os_version ( ) const
throw ( )

version of the operating system

Returns
Operating OksSystem version

Definition at line 271 of file Host.cpp.

271 {
272 return m_version;
273} // os_version

Member Data Documentation

◆ m_description

std::string OksSystem::LocalHost::m_description
mutableprotected

machine description (cached)

Definition at line 70 of file Host.hpp.

◆ m_machine

std::string OksSystem::LocalHost::m_machine
protected

machine type

Definition at line 69 of file Host.hpp.

◆ m_os_name

std::string OksSystem::LocalHost::m_os_name
protected

name of the operating system

Definition at line 66 of file Host.hpp.

◆ m_release

std::string OksSystem::LocalHost::m_release
protected

release of the operating system

Definition at line 67 of file Host.hpp.

◆ m_version

std::string OksSystem::LocalHost::m_version
protected

version of the operating system

Definition at line 68 of file Host.hpp.

◆ s_instance

OksSystem::LocalHost * OksSystem::LocalHost::s_instance = 0
staticprotected

singleton for local host

LocalHost singleton.

Instance of local host

Definition at line 65 of file Host.hpp.


The documentation for this class was generated from the following files: