VLP-28 Moved kernel class declarations to the header file. Code refactor.
[vlp.git] / src / kernel / kernel.h
1 /**************************************************************
2
3   Copyright (C) 1997  Oskar Swida
4
5  This program is free software; you can redistribute it and/or
6  modify it under the terms of the GNU General Public License
7  as published by the Free Software Foundation; either version 2
8  of the License, or (at your option) any later version.
9
10  This program is distributed in the hope that it will be useful, 
11  but WITHOUT ANY WARRANTY; without even the implied warranty of
12  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13  GNU General Public License for more details.
14
15  You should have received a copy of the GNU General Public License
16  along with this program; if not, write to the Free Software
17  Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
18
19
20
21
22  NOTE: This software is using the free software license of 
23        the QT library v.1.30 from Troll Tech AS.
24        See the file LICENSE.QT.
25
26  
27   To contact the author, write:
28      e-mail: swida@aragorn.pb.bialystok.pl
29
30 ************************************************************/
31
32 #ifndef VLP_KERNEL_H
33 #define VLP_KERNEL_H
34
35 #include <QtGui/QMainWindow>
36 #include <QtGui/QListWidget>
37 #include <QtGui/QTextEdit>
38 #include <QtCore/QSocketNotifier>
39
40 #include "comm.h"
41
42 #define GPATH "loggr"
43 #define IPATH "logi"
44 #define NPATH "logn"
45 #define REMOTE_PATH "REMOTE"
46 #define MAXINTERP 20
47 #define MAXINSTANCES 256 
48
49
50 #define MESG_COL        0
51 #define WARN_COL        1
52 #define NORM_COL        2
53
54
55 /**
56  * Interpreter slot
57  */
58 class InterpEntry {
59 public:
60         /** Interpreter identifier */
61         int ID;
62         /** Defines if interpreter is remote or not */
63         bool remote;
64         /* Program name */
65         char fullname[255];
66         char shortname[255];
67         
68         /* Socket */
69         int sock;
70         QSocketNotifier *notify;
71         /* IDs of my remote INT modules */
72         int RInstances[MAXINSTANCES];
73         /* Parent interpreter info */
74         ctx_struct p_ctx;
75 };
76
77 /**
78  * Connection slot
79  */
80 class ConnectEntry {
81 public:
82         char addr[256];
83         
84         ConnectEntry(char *s) {
85                 strcpy(addr, s);
86         };
87 };
88
89
90 /**
91  * Kernel class
92  */
93 class QKernel : public QMainWindow {
94         Q_OBJECT
95 public:
96         QTextEdit *desktop;
97         QMenuBar *bar;
98         QMenu *programMenu;
99         QMenu *machineMenu;
100         QMenu *toolsMenu;
101         char progdir[256];
102         int NodeNumber;
103         int ConType;
104
105         QKernel();
106
107         virtual void resizeEvent(QResizeEvent *ev);
108
109         void WriteMessage(char* msg);
110         void InitMessage();
111
112 public slots:
113         void n_impl();
114         void Run_Prog();
115         void Edit();
116         void Help();
117         void SetOptions();
118         void AddAddress();
119         void DelAddress();
120         void LockConsole();
121         void UnlockConsole();
122         void MessageToNode();
123         void QuitProc();
124         void NetMessage();
125         void IntMessage(int);
126         void KillInterpreter();
127         void Disconnect();
128         void SetMessages();
129         void Connect();
130         void Info();
131
132 protected:
133         virtual void closeEvent (QCloseEvent * e);
134
135 private:
136         QList<InterpEntry*> Interpreters;
137         QList<ConnectEntry*> ConnectList;
138         QListWidget *connections;
139         
140         /**
141          * number of working interpreters
142          * @attention Currently not in use
143          */
144         int Tasks;
145         
146         /**
147          * number of connected VLPs
148          */
149         int ActiveConnections;
150         /**
151          * Indicates state of the Kernel Program. Is it locked or not.
152          */
153         bool LOCKED;
154         bool synchro;
155         bool wait_for_info;
156         char LockPasswd[25];
157         QAction * toolsEditorAction;
158         QAction * toolsOptionsAction;
159         QAction * toolsInfoAction;
160         QAction * programExecuteAction;
161         QAction * programKillAction;
162         QAction * machineMessageAction;
163         QAction * machineConnectAction;
164         QAction * machineDisconnectAction;
165         QAction * machineInfoAction;
166         QAction * toolsLockAction;
167         QAction * toolsUnlockAction;
168         QAction * quitAction;
169         
170         int net_sock;
171         int freeINTid;
172         QSocketNotifier *Net_Notify;
173         char HomeDir[255];
174         bool info_messages;
175
176         void LoadConfig(char *);
177         void RunGraphModule(char*);
178         void RunNetModule();
179         InterpEntry *findINTbySocket(int);
180         InterpEntry *findINTbyID(int);
181         InterpEntry *RunIntModule(char *ss, int r);
182         void RemoteInstance(InterpEntry*, int);
183         void CloseInstances(InterpEntry*);
184
185         /**
186          * Sets QKernel menu entries to the given status
187          * @param locked status which will be set on the menu entries.
188          */
189         void setLocked(bool locked);
190 };
191
192 #endif /* VLP_KERNEL_H */