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