]> git.sur5r.net Git - bacula/bacula/blobdiff - bacula/src/lib/jcr.c
Add jobs running to status of daemons
[bacula/bacula] / bacula / src / lib / jcr.c
index 887aa439f156771984d1e4f703898fac92b692f9..0367bf0671ee45b8d4d74f6067a81eca1eeca024 100644 (file)
@@ -1,7 +1,7 @@
 /*
    Bacula® - The Network Backup Solution
 
-   Copyright (C) 2000-2009 Free Software Foundation Europe e.V.
+   Copyright (C) 2000-2010 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.
@@ -31,8 +31,6 @@
  *
  *  Kern E. Sibbald, December 2000
  *
- *  Version $Id$
- *
  *  These routines are thread safe.
  *
  *  The job list routines were re-written in May 2005 to
@@ -523,7 +521,7 @@ void free_jcr(JCR *jcr)
    Dmsg1(dbglvl, "End job=%d\n", jcr->JobId);
 
    /* Keep some statistics */
-   switch (jcr->get_JobType()) {
+   switch (jcr->getJobType()) {
    case JT_BACKUP:
    case JT_VERIFY:
    case JT_RESTORE:
@@ -537,7 +535,7 @@ void free_jcr(JCR *jcr)
          je = (struct s_last_job *)malloc(sizeof(struct s_last_job));
          memset(je, 0, sizeof(struct s_last_job));  /* zero in case unset fields */
          je->Errors = jcr->JobErrors;
-         je->JobType = jcr->get_JobType();
+         je->JobType = jcr->getJobType();
          je->JobId = jcr->JobId;
          je->VolSessionId = jcr->VolSessionId;
          je->VolSessionTime = jcr->VolSessionTime;
@@ -545,7 +543,7 @@ void free_jcr(JCR *jcr)
          je->JobFiles = jcr->JobFiles;
          je->JobBytes = jcr->JobBytes;
          je->JobStatus = jcr->JobStatus;
-         je->JobLevel = jcr->get_JobLevel();
+         je->JobLevel = jcr->getJobLevel();
          je->start_time = jcr->start_time;
          je->end_time = time(NULL);
 
@@ -973,6 +971,24 @@ void jcr_walk_end(JCR *jcr)
    }
 }
 
+/*
+ * Return number of Jobs
+ */
+int job_count()
+{
+   JCR *jcr;
+   int count = 0;
+
+   lock_jcr_chain();
+   for (jcr = (JCR *)jcrs->first(); jcr = (JCR *)jcrs->next(jcr); ) {
+      if (jcr->JobId > 0) {
+         count++;
+      }
+   }
+   unlock_jcr_chain();
+   return count;
+}
+
 
 /*
  * Setup to call the timeout check routine every 30 seconds
@@ -1100,10 +1116,10 @@ extern "C" void timeout_handler(int sig)
 static dbg_jcr_hook_t *dbg_jcr_hooks[MAX_DBG_HOOK];
 static int dbg_jcr_handler_count;
 
-void dbg_jcr_add_hook(dbg_jcr_hook_t *fct)
+void dbg_jcr_add_hook(dbg_jcr_hook_t *hook)
 {
    ASSERT(dbg_jcr_handler_count < MAX_DBG_HOOK);
-   dbg_jcr_hooks[dbg_jcr_handler_count++] = fct;
+   dbg_jcr_hooks[dbg_jcr_handler_count++] = hook;
 }
 
 /*
@@ -1112,7 +1128,7 @@ void dbg_jcr_add_hook(dbg_jcr_hook_t *fct)
  * This function should be used ONLY after a fatal signal. We walk through the
  * JCR chain without doing any lock, Bacula should not be running.
  */
-void _dbg_print_jcr(FILE *fp)
+void dbg_print_jcr(FILE *fp)
 {
    char buf1[128], buf2[128], buf3[128], buf4[128];
    if (!jcrs) {
@@ -1122,12 +1138,11 @@ void _dbg_print_jcr(FILE *fp)
    fprintf(fp, "Attempt to dump current JCRs\n");
 
    for (JCR *jcr = (JCR *)jcrs->first(); jcr ; jcr = (JCR *)jcrs->next(jcr)) {
-
-      fprintf(fp, "JCR=%p JobId=%i name=%s JobStatus=%c\n", 
-              jcr, jcr->JobId, jcr->Job, jcr->JobStatus);
+      fprintf(fp, "JCR=%p JobId=%d name=%s JobStatus=%c\n", 
+              jcr, (int)jcr->JobId, jcr->Job, jcr->JobStatus);
       fprintf(fp, "\tuse_count=%i\n", jcr->use_count());
       fprintf(fp, "\tJobType=%c JobLevel=%c\n",
-              jcr->get_JobType(), jcr->get_JobLevel());
+              jcr->getJobType(), jcr->getJobLevel());
       bstrftime(buf1, sizeof(buf1), jcr->sched_time);
       bstrftime(buf2, sizeof(buf2), jcr->start_time);
       bstrftime(buf3, sizeof(buf3), jcr->end_time);
@@ -1141,8 +1156,8 @@ void _dbg_print_jcr(FILE *fp)
        * Call all the jcr debug hooks
        */
       for(int i=0; i < dbg_jcr_handler_count; i++) {
-         dbg_jcr_hook_t *fct = dbg_jcr_hooks[i];
-         fct(jcr, fp);
+         dbg_jcr_hook_t *hook = dbg_jcr_hooks[i];
+         hook(jcr, fp);
       }
    }
 }