00001 #include "Jint.h"
00002
00003 #include <JobControl/JobC.h>
00004 #include <JobControl/JobCResult.h>
00005 #include <JobControl/JobCPath.h>
00006 #include <JobControl/JobCPathModule.h>
00007 #include <JobControl/JobCPathRegistry.h>
00008 #include <MinosObjectMap/MomNavigator.h>
00009
00010 #include <sigc++/sigc++.h>
00011 using namespace SigC;
00012
00013
00014 static void chirp(const char* what)
00015 {
00016 cerr << what << endl;
00017 }
00018
00019 Jint::Jint(JobC& jc)
00020 : fJC(jc)
00021 ,fJobState(false)
00022 ,fFirstPath(0)
00023 {
00024 fJobState.SetName("Job State");
00025 Registry paths(false);
00026 paths.SetName("Paths");
00027 fJobState.Set("paths",paths);
00028
00029 const JobCPathRegistry* jcpr = fJC.Path.GetPathRegistry();
00030 if (!jcpr) {
00031 cerr << "Jint: no JobCPathRegistry, I may miss some paths\n";
00032 }
00033 else {
00034 JobCPathRegistry::PathIterator pit, end = jcpr->GetPathEnd();
00035 for (pit = jcpr->GetPathBegin(); pit != end; ++pit)
00036 this->AddPath(*pit);
00037 }
00038
00039 fJC.Path.SigNewPath.connect(slot(*this,&Jint::AddPath));
00040
00041
00042 fJC.Input.SigGet.connect(bind(slot(chirp),"Get"));
00043 fJC.Input.SigNext.connect(bind(slot(chirp),"Next"));
00044 fJC.Input.SigPrev.connect(bind(slot(chirp),"Prev"));
00045 fJC.Input.SigGoTo.connect(bind(slot(chirp),"GoTo"));
00046 }
00047
00048 Jint::~Jint(void)
00049 {
00050 }
00051
00052 void Jint::AddPath(JobCPath* jcp)
00053 {
00054 Registry paths;
00055 bool ok = fJobState.Get("paths",paths);
00056 if (!ok) {
00057 cerr << "Jint::AddPath - no paths in JobState!\n";
00058 return;
00059 }
00060 cerr << "Jint::AddPath: \"" << jcp->GetName() << "\" added\n";
00061
00062 if (!fFirstPath) fFirstPath = jcp->GetName();
00063
00064 Registry path(false);
00065 paths.Set(jcp->GetName(),path);
00066 fJobState.Set("paths",paths);
00067
00068
00069 jcp->SigDelete.connect(slot(*this,&Jint::RemovePath));
00070 jcp->SigUpdate.connect(slot(*this,&Jint::UpdatePath));
00071 jcp->SigStartRun.connect(slot(*this,&Jint::StartPathRun));
00072 jcp->SigEndRun.connect(slot(*this,&Jint::EndPathRun));
00073
00074 job_modified.emit();
00075 }
00076
00077 void Jint::RemovePath(JobCPath* jcp)
00078 {
00079 cerr << "Path: " << jcp->GetName() << " removed\n";
00080 }
00081
00082 void Jint::UpdatePath(JobCPath* jcp, JobCPath::Update_t utype)
00083 {
00084 cerr << "Path: " << jcp->GetName() << " updated by: " << utype << endl;
00085 }
00086
00087 void Jint::StartPathRun(JobCPath* )
00088 {
00089
00090
00091 }
00092
00093 void Jint::EndPathRun(JobCPath* jcp)
00094 {
00095
00096 if (jcp->LastResult().EndOfInputStream()) {
00097 cerr << "Path: " << jcp->GetName() << " end of input stream\n";
00098 return;
00099 }
00100 mom_modified();
00101 }
00102
00103 const MomNavigator* Jint::GetMom() const
00104 {
00105 return &fJC.Mom;
00106 }
00107
00108
00109
00110 void Jint::Next(int n, const char* path_name)
00111 {
00112 if (path_name) {
00113 cerr << "Jint: Next on path \"" << path_name << "\"\n";
00114 fJC.Input.Next(n);
00115 fJC.Path(path_name).Run(0);
00116 return;
00117 }
00118
00119 if (!fFirstPath) {
00120 cerr << "Jint:: no paths created yet\n";
00121 return;
00122 }
00123 fJC.Input.Next(n);
00124 fJC.Path(fFirstPath).Run(0);
00125 }
00126 void Jint::NextPass(int n, const char* path_name)
00127 {
00128 if (!path_name && !fFirstPath) {
00129 cerr << "Jint::NextPass no path name given and not default\n";
00130 return;
00131 }
00132
00133 if (!path_name) path_name = fFirstPath;
00134
00135 fJC.Path(path_name).RunNpass(n);
00136 }
00137 void Jint::Prev(int n, const char* path_name)
00138 {
00139 if (path_name) {
00140 fJC.Input.Prev(n);
00141 fJC.Path(path_name).Run(0);
00142 return;
00143 }
00144
00145 if (!fFirstPath) {
00146 cerr << "Jint:: no paths created yet\n";
00147 return;
00148 }
00149 fJC.Input.Prev(n);
00150 fJC.Path(fFirstPath).Run(0);
00151 }
00152 void Jint::Rerun(const char* path_name)
00153 {
00154 if (path_name) {
00155 fJC.Path(path_name).Run(0);
00156 return;
00157 }
00158
00159 if (!fFirstPath) {
00160 cerr << "Jint:: no paths created yet\n";
00161 return;
00162 }
00163
00164 fJC.Path(fFirstPath).Run(0);
00165 }
00166 void Jint::GoTo(int run, int snarl)
00167 {
00168 fJC.Input.GoTo(run,snarl);
00169 fJC.Path(fFirstPath).Run(0);
00170 }
00171 void Jint::Run(int n, JobCPath::RunMode_t mode, const char* path_name)
00172 {
00173 if (path_name) {
00174 fJC.Path(path_name).Run(n,mode);
00175 return;
00176 }
00177
00178 if (!fFirstPath) {
00179 cerr << "Jint:: no paths created yet\n";
00180 return;
00181 }
00182
00183 fJC.Path(fFirstPath).Run(n,mode);
00184 }