Home || Architecture || Video Search || Visual Search || Scripts || Applications || Important Messages || OGL || Src

mainIDashServer.cpp

Go to the documentation of this file.
00001 #include "Core/IDash/VideoSetWrapper.h"
00002 #include "Util/Sleep.h"
00003 #include "Basis/CmdOptions.h"
00004 #include "Util/ChannelPool.h"
00005 #include "Job/Server.h"
00006 #include "Core/VideoJob/ServerProxy.h"
00007 #include "Core/IDash/Server.h"
00008 #include "Core/IDash/XmlJob.h"
00009 #include "Core/IDash/XmlJobReference.h"
00010 #include "Core/IDash/Client.h"
00011 #include "Persistency/AnnotationTableSetRepository.h"
00012 
00013 // since we are not using libraries:
00014 #include "Link/ImpalaLib.cpp"
00015 
00016 
00017 namespace Impala
00018 {
00019 namespace Application
00020 {
00021 namespace IDash
00022 {
00023 
00024 void
00025 DoProcessAnnotationSet(CString setArg)
00026 {
00027     ILOG_VAR(Impala.Application.IDash.DoProcessAnnotationSet);
00028     using namespace Persistency;
00029 
00030     Util::StringParser p(setArg);
00031     if (p.Contains("keyvalue"))
00032     {
00033         ILOG_ERROR("annotationset should not contain keyvalue");
00034         return;
00035     }
00036     p.Eat("keyword=");
00037     if (p.TheEnd())
00038     {
00039         ILOG_ERROR("annotationset should contain keyword");
00040         return;
00041     }
00042     String keyword = p.GetString('&', false);
00043     Core::Table::KeywordList keyList;
00044     keyList.push_back(keyword);
00045     Core::Table::AnnotationTableSet annoSet(keyList, 0);
00046 
00047     Core::IDash::VideoSetWrapper vidSet("idash_annotator.txt");
00048     Core::IDash::XmlAnnotationSet xmlAnnotationSetT(setArg + "&keyvalue=true");
00049     if (!xmlAnnotationSetT.Valid())
00050         return;
00051     Core::Table::AnnotationTable* tab = annoSet.GetTable(keyword);
00052     for (int i=0 ; i<xmlAnnotationSetT.GetNrMoments() ; i++)
00053     {
00054         Core::IDash::XmlShot xmlShot(xmlAnnotationSetT.GetMoment(i));
00055         Core::IDash::XmlVideo xmlVideo(xmlShot.GetVideo());
00056         Quid q = vidSet.Add(xmlVideo, xmlShot.GetShotIndex());
00057         tab->AddPositive(q);
00058     }
00059 
00060     Core::IDash::XmlAnnotationSet xmlAnnotationSetF(setArg + "&keyvalue=false");
00061     if (!xmlAnnotationSetF.Valid())
00062         return ;
00063     for (int i=0 ; i<xmlAnnotationSetF.GetNrMoments() ; i++)
00064     {
00065         Core::IDash::XmlShot xmlShot(xmlAnnotationSetF.GetMoment(i));
00066         Core::IDash::XmlVideo xmlVideo(xmlShot.GetVideo());
00067         Quid q = vidSet.Add(xmlVideo, xmlShot.GetShotIndex());
00068         tab->AddNegative(q);
00069     }
00070 
00071     Core::VideoSet::VideoSet* vs = vidSet.GetVideoSet();
00072     AnnotationTableSetLocator setLoc(vs->GetLocator(), QUID_CLASS_FRAME,
00073                                      "conceptsAnnotator.txt");
00074     AnnotationTableSetRepository().Add(setLoc, &annoSet);
00075 }
00076 
00077 int
00078 mainIDashServer(int argc, char* argv[])
00079 {
00080     CmdOptions& options = CmdOptions::GetInstance();
00081     options.Initialise(false, false, true);
00082     options.AddOption(0, "noIdle", "", "0");
00083     String usageStr = "cmd, with cmd = \n\n";
00084     usageStr += "  jobstatus jobserveraddr jobid\n";
00085     if (! options.ParseArgs(argc, argv, usageStr, 2))
00086         return 1;
00087 
00088     ILOG_VAR(Impala.Application.IDash.mainIDashServer);
00089 
00090     String passwordFile = options.GetString("passwordFile");
00091     String cmd = options.GetArg(0);
00092     if (cmd == "jobstate")
00093     {
00094         String jobServerAddr = options.GetArg(1);
00095         Core::VideoJob::ServerProxy jobServer(jobServerAddr, passwordFile, 10);
00096         if (!jobServer.IsConnected())
00097             return 1;
00098 
00099         int jobId = Impala::atol(options.GetArg(2));
00100         Job::State::StateType state;
00101         int exitCode;
00102         String errorLog;
00103         jobServer.GetJobState(jobId, state, exitCode, errorLog);
00104         ILOG_INFO("state = " << Job::State::ToString(state));
00105     }
00106     else if (cmd == "schedulejob")
00107     {
00108         String jobServerAddr = options.GetArg(1);
00109         Core::VideoJob::ServerProxy jobServer(jobServerAddr, passwordFile, 10);
00110         if (!jobServer.IsConnected())
00111             return 1;
00112 
00113         String cmdLine = options.GetArg(2);
00114         int res = jobServer.ScheduleJob(cmdLine, 0);
00115         ILOG_INFO("res = " << res);
00116         Util::Sleep(100); // need to stay alive a little for job to live on server
00117     }
00118     else if (cmd == "serve")
00119     {
00120         if (options.GetNrArg() < 4)
00121         {
00122             ILOG_ERROR("Need more parameters");
00123             return 1;
00124         }
00125         int port = atol(options.GetArg(1));
00126         int nrPorts = atol(options.GetArg(2));
00127         String jobServerAddr = options.GetArg(3);
00128         Core::IDash::Server server(port, nrPorts, passwordFile, jobServerAddr);
00129         bool doIdle = ! options.GetBool("noIdle");
00130         server.Start(doIdle);
00131     }
00132     else if (cmd == "processvideo")
00133     {
00134         if (options.GetNrArg() < 3)
00135         {
00136             ILOG_ERROR("Need more parameters");
00137             return 1;
00138         }
00139         String vidArg = options.GetArg(1);
00140         Core::IDash::XmlVideo xmlVideo(vidArg);
00141         if (!xmlVideo.Valid())
00142             return 1;
00143         String setArg = options.GetArg(2);
00144         Core::IDash::XmlQuerySet xmlQuerySet(setArg);
00145         if (!xmlQuerySet.Valid())
00146             return 1;
00147         Core::IDash::VideoSetWrapper vidSet("idash_vds.txt");
00148         vidSet.Add(xmlVideo, xmlQuerySet);
00149     }
00150     else if (cmd == "processqueryset")
00151     {
00152         if (options.GetNrArg() < 2)
00153         {
00154             ILOG_ERROR("Need more parameters");
00155             return 1;
00156         }
00157         String setArg = options.GetArg(1);
00158         Core::IDash::XmlQuerySet xmlQuerySet(setArg);
00159         if (!xmlQuerySet.Valid())
00160             return 1;
00161         Core::IDash::VideoSetWrapper vidSet("idash_vds.txt");
00162         vidSet.Add(xmlQuerySet);
00163     }
00164     else if (cmd == "processannotationset")
00165     {
00166         if (options.GetNrArg() < 2)
00167         {
00168             ILOG_ERROR("Need more parameters");
00169             return 1;
00170         }
00171         String setArg = options.GetArg(1);
00172         DoProcessAnnotationSet(setArg);
00173     }
00174     else if (cmd == "client")
00175     {
00176         String idashServerAddr = options.GetArg(1);
00177         Core::IDash::Client client(idashServerAddr, passwordFile);
00178         if (!client.IsConnected())
00179             return 1;
00180 
00181         String jobFileName = options.GetArg(2);
00182 
00183         Util::IOBufferFile srcBuf(jobFileName, true, true);
00184         char* charBuf = new char[srcBuf.Size()];
00185         srcBuf.Read(charBuf, srcBuf.Size());
00186         String job(charBuf, srcBuf.Size());
00187 
00188         ILOG_INFO("Sending [" << job << "], size = " << job.size());
00189         String ref = client.ScheduleJob("http://myserver:8080/", job);
00190         ILOG_INFO("ref = [" << ref << "]");
00191         delete charBuf;
00192     }
00193     else
00194     {
00195         ILOG_ERROR("Unknown cmd : " << cmd);
00196     }
00197 
00198     //Util::IOBufferFile srcBuf(jobServerAddr, true, true);
00199     //Core::IDash::XmlJobReference job(jobServerAddr, &srcBuf);
00200     //Util::IOBufferFile dstBuf("jobref_out.xml", false, false);
00201     //job.Export(&dstBuf);
00202 
00203     return ILOG_ERROR_COUNT;
00204 }
00205 
00206 } // namespace IDash
00207 } // namespace Application
00208 } // namespace Impala
00209 
00210 int
00211 main(int argc, char* argv[])
00212 {
00213     return Impala::Application::IDash::mainIDashServer(argc, argv);
00214 }

Generated on Fri Mar 19 09:30:28 2010 for ImpalaSrc by  doxygen 1.5.1