d396843aba50798140df604e71e0746ef0727b5e
[pierogi] / main.cpp
1 #include "mainwindow.h"
2
3 /*
4 #include <unistd.h> // for fork()
5 #include <sys/types.h> // for pid_t
6 #include <sys/wait.h> // for waitpid()
7 #include "pirexception.h"
8 #include <sstream>
9 #include <errno.h>
10 */
11
12 #include <QtGui/QApplication>
13
14 /*
15 int loadRX51Module()
16 {
17   // First, fork off a child process:
18   pid_t pid = fork();
19
20   if (pid == -1)
21   {
22     // The fork failed!  Tell our user about the error:
23     std::stringstream ss;
24     ss << "Failed to fork a child process.\n";
25     ss << "Error returned was: " << strerror(errno) << "\n";
26     PIRException e(ss.str());
27     e.display();
28     return -1;
29   }
30   else if (pid == 0)
31   {
32     // We're inside the child process, so exec a modprobe:
33     execl("/sbin/modprobe", "/sbin/modprobe", "lirc_rx51", NULL);
34     // The execl call should overwrite the child process.  So, if we still
35     // exist at this point, an error has occurred:
36     std::stringstream ss;
37     ss << "Failed to successfully call execl().\n";
38     ss << "Error returned was: " << strerror(errno) << "\n";
39     PIRException e(ss.str());
40     e.display();
41     return -1;
42   }
43
44   // If we reach this point, we are inside the parent process.  So, we'll wait
45   // for the child process to complete:
46   int *stat_loc = NULL;
47   if (waitpid(pid, stat_loc, 0) == -1)
48   {
49     // The call to modprobe failed.
50     std::stringstream ss;
51     ss << "Call to modprobe failed.\n";
52     ss << "Error returned was: " << strerror(errno) << "\n";
53     PIRException e(ss.str());
54     e.display();
55     return -1;
56   }
57
58   if (stat_loc)
59   {
60     if (WIFEXITED(*stat_loc) == 0)
61     {
62       // modprobe encountered an error of some sort.
63       std::stringstream ss;
64       ss << "'modprobe' was unable to load the lirc_rx51 module.\n";
65       // Need better details about the error here!
66       PIRException e(ss.str());
67       e.display();
68       return -1;
69     }
70   }
71
72   // By this point, we should have successfully ensured the module is loaded.
73   return 0;
74 }
75 */
76
77 int main(int argc, char *argv[])
78 {
79   QApplication app(argc, argv);
80
81   MainWindow mainWindow;
82   mainWindow.setOrientation(MainWindow::ScreenOrientationLockLandscape);
83   mainWindow.showExpanded();
84
85 /*
86   // Make sure lirc_rx51 module is loaded:
87   if (loadRX51Module() != 0)
88   {
89     // Couldn't load module, quit:
90     app.quit();
91   }
92 */
93
94   return app.exec();
95 }
96