aaef05d22609964027ed47122f8b7263984d17b1
[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 #include <QtCore/QDir>
40
41 #include "comm.h"
42
43 #include "ui/KernelWindow.h"
44
45 #define GPATH "loggr"
46 #define IPATH "logi"
47 #define NPATH "logn"
48 #define REMOTE_PATH "REMOTE"
49 #define MAXINTERP 20
50 #define MAXINSTANCES 256 
51
52
53 #define MESG_COL        0
54 #define WARN_COL        1
55 #define NORM_COL        2
56
57
58 namespace loglan {
59 namespace vlp {
60
61 /**
62  * Interpreter slot
63  */
64 class InterpEntry {
65 public:
66         /** Interpreter identifier */
67         int ID;
68         /** Defines if interpreter is remote or not */
69         bool remote;
70         /* Program name */
71         char fullname[255];
72         char shortname[255];
73         
74         /* Socket */
75         int sock;
76         QSocketNotifier *notify;
77         /* IDs of my remote INT modules */
78         int RInstances[MAXINSTANCES];
79         /* Parent interpreter info */
80         ctx_struct p_ctx;
81 };
82
83 /**
84  * Connection slot
85  */
86 class ConnectEntry {
87 public:
88         char addr[256];
89
90         ConnectEntry(char *s) {
91                 strcpy(addr, s);
92         };
93
94         ConnectEntry(const char *s) {
95                 strcpy(addr, s);
96         };
97 };
98
99
100 /**
101  * Kernel class
102  */
103 class QKernel : public QMainWindow, private Ui::KernelWindow {
104         Q_OBJECT
105 public:
106         QMenu *toolsMenu;
107         char progdir[256];
108         int NodeNumber;
109         int ConType;
110
111         QKernel(int argc, char **argv);
112
113         void WriteMessage(const char * msg);
114
115 public slots:
116         void NetMessage();
117         void IntMessage(int);
118
119 protected:
120         virtual void closeEvent (QCloseEvent * e);
121
122 private:
123         QList<InterpEntry*> Interpreters;
124         QList<ConnectEntry*> ConnectList;
125         
126         /**
127          * number of working interpreters
128          * @attention Currently not in use
129          */
130         int Tasks;
131         
132         /**
133          * number of connected VLPs
134          */
135         int ActiveConnections;
136         /**
137          * Indicates state of the Kernel Program. Is it locked or not.
138          */
139         bool LOCKED;
140         bool synchro;
141         bool wait_for_info;
142         char LockPasswd[25];
143         
144         int net_sock;
145         int freeINTid;
146         QSocketNotifier *Net_Notify;
147         QDir homeDir;
148         char myargs[5][255];
149         bool info_messages;
150
151         void loadConfig(const QString &fname);
152         void loadConfig(const char *);
153
154         void RunGraphModule(char*);
155         void RunNetModule();
156         InterpEntry *findINTbySocket(int);
157         InterpEntry *findINTbyID(int);
158         InterpEntry *RunIntModule(char *ss, int r);
159         void RemoteInstance(InterpEntry*, int);
160         void CloseInstances(InterpEntry*);
161
162         /**
163          * Sets QKernel menu entries to the given status
164          * @param locked status which will be set on the menu entries.
165          */
166         void setLocked(bool locked);
167
168         QString getConfigFilePath();
169         const char * getHomeDir();
170         const char * getRemoteDir();
171
172         const char * getNetModuleSocket();
173         const char * getGraphModuleSocket();
174
175 private slots:
176         void on_actionExecute_triggered();
177         void on_actionKill_triggered();
178         void on_actionQuit_triggered();
179         
180         void on_actionMessage_triggered();
181         void on_actionConnect_triggered();
182         void on_actionDisconnect_triggered();
183         void on_actionInfo_triggered();
184
185         void on_actionEditor_triggered();
186         void on_actionHelp_triggered();
187         void on_actionOptions_triggered();
188         void on_actionInfo_messages_triggered();
189         void on_actionLock_console_triggered();
190         void on_actionUnlock_console_triggered();
191 };
192
193 }
194 }
195
196 #endif /* VLP_KERNEL_H */