1
/* Copyright (C) 2004 MySQL AB
3
This program is free software; you can redistribute it and/or modify
4
it under the terms of the GNU General Public License as published by
5
the Free Software Foundation; version 2 of the License.
7
This program is distributed in the hope that it will be useful,
8
but WITHOUT ANY WARRANTY; without even the implied warranty of
9
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10
GNU General Public License for more details.
12
You should have received a copy of the GNU General Public License
13
along with this program; if not, write to the Free Software
14
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA */
18
using System.Collections;
19
using System.ComponentModel;
20
using System.Windows.Forms;
23
using NDB_CPC.socketcomm;
24
using NDB_CPC.simpleparser;
30
/// Summary description for Computer.
34
public enum Status {Disconnected=1,Connected=2, Unknown=3}
36
private int m_cpcdPort;
37
private string m_name;
38
private Status m_status;
39
private ArrayList m_processes;
40
private SocketComm m_socket;
41
public Computer(string name, int port)
44
m_status = Status.Disconnected;
45
m_processes = new ArrayList();
47
m_socket = new SocketComm(m_name,m_cpcdPort);
50
public Computer(string name, string ip)
54
m_status = Status.Disconnected;
55
m_processes = new ArrayList();
56
m_cpcdPort=1234; //default port
57
m_socket = new SocketComm(m_ip,m_cpcdPort);
60
public void connectToCpcd()
65
private bool sendMessage(string str)
67
return m_socket.writeMessage(str);
71
public string getName() {return m_name;}
72
public string getIp() {return m_ip;}
73
public ArrayList getProcesses()
75
if(m_processes.Count>0)
80
public string getStatusString()
84
if(m_socket.isConnected())
87
return "Disconnected";
96
public bool isConnected()
98
if(m_socket.isConnected())
103
public Status getStatus()
107
if(m_socket.isConnected())
108
return Status.Connected;
110
return Status.Disconnected;
114
return Status.Unknown;
118
public void setStatus(Status status)
123
public void addProcess(Process process)
125
m_processes.Add(process);
128
public Process getProcessByName(string name)
130
foreach(Process process in m_processes)
132
if(process.getName().Equals(name))
139
public bool removeProcess(string name, string database)
141
foreach(Process p in m_processes)
143
if(p.getName().Equals(name) && p.getDatabase().Equals(database))
145
m_processes.Remove(p);
152
public void disconnect()
154
m_socket.disconnect();
156
public Process getProcess(string id)
158
foreach(Process process in m_processes)
160
if(process.getId().Equals(id))
166
public int listProcesses()
168
string list = "list processes\n\n";
170
if(!sendMessage(list))
173
SimpleCPCParser.parse(m_processes, this, m_socket);
177
public int defineProcess(Process p)
179
string define = "define process \n";
180
define = define + "name:" + p.getName() + "\n";
181
define = define + "group:" + p.getDatabase() + "\n";
182
define = define + "env:" + "NDB_CONNECTSTRING="+p.getConnectString() ;
183
if(p.getEnv().Equals(""))
184
define = define + "\n";
186
define = define + " " + p.getEnv() + "\n";
188
//if(p.getPath().EndsWith("\\"))
189
// define = define + "path:" + p.getPath()+ "ndb" + "\n";
191
define = define + "path:" + p.getPath() + "\n";
192
define = define + "args:" + p.getArgs() + "\n";
193
define = define + "type:" + "permanent" + "\n";
194
define = define + "cwd:" + p.getCwd() + "\n";
195
define = define + "owner:" + "ejohson" + "\n\n";
197
if(!sendMessage(define))
200
SimpleCPCParser.parse(p, m_socket);
208
public int startProcess(Process p)
212
this.defineProcess(p);
214
return -4; //process misconfigured
217
string start= "start process \n";
218
start = start + "id:" + p.getId() + "\n\n";
219
if(!sendMessage(start))
221
SimpleCPCParser.parse(p, m_socket);
222
if(p.getStatus().Equals(Process.Status.Running))
228
public int stopProcess(Process p)
232
return -4; //process not defined
234
string stop= "stop process \n";
235
stop = stop + "id:" + p.getId() + "\n\n";
236
if(!sendMessage(stop))
238
SimpleCPCParser.parse(p, m_socket);
240
if(p.getStatus().Equals(Process.Status.Stopped))
246
public int undefineProcess(Process p)
250
return -4; //process not defined
252
string undefine= "undefine process \n";
253
undefine = undefine + "id:" + p.getId() + "\n\n";
254
if(!sendMessage(undefine))
256
SimpleCPCParser.parse(p, m_socket);
265
public int getCpcdPort()
267
return this.m_cpcdPort;