]> git.vomp.tv Git - vompclient.git/blob - command.h
v0.6 dev
[vompclient.git] / command.h
1 /*
2     Copyright 2004-2020 Chris Tallon
3
4     This file is part of VOMP.
5
6     VOMP is free software; you can redistribute it and/or modify
7     it under the terms of the GNU General Public License as published by
8     the Free Software Foundation; either version 2 of the License, or
9     (at your option) any later version.
10
11     VOMP is distributed in the hope that it will be useful,
12     but WITHOUT ANY WARRANTY; without even the implied warranty of
13     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14     GNU General Public License for more details.
15
16     You should have received a copy of the GNU General Public License
17     along with VOMP.  If not, see <https://www.gnu.org/licenses/>.
18 */
19
20 #ifndef COMMAND_H
21 #define COMMAND_H
22
23 #ifndef WIN32
24 #include <unistd.h> // for reboot
25 #include <linux/reboot.h>
26 #include <sys/reboot.h>
27 #endif
28
29 #include <time.h>
30 #ifndef WIN32
31 #include <pthread.h>
32 #endif
33
34 #include <signal.h>
35
36 #include <string>
37 #include <vector>
38
39 #include "defines.h"
40 #include "messagequeue.h"
41 #include "udp.h"
42
43 class VConnect;
44 class Message;
45 class Remote;
46 class Boxx;
47 class BoxStack;
48 class Log;
49 class VInfo;
50 class WJpeg;
51
52 struct ASLPref {
53         std::string langcode;
54         int audiopref;
55         int subtitlepref;
56 };
57
58 typedef std::vector<struct ASLPref> ASLPrefList;
59
60 class Command : public MessageQueue
61 {
62   public:
63     Command();
64     ~Command();
65     static Command* getInstance();
66
67     int init(bool crashed = false, char* server = NULL);
68     int shutdown();
69     void run();
70     void doReboot();
71     void postMessage(Message* m); // override of MessageQueue::postMessage
72     void postMessageNoLock(Message* m); // override of MessageQueue::postMessage
73     bool postMessageIfNotBusy(Message* m); // for timers, when masterMutex might be locked
74     void postMessageFromOuterSpace(Message* m); // err, read the cc comments.
75     void setSignal(int signalReceived);
76     void connectionLost();
77
78     void setAdvMenus(bool adv) { advMenus = adv; };
79     bool isAdvMenus() { return advMenus; };
80     int getLangPref(bool subtitle,const char* langcode);
81     void setSubDefault(int subon) {subdefault=subon;};
82     int getSubDefault() { return subdefault;};
83     ASLPrefList &getASLList(){return langcodes;};
84
85   private:
86     void stop();
87     void handleCommand(int);
88     void processSignals();
89     void doStandby();
90     void doPowerOn();
91     void doPowerOff();
92     void doJustConnected(VConnect* vconnect);
93     void doWallpaper();
94     void doFromTheTop(bool which);  // true - show vinfo,wait. false - del vinfo,restart
95     void buildCrashedBox();
96     void sig1();
97
98     static Command* instance;
99 #ifndef WIN32
100     pid_t mainPid;
101     pthread_mutex_t masterLock;
102 #else
103     HANDLE masterLock;
104     HANDLE mainPid; //Window
105 #endif
106     bool initted{};
107     bool irun{};
108     bool isStandby{};
109     bool firstBoot{true};
110     int signals{};
111
112     Log* logger;
113     BoxStack* boxstack;
114     Remote* remote;
115     Boxx* wallpaper{};
116     WJpeg* wallpaper_pict{};
117     VInfo* connLost{};
118     bool crashed{};
119     char* server{};
120
121     bool advMenus{};
122     ASLPrefList langcodes;
123     int subdefault;
124         
125     UDP udp;
126
127     void processMessage(Message* m);
128
129     const static int SIG_INT{1};
130     const static int SIG_TERM{2};
131     const static int SIG_USR1{4};
132     const static int SIG_USR2{8};
133     const static int SIG_URG{16};
134
135 };
136
137 #endif