11 package com.generalrobotix.ui.util;
14 import java.io.IOException;
15 import java.util.Vector;
17 import org.eclipse.jface.preference.IPreferenceStore;
18 import org.eclipse.ui.preferences.ScopedPreferenceStore;
19 import org.eclipse.core.runtime.IProgressMonitor;
29 @SuppressWarnings(
"serial")
31 private static volatile Vector<ProcessInfo> vecServerInfo =
new Vector<ProcessInfo>();
36 private static final int MAXMUM_PORT_NUMBER = 65535;
37 private static final String LINE_SEPARATOR =
new String( System.getProperty(
"line.separator") );
42 public String serverInfoDefaultDir_ =
"";
43 public int serverInfoDefaultWaitCount_ = 0;
47 setServerInfoToPreferenceStore();
48 setNameServerInfoToPreferenceStore();
71 return nameServerInfo;
76 return newHost_.
get();
80 return newPort_.
get();
84 return nameServerLogDir.
get();
87 public String
setNewHostPort(String host, String port,StringBuffer refHost, StringBuffer refPort){
88 String retHost = checkHostFormat(host);
89 String retPort = checkPortFormat(port);
91 String
ret = retHost + retPort;
93 newPort_.
set(Integer.valueOf(port));
96 if(!retHost.isEmpty()){
97 refHost.append( getNewHost() );
99 if(!retPort.isEmpty()){
100 refPort.append( Integer.toString(getNewPort()) );
117 StringBuffer nsHost =
new StringBuffer(
"");
118 StringBuffer nsPort =
new StringBuffer(
"");
120 String nsOpt =
"-ORBInitRef NameService=corbaloc:iiop:" + nsHost +
121 ":" + nsPort +
"/NameService";
133 if(!(
new File(s)).isAbsolute()){
135 String ss = comToAbsolutePath(s);
141 for(
int i=0;
i<pInfo.
com.size();
i++)
142 pInfo.
com.set(
i, pInfo.
com.get(
i) +
" " + nsOpt);
165 if (pi.id.equals(pInfo.
id)) {
170 if (pInfo.
useORB != pi.useORB) {
174 if (!pInfo.
com.equals(pi.com)) {
176 for (String
i : pInfo.
com) {
177 pi.com.add(
new String(i));
181 if (!pInfo.
args.equals(pi.args)) {
182 pi.args = pInfo.
args;
194 if(host.length() > 255){
195 return MessageBundle.
get(
"GrxServerManager.message.hostFormat.num") + LINE_SEPARATOR;
198 int limit = host.length() - host.replace(
".",
"").length();
200 String [] splitStr = host.split(
"\\.", limit == 0 ? limit : limit + 1);
202 for(String
i : splitStr){
203 if(
i.length() < 1 ||
i.length() > 63){
204 return MessageBundle.
get(
"GrxServerManager.message.hostFormat.label") + LINE_SEPARATOR;
206 if(
i.matches(
"^[a-zA-Z0-9][a-zA-Z0-9\\-]*[a-zA-Z0-9]$") ||
207 i.matches(
"^[a-zA-Z0-9]$") ){
210 return MessageBundle.
get(
"GrxServerManager.message.hostFormat.rfc") + LINE_SEPARATOR;
219 int portInt = Integer.valueOf(port);
220 if( portInt > MAXMUM_PORT_NUMBER || portInt < 0)
222 Integer.toString(MAXMUM_PORT_NUMBER) +
MessageBundle.
get(
"GrxServerManager.message.portFormat2") + LINE_SEPARATOR;
223 }
catch (NumberFormatException ex){
225 Integer.toString(MAXMUM_PORT_NUMBER) +
MessageBundle.
get(
"GrxServerManager.message.portFormat2") + LINE_SEPARATOR;
231 getNameServerInfoFromPerferenceStore();
232 vecServerInfo.clear();
233 getServerInfoFromPerferenceStore();
234 newPort_.
set(NAME_SERVER_PORT_);
235 newHost_.
set(NAME_SERVER_HOST_);
236 nameServerLogDir.
set(NAME_SERVER_LOG_DIR_);
239 public void restart(IProgressMonitor monitor){
240 NAME_SERVER_PORT_ = newPort_.
get();
241 NAME_SERVER_HOST_ = newHost_.
get();
242 nameServerInfo.
args = generateNameServerArgs();
249 ret =
"-start " + Integer.toString(NAME_SERVER_PORT_) +
" -logdir " + NAME_SERVER_LOG_DIR_ +
250 " -ORBendPointPublish giop:tcp:"+ NAME_SERVER_HOST_ +
":";
256 String _dir = store.getString(
259 if(!NAME_SERVER_LOG_DIR_.isEmpty()){
260 String localStr = NAME_SERVER_LOG_DIR_.replaceFirst(
"^\"",
"");
261 File logDir =
new File(localStr.replaceFirst(
"\"$",
""));
262 if(!logDir.exists()){
266 NAME_SERVER_PORT_ = store.getInt(
268 if(NAME_SERVER_PORT_==0)
269 NAME_SERVER_PORT_ = store.getDefaultInt(
271 NAME_SERVER_HOST_ = store.getString(
273 if(NAME_SERVER_HOST_.equals(
""))
274 NAME_SERVER_HOST_ = store.getDefaultString(
277 nameServerInfo.
args = generateNameServerArgs();
279 String s = store.getString(
282 String ss=comToAbsolutePath(s);
284 nameServerInfo.
com.add(ss);
285 nameServerInfo.
com.add(s);
289 nameServerInfo.
com.add(s);
294 nameServerInfo.
dir = store.getString(
303 private String[]
parse(String
string){
306 if(ret[0].charAt(0)==
'\"')
307 ret[0] = ret[0].substring(1,ret[0].
length());
308 String s=ret[ret.length-1];
309 if(s.charAt(s.length()-1)==
'\"')
310 ret[ret.length-1] = s.substring(0,s.length()-1);
320 String[] dir = parse(dirList);
324 String[]
com = parse(comList);
326 String[] args = parse(argsList);
333 for(
int i=1;
i<
id.length;
i++){
335 processInfo.
id =
id[
i];
337 if(
i<com.length && !com[
i].equals(
""))
342 if((
new File(s)).isAbsolute())
343 processInfo.
com.add(s);
345 String ss=comToAbsolutePath(s);
347 processInfo.
com.add(ss);
350 processInfo.
com.add(s);
352 if(
i<args.length && !args[
i].equals(
""))
353 processInfo.
args = args[
i].trim();
355 processInfo.
args = args[0].trim();
356 if(
i<autoStart.length && !autoStart[
i].equals(
""))
357 processInfo.
autoStart = autoStart[
i].equals(
"true")?
true :
false;
359 processInfo.
autoStart = autoStart[0].equals(
"true")?
true :
false;
360 if(
i<useORB.length && !useORB[
i].equals(
""))
361 processInfo.
useORB = useORB[
i].equals(
"true")?
true :
false;
363 processInfo.
useORB = useORB[0].equals(
"true")?
true :
false;
364 if(
i<hasShutDown.length && !hasShutDown[
i].equals(
""))
365 processInfo.
hasShutdown = hasShutDown[
i].equals(
"true")?
true :
false;
367 processInfo.
hasShutdown = hasShutDown[0].equals(
"true")?
true :
false;
368 if(
i<waitCount.length && !waitCount[
i].equals(
""))
369 processInfo.
waitCount = Integer.parseInt(waitCount[
i]);
371 processInfo.
waitCount = Integer.parseInt(waitCount[0]);
372 if(i<dir.length && !dir[i].equals(
""))
373 processInfo.
dir = dir[i].trim();
375 processInfo.
dir = dir[0].trim();
379 vecServerInfo.add(processInfo);
381 serverInfoDefaultDir_ = dir[0].trim();
382 serverInfoDefaultWaitCount_ = Integer.parseInt(waitCount[0]);
385 nameServerInfo.
waitCount = serverInfoDefaultWaitCount_;
386 if(nameServerInfo.
dir.equals(
""))
387 nameServerInfo.
dir = serverInfoDefaultDir_;
391 if((
new File(com)).isAbsolute())
394 String serverDir = store.getString(
"SERVER_DIR");
395 if(!serverDir.equals(
"")){
397 String[] list = file.list();
398 for(
int i=0;
i<list.length;
i++){
399 int endIndex = list[
i].lastIndexOf(
".");
401 endIndex = list[
i].length();
402 String s=list[
i].substring(0, endIndex);
404 return serverDir+
"/"+com;
415 String args =
"\"\"";
416 String autoStart=
"false";
417 String useORB=
"false";
418 for(
int i=0;
i<vecServerInfo.size();
i++){
static void setNameServerInfoToPreferenceStore()
static final String get(String key)
synchronized void set(T val)
String[] parse(String string)
static final String ALLSERVER
static final String NAMESERVER
#define null
our own NULL pointer
static final String WAITCOUNT
GrxServerManager(String name, GrxPluginManager manager)
png_infop png_charpp name
RTC::ReturnCode_t ret(RTC::Local::ReturnCode_t r)
boolean toggleProcess(ProcessInfo pInfo)
サーバプログラムの起動トグル
String getNameserverLogDir()
png_bytep png_bytep png_size_t length
ProcessInfo getNameServerInfo()
NameServerのProcessInfo取得
static final String SEPARATOR
static void setServerInfoToPreferenceStore()
String comToAbsolutePath(String com)
String generateNameServerArgs()
boolean unregister(String id)
void restart(IProgressMonitor monitor)
static Activator getDefault()
void restart(IProgressMonitor monitor)
static String NAME_SERVER_LOG_DIR_
boolean register(ProcessInfo pi)
static void refNSHostPort(StringBuffer nsHost, StringBuffer nsPort)
boolean updatedParam(ProcessInfo pInfo)
vecServerInfoの更新 vecServerInfoに同名のidが存在すればpInfoを元に更新する
String checkPortFormat(String port)
static int NAME_SERVER_PORT_
static final String LOGGIR
static final String HASSHUTDOWN
static String expandEnvVal(String str)
static String NAME_SERVER_HOST_
String setNewHostPort(String host, String port, StringBuffer refHost, StringBuffer refPort)
プラグイン管理クラス GrxUIの核になるクラス。プラグインのロード等の、初期化を実行する。 プラグインとそ...
AProcess get(String name)
Vector< ProcessInfo > getServerInfo()
vecServerInfoの取得
void getServerInfoFromPerferenceStore()
static final String PROCESS
static final String AUTOSTART
synchronized void SaveServerInfo()
static final String USEORB
void getNameServerInfoFromPerferenceStore()
String checkHostFormat(String host)
boolean start(String opt)