General Purpose Geodetic Library
SgIdentities.cpp
Go to the documentation of this file.
1 /*
2  *
3  * This file is a part of Space Geodetic Library. The library is used by
4  * nuSolve, a part of CALC/SOLVE system, and designed to make analysis of
5  * geodetic VLBI observations.
6  * Copyright (C) 2010-2020 Sergei Bolotin.
7  *
8  * This program is free software: you can redistribute it and/or modify
9  * it under the terms of the GNU General Public License as published by
10  * the Free Software Foundation, either version 3 of the License, or
11  * (at your option) any later version.
12  *
13  * This program is distributed in the hope that it will be useful,
14  * but WITHOUT ANY WARRANTY; without even the implied warranty of
15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16  * GNU General Public License for more details.
17  *
18  * You should have received a copy of the GNU General Public License
19  * along with this program. If not, see <http://www.gnu.org/licenses/>.
20  *
21  */
22 
23 #include <iostream>
24 #include <pwd.h>
25 #include <stdlib.h>
26 #include <stdio.h>
27 #include <sys/utsname.h>
28 #include <unistd.h>
29 
30 #include <SgIdentities.h>
31 
32 
33 #include <QtCore/QList>
34 #include <QtCore/QMap>
35 
36 
37 
38 #include <SgLogger.h>
39 
40 
41 
42 
43 /*=======================================================================================================
44 *
45 * METHODS:
46 *
47 *======================================================================================================*/
48 //
49 // static first:
50 const QString SgIdentities::className()
51 {
52  return "SgIdentities";
53 };
54 
55 
56 
57 //
58 //
59 // CONSTRUCTORS:
60 //
61 // An empty constructor:
63  // identities (defaults should be obviously fictional):
64  userName_ ("Luavrik L. Luavrik"),
65  userEmailAddress_ ("luavrik@localhost"),
66  userDefaultInitials_("LL"),
67  acFullName_ ("Space Research Center, National Academy of Science of Irukan"),
68  acAbbrevName_ ("SRC NASI"),
69  acAbbName_ ("SRI"),
70  execDir_ ("./"),
71  currentDir_ ("./"),
72  execBinaryName_ ("a.out"),
73  driverVersion_ (),
74  machineNodeName_ (""),
75  machineMachineName_ (""),
76  machineSysName_ (""),
77  machineRelease_ ("")
78 // altConfigName_ ("")
79 {
80  char buff[256];
81  QString hostName("localhost");
82  struct utsname uts;
83  struct passwd *pw=NULL;
84  //
85  // guess OS name:
86  if (uname(&uts) == -1)
87  perror("uname: ");
88  else
89  {
90  machineNodeName_ = QString(uts.nodename);
91  machineMachineName_ = QString(uts.machine);
92  machineSysName_ = QString(uts.sysname);
93  machineRelease_ = QString(uts.release);
94  };
95  //
96  // guess host name:
97  if (gethostname(buff, sizeof(buff)) == -1)
98  perror("gethostname: ");
99  else
100  hostName = QString(buff);
101  // If hostname contain at least one dot, assume this is F.Q.D.N. host name
102  if (!hostName.contains("."))
103  {
104  if (getdomainname(buff, sizeof(buff))==-1)
105  perror("getdomainname: ");
106  else if (!strstr(buff, "(none)"))
107  hostName += "." + QString(buff);
108  };
109  //
110  //
111  // guess login name:
112  pw = getpwuid(geteuid());
113  if (!pw)
114  perror("getpwuid: ");
115  else
116  {
117  userEmailAddress_ = QString(pw->pw_name) + "@" + hostName;
118  // guess user name:
119  if (!strtok(pw->pw_gecos, ","))
120  userName_ = QString(pw->pw_gecos);
121  else
122  userName_ = QString(strtok(pw->pw_gecos, ","));
123  };
124 };
125 
126 
127 
128 // A copying constructor:
130  userName_(id.getUserName()),
131  userEmailAddress_(id.getUserEmailAddress()),
132  userDefaultInitials_(id.getUserDefaultInitials()),
133  acFullName_(id.getAcFullName()),
134  acAbbrevName_(id.getAcAbbrevName()),
135  acAbbName_(id.getAcAbbName()),
136  execDir_(id.getExecDir()),
137  currentDir_(id.getCurrentDir()),
138  execBinaryName_(id.getExecBinaryName()),
139  driverVersion_(id.getDriverVersion()),
140  machineNodeName_(id.getMachineNodeName()),
141  machineMachineName_(id.getMachineMachineName()),
142  machineSysName_(id.getMachineSysName()),
143  machineRelease_(id.getMachineRelease())
144 {
145 };
146 
147 
148 
149 //
151 {
152  setUserName(id.getUserName());
158  setExecDir(id.getExecDir());
166  return *this;
167 };
168 
169 
170 
171 //
173 {
180 };
181 
182 
183 
184 //
186 {
187  std::cout << "User/Analysis Center Identities:\n";
188 
189  std::cout
190  << "User:\n"
191  << " Name:\t\t\t\t\"" << qPrintable(userName_) << "\"\n"
192  << " E-mail adderess:\t\t\t\"" << qPrintable(userEmailAddress_) << "\"\n"
193  << " Initials:\t\t\t\t\"" << qPrintable(userDefaultInitials_) << "\"\n"
194 
195  << "Analysis Center:\n"
196  << " Name:\t\t\t\t\"" << qPrintable(acFullName_) << "\"\n"
197  << " Abbreviation:\t\t\t\"" << qPrintable(acAbbrevName_) << "\"\n"
198  << " Abbreviation, short version:\t\t\"" << qPrintable(acAbbName_) << "\"\n"
199  ;
200 
201 /*
202  std::cout
203  << "The executable:\n"
204  << " Name of the executable file:\t\t\"" << qPrintable(execBinaryName_) << "\"\n"
205  << " Path to the executable file:\t\t\"" << qPrintable(execDir_) << "\"\n"
206  << " Current directory:\t\t\t\"" << qPrintable(currentDir_) << "\"\n"
207  ;
208 
209  // SgVersion driverVersion_;
210 
211  std::cout
212  << "The computer:\n"
213  << " Node name:\t\t\t\t\"" << qPrintable(machineNodeName_) << "\"\n"
214  << " Hardware ID:\t\t\t\t\"" << qPrintable(machineMachineName_) << "\"\n"
215  << " OS name:\t\t\t\t\"" << qPrintable(machineSysName_) << "\"\n"
216  << " OS release:\t\t\t\t\"" << qPrintable(machineRelease_) << "\"\n"
217  ;
218  */
219 
220 };
221 
222 /*=====================================================================================================*/
223 
224 
225 
226 
227 
228 
229 /*=====================================================================================================*/
230 //
231 // FRIENDS:
232 //
233 /*=====================================================================================================*/
234 //
235 
236 /*=====================================================================================================*/
237 //
238 // aux functions:
239 //
240 
241 /*=====================================================================================================*/
242 //
243 // constants:
244 //
245 
246 /*=====================================================================================================*/
QString machineMachineName_
Definition: SgIdentities.h:185
SgIdentities & operator=(const SgIdentities &)
const QString & getExecBinaryName() const
Definition: SgIdentities.h:279
const QString & getAcAbbrevName() const
Definition: SgIdentities.h:247
void setMachineMachineName(const QString &)
Definition: SgIdentities.h:415
const QString & getAcAbbName() const
Definition: SgIdentities.h:255
QString userDefaultInitials_
Definition: SgIdentities.h:173
QString acAbbrevName_
Definition: SgIdentities.h:176
QString machineSysName_
Definition: SgIdentities.h:186
void setAcAbbrevName(const QString &)
Definition: SgIdentities.h:367
void setAcFullName(const QString &)
Definition: SgIdentities.h:359
const QString & getUserEmailAddress() const
Definition: SgIdentities.h:223
void setCurrentDir(const QString &)
Definition: SgIdentities.h:391
void setAcAbbName(const QString &)
Definition: SgIdentities.h:375
QString machineRelease_
Definition: SgIdentities.h:187
const QString & getMachineMachineName() const
Definition: SgIdentities.h:303
QString userEmailAddress_
Definition: SgIdentities.h:172
const QString & getMachineRelease() const
Definition: SgIdentities.h:319
void setMachineNodeName(const QString &)
Definition: SgIdentities.h:407
SgVersion driverVersion_
Definition: SgIdentities.h:182
const QString & getMachineNodeName() const
Definition: SgIdentities.h:295
const QString & getUserDefaultInitials() const
Definition: SgIdentities.h:231
const QString & getAcFullName() const
Definition: SgIdentities.h:239
void setMachineRelease(const QString &)
Definition: SgIdentities.h:431
QString machineNodeName_
Definition: SgIdentities.h:184
void print2stdOut()
const SgVersion & getDriverVersion() const
Definition: SgIdentities.h:287
static const QString className()
void setUserDefaultInitials(const QString &)
Definition: SgIdentities.h:351
const QString & getCurrentDir() const
Definition: SgIdentities.h:271
void setUserEmailAddress(const QString &)
Definition: SgIdentities.h:343
QString acFullName_
Definition: SgIdentities.h:175
void setExecBinaryName(const QString &)
Definition: SgIdentities.h:399
void setMachineSysName(const QString &)
Definition: SgIdentities.h:423
QString acAbbName_
Definition: SgIdentities.h:177
QString userName_
Definition: SgIdentities.h:171
void setUserName(const QString &)
Definition: SgIdentities.h:335
const QString & getExecDir() const
Definition: SgIdentities.h:263
const QString & getUserName() const
Definition: SgIdentities.h:215
const QString & getMachineSysName() const
Definition: SgIdentities.h:311
void setExecDir(const QString &)
Definition: SgIdentities.h:383
void setDriverVersion(const SgVersion &)
void setTeenyNumber(int)
Definition: SgVersion.h:328
void setCodeName(const QString &)
Definition: SgVersion.h:336
int getMinorNumber() const
Definition: SgVersion.h:270
const SgMJD & getReleaseEpoch() const
Definition: SgVersion.h:294
const QString & getSoftwareName() const
Definition: SgVersion.h:254
void setReleaseEpoch(const SgMJD &)
Definition: SgVersion.h:344
void setMinorNumber(int)
Definition: SgVersion.h:320
int getTeenyNumber() const
Definition: SgVersion.h:278
void setMajorNumber(int)
Definition: SgVersion.h:312
const QString & getCodeName() const
Definition: SgVersion.h:286
void setSoftwareName(const QString &)
Definition: SgVersion.h:304
int getMajorNumber() const
Definition: SgVersion.h:262