]> git.sur5r.net Git - bacula/bacula/blobdiff - bacula/src/lib/jcr.c
fix variable name
[bacula/bacula] / bacula / src / lib / jcr.c
index d599a94a149411fadb00856c4795f4ae3008103a..477fde6161b9eca5e75a1ec75a7569dcca82c757 100644 (file)
@@ -1,7 +1,7 @@
 /*
    Bacula® - The Network Backup Solution
 
-   Copyright (C) 2000-2008 Free Software Foundation Europe e.V.
+   Copyright (C) 2000-2009 Free Software Foundation Europe e.V.
 
    The main author of Bacula is Kern Sibbald, with contributions from
    many others, a complete list can be found in the file AUTHORS.
@@ -270,18 +270,6 @@ const char *JCR::get_ActionName(bool past)
    }
 }
 
-/* Set Job type in JCR and also set appropriate read flag */
-void JCR::set_JobType(int32_t JobType)
-{
-   m_JobType = JobType;
-}
-
-/* Set Job level in JCR and also set appropriate read flag */
-void JCR::set_JobLevel(int32_t JobLevel)
-{
-   m_JobLevel = JobLevel;
-}
-
 bool JCR::JobReads()
 {
    switch (m_JobType) {
@@ -367,9 +355,9 @@ JCR *new_jcr(int size, JCR_free_HANDLER *daemon_free_jcr)
    /* Setup some dummy values */
    bstrncpy(jcr->Job, "*System*", sizeof(jcr->Job));
    jcr->JobId = 0;
-   jcr->set_JobType(JT_SYSTEM);          /* internal job until defined */
-   jcr->set_JobLevel(L_NONE);
-   set_jcr_job_status(jcr, JS_Created);       /* ready to run */
+   jcr->setJobType(JT_SYSTEM);           /* internal job until defined */
+   jcr->setJobLevel(L_NONE);
+   jcr->setJobStatus(JS_Created);        /* ready to run */
    set_jcr_in_tsd(jcr);
    sigtimer.sa_flags = 0;
    sigtimer.sa_handler = timeout_handler;
@@ -653,6 +641,30 @@ JCR *get_jcr_by_id(uint32_t JobId)
    return jcr;
 }
 
+/*
+ * Given a thread id, find the JobId
+ *   Returns: JobId on success
+ *            0 on failure
+ */
+uint32_t get_jobid_from_tid(pthread_t tid)
+{
+   JCR *jcr = NULL;
+   bool found = false;
+
+   foreach_jcr(jcr) {
+      if (pthread_equal(jcr->my_thread_id, tid)) {
+         found = true;
+         break;
+      }
+   }
+   endeach_jcr(jcr);
+   if (found) {
+      return jcr->JobId;
+   }
+   return 0;
+}
+
+
 /*
  * Given a SessionId and SessionTime, find the JCR
  *   Returns: jcr on success
@@ -739,10 +751,9 @@ static int get_status_priority(int JobStatus)
    switch (JobStatus) {
    case JS_ErrorTerminated:
    case JS_FatalError:
-      priority = 10;
-      break;
    case JS_Canceled:
-      priority = 9;
+   case JS_Incomplete:
+      priority = 10;
       break;
    case JS_Error:
       priority = 8;
@@ -809,22 +820,28 @@ static void update_wait_time(JCR *jcr, int newJobStatus)
 
 void set_jcr_job_status(JCR *jcr, int JobStatus)
 {
+   jcr->setJobStatus(JobStatus);
+}
+
+void JCR::setJobStatus(int JobStatus)
+{
+   JCR *jcr = this;
    int priority, old_priority;
-   int oldJobStatus = jcr->JobStatus;
+   int oldJobStatus = JobStatus;
    priority = get_status_priority(JobStatus);
    old_priority = get_status_priority(oldJobStatus);
    
-   Dmsg2(800, "set_jcr_job_status(%s, %c)\n", jcr->Job, JobStatus);
+   Dmsg2(800, "set_jcr_job_status(%s, %c)\n", Job, JobStatus);
 
    /* Update wait_time depending on newJobStatus and oldJobStatus */
-   update_wait_time(jcr, JobStatus);
+   update_wait_time(this, JobStatus);
 
    /*
     * For a set of errors, ... keep the current status
     *   so it isn't lost. For all others, set it.
     */
-   Dmsg3(300, "jid=%u OnEntry JobStatus=%c set=%c\n", (uint32_t)jcr->JobId,
-         jcr->JobStatus, JobStatus);
+   Dmsg3(300, "jid=%u OnEntry JobStatus=%c set=%c\n", (uint32_t)JobId,
+         JobStatus, JobStatus);
    if (priority >= old_priority) {
       jcr->JobStatus = JobStatus;     /* replace with new priority */
    }
@@ -1016,6 +1033,41 @@ static void jcr_timeout_check(watchdog_t *self)
    Dmsg0(dbglvl, "Finished JCR timeout checks\n");
 }
 
+/* 
+ * Return next JobId from comma separated list   
+ *
+ * Returns:
+ *   1 if next JobId returned
+ *   0 if no more JobIds are in list
+ *  -1 there is an error
+ */
+int get_next_jobid_from_list(char **p, uint32_t *JobId)
+{
+   const int maxlen = 30;
+   char jobid[maxlen+1];
+   char *q = *p;
+
+   jobid[0] = 0;
+   for (int i=0; i<maxlen; i++) {
+      if (*q == 0) {
+         break;
+      } else if (*q == ',') {
+         q++;
+         break;
+      }
+      jobid[i] = *q++;
+      jobid[i+1] = 0;
+   }
+   if (jobid[0] == 0) {
+      return 0;
+   } else if (!is_a_number(jobid)) {
+      return -1;                      /* error */
+   }
+   *p = q;
+   *JobId = str_to_int64(jobid);
+   return 1;
+}
+
 /*
  * Timeout signal comes here
  */