Official websites use .gov
A .gov website belongs to an official government organization in the United States.

Secure .gov websites use HTTPS
A lock ( ) or https:// means you’ve safely connected to the .gov website. Share sensitive information only on official, secure websites.

Isis 3 Programmer Reference
Application.cpp
1
5
6/* SPDX-License-Identifier: CC0-1.0 */
7
8#include <cstdio>
9#include <sstream>
10#include <unistd.h>
11#include <sys/wait.h>
12#include <errno.h>
13
14extern int errno;
15
16#include <fstream>
17
18#include <iostream>
19#include <sstream>
20#include <locale.h>
21
22#include <QApplication>
23#include <QCoreApplication>
24#include <QLocalSocket>
25#include <QString>
26#include <QTime>
27
28#include "gdal_priv.h"
29
30#include "Application.h"
31#include "FileName.h"
32#include "IException.h"
33#include "IString.h"
34#include "Message.h"
35#include "Preference.h"
36#include "ProgramLauncher.h"
37#include "Pvl.h"
38#include "PvlGroup.h"
39#include "PvlObject.h"
40#include "SessionLog.h"
41#include "TextFile.h"
42#include "UserInterface.h"
43
44using namespace std;
45
46namespace Isis {
47 Application *iApp = NULL;
48 bool Application::p_applicationForceGuiApp = false;
49
60 Application::Application(int &argc, char *argv[]) {
61 p_ui = NULL;
62 p_connectionToParent = NULL;
63
64 // Save the application name
65 p_appName = argv[0];
66
67 // Get the starting wall clock time
68 // p_datetime = DateTime(&p_startTime);
69
70 // Init
71 p_startClock = 0;
72 p_startDirectIO = 0;
73 p_startPageFaults = 0;
74 p_startProcessSwaps = 0;
75 p_BatchlistPass = 0;
76
77 // try to use US locale for numbers so we don't end up printing "," instead
78 // of "." where it might count.
79 setlocale(LC_ALL, "en_US.UTF-8");
80
81 char env[1024];
82 strncpy(env, "LANG=en_US.UTF-8", 1023);
83 putenv(env);
84
85 // add qt path to 3rdParty so no default is taken from enviroment
86 QString pluginPath = getenv("ISISROOT");
87 pluginPath.append("/3rdParty/lib/");
88 QCoreApplication::addLibraryPath(pluginPath);
89
90 // Get the starting cpu time, direct I/Os, page faults, and swaps
91 //p_startClock = clock();
92 p_startDirectIO = DirectIO();
93 p_startPageFaults = PageFaults();
94 p_startProcessSwaps = ProcessSwaps();
95
96 // Setup gdal drivers and error handler
97 try {
98 GDALAllRegister();
99 CPLSetErrorHandler(CPLQuietErrorHandler);
100 }
101 catch(exception &e) {
102 QString msg = "Failed to load GDAL Drivers, with error [" + QString(e.what()) + "]";
103 throw IException(IException::Unknown, msg, _FILEINFO_);
104 }
105
106 // Create user interface and log
107 try {
108 FileName f(QString(argv[0]) + ".xml");
109
110 // Create preferences
111 Preference::Preferences(f.name() == "unitTest.xml");
112
113 if (!f.fileExists()) {
114 f = "$ISISROOT/bin/xml/" + f.name();
115 if (!f.fileExists()) {
116 QString message = Message::FileOpen(f.expanded());
117 throw IException(IException::Io, message, _FILEINFO_);
118 }
119 }
120 QString xmlfile = f.expanded();
121
122 p_ui = new UserInterface(xmlfile, argc, argv);
123
124 if (!p_ui->IsInteractive()) {
125 // Get the starting wall clock time
126 p_datetime = DateTime(&p_startTime);
127 m_connectTime.start();
128 p_startClock = clock();
129
130 if (p_applicationForceGuiApp) {
131 new QApplication(argc, argv);
132 // When QApplication is initialized, it will reset the locale to the shells locale. As a result
133 // the locale needs to be reset after QApplications initialization.
134 setlocale(LC_ALL, "en_US.UTF-8");
135 }
136 else {
137 new QCoreApplication(argc, argv);
138 // When QCoreApplication is initialized, it will reset the locale to the shells locale. As a result
139 // the locale needs to be reset after QCoreApplications initialization.
140 setlocale(LC_ALL, "en_US.UTF-8");
141 }
142
143 QCoreApplication::setApplicationName(FileName(p_appName).baseName());
144 }
145 }
146 catch (IException &e) {
147 e.print();
148 exit(e.errorType());
149 }
150
151 iApp = this;
152
153 // If we were run by another Isis app, connect to it
154 if (GetUserInterface().ParentId()) {
155 p_connectionToParent = new QLocalSocket;
156
157 QString serverName = "isis_" + UserName() +
158 "_" + toString(iApp->GetUserInterface().ParentId());
159
160 p_connectionToParent->connectToServer(serverName);
161 if (!p_connectionToParent->waitForConnected()) {
162 delete p_connectionToParent;
163 p_connectionToParent = NULL;
164 }
165 }
166 }
167
170 if (p_ui) {
171 delete p_ui;
172 p_ui = NULL;
173 }
174 }
175
183 int Application::Run(void (*funct)()) {
184 int status = 0;
185 try {
186 if (p_ui->IsInteractive()) {
187 p_ui->TheGui()->Exec(funct);
188 }
189 else {
190 if (p_ui->BatchListSize() > 0) {
191 for (int i = 0; i < p_ui->BatchListSize(); i++) {
192 try {
193 p_ui->SetBatchList(i);
194
195 if (i != 0) {
196 p_datetime = DateTime(&p_startTime);
197 m_connectTime.start();
198 p_startClock = clock();
199 p_startDirectIO = DirectIO();
200 p_startPageFaults = PageFaults();
201 p_startProcessSwaps = ProcessSwaps();
202 SessionLog::TheLog(true);
203 }
204
205 funct();
207 p_BatchlistPass++;
208 }
209 catch (IException &e) {
210 p_ui->SetErrorList(i);
211 status = Application::FunctionError(e);
212 if (p_ui->AbortOnError()) {
213 for (int j = (i + 1); j < p_ui->BatchListSize(); j++) {
214 p_ui->SetErrorList(j);
215 p_BatchlistPass++;
216 }
217 break;
218 }
219 }
220 }
221 }
222 else {
223 p_ui->SaveHistory();
224 // The gui checks everything but not the command line mode so
225 // verify if necessary. Batchlist verifies on SetBatchList
226 p_ui->VerifyAll();
227 funct();
229 }
230 }
231 }
232 catch (IException &e) {
233 status = Application::FunctionError(e);
234 }
235
236#if 0
237 catch (exception &e) {
238 QString message = e.what();
239 Isis::iExceptionSystem i(message, _FILEINFO_);
240 status = i.Report();
241 }
242 catch (...) {
243 QString message = "Unknown error expection";
244 Isis::iExceptionSystem i(message, _FILEINFO_);
245 status = i.Report();
246 }
247#endif
248
249 return status;
250 }
251
258 if (p_ui->IsInteractive()) {
259 p_startClock = clock();
260 p_datetime = DateTime(&p_startTime);
261 m_connectTime.start();
262 //cerr << "History GUI start clock=" << p_startClock << " time=" << p_startTime << endl;
263 }
264 PvlObject history(p_ui->ProgramName());
265 history += PvlKeyword("IsisVersion", Version());
266 history += PvlKeyword("AleVersion", AleVersion());
267 history += PvlKeyword("ProgramVersion", p_ui->Version());
268 QString path = QCoreApplication::applicationDirPath();
269 history += PvlKeyword("ProgramPath", path);
270 history += PvlKeyword("ExecutionDateTime", p_datetime);
271 history += PvlKeyword("HostName", HostName());
272 history += PvlKeyword("UserName", UserName());
273 history += PvlKeyword("Description", p_ui->Brief());
274
275 // Add the user parameters
276 Pvl pvl;
277 p_ui->CommandLine(pvl);
278 history.addGroup(pvl.findGroup("UserParameters"));
279
280 return history;
281 }
282//
289 double seconds = m_connectTime.elapsed() / 1000.0;
290 int minutes = (int)(seconds / 60.0);
291 seconds = seconds - minutes * 60.0;
292 int hours = minutes / 60;
293 minutes = minutes - hours * 60;
294 char temp[80];
295 snprintf(temp, sizeof(temp), "%02d:%02d:%04.1f", hours, minutes, seconds);
296 QString conTime = temp;
297
298 //cerr << "Accounting GUI end time=" << endTime << " start time=" << p_startTime << " total=" << seconds << endl;
299
300 // Grab the ending cpu time to compute total cpu time
301 clock_t endClock = clock();
302 seconds = (double(endClock) - (double)p_startClock) / CLOCKS_PER_SEC;
303 minutes = (int)(seconds / 60.0);
304 seconds = seconds - minutes * 60.0;
305 hours = minutes / 60;
306 minutes = minutes - hours * 60;
307 snprintf(temp, sizeof(temp), "%02d:%02d:%04.1f", hours, minutes, seconds);
308 QString cpuTime = temp;
309
310 // Add this information to the log
311 PvlGroup acct("Accounting");
312 acct += PvlKeyword("ConnectTime", conTime);
313 acct += PvlKeyword("CpuTime", cpuTime);
314
315 // Not sure if these are really valuable. If deemed so then
316 // uncomment and complete private methods (DirectIO, Pagefaults, and
317 // ProcessSwaps).
318 //int directIO = DirectIO();
319 //int pageFaults = PageFaults();
320 //int processSwaps = ProcessSwaps();
321 //acct += Isis::PvlKeyword("DirectIo",directIO);
322 //acct += Isis::PvlKeyword("PageFaults",pageFaults);
323 //acct += Isis::PvlKeyword("ProcessSwaps",processSwaps);
324
325 return acct;
326 }
327
334 return 0 - p_startDirectIO;
335 }
336
343 return 0 - p_startPageFaults;
344 }
345
352 return 0 - p_startProcessSwaps;
353 }
354
360 void Application::Log(PvlGroup &results) {
361 // Add it to the log file
362 static bool blankLine = false;
363 if (iApp) {
364 SessionLog::TheLog().AddResults(results);
365 }
366
367 // See if the log file will be written to the terminal/gui
368 // The results group of the Sessoion::Log will be written later
369 // in Application::FunctionCleanup if TerminalOutput is on
370 if (iApp && SessionLog::TheLog().TerminalOutput()) return;
371
372 // See if we should write the info to our parents gui
373 if (iApp && HasParent()) {
374 ostringstream ostr;
375 if (blankLine) ostr << endl;
376 ostr << results << endl;
377 QString data = ostr.str().c_str();
378 iApp->SendParentData("LOG", data);
379 }
380
381 // Otherwise see if we need to write to our gui
382 else if (iApp && iApp->GetUserInterface().IsInteractive()) {
383 ostringstream ostr;
384 if (blankLine) ostr << endl;
385 ostr << results << endl;
386 iApp->GetUserInterface().TheGui()->Log(ostr.str().c_str());
387 iApp->GetUserInterface().TheGui()->ShowLog();
388 }
389
390 // Otherwise its command line mode
391 else {
392 if (blankLine) cout << endl;
393 cout << results << endl;
394 }
395 blankLine = true;
396 }
397
406 void Application::AppendAndLog(PvlGroup &results, Pvl *log) {
407 Application::Log(results);
408 if (log) {
409 log->addGroup(results);
410 }
411 }
412
418 void Application::GuiLog(const Pvl &results) {
419 // See if we should write the info to our parents gui
420 Pvl copy(results);
421
422 if (HasParent()) {
423 ostringstream ostr;
424 ostr << copy << endl;
425 QString data = ostr.str().c_str();
426 iApp->SendParentData("GUILOG", data);
427 }
428
429 // Otherwise see if we need to write to our gui
430 else if (iApp->GetUserInterface().IsInteractive()) {
431 ostringstream ostr;
432 ostr << copy << endl;
433 iApp->GetUserInterface().TheGui()->Log(ostr.str().c_str());
434 iApp->GetUserInterface().TheGui()->ShowLog();
435 }
436 }
437
443 void Application::GuiLog(const PvlGroup &results) {
444 // See if we should write the info to our parents gui
445 PvlGroup copy(results);
446
447 if (HasParent()) {
448 ostringstream ostr;
449 ostr << copy << endl;
450 QString data = ostr.str().c_str();
451 iApp->SendParentData("GUILOG", data);
452 }
453
454 // Otherwise see if we need to write to our gui
455 else if (iApp->GetUserInterface().IsInteractive()) {
456 ostringstream ostr;
457 ostr << copy << endl;
458 iApp->GetUserInterface().TheGui()->Log(ostr.str().c_str());
459 iApp->GetUserInterface().TheGui()->ShowLog();
460 }
461 }
462
468 void Application::GuiLog(const QString &results) {
469 // See if we should write the info to our parents gui
470 if (HasParent()) {
471 iApp->SendParentData("GUILOG", results);
472 }
473
474 // Otherwise see if we need to write to our gui
475 else if (iApp->GetUserInterface().IsInteractive()) {
476 iApp->GetUserInterface().TheGui()->Log(results);
477 iApp->GetUserInterface().TheGui()->ShowLog();
478 }
479 }
480
487 return *iApp->p_ui;
488 }
489
496 if (iApp == NULL) return false;
497 if (iApp->p_ui == NULL) return false;
498 if (iApp->p_ui->ParentId() == 0) return false;
499 return true;
500 }
501
507 void Application::SendParentErrors(Isis::PvlObject &errors) {
508 if (!HasParent()) return;
509
510 for (int i = 0; i < errors.groups(); i++) {
511 ostringstream ostr;
512 ostr << errors.group(i) << endl;
513 QString data = ostr.str().c_str();
514 iApp->SendParentData("ERROR", data);
515 }
516 }
517
518
523 void Application::SendParentData(const QString code,
524 const QString &message) {
525 // See if we need to connect to the parent
526 if (p_connectionToParent == NULL) {
527 QString msg = "This process (program) was executed by an existing Isis "
528 "process. However, we failed to establish a communication channel "
529 "with the parent (launcher) process. The parent process has a PID of "
530 "[" + toString(iApp->GetUserInterface().ParentId()) + "]";
531 throw IException(IException::Unknown, msg, _FILEINFO_);
532 }
533
534 // Have connection so build data QString and send it
535 QString data = code;
536 data += char(27);
537 data += message;
538 data += char(27);
539 data += '\n';
540
541 if (p_connectionToParent->write(data.toLatin1().data(), data.toLatin1().size()) == -1) {
542 QString msg = "This process (program) was executed by an exiting Isis "
543 "process. A communication channel was established with the parent "
544 "(launcher) process, but when we tried to send data to the parent "
545 "process an error occurred. The parent process has a PID of [" +
546 QString::number(iApp->GetUserInterface().ParentId()) + "]";
547 throw IException(IException::Unknown, msg, _FILEINFO_);
548 }
549
550 p_connectionToParent->waitForBytesWritten(-1);
551 }
552
553
560
561 SessionLog::TheLog().Write();
562
563 if (SessionLog::TheLog().TerminalOutput()) {
564 if (HasParent()) {
565 ostringstream ostr;
566 ostr << SessionLog::TheLog() << endl;
567 QString data = ostr.str().c_str();
568 iApp->SendParentData("LOG", data);
569 }
570 else if (p_ui->IsInteractive()) {
571 ostringstream ostr;
572 ostr << SessionLog::TheLog() << endl;
573 p_ui->TheGui()->Log(ostr.str().c_str());
574 p_ui->TheGui()->ShowLog();
575 }
576 else {
577 cout << SessionLog::TheLog() << endl;
578 }
579 }
580
581 // If debugging flag on write debugging log
582 if (p_ui->GetInfoFlag()) {
583 QString filename = p_ui->GetInfoFileName();
584 Pvl log;
585 QString app = (QString)QCoreApplication::applicationDirPath() + "/" + p_appName;
586 if (p_BatchlistPass == 0) {
587 stringstream ss ;
588 ss << SessionLog::TheLog();
589 ss.clear();
590 ss >> log;
591 PvlGroup uname = GetUnameInfo();
592 PvlGroup env = GetEnviromentInfo();
593 log.addGroup(uname);
594 log.addGroup(env);
595 }
596
597 // Write to file
598 if (filename.compare("") != 0) {
599
600 if (p_BatchlistPass == 0) {
601 ofstream debugingLog(filename.toLatin1().data());
602 if (!debugingLog.good()) {
603 QString msg = "Error opening debugging log file [" + filename + "]";
604 throw IException(IException::Io, msg, _FILEINFO_);
605 }
606 debugingLog << log << endl;
607 debugingLog << "\n############### User Preferences ################\n" << endl;
608 debugingLog << Preference::Preferences();
609 debugingLog << "\n############## System Disk Space ################\n" << endl;
610 debugingLog << GetSystemDiskSpace() << endl;
611 debugingLog << "\n############ Executable Information #############\n" << endl;
612 debugingLog << GetLibraryDependencies(app) << endl;
613 debugingLog.close();
614 }
615 else {
616 ofstream debugingLog(filename.toLatin1().data(), ios_base::app);
617 debugingLog << SessionLog::TheLog() << endl;
618 debugingLog.close();
619 }
620 }
621 else { // Write to std out
622 if (p_BatchlistPass == 0) {
623 cout << log << endl;
624 cout << "\n############### User Preferences ################\n" << endl;
625 cout << Preference::Preferences();
626 cout << "\n############## System Disk Space ################\n" << endl;
627 cout << GetSystemDiskSpace() << endl;
628 cout << "\n############ Executable Information #############\n" << endl;
629 cout << GetLibraryDependencies(app) << endl;
630 }
631 else {
632 cout << SessionLog::TheLog() << endl;
633 }
634 }
635 }
636
637
638 }
639
649 int Application::FunctionError(IException &e) {
650 Pvl errors = e.toPvl();
651 for (int i = 0; i < errors.groups(); i++) {
652 PvlGroup &group = errors.group(i);
653 if (group.isNamed("Error")) {
654 group += PvlKeyword("Program", Application::Name());
655 }
656 }
657 SessionLog::TheLog().AddError(errors);
658 SessionLog::TheLog().Write();
659
660 if (HasParent()) {
661 SendParentErrors(errors);
662 }
663 else if (p_ui->IsInteractive()) {
664 p_ui->TheGui()->LoadMessage(Application::formatError(e));
665 }
666 else if (SessionLog::TheLog().TerminalOutput()) {
667 cerr << SessionLog::TheLog() << endl;
668 }
669 else {
670 cerr << Application::formatError(e) << endl;
671 }
672
673 // If debugging flag on write debugging log
674 if (p_ui->GetInfoFlag()) {
675 QString filename = p_ui->GetInfoFileName();
676 Pvl log;
677 QString app = (QString)QCoreApplication::applicationDirPath() + "/" + p_appName;
678 if (p_BatchlistPass == 0) {
679 stringstream ss ;
680 ss << SessionLog::TheLog();
681 ss.clear();
682 ss >> log;
683 PvlGroup uname = GetUnameInfo();
684 PvlGroup env = GetEnviromentInfo();
685 log.addGroup(uname);
686 log.addGroup(env);
687 }
688
689 // Write to file
690 if (filename.compare("") != 0) {
691 if (p_BatchlistPass == 0) {
692 ofstream debugingLog(filename.toLatin1().data());
693 if (!debugingLog.good()) {
694 QString msg = "Error opening debugging log file [" + filename + "]";
695 throw IException(IException::Io, msg, _FILEINFO_);
696 }
697 debugingLog << log << endl;
698 debugingLog << "\n############### User Preferences ################\n" << endl;
699 debugingLog << Preference::Preferences();
700 debugingLog << "\n############ System Disk Space #############\n" << endl;
701 debugingLog << GetSystemDiskSpace() << endl;
702 debugingLog << "\n############ Executable Information #############\n" << endl;
703 debugingLog << GetLibraryDependencies(app) << endl;
704 debugingLog.close();
705 }
706 else {
707 ofstream debugingLog(filename.toLatin1().data(), ios_base::app);
708 debugingLog << SessionLog::TheLog() << endl;
709 debugingLog.close();
710 }
711 }
712 else { // Write to std out
713 if (p_BatchlistPass == 0) {
714 cout << log << endl;
715 cout << "\n############### User Preferences ################\n" << endl;
716 cout << Preference::Preferences();
717 cout << "\n############ System Disk Space #############\n" << endl;
718 cout << GetSystemDiskSpace() << endl;
719 cout << "\n############ Executable Information #############\n" << endl;
720 cout << GetLibraryDependencies(app) << endl;
721 }
722 else {
723 cout << SessionLog::TheLog() << endl;
724 }
725 }
726 }
727
728 return (int)e.errorType();
729 }
730
737 void Application::GuiReportError(IException &e) {
738 QString errorMessage = Application::formatError(e);
739 if (errorMessage == "") {
740 p_ui->TheGui()->ProgressText("Stopped");
741 }
742 else {
743 p_ui->TheGui()->LoadMessage(errorMessage);
744 p_ui->TheGui()->ProgressText("Error");
745 }
746
747 if (p_ui->TheGui()->ShowWarning())
748 exit(0);
749 }
750
751 QString Application::formatError(IException &e) {
752 stringstream stringStream;
753 QString stringErrors = e.toString(Preference::Preferences().reportFileLine());
754
755 if (Preference::Preferences().outputErrorAsPvl()) {
756 stringStream << stringErrors;
757 Pvl errors;
758 stringStream >> errors;
759 for (int i = 0; i < errors.groups(); i++) {
760 PvlGroup &group = errors.group(i);
761 if (group.isNamed("Error")) {
762 group += PvlKeyword("Program", Application::Name());
763 }
764 }
765 stringStream.str(std::string());
766 stringStream.clear();
767 stringStream << errors;
768 stringErrors = stringStream.str().c_str();
769 }
770
771 return stringErrors;
772 }
773
774 QString Application::p_appName("Unknown");
782 return p_appName;
783 }
784
792 void Application::UpdateProgress(const QString &text, bool print) {
793 if (HasParent() && print) {
794 iApp->SendParentData(QString("PROGRESSTEXT"), text);
795 }
796 else if (p_ui->IsInteractive()) {
797 p_ui->TheGui()->ProgressText(text);
798 }
799 else if (print) {
800 QString msg = p_ui->ProgramName() + ": " + text;
801 cout << msg << endl;
802 }
803
805 }
806
814 void Application::UpdateProgress(int percent, bool print) {
815 if (HasParent() && print) {
816 QString data = toString(percent);
817 iApp->SendParentData(QString("PROGRESS"), data);
818 }
819 else if (p_ui->IsInteractive()) {
820 p_ui->TheGui()->Progress(percent);
821 }
822 else if (print) {
823 if (percent < 100) {
824 cout << percent << "% Processed\r" << flush;
825 }
826 else {
827 cout << percent << "% Processed" << endl;
828 }
829 }
830 }
831
839 if (p_ui->IsInteractive()) {
840 if (p_ui->TheGui()->ProcessEvents()) {
841 throw IException();
842 }
843 }
844 }
845
846
854 QString Application::DateTime(time_t *curtime) {
855 time_t startTime = time(NULL);
856 if (curtime != 0) *curtime = startTime;
857 struct tm *tmbuf = localtime(&startTime);
858 char timestr[80];
859 strftime(timestr, 80, "%Y-%m-%dT%H:%M:%S", tmbuf);
860 return(QString) timestr;
861 }
862
869 return userName();
870 }
871
878 return hostName();
879 }
880
887 return isisVersion();
888 }
889
896 return aleVersion();
897 }
898
899
906 // Create a temporary file to store console output to
907 FileName temp = FileName::createTempFile("$temporary/UnameConsoleInfo.txt");
908 QString tempFile = temp.expanded();
909
910 // Uname commands output to temp file with each of the following
911 // values on its own line in this order:
912 // machine hardware name, processor, hardware platform name,
913 // operating system, kernel name, kernel version, kernel release, all
914 PvlGroup unameGroup("UNAME");
915 ifstream readTemp;
916
917#if defined(__linux__)
918 // Write uname outputs to temp file
919 ProgramLauncher::RunSystemCommand("uname -m > " + tempFile);
920 ProgramLauncher::RunSystemCommand("uname -p > " + tempFile);
921 ProgramLauncher::RunSystemCommand("uname -i > " + tempFile);
922 ProgramLauncher::RunSystemCommand("uname -o > " + tempFile);
923 ProgramLauncher::RunSystemCommand("uname -s > " + tempFile);
924 ProgramLauncher::RunSystemCommand("uname -v > " + tempFile);
925 ProgramLauncher::RunSystemCommand("uname -r > " + tempFile);
926 ProgramLauncher::RunSystemCommand("uname -a > " + tempFile);
927 // Read data from temp file
928 char value[256];
929 readTemp.open(tempFile.toLatin1().data(), ifstream::in);
930 readTemp.getline(value, 256);
931 unameGroup.addKeyword(PvlKeyword("MachineHardware", value));
932 readTemp.getline(value, 256);
933 unameGroup.addKeyword(PvlKeyword("Processor", value));
934 readTemp.getline(value, 256);
935 unameGroup.addKeyword(PvlKeyword("HardwarePlatform", value));
936 readTemp.getline(value, 256);
937 unameGroup.addKeyword(PvlKeyword("OperatingSystem", value));
938 readTemp.getline(value, 256);
939 unameGroup.addKeyword(PvlKeyword("KernelName", value));
940 readTemp.getline(value, 256);
941 unameGroup.addKeyword(PvlKeyword("KernelVersion", value));
942 readTemp.getline(value, 256);
943 unameGroup.addKeyword(PvlKeyword("KernelRelease", value));
944 readTemp.getline(value, 256);
945 unameGroup.addKeyword(PvlKeyword("FullUnameString", value));
946
947#elif defined(__APPLE__)
948 // Write uname outputs to temp file
949 ProgramLauncher::RunSystemCommand("uname -m > " + tempFile);
950 ProgramLauncher::RunSystemCommand("uname -p > " + tempFile);
951 ProgramLauncher::RunSystemCommand("uname -s > " + tempFile);
952 ProgramLauncher::RunSystemCommand("uname -v > " + tempFile);
953 ProgramLauncher::RunSystemCommand("uname -r > " + tempFile);
954 ProgramLauncher::RunSystemCommand("uname -a > " + tempFile);
955
956 // Read data from temp file
957 char value[256];
958 readTemp.open(tempFile.toLatin1().data(), ifstream::in);
959 readTemp.getline(value, 256);
960 unameGroup.addKeyword(PvlKeyword("MachineHardware", value));
961 readTemp.getline(value, 256);
962 unameGroup.addKeyword(PvlKeyword("Processor", value));
963 readTemp.getline(value, 256);
964 unameGroup.addKeyword(PvlKeyword("OperatingSystem", value));
965 readTemp.getline(value, 256);
966 unameGroup.addKeyword(PvlKeyword("OperatingSystemVersion", value));
967 readTemp.getline(value, 256);
968 unameGroup.addKeyword(PvlKeyword("OperatingSystemRelease", value));
969 readTemp.getline(value, 256);
970 unameGroup.addKeyword(PvlKeyword("FullUnameString", value));
971#endif
972
973 // remove temp file and return
974 remove(tempFile.toLatin1().data());
975 return unameGroup;
976 }
977
984
985 PvlGroup envGroup("EnviromentVariables");
986
987 envGroup.addKeyword(PvlKeyword("Shell", getenv("SHELL")));
988 envGroup.addKeyword(PvlKeyword("Home", getenv("HOME")));
989 envGroup.addKeyword(PvlKeyword("PWD", getenv("PWD")));
990 envGroup.addKeyword(PvlKeyword("ISISROOT", getenv("ISISROOT")));
991 envGroup.addKeyword(PvlKeyword("ISISDATA", getenv("ISISDATA")));
992 envGroup.addKeyword(PvlKeyword("SPICEQL_CACHE_DIR", getenv("SPICEQL_CACHE_DIR")));
993
994 return envGroup;
995 }
996
1003 FileName temp = FileName::createTempFile("$temporary/SystemDiskSpace.txt");
1004 QString tempFile = temp.expanded();
1005 ifstream readTemp;
1006 QString diskspace = "df >| " + tempFile;
1008 readTemp.open(tempFile.toLatin1().data(), ifstream::in);
1009
1010 QString results = "";
1011 char tmp[512];
1012 while (!readTemp.eof()) {
1013 readTemp.getline(tmp, 512);
1014 results += tmp;
1015 results += "\n";
1016 }
1017
1018 // remove temp file and return
1019 QString cleanup = "rm -f " + tempFile;
1021 return results;
1022 }
1023
1030 FileName temp = FileName::createTempFile("$temporary/LibraryDependencies.txt");
1031 QString tempFile = temp.expanded();
1032 ifstream readTemp;
1033 QString dependencies = "";
1034#if defined(__linux__)
1035 dependencies = "ldd -v " + file + " >| " + tempFile;
1036#elif defined(__APPLE__)
1037 dependencies = "otool -L " + file + " >| " + tempFile;
1038#elif defined (__sun__)
1039 dependencies = "ldd -v " + file + " >| " + tempFile;
1040#endif
1042 readTemp.open(tempFile.toLatin1().data(), ifstream::in);
1043
1044 QString results = "";
1045 char tmp[512];
1046 while (!readTemp.eof()) {
1047 readTemp.getline(tmp, 512);
1048 results += tmp;
1049 results += "\n";
1050 }
1051
1052 // remove temp file and return
1053 QString cleanup = "rm -f " + tempFile;
1055 return results;
1056 }
1057} //end namespace isis
int Run(void(*funct)())
Runs the program defined in the function funct.
static QString DateTime(time_t *curtime=0)
Returns the date and time as a QString.
PvlObject History()
Creates an application history PvlObject.
void FunctionCleanup()
Cleans up after the function by writing the log, saving the history, and either sending the log to th...
static void Log(PvlGroup &results)
Writes Pvl results to sessionlog and printfile.
PvlGroup Accounting()
Creates accounting PvlGroup.
void SendParentData(QString, const QString &)
static QString AleVersion()
The Ale Version for this application.
static void GuiLog(const Pvl &results)
Writes the Pvl results to the sessionlog, but not to the printfile.
static QString HostName()
Returns the host name.
void GuiReportError(IException &e)
Loads the error message into the gui, but does not write it to the session log.
int DirectIO()
Returns the current number of I/O's.
QElapsedTimer m_connectTime
Used to calculate program's run time.
static QString Version()
The Isis Version for this application.
static QString Name()
Returns the name of the application.
int PageFaults()
Returns the current number of faults.
static void AppendAndLog(PvlGroup &results, Pvl *log)
Writes the pvl group results to both a passed in Pvl log and the applications log (either GUI or comm...
void ProcessGuiEvents()
Processes the gui events.
int ProcessSwaps()
Returns the current number of swaps.
static QString GetLibraryDependencies(QString file)
Runs ldd on linux and sun and otool on macs to get information about the applicaiton run.
static bool HasParent()
Returns whether the application has a parent or not.
static QString GetSystemDiskSpace()
Runs df to see the disk space availability.
void UpdateProgress(const QString &text, bool print)
Updates the progress bar in the gui.
void SendParentErrors(PvlObject &errors)
Sends errors to the parent.
UserInterface * p_ui
Pointer to a User Interface object.
static PvlGroup GetEnviromentInfo()
Returns ISIS-related Enviroment Variables.
static QString UserName()
Returns the user name.
static UserInterface & GetUserInterface()
Returns the UserInterface object.
Application(int &argc, char *argv[])
Constuctor for the Application object.
int FunctionError(IException &e)
Adds the error to the session log, sends the error to the parent if it has one, loads the error messa...
~Application()
Destroys the Application object.
static PvlGroup GetUnameInfo()
Runs various system specific uname commands and returns the results.
static QString isisVersion()
static QString hostName()
static QString aleVersion()
static QString userName()
@Returns the user name.
static void RunSystemCommand(QString commandLine)
This runs arbitrary system commands.
Command Line and Xml loader, validation, and access.
This is free and unencumbered software released into the public domain.
Definition Apollo.h:16
QString toString(const LinearAlgebra::Vector &vector, int precision)
A global function to format LinearAlgebra::Vector as a QString with the given precision.
Namespace for the standard library.