]> git.vomp.tv Git - vompclient.git/blob - command.h
746b01121d64d9c7bf71977dd4b237d2049b086c
[vompclient.git] / command.h
1 /*
2     Copyright 2004-2005 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, write to the Free Software
18     Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
19 */
20
21 #ifndef COMMAND_H
22 #define COMMAND_H
23
24 #ifndef WIN32
25 #include <unistd.h> // for reboot
26 #include <linux/reboot.h>
27 #include <sys/reboot.h>
28 #endif
29
30 #include <time.h>
31 #ifndef WIN32
32 #include <pthread.h>
33 #endif
34
35 #include <signal.h>
36
37 #include "defines.h"
38 #include "messagequeue.h"
39 #include "udp.h"
40
41 class VConnect;
42 class Message;
43 class Remote;
44 class Boxx;
45 class BoxStack;
46 class Log;
47 class VInfo;
48
49 class Command : public MessageQueue
50 {
51   public:
52     Command();
53     ~Command();
54     static Command* getInstance();
55
56     int init(bool crashed = false, char* server = NULL);
57     int shutdown();
58     void run();
59     void stop();
60     void doReboot();
61     void postMessage(Message* m); // override of MessageQueue::postMessage
62     void postMessageNoLock(Message* m); // override of MessageQueue::postMessage
63     bool postMessageIfNotBusy(Message* m); // for timers, when masterMutex might be locked
64     void postMessageFromOuterSpace(Message* m); // err, read the cc comments.
65     void sig1();
66     void connectionLost();
67
68   private:
69     void handleCommand(int);
70     void doStandby();
71     void doPowerOn();
72     void doPowerOff();
73     void doJustConnected(VConnect* vconnect);
74     void doWallpaper();
75     void doFromTheTop(bool which);  // true - show vinfo,wait. false - del vinfo,restart
76     void buildCrashedBox();
77
78     static Command* instance;
79 #ifndef WIN32
80     pid_t mainPid;
81     pthread_mutex_t masterLock;
82 #else
83     HANDLE masterLock;
84     HANDLE mainPid; //Window
85 #endif
86     UCHAR initted;
87     UCHAR irun;
88     UCHAR isStandby;
89     UCHAR firstBoot;
90
91     Log* logger;
92     BoxStack* boxstack;
93     Remote* remote;
94     Boxx* wallpaper;
95     VInfo* connLost;
96     bool crashed;
97     char* server;
98         
99     UDP udp;
100
101     void processMessage(Message* m);
102 };
103
104 #endif