Back to index

nordugrid-arc-nox  1.1.0~rc6
job.cpp
Go to the documentation of this file.
00001 #ifdef HAVE_CONFIG_H
00002 #include <config.h>
00003 #endif
00004 
00005 #include <arc/GUID.h>
00006 #include "job.h"
00007 
00008 namespace Arc {
00009 
00010 Job::Job(void):buffer_(0)
00011 {
00012     // NOP
00013 }
00014 
00015 Job::Job(JobRequest &r, JobSchedMetaData &m):buffer_(0)
00016 {
00017     id_ = Arc::UUID();
00018     request_ = new JobRequest(r);
00019     sched_meta_ = new JobSchedMetaData(m);
00020     status_ = JOB_STATUS_SCHED_NEW;
00021 }
00022 
00023 Job::Job(ByteArray &buffer)
00024 {
00025     size_t buf_len = 0;
00026     char *buf = buffer.data();
00027     
00028     // get id
00029     id_ = buf;
00030     buf_len = id_.size() + 1;
00031     // get status
00032     status_ = *((SchedJobStatus *)(buf + buf_len));
00033     buf_len += sizeof(SchedJobStatus);
00034     // get request class
00035     size_t bs = *((size_t *)(buf + buf_len));
00036     buf_len += sizeof(size_t);
00037     ByteArray a1(bs);
00038     a1.append(buf + buf_len, bs);
00039     buf_len += bs;
00040     request_ = new JobRequest(a1);
00041     // get sched meta class
00042     bs = *((size_t *)(buf + buf_len));
00043     buf_len += sizeof(size_t);
00044     ByteArray a2(bs);
00045     a2.append(buf + buf_len, bs);
00046     buf_len += bs;
00047     sched_meta_ = new JobSchedMetaData(a2);
00048 }
00049 
00050 ByteArray &Job::serialize(void)
00051 {
00052     buffer_.clean();
00053     buffer_.append(id_);
00054     buffer_.append(&status_, sizeof(SchedJobStatus));
00055     ByteArray &a1 = request_->serialize();
00056     buffer_.append(a1);
00057     ByteArray &a2 = sched_meta_->serialize();
00058     buffer_.append(a2);
00059     return buffer_;
00060 }
00061 
00062 Job::~Job(void) 
00063 {
00064     delete request_;
00065     delete sched_meta_;
00066 }
00067 
00068 Job::operator std::string(void) const
00069 {
00070     std::string out =   "ID: " + id_ + "\n"
00071                       + "Status: " + sched_status_to_string(status_) + "\n"
00072                       + (std::string)*request_ 
00073                       + (std::string)*sched_meta_;
00074     return out;
00075 }
00076 
00077 }