00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018 #include "TGo4Master.h"
00019
00020 #include "Go4Log/TGo4Log.h"
00021 #include "TGo4Task.h"
00022 #include "TGo4ServerTask.h"
00023 #include "TGo4ClientTask.h"
00024 #include "Go4CommandsBase/TGo4CommandInvoker.h"
00025 #include "Go4CommandsTaskHandler/TGo4TaskHandlerCommandList.h"
00026 #include "TGo4LocalCommandRunnable.h"
00027 #include "Go4Queue/TGo4ObjectQueue.h"
00028 #include <Rtypes.h>
00029
00030 TGo4Master::TGo4Master(const char* name, Bool_t isserver, const char* serverhost, UInt_t negotport)
00031 : TGo4TaskOwner(isserver)
00032 {
00033 TGo4CommandInvoker::Instance();
00034 TGo4CommandInvoker::Register("MasterTask", this);
00035 TGo4Task* task=0;
00036 if(IsServer())
00037 {
00038 task=new TGo4ServerTask(name, negotport,
00039 kFALSE,
00040 kFALSE,
00041 kTRUE,
00042 kTRUE,
00043 kTRUE
00044 );
00045 }
00046 else
00047 {
00048 task=new TGo4ClientTask(name, serverhost, negotport,
00049 kFALSE,
00050 kFALSE,
00051 kFALSE,
00052 kTRUE,
00053 kTRUE,
00054 kFALSE);
00055 }
00056 SetTask(task);
00057 }
00058
00059
00060
00061 TGo4Master::TGo4Master()
00062 {
00063
00064 }
00065
00066 TGo4Master::~TGo4Master()
00067 {
00068
00069 }
00070
00071 TGo4TaskHandlerCommandList* TGo4Master::CreateCommandList()
00072 {
00073 return (new TGo4TaskHandlerCommandList("Go4ServerTaskDefaultCommandList") );
00074 }
00075
00076 Bool_t TGo4Master::SubmitCommand(const char* name)
00077 {
00078 return (GetTask()->SubmitCommand(name));
00079 }
00080
00081 Bool_t TGo4Master::SubmitEmergencyCommand(Go4EmergencyCommand_t val)
00082 {
00083 return (GetTask()->SubmitEmergencyCommand(val));
00084 }
00085 Bool_t TGo4Master::SubmitCommand(TGo4Command* com)
00086 {
00087 return (GetTask()->SubmitCommand(com));
00088 }
00089
00090 void TGo4Master::SetSlave(const char* node, const char* shell, const char* command)
00091 {
00092 fxSlaveNode=node;
00093 fxSlaveShell=shell;
00094 fxSlaveExec=command;
00095 }
00096
00097 const char * TGo4Master::GetSlaveNode()
00098 {
00099 return fxSlaveNode.Data();
00100 }
00101
00102 const char * TGo4Master::GetSlaveShell()
00103 {
00104 return fxSlaveShell.Data();
00105 }
00106
00107 const char * TGo4Master::GetSlaveExec()
00108 {
00109 return fxSlaveExec.Data();
00110 }
00111 void TGo4Master::StartSlaveWindow(const char*)
00112 {
00113
00114 }
00115 Bool_t TGo4Master::ConnectSlave(const char* name,
00116 const char* remotehost,
00117 UInt_t negport,
00118 const char* remotedir,
00119 const char* remotecommand,
00120 Int_t mode,
00121 Bool_t startserver,
00122 Go4CommandMode_t role,
00123 const char* passwd
00124 )
00125 {
00126 Bool_t rev=kTRUE;
00127 if(IsServer())
00128 {
00129 TGo4ServerTask* server=dynamic_cast<TGo4ServerTask*> (GetTask());
00130 if(server)
00131 {
00132 if(server->LaunchClient(name,
00133 remotehost,
00134 remotedir,
00135 remotecommand,
00136 mode
00137 ) !=0)
00138 rev=kFALSE;
00139 else
00140 rev=kTRUE;
00141 }
00142 }
00143 else
00144 {
00145 if(startserver)
00146 {
00147
00148 LaunchSlaveServer(name,
00149 remotehost,
00150 remotedir,
00151 remotecommand,
00152 mode
00153 );
00154 rev=kFALSE;
00155 }
00156 else
00157 {
00158 TGo4ClientTask* client=dynamic_cast<TGo4ClientTask*> (GetTask());
00159 if(client)
00160 rev=client->ConnectServer(remotehost,negport, role, passwd);
00161 else
00162 rev=kFALSE;
00163 }
00164 }
00165 return rev;
00166 }
00167
00168
00169 Bool_t TGo4Master::DisconnectSlave(const char* name, Bool_t waitforslave)
00170 {
00171 Bool_t rev=kTRUE;
00172 if(IsServer())
00173 {
00174 TGo4ServerTask* server=dynamic_cast<TGo4ServerTask*> (GetTask());
00175 if(server)
00176 rev=server->RemoveClient(name, waitforslave);
00177 else
00178 rev=kFALSE;
00179 }
00180 else
00181 {
00182 TGo4ClientTask* client=dynamic_cast<TGo4ClientTask*> (GetTask());
00183 if(client)
00184 rev=client->DisconnectServer();
00185 else
00186 rev=kFALSE;
00187 }
00188 return rev;
00189 }
00190
00191 Int_t TGo4Master::LaunchSlaveServer(const char* name,
00192 const char* remotehost,
00193 const char* remotedir,
00194 const char* remotecommand,
00195 Int_t mode)
00196 {
00197 Int_t rev = 0;
00198 UInt_t negport=1234;
00199 Text_t commandstring[5*TGo4ThreadManager::fguTEXTLENGTH];
00200 Text_t formatstring[2*TGo4ThreadManager::fguTEXTLENGTH];
00201 Text_t filename[2*TGo4ThreadManager::fguTEXTLENGTH];
00202 Text_t shcom[TGo4ThreadManager::fguTEXTLENGTH];
00203 Text_t serverdisplay[TGo4ThreadManager::fguTEXTLENGTH];
00204 if(mode & TGo4ServerTask::kSecureShell)
00205 sprintf(shcom,"ssh ");
00206 else
00207 sprintf(shcom,"rsh -n");
00208 const Text_t* serverhost=gSystem->HostName();
00209 const Text_t* sdisplay=gSystem->Getenv("DISPLAY");
00210 const Text_t* go4system=gSystem->Getenv("GO4SYS");
00211 const Text_t* rootsystem=gSystem->Getenv("ROOTSYS");
00212 const Text_t* path=gSystem->Getenv("PATH");
00213 const Text_t* ldpath=gSystem->Getenv("LD_LIBRARY_PATH");
00214 snprintf(serverdisplay, 2*TGo4ThreadManager::fguTEXTLENGTH,"-display %s",sdisplay);
00215 if(remotehost==0)
00216 {
00217 remotehost="localhost";
00218 }
00219 else
00220 { }
00221 SetSlave(remotehost,shcom,remotecommand);
00222
00223 snprintf(filename, 2*TGo4ThreadManager::fguTEXTLENGTH,
00224 "%s/%s",go4system, TGo4ServerTask::fgcLAUNCHPREFSFILE);
00225 ifstream launchprefs(filename);
00226 if(!launchprefs)
00227 {
00228 TGo4Log::Debug(" Master -- ERROR: Preferences file %s not existing, could not launch client ",
00229 filename);
00230 return -1;
00231 }
00232 TGo4Log::Debug(" Master -- Launching new slave server process %s on host %s",
00233 name, remotehost);
00234 launchprefs.getline(formatstring, 2*TGo4ThreadManager::fguTEXTLENGTH, '\n' );
00235 launchprefs.getline(formatstring, 2*TGo4ThreadManager::fguTEXTLENGTH, '\n' );
00236
00237 launchprefs.getline(formatstring, 2*TGo4ThreadManager::fguTEXTLENGTH, '\n' );
00238 if((mode & TGo4ServerTask::kGuiEmbed))
00239 {
00240
00241
00242
00243 snprintf(commandstring,
00244 5*TGo4ThreadManager::fguTEXTLENGTH-1,
00245 formatstring,
00246 shcom, remotehost, go4system, rootsystem,
00247 path, ldpath, remotedir, remotecommand, name, serverhost, negport);
00248
00249 StartSlaveWindow(commandstring);
00250 }
00251 else
00252 {
00253 if (mode & TGo4ServerTask::kSecureShell) {
00254
00255
00256 launchprefs.getline(formatstring, 2*TGo4ThreadManager::fguTEXTLENGTH, '\n');
00257 snprintf(commandstring,
00258 5*TGo4ThreadManager::fguTEXTLENGTH-1,
00259 formatstring,
00260 shcom, remotehost, "", name, remotehost, go4system, rootsystem,
00261 path, ldpath, remotedir, remotecommand, name, serverhost, negport);
00262 }else {
00263
00264 launchprefs.getline(formatstring, 2*TGo4ThreadManager::fguTEXTLENGTH, '\n');
00265 snprintf(commandstring,
00266 5*TGo4ThreadManager::fguTEXTLENGTH-1,
00267 formatstring,
00268 shcom, remotehost, serverdisplay, name, remotehost, go4system, rootsystem,
00269 path, ldpath, remotedir, remotecommand, name, serverhost, negport);
00270 }
00271
00272 rev=gSystem->Exec(commandstring);
00273 }
00274
00275
00276
00277 return rev;
00278 }
00279
00280