File failed to load: https://isis.astrogeology.usgs.gov/9.0.0/Object/assets/jax/output/NativeMML/config.js
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 "Application.h"
29#include "FileName.h"
30#include "IException.h"
31#include "IString.h"
32#include "Message.h"
33#include "Preference.h"
34#include "ProgramLauncher.h"
35#include "Pvl.h"
36#include "PvlGroup.h"
37#include "PvlObject.h"
38#include "SessionLog.h"
39#include "TextFile.h"
40#include "UserInterface.h"
41
42using namespace std;
43
44namespace Isis {
45 Application *iApp = NULL;
46 bool Application::p_applicationForceGuiApp = false;
47
58 Application::Application(int &argc, char *argv[]) {
59 p_ui = NULL;
60 p_connectionToParent = NULL;
61
62 // Save the application name
63 p_appName = argv[0];
64
65 // Get the starting wall clock time
66 // p_datetime = DateTime(&p_startTime);
67
68 // Init
69 p_startClock = 0;
70 p_startDirectIO = 0;
71 p_startPageFaults = 0;
72 p_startProcessSwaps = 0;
73 p_BatchlistPass = 0;
74
75 // try to use US locale for numbers so we don't end up printing "," instead
76 // of "." where it might count.
77 setlocale(LC_ALL, "en_US");
78
79 char env[1024];
80 strncpy(env, "LANG=en_US", 1023);
81 putenv(env);
82
83 // add qt path to 3rdParty so no default is taken from enviroment
84 QString pluginPath = getenv("ISISROOT");
85 pluginPath.append("/3rdParty/lib/");
86 QCoreApplication::addLibraryPath(pluginPath);
87
88 // Get the starting cpu time, direct I/Os, page faults, and swaps
89 //p_startClock = clock();
90 p_startDirectIO = DirectIO();
91 p_startPageFaults = PageFaults();
92 p_startProcessSwaps = ProcessSwaps();
93
94 // Create user interface and log
95 try {
96 FileName f(QString(argv[0]) + ".xml");
97
98 // Create preferences
99 Preference::Preferences(f.name() == "unitTest.xml");
100
101 if (!f.fileExists()) {
102 f = "$ISISROOT/bin/xml/" + f.name();
103 if (!f.fileExists()) {
104 QString message = Message::FileOpen(f.expanded());
105 throw IException(IException::Io, message, _FILEINFO_);
106 }
107 }
108 QString xmlfile = f.expanded();
109
110 p_ui = new UserInterface(xmlfile, argc, argv);
111
112 if (!p_ui->IsInteractive()) {
113 // Get the starting wall clock time
114 p_datetime = DateTime(&p_startTime);
115 m_connectTime.start();
116 p_startClock = clock();
117
118 if (p_applicationForceGuiApp) {
119 new QApplication(argc, argv);
120 // When QApplication is initialized, it will reset the locale to the shells locale. As a result
121 // the locale needs to be reset after QApplications initialization.
122 setlocale(LC_ALL, "en_US");
123 }
124 else {
125 new QCoreApplication(argc, argv);
126 // When QCoreApplication is initialized, it will reset the locale to the shells locale. As a result
127 // the locale needs to be reset after QCoreApplications initialization.
128 setlocale(LC_ALL, "en_US");
129 }
130
131 QCoreApplication::setApplicationName(FileName(p_appName).baseName());
132 }
133 }
134 catch (IException &e) {
135 e.print();
136 exit(e.errorType());
137 }
138
139 iApp = this;
140
141 // If we were run by another Isis app, connect to it
142 if (GetUserInterface().ParentId()) {
143 p_connectionToParent = new QLocalSocket;
144
145 QString serverName = "isis_" + UserName() +
146 "_" + toString(iApp->GetUserInterface().ParentId());
147
148 p_connectionToParent->connectToServer(serverName);
149 if (!p_connectionToParent->waitForConnected()) {
150 delete p_connectionToParent;
151 p_connectionToParent = NULL;
152 }
153 }
154 }
155
158 if (p_ui) {
159 delete p_ui;
160 p_ui = NULL;
161 }
162 }
163
171 int Application::Run(void (*funct)()) {
172 int status = 0;
173 try {
174 if (p_ui->IsInteractive()) {
175 p_ui->TheGui()->Exec(funct);
176 }
177 else {
178 if (p_ui->BatchListSize() > 0) {
179 for (int i = 0; i < p_ui->BatchListSize(); i++) {
180 try {
181 p_ui->SetBatchList(i);
182
183 if (i != 0) {
184 p_datetime = DateTime(&p_startTime);
185 m_connectTime.start();
186 p_startClock = clock();
187 p_startDirectIO = DirectIO();
188 p_startPageFaults = PageFaults();
189 p_startProcessSwaps = ProcessSwaps();
190 SessionLog::TheLog(true);
191 }
192
193 funct();
195 p_BatchlistPass++;
196 }
197 catch (IException &e) {
198 p_ui->SetErrorList(i);
199 status = Application::FunctionError(e);
200 if (p_ui->AbortOnError()) {
201 for (int j = (i + 1); j < p_ui->BatchListSize(); j++) {
202 p_ui->SetErrorList(j);
203 p_BatchlistPass++;
204 }
205 break;
206 }
207 }
208 }
209 }
210 else {
211 p_ui->SaveHistory();
212 // The gui checks everything but not the command line mode so
213 // verify if necessary. Batchlist verifies on SetBatchList
214 p_ui->VerifyAll();
215 funct();
217 }
218 }
219 }
220 catch (IException &e) {
221 status = Application::FunctionError(e);
222 }
223
224#if 0
225 catch (exception &e) {
226 QString message = e.what();
227 Isis::iExceptionSystem i(message, _FILEINFO_);
228 status = i.Report();
229 }
230 catch (...) {
231 QString message = "Unknown error expection";
232 Isis::iExceptionSystem i(message, _FILEINFO_);
233 status = i.Report();
234 }
235#endif
236
237 return status;
238 }
239
246 if (p_ui->IsInteractive()) {
247 p_startClock = clock();
248 p_datetime = DateTime(&p_startTime);
249 m_connectTime.start();
250 //cerr << "History GUI start clock=" << p_startClock << " time=" << p_startTime << endl;
251 }
252 PvlObject history(p_ui->ProgramName());
253 history += PvlKeyword("IsisVersion", Version());
254 history += PvlKeyword("ProgramVersion", p_ui->Version());
255 QString path = QCoreApplication::applicationDirPath();
256 history += PvlKeyword("ProgramPath", path);
257 history += PvlKeyword("ExecutionDateTime", p_datetime);
258 history += PvlKeyword("HostName", HostName());
259 history += PvlKeyword("UserName", UserName());
260 history += PvlKeyword("Description", p_ui->Brief());
261
262 // Add the user parameters
263 Pvl pvl;
264 p_ui->CommandLine(pvl);
265 history.addGroup(pvl.findGroup("UserParameters"));
266
267 return history;
268 }
269//
276 double seconds = m_connectTime.elapsed() / 1000.0;
277 int minutes = (int)(seconds / 60.0);
278 seconds = seconds - minutes * 60.0;
279 int hours = minutes / 60;
280 minutes = minutes - hours * 60;
281 char temp[80];
282 snprintf(temp, sizeof(temp), "%02d:%02d:%04.1f", hours, minutes, seconds);
283 QString conTime = temp;
284
285 //cerr << "Accounting GUI end time=" << endTime << " start time=" << p_startTime << " total=" << seconds << endl;
286
287 // Grab the ending cpu time to compute total cpu time
288 clock_t endClock = clock();
289 seconds = (double(endClock) - (double)p_startClock) / CLOCKS_PER_SEC;
290 minutes = (int)(seconds / 60.0);
291 seconds = seconds - minutes * 60.0;
292 hours = minutes / 60;
293 minutes = minutes - hours * 60;
294 snprintf(temp, sizeof(temp), "%02d:%02d:%04.1f", hours, minutes, seconds);
295 QString cpuTime = temp;
296
297 // Add this information to the log
298 PvlGroup acct("Accounting");
299 acct += PvlKeyword("ConnectTime", conTime);
300 acct += PvlKeyword("CpuTime", cpuTime);
301
302 // Not sure if these are really valuable. If deemed so then
303 // uncomment and complete private methods (DirectIO, Pagefaults, and
304 // ProcessSwaps).
305 //int directIO = DirectIO();
306 //int pageFaults = PageFaults();
307 //int processSwaps = ProcessSwaps();
308 //acct += Isis::PvlKeyword("DirectIo",directIO);
309 //acct += Isis::PvlKeyword("PageFaults",pageFaults);
310 //acct += Isis::PvlKeyword("ProcessSwaps",processSwaps);
311
312 return acct;
313 }
314
321 return 0 - p_startDirectIO;
322 }
323
330 return 0 - p_startPageFaults;
331 }
332
339 return 0 - p_startProcessSwaps;
340 }
341
347 void Application::Log(PvlGroup &results) {
348 // Add it to the log file
349 static bool blankLine = false;
350 if (iApp) {
351 SessionLog::TheLog().AddResults(results);
352 }
353
354 // See if the log file will be written to the terminal/gui
355 // The results group of the Sessoion::Log will be written later
356 // in Application::FunctionCleanup if TerminalOutput is on
357 if (iApp && SessionLog::TheLog().TerminalOutput()) return;
358
359 // See if we should write the info to our parents gui
360 if (iApp && HasParent()) {
361 ostringstream ostr;
362 if (blankLine) ostr << endl;
363 ostr << results << endl;
364 QString data = ostr.str().c_str();
365 iApp->SendParentData("LOG", data);
366 }
367
368 // Otherwise see if we need to write to our gui
369 else if (iApp && iApp->GetUserInterface().IsInteractive()) {
370 ostringstream ostr;
371 if (blankLine) ostr << endl;
372 ostr << results << endl;
373 iApp->GetUserInterface().TheGui()->Log(ostr.str().c_str());
374 iApp->GetUserInterface().TheGui()->ShowLog();
375 }
376
377 // Otherwise its command line mode
378 else {
379 if (blankLine) cout << endl;
380 cout << results << endl;
381 }
382 blankLine = true;
383 }
384
394 Application::Log(results);
395 if (log) {
396 log->addGroup(results);
397 }
398 }
399
405 void Application::GuiLog(const Pvl &results) {
406 // See if we should write the info to our parents gui
407 Pvl copy(results);
408
409 if (HasParent()) {
410 ostringstream ostr;
411 ostr << copy << endl;
412 QString data = ostr.str().c_str();
413 iApp->SendParentData("GUILOG", data);
414 }
415
416 // Otherwise see if we need to write to our gui
417 else if (iApp->GetUserInterface().IsInteractive()) {
418 ostringstream ostr;
419 ostr << copy << endl;
420 iApp->GetUserInterface().TheGui()->Log(ostr.str().c_str());
421 iApp->GetUserInterface().TheGui()->ShowLog();
422 }
423 }
424
430 void Application::GuiLog(const PvlGroup &results) {
431 // See if we should write the info to our parents gui
432 PvlGroup copy(results);
433
434 if (HasParent()) {
435 ostringstream ostr;
436 ostr << copy << endl;
437 QString data = ostr.str().c_str();
438 iApp->SendParentData("GUILOG", data);
439 }
440
441 // Otherwise see if we need to write to our gui
442 else if (iApp->GetUserInterface().IsInteractive()) {
443 ostringstream ostr;
444 ostr << copy << endl;
445 iApp->GetUserInterface().TheGui()->Log(ostr.str().c_str());
446 iApp->GetUserInterface().TheGui()->ShowLog();
447 }
448 }
449
455 void Application::GuiLog(const QString &results) {
456 // See if we should write the info to our parents gui
457 if (HasParent()) {
458 iApp->SendParentData("GUILOG", results);
459 }
460
461 // Otherwise see if we need to write to our gui
462 else if (iApp->GetUserInterface().IsInteractive()) {
463 iApp->GetUserInterface().TheGui()->Log(results);
464 iApp->GetUserInterface().TheGui()->ShowLog();
465 }
466 }
467
474 return *iApp->p_ui;
475 }
476
483 if (iApp == NULL) return false;
484 if (iApp->p_ui == NULL) return false;
485 if (iApp->p_ui->ParentId() == 0) return false;
486 return true;
487 }
488
495 if (!HasParent()) return;
496
497 for (int i = 0; i < errors.groups(); i++) {
498 ostringstream ostr;
499 ostr << errors.group(i) << endl;
500 QString data = ostr.str().c_str();
501 iApp->SendParentData("ERROR", data);
502 }
503 }
504
505
510 void Application::SendParentData(const QString code,
511 const QString &message) {
512 // See if we need to connect to the parent
513 if (p_connectionToParent == NULL) {
514 QString msg = "This process (program) was executed by an existing Isis "
515 "process. However, we failed to establish a communication channel "
516 "with the parent (launcher) process. The parent process has a PID of "
517 "[" + toString(iApp->GetUserInterface().ParentId()) + "]";
518 throw IException(IException::Unknown, msg, _FILEINFO_);
519 }
520
521 // Have connection so build data QString and send it
522 QString data = code;
523 data += char(27);
524 data += message;
525 data += char(27);
526 data += '\n';
527
528 if (p_connectionToParent->write(data.toLatin1().data(), data.toLatin1().size()) == -1) {
529 QString msg = "This process (program) was executed by an exiting Isis "
530 "process. A communication channel was established with the parent "
531 "(launcher) process, but when we tried to send data to the parent "
532 "process an error occurred. The parent process has a PID of [" +
533 QString(iApp->GetUserInterface().ParentId()) + "]";
534 throw IException(IException::Unknown, msg, _FILEINFO_);
535 }
536
537 p_connectionToParent->waitForBytesWritten(-1);
538 }
539
540
547
548 SessionLog::TheLog().Write();
549
550 if (SessionLog::TheLog().TerminalOutput()) {
551 if (HasParent()) {
552 ostringstream ostr;
553 ostr << SessionLog::TheLog() << endl;
554 QString data = ostr.str().c_str();
555 iApp->SendParentData("LOG", data);
556 }
557 else if (p_ui->IsInteractive()) {
558 ostringstream ostr;
559 ostr << SessionLog::TheLog() << endl;
560 p_ui->TheGui()->Log(ostr.str().c_str());
561 p_ui->TheGui()->ShowLog();
562 }
563 else {
564 cout << SessionLog::TheLog() << endl;
565 }
566 }
567
568 // If debugging flag on write debugging log
569 if (p_ui->GetInfoFlag()) {
570 QString filename = p_ui->GetInfoFileName();
571 Pvl log;
572 QString app = (QString)QCoreApplication::applicationDirPath() + "/" + p_appName;
573 if (p_BatchlistPass == 0) {
574 stringstream ss ;
575 ss << SessionLog::TheLog();
576 ss.clear();
577 ss >> log;
578 PvlGroup uname = GetUnameInfo();
580 log.addGroup(uname);
581 log.addGroup(env);
582 }
583
584 // Write to file
585 if (filename.compare("") != 0) {
586
587 if (p_BatchlistPass == 0) {
588 ofstream debugingLog(filename.toLatin1().data());
589 if (!debugingLog.good()) {
590 QString msg = "Error opening debugging log file [" + filename + "]";
591 throw IException(IException::Io, msg, _FILEINFO_);
592 }
593 debugingLog << log << endl;
594 debugingLog << "\n############### User Preferences ################\n" << endl;
595 debugingLog << Preference::Preferences();
596 debugingLog << "\n############## System Disk Space ################\n" << endl;
597 debugingLog << GetSystemDiskSpace() << endl;
598 debugingLog << "\n############ Executable Information #############\n" << endl;
599 debugingLog << GetLibraryDependencies(app) << endl;
600 debugingLog.close();
601 }
602 else {
603 ofstream debugingLog(filename.toLatin1().data(), ios_base::app);
604 debugingLog << SessionLog::TheLog() << endl;
605 debugingLog.close();
606 }
607 }
608 else { // Write to std out
609 if (p_BatchlistPass == 0) {
610 cout << log << endl;
611 cout << "\n############### User Preferences ################\n" << endl;
612 cout << Preference::Preferences();
613 cout << "\n############## System Disk Space ################\n" << endl;
614 cout << GetSystemDiskSpace() << endl;
615 cout << "\n############ Executable Information #############\n" << endl;
616 cout << GetLibraryDependencies(app) << endl;
617 }
618 else {
619 cout << SessionLog::TheLog() << endl;
620 }
621 }
622 }
623
624
625 }
626
637 Pvl errors = e.toPvl();
638 for (int i = 0; i < errors.groups(); i++) {
639 PvlGroup &group = errors.group(i);
640 if (group.isNamed("Error")) {
641 group += PvlKeyword("Program", Application::Name());
642 }
643 }
644 SessionLog::TheLog().AddError(errors);
645 SessionLog::TheLog().Write();
646
647 if (HasParent()) {
648 SendParentErrors(errors);
649 }
650 else if (p_ui->IsInteractive()) {
651 p_ui->TheGui()->LoadMessage(Application::formatError(e));
652 }
653 else if (SessionLog::TheLog().TerminalOutput()) {
654 cerr << SessionLog::TheLog() << endl;
655 }
656 else {
657 cerr << Application::formatError(e) << endl;
658 }
659
660 // If debugging flag on write debugging log
661 if (p_ui->GetInfoFlag()) {
662 QString filename = p_ui->GetInfoFileName();
663 Pvl log;
664 QString app = (QString)QCoreApplication::applicationDirPath() + "/" + p_appName;
665 if (p_BatchlistPass == 0) {
666 stringstream ss ;
667 ss << SessionLog::TheLog();
668 ss.clear();
669 ss >> log;
670 PvlGroup uname = GetUnameInfo();
672 log.addGroup(uname);
673 log.addGroup(env);
674 }
675
676 // Write to file
677 if (filename.compare("") != 0) {
678 if (p_BatchlistPass == 0) {
679 ofstream debugingLog(filename.toLatin1().data());
680 if (!debugingLog.good()) {
681 QString msg = "Error opening debugging log file [" + filename + "]";
682 throw IException(IException::Io, msg, _FILEINFO_);
683 }
684 debugingLog << log << endl;
685 debugingLog << "\n############### User Preferences ################\n" << endl;
686 debugingLog << Preference::Preferences();
687 debugingLog << "\n############ System Disk Space #############\n" << endl;
688 debugingLog << GetSystemDiskSpace() << endl;
689 debugingLog << "\n############ Executable Information #############\n" << endl;
690 debugingLog << GetLibraryDependencies(app) << endl;
691 debugingLog.close();
692 }
693 else {
694 ofstream debugingLog(filename.toLatin1().data(), ios_base::app);
695 debugingLog << SessionLog::TheLog() << endl;
696 debugingLog.close();
697 }
698 }
699 else { // Write to std out
700 if (p_BatchlistPass == 0) {
701 cout << log << endl;
702 cout << "\n############### User Preferences ################\n" << endl;
703 cout << Preference::Preferences();
704 cout << "\n############ System Disk Space #############\n" << endl;
705 cout << GetSystemDiskSpace() << endl;
706 cout << "\n############ Executable Information #############\n" << endl;
707 cout << GetLibraryDependencies(app) << endl;
708 }
709 else {
710 cout << SessionLog::TheLog() << endl;
711 }
712 }
713 }
714
715 return (int)e.errorType();
716 }
717
725 QString errorMessage = Application::formatError(e);
726 if (errorMessage == "") {
727 p_ui->TheGui()->ProgressText("Stopped");
728 }
729 else {
730 p_ui->TheGui()->LoadMessage(errorMessage);
731 p_ui->TheGui()->ProgressText("Error");
732 }
733
734 if (p_ui->TheGui()->ShowWarning())
735 exit(0);
736 }
737
738 QString Application::formatError(IException &e) {
739 stringstream stringStream;
740 QString stringErrors = e.toString(Preference::Preferences().reportFileLine());
741
742 if (Preference::Preferences().outputErrorAsPvl()) {
743 stringStream << stringErrors;
744 Pvl errors;
745 stringStream >> errors;
746 for (int i = 0; i < errors.groups(); i++) {
747 PvlGroup &group = errors.group(i);
748 if (group.isNamed("Error")) {
749 group += PvlKeyword("Program", Application::Name());
750 }
751 }
752 stringStream.str(std::string());
753 stringStream.clear();
754 stringStream << errors;
755 stringErrors = stringStream.str().c_str();
756 }
757
758 return stringErrors;
759 }
760
761 QString Application::p_appName("Unknown");
769 return p_appName;
770 }
771
779 void Application::UpdateProgress(const QString &text, bool print) {
780 if (HasParent() && print) {
781 iApp->SendParentData(QString("PROGRESSTEXT"), text);
782 }
783 else if (p_ui->IsInteractive()) {
784 p_ui->TheGui()->ProgressText(text);
785 }
786 else if (print) {
787 QString msg = p_ui->ProgramName() + ": " + text;
788 cout << msg << endl;
789 }
790
792 }
793
801 void Application::UpdateProgress(int percent, bool print) {
802 if (HasParent() && print) {
803 QString data = toString(percent);
804 iApp->SendParentData(QString("PROGRESS"), data);
805 }
806 else if (p_ui->IsInteractive()) {
807 p_ui->TheGui()->Progress(percent);
808 }
809 else if (print) {
810 if (percent < 100) {
811 cout << percent << "% Processed\r" << flush;
812 }
813 else {
814 cout << percent << "% Processed" << endl;
815 }
816 }
817 }
818
826 if (p_ui->IsInteractive()) {
827 if (p_ui->TheGui()->ProcessEvents()) {
828 throw IException();
829 }
830 }
831 }
832
833
841 QString Application::DateTime(time_t *curtime) {
842 time_t startTime = time(NULL);
843 if (curtime != 0) *curtime = startTime;
844 struct tm *tmbuf = localtime(&startTime);
845 char timestr[80];
846 strftime(timestr, 80, "%Y-%m-%dT%H:%M:%S", tmbuf);
847 return(QString) timestr;
848 }
849
856 return userName();
857 }
858
865 return hostName();
866 }
867
874 return isisVersion();
875 }
876
877
884 // Create a temporary file to store console output to
885 FileName temp = FileName::createTempFile("$temporary/UnameConsoleInfo.txt");
886 QString tempFile = temp.expanded();
887
888 // Uname commands output to temp file with each of the following
889 // values on its own line in this order:
890 // machine hardware name, processor, hardware platform name,
891 // operating system, kernel name, kernel version, kernel release, all
892 PvlGroup unameGroup("UNAME");
893 ifstream readTemp;
894
895#if defined(__linux__)
896 // Write uname outputs to temp file
897 ProgramLauncher::RunSystemCommand("uname -m > " + tempFile);
898 ProgramLauncher::RunSystemCommand("uname -p > " + tempFile);
899 ProgramLauncher::RunSystemCommand("uname -i > " + tempFile);
900 ProgramLauncher::RunSystemCommand("uname -o > " + tempFile);
901 ProgramLauncher::RunSystemCommand("uname -s > " + tempFile);
902 ProgramLauncher::RunSystemCommand("uname -v > " + tempFile);
903 ProgramLauncher::RunSystemCommand("uname -r > " + tempFile);
904 ProgramLauncher::RunSystemCommand("uname -a > " + tempFile);
905 // Read data from temp file
906 char value[256];
907 readTemp.open(tempFile.toLatin1().data(), ifstream::in);
908 readTemp.getline(value, 256);
909 unameGroup.addKeyword(PvlKeyword("MachineHardware", value));
910 readTemp.getline(value, 256);
911 unameGroup.addKeyword(PvlKeyword("Processor", value));
912 readTemp.getline(value, 256);
913 unameGroup.addKeyword(PvlKeyword("HardwarePlatform", value));
914 readTemp.getline(value, 256);
915 unameGroup.addKeyword(PvlKeyword("OperatingSystem", value));
916 readTemp.getline(value, 256);
917 unameGroup.addKeyword(PvlKeyword("KernelName", value));
918 readTemp.getline(value, 256);
919 unameGroup.addKeyword(PvlKeyword("KernelVersion", value));
920 readTemp.getline(value, 256);
921 unameGroup.addKeyword(PvlKeyword("KernelRelease", value));
922 readTemp.getline(value, 256);
923 unameGroup.addKeyword(PvlKeyword("FullUnameString", value));
924
925#elif defined(__APPLE__)
926 // Write uname outputs to temp file
927 ProgramLauncher::RunSystemCommand("uname -m > " + tempFile);
928 ProgramLauncher::RunSystemCommand("uname -p > " + tempFile);
929 ProgramLauncher::RunSystemCommand("uname -s > " + tempFile);
930 ProgramLauncher::RunSystemCommand("uname -v > " + tempFile);
931 ProgramLauncher::RunSystemCommand("uname -r > " + tempFile);
932 ProgramLauncher::RunSystemCommand("uname -a > " + tempFile);
933
934 // Read data from temp file
935 char value[256];
936 readTemp.open(tempFile.toLatin1().data(), ifstream::in);
937 readTemp.getline(value, 256);
938 unameGroup.addKeyword(PvlKeyword("MachineHardware", value));
939 readTemp.getline(value, 256);
940 unameGroup.addKeyword(PvlKeyword("Processor", value));
941 readTemp.getline(value, 256);
942 unameGroup.addKeyword(PvlKeyword("OperatingSystem", value));
943 readTemp.getline(value, 256);
944 unameGroup.addKeyword(PvlKeyword("OperatingSystemVersion", value));
945 readTemp.getline(value, 256);
946 unameGroup.addKeyword(PvlKeyword("OperatingSystemRelease", value));
947 readTemp.getline(value, 256);
948 unameGroup.addKeyword(PvlKeyword("FullUnameString", value));
949#endif
950
951 // remove temp file and return
952 remove(tempFile.toLatin1().data());
953 return unameGroup;
954 }
955
964 // Create a temporary file to store console output to
965 FileName temp = FileName::createTempFile("$temporary/EnviromentInfo.txt");
966 QString tempFile = temp.expanded();
967 PvlGroup envGroup("EnviromentVariables");
968 ifstream readTemp;
969
970 QString env1 = "printenv SHELL >| " + tempFile;
971 QString env2 = "printenv HOME >> " + tempFile;
972 QString env3 = "printenv PWD >> " + tempFile;
973 QString env5 = "printenv ISISROOT >> " + tempFile;
974 QString env6 = "printenv ISISDATA >> " + tempFile;
980 // Read data from temp file
981 char value[511];
982 readTemp.open(tempFile.toLatin1().data(), ifstream::in);
983 readTemp.getline(value, 255);
984 envGroup.addKeyword(PvlKeyword("Shell", value));
985 readTemp.getline(value, 255);
986 envGroup.addKeyword(PvlKeyword("Home", value));
987 readTemp.getline(value, 255);
988 envGroup.addKeyword(PvlKeyword("Pwd", value));
989 readTemp.getline(value, 255);
990 envGroup.addKeyword(PvlKeyword("ISISROOT", value));
991 readTemp.getline(value, 255);
992 envGroup.addKeyword(PvlKeyword("ISISDATA", value));
993
994 // remove temp file and return
995 QString cleanup = "rm -f " + tempFile;
997 return envGroup;
998 }
999
1006 FileName temp = FileName::createTempFile("$temporary/SystemDiskSpace.txt");
1007 QString tempFile = temp.expanded();
1008 ifstream readTemp;
1009 QString diskspace = "df >| " + tempFile;
1011 readTemp.open(tempFile.toLatin1().data(), ifstream::in);
1012
1013 QString results = "";
1014 char tmp[512];
1015 while (!readTemp.eof()) {
1016 readTemp.getline(tmp, 512);
1017 results += tmp;
1018 results += "\n";
1019 }
1020
1021 // remove temp file and return
1022 QString cleanup = "rm -f " + tempFile;
1024 return results;
1025 }
1026
1033 FileName temp = FileName::createTempFile("$temporary/LibraryDependencies.txt");
1034 QString tempFile = temp.expanded();
1035 ifstream readTemp;
1036 QString dependencies = "";
1037#if defined(__linux__)
1038 dependencies = "ldd -v " + file + " >| " + tempFile;
1039#elif defined(__APPLE__)
1040 dependencies = "otool -L " + file + " >| " + tempFile;
1041#elif defined (__sun__)
1042 dependencies = "ldd -v " + file + " >| " + tempFile;
1043#endif
1045 readTemp.open(tempFile.toLatin1().data(), ifstream::in);
1046
1047 QString results = "";
1048 char tmp[512];
1049 while (!readTemp.eof()) {
1050 readTemp.getline(tmp, 512);
1051 results += tmp;
1052 results += "\n";
1053 }
1054
1055 // remove temp file and return
1056 QString cleanup = "rm -f " + tempFile;
1058 return results;
1059 }
1060} //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 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()
Runs some printenv commands that return 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 userName()
@Returns the user name.
File name manipulation and expansion.
Definition FileName.h:100
bool fileExists() const
Returns true if the file exists; false otherwise.
Definition FileName.cpp:449
QString name() const
Returns the name of the file excluding the path and the attributes in the file name.
Definition FileName.cpp:162
QString expanded() const
Returns a QString of the full file name including the file path, excluding the attributes.
Definition FileName.cpp:196
static FileName createTempFile(FileName templateFileName="$TEMPORARY/temp")
Creates a temporary file and returns a FileName object created using the temporary file.
Definition FileName.cpp:478
Isis exception class.
Definition IException.h:91
@ Unknown
A type of error that cannot be classified as any of the other error types.
Definition IException.h:118
@ Io
A type of error that occurred when performing an actual I/O operation.
Definition IException.h:155
const char * what() const
Returns a string representation of this exception in its current state.
ErrorType errorType() const
Returns the source of the error for this exception.
QString toString() const
Returns a string representation of this exception.
void print() const
Prints a string representation of this exception to stderr.
Pvl toPvl() const
Returns a PVL object representing the contents of this exception.
static void RunSystemCommand(QString commandLine)
This runs arbitrary system commands.
bool isNamed(const QString &match) const
Returns whether the given string is equal to the container name or not.
void addKeyword(const PvlKeyword &keyword, const InsertMode mode=Append)
Add a keyword to the container.
Contains multiple PvlContainers.
Definition PvlGroup.h:41
Container for cube-like labels.
Definition Pvl.h:119
A single keyword-value pair.
Definition PvlKeyword.h:87
Contains Pvl Groups and Pvl Objects.
Definition PvlObject.h:61
PvlGroup & group(const int index)
Return the group at the specified index.
int groups() const
Returns the number of groups contained.
Definition PvlObject.h:75
void clear()
Remove everything from the current PvlObject.
Definition PvlObject.h:341
void addGroup(const Isis::PvlGroup &group)
Add a group to the object.
Definition PvlObject.h:186
PvlGroupIterator findGroup(const QString &name, PvlGroupIterator beg, PvlGroupIterator end)
Find a group with the specified name, within these indexes.
Definition PvlObject.h:129
Command Line and Xml loader, validation, and access.
QString FileOpen(const QString &filename)
This error should be used when a file could not be opened.
Definition FileOpen.cpp:11
This is free and unencumbered software released into the public domain.
Definition Apollo.h:16
QString toString(bool boolToConvert)
Global function to convert a boolean to a string.
Definition IString.cpp:211
Namespace for the standard library.