Main Page   Class Hierarchy   Compound List   File List   Compound Members  

JobCollection.h

00001 #ifndef EDG_WORKLOAD_USERINTERFACE_CLIENT_JOBCOLLECTION_H
00002 #define EDG_WORKLOAD_USERINTERFACE_CLIENT_JOBCOLLECTION_H
00003 /*
00004  * JobCollection.h
00005  * Copyright (c) 2001 The European Datagrid Project - IST programme, all rights reserved.
00006  * Contributors are mentioned in the code where appropriate.
00007  *
00008  */
00009 #include "edg/workload/userinterface/client/Job.h"
00010 #include "edg/workload/logging/client/JobStatus.h"
00011 #define MAX_THREAD_NUMBER  10
00012 namespace edg{  namespace  workload{
00013        // namespace logging{   namespace client { class JobStatus ; }   }
00014        namespace  common{ namespace jobid {  class JobId ;       }   }
00015 } }
00016 USERINTERFACE_NAMESPACE_BEGIN //Defining UserInterFace NameSpace
00017 class JobCollection ;
00020 class resultStruct {
00021         typedef edg::workload::common::utilities::ResultCode ResultCode ;
00022         public:
00024                 resultStruct ( ){ set(edg::workload::common::utilities::SUCCESS) ; };
00027                 ResultCode  get () { return  result;  }
00032                 edg::workload::logging::client::JobStatus* getStatus() { return &status ; }
00035                 std::string getError (){      if (result == edg::workload::common::utilities::SUCCESS) return "" ;    else return error ;  }
00036                 std::string getMessage (){if (result == edg::workload::common::utilities::SUCCESS) return error; else return   ""   ;  }
00038                 virtual ~resultStruct () {
00039                 }
00040         private:
00042                 resultStruct (ResultCode res  ){ set(res) ; }
00044                 resultStruct (ResultCode res ,  edg::workload::logging::client::JobStatus stat ){ set(res,stat) ;}
00046                 resultStruct (ResultCode res ,  std::string err){ set(res,err); }
00048                 void set (  ResultCode res  );
00050                 void set (  ResultCode res ,  edg::workload::logging::client::JobStatus stat){ set(res);  status = stat; }
00052                 void set (  ResultCode res ,  std::string err ) {  set (res) ; error = err ; }
00053                 friend class JobCollection ;
00054                 ResultCode result ;
00055                 edg::workload::logging::client::JobStatus status ;
00056                 std::string error ;
00057 };
00058 
00059 /*
00060  * This Class is used to store all the required paramethers needed by the threads
00061 */
00062 class paramStruct {
00063         private:
00064                 int jobNumber ;
00066                 std::vector<edg::workload::userinterface::Job>::iterator job ;
00068                 std::string parA, parB ,parC ;
00069                 int parX , parY , parZ ; //integer parameter
00070                 friend class JobCollection ;
00071      };
00072 
00076 struct CollectionResult {
00077         std::vector < std::pair <std::string, resultStruct> >   result ;
00078 };
00079 
00099 class JobCollection{
00100  public:
00104         virtual ~JobCollection() {};
00106         JobCollection();
00110         JobCollection(const Job& job , unsigned int n) ;
00115         JobCollection(const std::vector<Job>& jobs);
00117    
00118    
00119 
00120 
00125         bool empty(){ return jobs.empty();  };
00127         unsigned int size(){  return jobs.size();  };
00130         void insert(const Job& job);
00135         void remove(const Job& job);
00137         void clear()   { jobs.clear(); };
00143         void setLoggerLevel ( int level ) ;
00146         void setCredPath(const std::string cp) ;
00148         void unsetCredPath();
00151         void setMaxThreadNumber (unsigned int  maxThread){ maxThreadNumber = maxThread ; };
00153 
00156         std::vector<Job>::iterator begin(){   return jobs.begin();   };
00158         std::vector<Job>::iterator end()  {   return jobs.end();     };
00160         
00161 
00170    CollectionResult submit(const std::string& ns_host , int ns_port , std::vector < std::pair < std::string , int > > lbAddrs , const std::string& ce_id = "") ;
00174    CollectionResult cancel( );
00178     CollectionResult getStatus( );
00182    CollectionResult getOutput(const std::string& dir_path);
00184 private:
00188         CollectionResult launch( const paramStruct  &params ) ;
00190         unsigned int getMaxThreadNumber (){
00191                 if (maxThreadNumber>0)   return maxThreadNumber;
00192                 else  return  MAX_THREAD_NUMBER ;
00193         };
00197         pthread_t ExecuteThread(void* (*fn)(void*), void *arg) ;
00201         resultStruct   retrieve           (pthread_t    tid ,  int jobNumber )  ;
00203         std::vector<edg::workload::userinterface::Job> jobs ;
00205         UserCredential userCred ;
00206         
00207         enum collection_operation {   SUBMIT,   STATUS ,   CANCEL ,   OUTPUT ,   LOGINFO ,   LISTMATCH };
00208         collection_operation operation ;        
00209         std::string nsHost  ;
00210         int nsPort ;
00211         std::vector< std::pair<std::string , int > > lbAddresses ;
00212         int lbPosition ;
00213         //Static Thread Job methods:
00214         static void* submitTo    (void* paramStruct);
00215         static void* cancelTo    (void* paramStruct) ;
00216         static void* statusTo      (void* paramStruct) ;
00217         static void* getOutputTo (void* paramStruct) ;
00219         std::string cred_path  ;
00220         /*This variable indicates the number of maximum simultaneous executing threads */
00221         unsigned int maxThreadNumber ;
00222         unsigned int loggerLevel ;
00223 };
00224 USERINTERFACE_NAMESPACE_END } //Closing  UserInterFace NameSpace
00225 #endif
00226 

Generated on Fri May 14 14:19:39 2004 for USERINTERFACE C++ API by doxygen1.2.14 written by Dimitri van Heesch, © 1997-2002